:root {
    --bg-app: #2a2a2a;
    --bg-sidebar: #353535;
    --bg-card: #3d3d3e;
    --bg-input: #525252;
    --border: #4a4a4a;
    --text-main: #ffffff;
    --text-muted: #c0c0c0;
    --accent: #3395ff;
    --accent-hover: #57a9ff;
    --success: #2da144;
    --warning: #664d00;
    --warning-text: #ffe082;
    --error: #ff5757;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    margin: 0;
    background: var(--bg-app);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
        height: auto;
        overflow: auto;
    }

    .sidebar {
        width: 100% !important;
        height: auto !important;
        flex-direction: row !important;
        padding: 5px 0 !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border);
        overflow-x: auto;
    }

    .logo {
        display: none;
    }

    .nav-item {
        padding: 10px 15px !important;
        font-size: 12px !important;
        border-left: none !important;
        border-bottom: 3px solid transparent;
        white-space: nowrap;
    }

    .nav-item.active {
        border-bottom-color: var(--accent) !important;
    }

    .top-bar {
        flex-direction: column;
        height: auto !important;
        padding: 10px !important;
        gap: 10px;
    }

    #top-actions {
        width: 100%;
        justify-content: center;
    }

    button {
        flex: 1;
        padding: 8px 5px !important;
        font-size: 10px !important;
    }
}

.sidebar {
    width: 200px;
    /* Reduced from 220px */
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 10px 0;
    /* Reduced from 20px */
    flex-shrink: 0;
}

.logo {
    font-weight: 800;
    font-size: 16px;
    /* Reduced from 18px */
    padding: 0 16px 20px;
    /* Reduced padding */
    color: #fff;
    letter-spacing: 1px;
}

.nav-group {
    margin-bottom: 10px;
}

.nav-header {
    font-size: 10px;
    /* Reduced from 11px */
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    padding: 6px 16px 4px;
    /* Compact padding */
    opacity: 0.7;
    letter-spacing: 0.5px;
}

.nav-item {
    padding: 8px 16px;
    /* Reduced from 10px 20px */
    color: var(--text-muted);
    font-size: 13px;
    /* Reduced from 14px */
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: 0.2s;
}

.nav-group .nav-item {
    padding-left: 24px;
    /* Reduced indentation */
    font-size: 12px;
    /* Reduced from 13px */
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    background: #4d4d4d;
    color: #fff;
    border-left-color: var(--accent);
}

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.top-bar {
    height: 48px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    background: #353535;
    position: sticky;
    /* Make sticky */
    top: 0;
    /* Stick to top */
    z-index: 50;
    /* Ensure it stays above scrolled content */
}

.container {
    padding: 16px;
    /* Reduced from 24px */
    display: grid;
    gap: 12px;
    /* Reduced from 20px */
    align-items: start;
}

#view-imposition.container {
    grid-template-columns: 300px 280px 1fr;
}

@media(max-width:1400px) {
    #view-imposition.container {
        grid-template-columns: 340px 1fr;
        /* Adjusted for smaller screens */
    }

    #tyrageCard {
        grid-column: 1;
    }
}

@media(max-width:1024px) {
    #view-imposition.container {
        grid-template-columns: 1fr;
    }

    #tyrageCard {
        grid-column: auto;
    }
}

#view-brochure.container {
    grid-template-columns: 300px 1fr;
}

.results-grid {
    display: grid;
    grid-template-columns: 260px 1fr;
    /* Reduced width */
    gap: 12px;
    /* Reduced gap */
}

@media (max-width: 1200px) {
    #view-brochure.container {
        grid-template-columns: 1fr;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    /* Reduced from 16px */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

h1 {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 0 6px 0;
    /* Reduced margin */
    letter-spacing: 0.5px;
}

label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 2px;
    margin-top: 4px;
    /* Reduced margin */
}

/* ... */

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 12px;
    /* Reduced padding */
    text-align: center;
    cursor: pointer;
    transition: 0.2s;
    margin-bottom: 8px;
    /* Reduced margin */
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--accent);
    background: rgba(51, 149, 255, 0.05);
}

.upload-zone i {
    font-size: 24px;
    /* Reduced icon size */
    display: block;
    margin-bottom: 4px;
    /* Reduced margin */
}



input,
select {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: #fff;
    padding: 6px 8px;
    /* Compact padding */
    border-radius: 4px;
    font-size: 12px;
    /* Reduced from 13px */
    box-sizing: border-box;
    outline: none;
    height: 28px;
    /* Fixed compact height */
}

.row {
    display: flex;
    gap: 6px;
    /* Reduced gap */
}

.col {
    flex: 1;
}

button {
    padding: 8px 12px;
    /* Compact padding */
    font-size: 10px;
    /* Reduced size */
    font-weight: 700;
    text-transform: uppercase;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: #5a5a5a;
    color: #fff;
    transition: 0.2s;
    height: 28px;
    /* Match input height */
    white-space: nowrap;
    /* Prevent wrap */
}

button.primary {
    background: var(--accent);
}

button.primary:hover {
    background: var(--accent-hover);
}

.sm-btn {
    padding: 6px 10px !important;
    font-size: 14px !important;
    min-width: 32px;
    background: #444;
}

.sm-btn:hover {
    background: #666;
}

.result {
    background: rgba(255, 255, 255, 0.05);
    padding: 12px;
    border-radius: 4px;
    margin-top: 10px;
}

.result h3 {
    font-size: 13px;
    margin: 0 0 8px 0;
    color: var(--accent);
}

.result-body {
    font-size: 10px;
    /* Reduced to 10px */
    line-height: 1.4;
}

.result-optimization {
    background: rgba(255, 255, 255, 0.04);
    padding: 7px 10px;
    border-radius: 4px;
    font-size: 11px;
    margin-top: 8px;
    border-left: 3px solid currentColor;
    line-height: 1.4;
}

.result-optimization-hint {
    background: #333;
    border-left: 3px solid #ffcc00;
    padding: 8px;
    margin-top: 8px;
    font-size: 11px;
    color: #ffd700;
    border-radius: 2px;
    line-height: 1.7;
}

.result-full-fill {
    background: #1a2e1a;
    border-left: 3px solid #4caf50;
    padding: 8px;
    margin-top: 8px;
    font-size: 11px;
    font-weight: 600;
    color: #81c784;
    border-radius: 2px;
}

.result-cut-info {
    font-size: 11px;
    color: #ff6b6b;
    font-weight: 600;
    margin-top: 8px;
    padding: 7px 10px;
    background: rgba(255, 107, 107, 0.08);
    border-left: 3px solid #ff6b6b;
    border-radius: 4px;
    line-height: 1.5;
}

.result-error {
    font-size: 11px;
    color: #ff4444;
    font-weight: 400;
    margin-top: 6px;
    padding: 8px 12px;
    background: rgba(255, 68, 68, 0.1);
    border-left: 3px solid #ff4444;
    border-radius: 4px;
    line-height: 1.5;
}

.res-main {
    font-size: 12px;
    /* Increased to 12px */
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.3;
}

.res-sub {
    font-size: 12px;
    /* Increased to 12px */
    font-weight: 600;
    /* Bold as requested */
    color: var(--text-main);
    /* Promoted to main color */
    margin-bottom: 2px;
    line-height: 1.3;
}

.res-opt {
    font-size: 12px;
    /* Increased to 12px */
    margin-top: 6px;
    line-height: 1.3;
}

.tech-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-bottom: 10px;
}

.tech-item {
    display: grid;
    grid-template-columns: 1fr 100px;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
}

.tech-label {
    padding: 6px 10px;
    color: var(--text-muted);
    font-size: 11px;
}

.tech-value {
    padding: 6px 8px;
    background: var(--bg-input);
    color: #fff;
    font-weight: 600;
    text-align: center;
    font-size: 12px;
    border-left: 1px solid var(--border);
}

.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 5px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    min-height: 32px;
}

.tag-item {
    background: #444;
    border: 1px solid #555;
    color: #ccc;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tag-remove {
    cursor: pointer;
    font-weight: bold;
    opacity: 0.7;
}

.tag-remove:hover {
    opacity: 1;
}

.text-error {
    color: var(--error) !important;
    font-weight: 800;
}

/* Updated Preview Logic for Stability */
.canvas-container {
    position: relative;
    width: 100%;
    /* Usage: High Density Layout + Pop-out Preview */
    max-width: 1200px;
    margin: 0 auto;
    max-height: 85vh;
    /* Layout constraint */
    overflow: visible;
    /* Allow preview to bleed out when zoomed */
    z-index: 100;
    /* Cover other elements */
    border: 1px solid var(--border);
    border-radius: 4px;
}

.canvas-header {
    background: #3d3d3e;
    border-radius: 4px 4px 0 0;
    padding: 6px 12px;
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 101;
    /* Above canvas */
}

canvas {
    max-width: 100%;
    max-height: 100%;
    /* Fit container initially */
    width: auto;
    height: auto;
    background: #fff;
    border-radius: 0 0 4px 4px;
    display: block;
    margin: 0 auto;
    position: relative;
    /* Promote to stacking context */
    z-index: 105;
    /* Above header (101) */
}

.footer-text,
.preview-info {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 10px;
    text-align: center;
}

.hidden {
    display: none;
}

.section-title {
    font-weight: bold;
    color: var(--accent);
    margin-top: 15px;
    margin-bottom: 8px;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
}

.section-title::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.sub-header {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin: 12px 0 6px 0;
    font-weight: 700;
    opacity: 0.8;
}

/* MODERN TOGGLE SWITCHES */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

/* The switch - the box around the slider */
.switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
    flex-shrink: 0;
}

/* Hide default HTML checkbox */
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

/* The slider */
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #525252;
    /* Grey OFF state */
    transition: .3s;
    border-radius: 18px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent);
    /* Blue ON state */
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--accent);
}

input:checked+.slider:before {
    transform: translateX(16px);
}

.checkbox-row span {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: normal;
    text-transform: none;
    cursor: pointer;
}

.checkbox-row span.muted {
    color: #ccc;
}

/* TOASTS & LOADERS */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: #333;
    color: #fff;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    min-width: 250px;
    transition: 0.3s;
    border-left: 4px solid var(--accent);
}

.toast-success {
    border-left-color: var(--success);
}

.toast-error {
    border-left-color: var(--error);
}

.toast-warning {
    border-left-color: #ffd700;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: 0.3s;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Dashboard Compact Styles */
.dash-card {
    width: 450px;
    text-align: center;
    padding: 20px;
    /* Reduced from 30px */
}

.dash-title {
    font-size: 18px;
    /* Reduced from 24px */
    margin-bottom: 6px;
    position: relative;
    text-transform: uppercase;
    color: var(--text-main);
}

.dash-desc {
    color: var(--text-muted);
    margin-bottom: 20px;
    /* Reduced from 30px */
    font-size: 12px;
}

.dash-upload {
    height: 90px;
    /* Reduced from 120px */
    border: 2px dashed var(--accent);
    background: rgba(59, 130, 246, 0.05);
    display: flex;
    /* Center content */
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.dash-upload i {
    font-size: 24px !important;
    /* Reduced from 36px */
    margin-bottom: 4px !important;
}

.dash-upload span {
    font-size: 13px !important;
    /* Reduced from 15px */
    margin-top: 4px !important;
}

.dash-results-box {
    margin-top: 20px;
    text-align: left;
    background: #2a2a2a;
    padding: 15px;
    /* Reduced from 20px */
    border-radius: 8px;
}

/* Wider columns for dashboard results */
.dash-results-box .tech-item {
    grid-template-columns: 70px 1fr;
}

.dash-results-box .tech-value {
    text-align: left;
    /* Align text left */
    padding-left: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Handle long names */
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}



/* Preflight Results */
.preflight-results {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-top: 15px;
    animation: fadeIn 0.3s ease;
}

.preflight-results h3 {
    margin: 0 0 12px 0;
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preflight-results h3::before {
    content: "🔍";
    font-size: 14px;
}

.preflight-content-wrapper {
    font-size: 12px;
}

.preflight-item {
    margin-bottom: 8px;
}

.preflight-warning-list {
    margin: 8px 0 0 0;
    padding-left: 18px;
    color: var(--text-muted);
    line-height: 1.5;
}

.preflight-warning-list li {
    margin-bottom: 4px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tech-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-bottom: 10px;
}

.tech-item {
    display: grid;
    grid-template-columns: 1fr 100px;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
}

.tech-label {
    padding: 6px 10px;
    color: var(--text-muted);
    font-size: 11px;
}

.tech-value {
    padding: 6px 8px;
    background: var(--bg-input);
    color: #fff;
    font-weight: 600;
    text-align: center;
    font-size: 12px;
    border-left: 1px solid var(--border);
}

/* Fold Panels Grid */
.fold-panels-grid {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
    overflow-x: auto;
}

.panel-input-wrapper {
    position: relative;
    flex: 1;
    min-width: 0;
}

.panel-input {
    width: 100%;
    text-align: center;
    padding-bottom: 14px;
    /* Space for index */
    font-weight: bold;
    color: var(--accent);
}

.panel-idx {
    position: absolute;
    bottom: 2px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 9px;
    color: #666;
    pointer-events: none;
}

/* ==========================================================================
   IMPOSITION TABS CSS
   ========================================================================== */
.imp-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    padding: 3px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.imp-tab {
    padding: 8px 4px;
    cursor: pointer;
    border-radius: 6px;
    color: #aaa;
    font-weight: 700;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    flex: 1;
    text-align: center;
    font-size: 10px;
    letter-spacing: 0.5px;
    border: 1px solid transparent;
}

.imp-tab:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

.imp-tab.active {
    color: var(--accent);
    background: #525252;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.imp-tab-content {
    display: none;
    animation: fadeIn 0.2s ease-in-out;
}

.imp-tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* PREVIEW CONTROLS & STALE STATES */
.preview-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
}

.preview-controls .switch-label {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
    margin: 0;
}

.btn-render-manual {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: all;
    opacity: 0.85;
}

.btn-render-manual.stale {
    background: #e67e22; /* Warning Orange */
    color: #fff;
    border-color: #d35400;
    pointer-events: all;
    opacity: 1;
    box-shadow: 0 0 10px rgba(230, 126, 34, 0.4);
    animation: pulse-orange 2s infinite;
}

.btn-render-manual:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-render-manual i {
    font-size: 12px;
}

.canvas-container.stale canvas {
    opacity: 0.4;
    filter: blur(1px) grayscale(0.2);
    transition: all 0.3s ease;
}

.stale-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    pointer-events: none;
    display: none;
    z-index: 110;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.canvas-container.stale .stale-overlay {
    display: block;
}

@keyframes pulse-orange {
    0% {
        box-shadow: 0 0 0 0 rgba(230, 126, 34, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(230, 126, 34, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(230, 126, 34, 0);
    }
}
