:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --border-color: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent-blue: #38bdf8;
    --accent-blue-hover: #0284c7;
    --accent-green: #22c55e;
    --accent-amber: #f59e0b;
    --accent-purple: #a855f7;
    --radius-md: 10px;
    --radius-sm: 6px;
    --shadow-main: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
}

.header-container {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-icon {
    font-size: 28px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.3);
}

.header-brand h1 {
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
}

.header-brand p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.header-badges {
    display: flex;
    gap: 8px;
}

.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success { background: rgba(34, 197, 94, 0.15); color: var(--accent-green); border: 1px solid rgba(34, 197, 94, 0.3); }
.badge-info { background: rgba(56, 189, 248, 0.15); color: var(--accent-blue); border: 1px solid rgba(56, 189, 248, 0.3); }

/* Main Layout Grid */
.main-container {
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    padding: 24px;
    display: grid;
    grid-template-columns: 480px 1fr;
    gap: 24px;
    flex: 1;
}

@media (max-width: 1100px) {
    .main-container {
        grid-template-columns: 1fr;
    }
}

/* Sidebar Panels */
.sidebar-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-main);
    overflow: hidden;
}

.card-header {
    padding: 14px 18px;
    background: rgba(15, 23, 42, 0.4);
    border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: #e2e8f0;
}

.card-body {
    padding: 18px;
}

/* Tab Mode Switcher in Card 2 */
.tab-mode-switcher {
    display: flex;
    gap: 4px;
    background: #0f172a;
    padding: 3px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.tab-mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-mode-btn:hover {
    color: #ffffff;
}

.tab-mode-btn.active {
    background: var(--accent-blue);
    color: #0f172a;
    box-shadow: 0 2px 6px rgba(56, 189, 248, 0.3);
}

/* TEST Mode Elements */
.test-mode-banner {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.test-mode-banner strong {
    font-size: 12px;
    color: var(--accent-amber);
}

.test-mode-banner span {
    font-size: 11px;
    color: #cbd5e1;
    line-height: 1.35;
}

.slot-quick-actions {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.btn-slot-action {
    flex: 1;
    background: #0f172a;
    border: 1px solid var(--border-color);
    color: #cbd5e1;
    padding: 6px 8px;
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-slot-action:hover {
    border-color: var(--accent-blue);
    color: #ffffff;
}

.slots-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
}

.slot-card {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s;
}

.slot-card.slot-active {
    border-color: var(--accent-green);
    background: rgba(34, 197, 94, 0.08);
}

.slot-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.slot-title {
    font-size: 12px;
    font-weight: 600;
    color: #ffffff;
}

.slot-sub {
    font-size: 10px;
    color: var(--text-muted);
}

/* Upload Dropzone */
.upload-dropzone {
    border: 2px dashed var(--accent-blue);
    background: rgba(56, 189, 248, 0.05);
    border-radius: var(--radius-md);
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

.upload-dropzone:hover {
    background: rgba(56, 189, 248, 0.12);
    border-color: #7dd3fc;
}

.file-input {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0;
    cursor: pointer;
}

.dropzone-icon {
    font-size: 36px;
    margin-bottom: 8px;
}

.dropzone-text strong {
    display: block;
    font-size: 14px;
    color: #ffffff;
    margin-bottom: 4px;
}

.dropzone-text span {
    font-size: 12px;
    color: var(--text-muted);
}

/* PCB Items List */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: 420px;
    overflow-y: auto;
}

.item-card {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: grid;
    grid-template-columns: 75px 1fr;
    gap: 12px;
    position: relative;
}

.item-thumb {
    width: 75px;
    height: 75px;
    object-fit: contain;
    background: #000;
    border-radius: 4px;
    border: 1px solid #475569;
}

.item-details {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.item-title {
    font-size: 13px;
    font-weight: 600;
    color: #f1f5f9;
    word-break: break-all;
}

.item-dim-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.item-dim-inputs label {
    display: flex;
    align-items: center;
    gap: 2px;
}

.input-num-sm {
    width: 60px;
    background: #0f172a;
    border: 1px solid var(--border-color);
    color: #fff;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
}

.item-controls-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 4px;
}

/* Settings Form */
.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.col-half { flex: 1; }

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #cbd5e1;
    margin-bottom: 6px;
}

.select-dark {
    width: 100%;
    background: #0f172a;
    border: 1px solid var(--border-color);
    color: #ffffff;
    padding: 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    outline: none;
}

.form-range {
    width: 100%;
    accent-color: var(--accent-blue);
    cursor: pointer;
}

.val-badge {
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent-blue);
    background: rgba(56, 189, 248, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #cbd5e1;
    cursor: pointer;
}

.input-with-suffix {
    display: flex;
    align-items: center;
    background: #0f172a;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.form-control {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 12px;
    color: #ffffff;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    outline: none;
}

.suffix {
    padding: 0 10px;
    font-size: 11px;
    color: var(--text-muted);
}

.format-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.format-card {
    border: 1px solid var(--border-color);
    background: #0f172a;
    border-radius: var(--radius-sm);
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.format-card:hover, .format-card.active {
    border-color: var(--accent-blue);
    background: rgba(56, 189, 248, 0.1);
}

.format-card input {
    display: none;
}

.format-title {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #ffffff;
}

.format-desc {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
}

.btn {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-blue), #0284c7);
    color: #ffffff;
}

.btn-primary:hover {
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
    transform: translateY(-1px);
}

.btn-block { width: 100%; }

/* Preview Panel & A4 Sheet Canvas */
.preview-panel {
    display: flex;
    flex-direction: column;
}

.full-height { height: 100%; min-height: 700px; display: flex; flex-direction: column; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

.page-stats {
    display: flex;
    gap: 8px;
}

.stat-tag {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
}

.tag-blue { background: rgba(56, 189, 248, 0.2); color: var(--accent-blue); }

.canvas-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #090d16;
    padding: 24px;
    overflow: auto;
}

.preview-empty {
    text-align: center;
    color: var(--text-muted);
    max-width: 360px;
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.preview-empty h3 { font-size: 16px; color: #ffffff; margin-bottom: 6px; }
.preview-empty p { font-size: 13px; line-height: 1.4; }

/* Real Scale A4 Paper Visualizer (Aspect Ratio 210 : 297 = 1 : 1.414) */
.a4-paper-sheet {
    background: #ffffff;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    position: relative;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    margin: auto;
    transition: width 0.15s ease-out, height 0.15s ease-out, padding 0.15s ease-out;
}

.a4-margin-box {
    width: 100%;
    height: 100%;
    border: 1px dashed #cbd5e1;
    overflow: hidden;
    position: relative;
}

.a4-grid-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    align-content: flex-start;
}

.a4-grid-row {
    display: flex;
    align-items: center;
    width: 100%;
}

.a4-pcb-item {
    border: 1px solid #000;
    background: #000;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.a4-pcb-item.slot-hidden {
    border: 1.5px dashed #cbd5e1 !important;
    background: transparent !important;
    box-shadow: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 9px;
    font-family: 'JetBrains Mono', monospace;
    text-align: center;
    padding: 2px;
}

.a4-pcb-item img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
}

/* Ultra Bold & Dark Cut Guidelines */
.a4-cut-divider-vert {
    border-left: 2.5px dashed #0f172a;
    height: 95%;
    align-self: center;
    flex-shrink: 0;
}

.a4-cut-divider-horiz {
    width: 100%;
    border-top: 2.5px dashed #0f172a;
    margin: 0;
}

.a4-watermark {
    position: absolute;
    bottom: 8px;
    right: 12px;
    font-size: 10px;
    font-family: 'JetBrains Mono', monospace;
    color: #94a3b8;
    pointer-events: none;
}

.hidden { display: none !important; }
