:root {
    --bg-primary: #f4f4f9;
    --bg-secondary: #ffffff;
    --bg-panel: #e0e0e0;
    --text-primary: #333;
    --accent: #4a90e2;
    --border: #ccc;
    --input-bg: #eaeaea;
}

[data-theme="dark"] {
    --bg-primary: #1e1e1e;
    --bg-secondary: #252526;
    --bg-panel: #333333;
    --text-primary: #f4f4f9;
    --accent: #61afef;
    --border: #444;
    --input-bg: #444;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', sans-serif; background: var(--bg-primary); color: var(--text-primary); height: 100vh; overflow: hidden; }

.app-container { display: flex; height: 100%; position: relative; }
.mobile-overlay { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 150; }

/* Sidebar */
.sidebar { width: 250px; background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; transition: width 0.3s, transform 0.3s; z-index: 200; }
.sidebar.collapsed { width: 70px; }
.sidebar.collapsed span { display: none; }

/* Reduced height for Brand */
.brand { padding: 10px 20px; font-size: 1.2rem; font-weight: bold; color: var(--accent); display: flex; align-items: center; gap: 10px; white-space: nowrap; height: 50px; }

/* Tool Nav: Compact Layout */
.tool-nav { flex: 1; padding: 5px; overflow-y: auto; }
.nav-btn { 
    width: 100%; 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    padding: 8px 12px; /* Reduced padding */
    border: none; 
    background: none; 
    color: var(--text-primary); 
    cursor: pointer; 
    border-radius: 6px; 
    text-align: left; 
    font-size: 0.9rem; /* Slightly smaller font */
    margin-bottom: 2px; /* Minimal margin */
}
.nav-btn:hover, .nav-btn.active { background: var(--bg-panel); color: var(--accent); }
.nav-btn i { font-size: 1rem; min-width: 20px; text-align: center; }

/* Main Content */
.main-content { flex: 1; display: flex; flex-direction: column; position: relative; min-width: 0; }
.top-bar { height: 50px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.top-left { display: flex; align-items: center; gap: 15px; }
.icon-btn { background: none; border: none; color: var(--text-primary); cursor: pointer; font-size: 1.1rem; padding: 8px; border-radius: 5px; }
.icon-btn:hover, .icon-btn.active { background: var(--bg-panel); color: var(--accent); }

/* Workspace & Panel */
.workspace { flex: 1; display: flex; padding: 20px; gap: 20px; overflow: hidden; position: relative; }
.panel { flex: 1; min-width: 0; background: var(--bg-secondary); border-radius: 10px; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border); position: relative; }

/* Header Actions & Dropdown Fix */
.panel-header { padding: 10px 15px; background: var(--bg-panel); font-weight: bold; font-size: 0.95rem; display: flex; justify-content: space-between; align-items: center; z-index: 10; flex-shrink: 0; }
.header-actions { display: flex; align-items: center; gap: 10px; position: relative; } 

/* Dropdown Container */
.dropdown { position: relative; display: inline-block; }

/* Dropdown Menu */
.dropdown-content {
    display: none; 
    position: absolute;
    right: 0;
    top: 100%; 
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 1000;
    min-width: 160px;
    padding: 5px 0;
    margin-top: 5px;
    flex-direction: column; 
}

.dropdown-content[style*="display: block"] {
    display: flex !important; 
}

.dl-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}
.dl-item:hover { background: var(--bg-primary); color: var(--accent); }
.dl-item small { font-size: 0.75rem; opacity: 0.6; margin-left: 10px; }

/* Canvas Area */
.canvas-container { flex: 1; overflow: hidden; background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 20px 20px; position: relative; display: flex; justify-content: center; align-items: center; padding: 10px; }
.canvas-wrapper { position: relative; box-shadow: 0 4px 6px rgba(0,0,0,0.1); display: inline-block; max-width: 100%; max-height: 100%; } 
canvas { display: block; max-width: 100%; max-height: 100%; object-fit: contain; } 

.transfer-controls { display: flex; flex-direction: column; justify-content: center; gap: 15px; flex-shrink: 0; }
.transfer-controls button { font-size: 1rem; padding: 8px; width: 36px; height: 36px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 50%; box-shadow: 0 2px 5px rgba(0,0,0,0.1); display: flex; align-items: center; justify-content: center; }

/* Options Panel */
.options-panel { height: 140px; background: var(--bg-secondary); border-top: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.options-header { padding: 8px 20px; background: var(--bg-panel); font-size: 0.9rem; font-weight: bold; }
.options-content { padding: 10px 15px; display: flex; gap: 20px; align-items: center; overflow-x: auto; height: 100%; }

/* Inputs (Rounded Style) */
.input-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 0; min-width: 70px; align-items: center; text-align: center; }
.input-group label { font-size: 0.75rem; font-weight: 600; opacity: 0.8; width: 100%; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 2px; }
.input-group.checkbox-group label { text-align: center; }
.input-row { display: flex; gap: 10px; align-items: center; }

input[type="number"], input[type="text"], select { 
    padding: 6px 10px; background: var(--input-bg); border: 1px solid transparent; 
    color: var(--text-primary); border-radius: 6px; width: 100%; height: 32px; line-height: normal; transition: background 0.2s, box-shadow 0.2s; outline: none; font-size: 0.85rem;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus { background: var(--bg-secondary); border-color: var(--accent); box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2); }
input[readonly] { cursor: pointer; text-align: center; }

input[type="checkbox"] { 
    appearance: none; -webkit-appearance: none; width: 32px; height: 32px; border: 1px solid transparent; border-radius: 6px; background: var(--input-bg); cursor: pointer; display: flex; align-items: center; justify-content: center; margin: 0;
}
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::after { content: '\f00c'; font-family: "Font Awesome 6 Free"; font-weight: 900; color: white; font-size: 1rem; }
input[type="range"] { height: 4px; margin: 0; cursor: pointer; vertical-align: middle; }

/* Mobile */
@media (max-width: 768px) {
    .workspace { flex-direction: column; overflow-y: auto; padding: 10px; gap: 15px; }
    .sidebar { position: absolute; height: 100%; transform: translateX(-100%); width: 220px; }
    .sidebar.open { transform: translateX(0); width: 220px !important; }
    .sidebar.open span { display: inline; }
    .mobile-overlay.active { display: block; }
    .transfer-controls { flex-direction: row; padding: 5px 0; }
    .transfer-controls button i { transform: rotate(90deg); }
    .panel { min-height: 300px; flex: none; width: 100%; }
    .options-panel { height: auto; min-height: auto; padding-bottom: 20px; }
    .options-content { flex-wrap: wrap; overflow-x: hidden; align-items: flex-start; gap: 15px; height: auto; justify-content: flex-start; }
    .input-row { flex-wrap: wrap; }
    .input-group { flex: 1 1 40%; min-width: 100px; }
}
