:root {
    --primary: #0B1A3E;
    --primary-dark: #060E24;
    --primary-light: #162a5a;
    --accent: #00897B;
    --accent-hover: #00796B;
    --accent-orange: #FF6F00;
    --success: #4caf50;
    --warning: #ff9800;
    --info: #00bcd4;
    --bg-dark: #f5f7f8;
    --border: #d1d5db;
    --text: #1a1a1a;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', 'Segoe UI', system-ui, sans-serif; overflow: hidden; background: var(--bg-dark); color: var(--text); }

/* Public header adjusts height — top-bar ~38px + header ~74px = ~112px */
.app-layout { display: flex; height: calc(100vh - 112px); width: 100vw; }

/* Header/Nav now provided by public-header.php + public.css */

/* --- SIDEBAR --- */
.sidebar {
    width: 400px;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    z-index: 20;
    box-shadow: 2px 0 15px rgba(0,0,0,0.05);
}

.scroll-wrapper { flex: 1; overflow-y: auto; padding: 20px; background: #f8fafc; }
.scroll-wrapper::-webkit-scrollbar { width: 6px; }
.scroll-wrapper::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.control-section { margin-bottom: 25px; }

.section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-weight: 700;
    color: #64748b;
    margin-bottom: 12px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 5px;
}

/* --- CONTAINER BUTTONS --- */
.btn-group { display: flex; flex-direction: column; gap: 8px; }

.cont-btn {
    width: 100%; display: flex; align-items: center; gap: 12px;
    padding: 14px; background: #fff; border: 2px solid var(--border);
    border-radius: 8px; cursor: pointer;
    transition: all 0.2s; text-align: left;
}
.cont-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.cont-btn.active { border-color: var(--accent); background: rgba(0,137,123,0.06); box-shadow: 0 0 0 2px rgba(0,137,123,0.15); }

.cont-icon {
    width: 40px; height: 40px; background: var(--accent-orange); color: white;
    border-radius: 8px; display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 12px;
}
.cont-icon.truck { background: var(--success); font-size: 18px; }

.cont-info strong { display: block; font-size: 14px; color: #1e293b; margin-bottom: 2px; }
.cont-info span { font-size: 12px; color: #64748b; font-family: monospace; }

/* --- SETTINGS GRID --- */
.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setting-item {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}

.setting-item label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

.setting-item input,
.setting-item select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: monospace;
}

.setting-item input:focus,
.setting-item select:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(13,115,119,0.1);
}

.setting-hint {
    display: block;
    font-size: 10px;
    color: #94a3b8;
    margin-top: 4px;
}

/* Side visibility toggles */
.setting-item.full-width {
    grid-column: 1 / -1;
}
.side-toggles {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 8px;
}
.side-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.side-toggle:hover {
    background: #f0fdfa;
    border-color: var(--accent);
}
.side-toggle input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
}

/* --- BUTTONS --- */
.btn-add {
    width: 100%; padding: 12px; border: 2px dashed #94a3b8;
    background: transparent; color: #64748b; font-weight: 700;
    border-radius: 8px; cursor: pointer; transition: 0.2s;
    margin-top: 10px;
}
.btn-add:hover { border-color: var(--accent); color: var(--accent); background: #fff; }

.action-footer { padding: 20px; border-top: 1px solid var(--border); background: #fff; }

.btn-primary {
    width: 100%; padding: 16px;
    background: var(--accent-orange);
    color: white; border: none; border-radius: 8px;
    font-weight: 700; font-size: 14px; cursor: pointer;
    box-shadow: 0 4px 15px rgba(255,111,0,0.3);
    transition: 0.2s; letter-spacing: 0.5px;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(255,111,0,0.4); background: #FF8F00; }

.btn-checkout {
    width: 100%; padding: 14px; margin-top: 10px;
    background: var(--accent);
    color: white; border: none; border-radius: 8px;
    font-weight: 700; font-size: 13px; cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,137,123,0.3);
    transition: 0.2s; letter-spacing: 0.5px;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-checkout:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,137,123,0.4); background: var(--accent-hover); }

/* --- CARGO CARD --- */
.cargo-card {
    background: #fff; 
    border: 1px solid var(--border); 
    border-radius: 8px;
    padding: 15px; 
    margin-bottom: 12px; 
    position: relative;
    border-left: 5px solid #ddd; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    transition: 0.2s;
}
.cargo-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.card-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    margin-bottom: 12px; 
    gap: 10px;
}

.input-sku {
    width: 80px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-weight: 700;
    color: #1a1a1a;
    font-size: 11px;
    padding: 8px 10px;
    font-family: monospace;
    background: #ffffff;
    text-transform: uppercase;
}
.input-sku:focus { border-color: var(--accent); outline: none; background: #fff; }

.input-name { 
    flex: 1;
    border: 1px solid var(--border); 
    border-radius: 4px;
    font-weight: 700; 
    color: #1a1a1a; 
    outline: none; 
    font-size: 14px; 
    transition: 0.2s;
    background: #ffffff;
    padding: 8px 10px;
}
.input-name:focus { border-color: var(--accent); background: #fff; }

/* Color Picker */
.color-picker-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.color-picker {
    width: 32px;
    height: 32px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    overflow: hidden;
}
.color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker::-webkit-color-swatch { border: none; border-radius: 4px; }

.btn-remove { 
    color: #ef4444; 
    background: #fee2e2; 
    border: none; 
    cursor: pointer; 
    font-size: 16px; 
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}
.btn-remove:hover { background: #ef4444; color: white; }

/* Input Grid */
.grid-inputs { 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    gap: 8px; 
    margin-bottom: 10px; 
}

.grid-inputs.extended {
    grid-template-columns: repeat(4, 1fr);
}

.supplier-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.supplier-row input {
    font-size: 12px;
}

.input-group label { 
    display: block; 
    font-size: 10px; 
    color: #64748b; 
    margin-bottom: 4px; 
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.input-group input { 
    width: 100%; 
    padding: 8px; 
    border: 1px solid var(--border); 
    border-radius: 6px; 
    font-size: 13px; 
    font-family: monospace; 
    color: #333;
    text-align: center;
}
.input-group input:focus { border-color: var(--accent); outline: none; }

/* Pallet Option */
.pallet-option { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    margin-top: 10px; 
    padding: 10px 12px; 
    background: linear-gradient(135deg, #e8f5f5 0%, #d0eded 100%);
    border-radius: 6px; 
    border: 1px solid #b2dfdb;
}
.pallet-option label {
    font-size: 12px;
    color: #00796B;
    font-weight: 600;
    cursor: pointer;
    flex: 1;
}
.pallet-option input { 
    cursor: pointer; 
    width: 18px; 
    height: 18px; 
    accent-color: var(--accent); 
}

.pallet-option.active {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    border-color: #86efac;
}
.pallet-option.active label { color: #166534; }

/* --- VIEWPORT --- */
.viewport { flex: 1; position: relative; background: #1a1a2e; }
#canvas-container { width: 100%; height: 100%; }

/* --- TOOLTIP --- */
.tooltip {
    position: absolute; 
    pointer-events: none;
    background: rgba(15, 23, 42, 0.95); 
    backdrop-filter: blur(8px);
    color: white; 
    border-radius: 10px;
    font-size: 12px; 
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    z-index: 100; 
    border: 1px solid rgba(255,255,255,0.1);
    min-width: 200px;
    overflow: hidden;
}
.tooltip.hidden { display: none; }

.tt-header {
    padding: 10px 14px;
    background: rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.tt-header strong { font-size: 13px; }

.tt-badge {
    font-size: 9px;
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--accent);
    font-weight: 700;
    text-transform: uppercase;
}

.tt-body { padding: 10px 14px; }
.tt-row { 
    margin-bottom: 6px; 
    display: flex; 
    justify-content: space-between; 
    gap: 15px; 
}
.tt-row:last-child { margin-bottom: 0; }
.tt-row span { color: rgba(255,255,255,0.6); }
.tt-row b { font-family: monospace; }

.tt-footer {
    padding: 8px 14px;
    background: var(--success);
    font-weight: 600;
    text-align: center;
    font-size: 11px;
}

/* --- OVERLAY CONTROLS --- */
.overlay-top {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(11, 26, 62, 0.88);
    backdrop-filter: blur(12px);
    padding: 5px;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.3);
    display: flex;
    gap: 4px;
    align-items: center;
    border: 1px solid rgba(255,255,255,0.08);
}

.view-divider {
    width: 1px;
    height: 24px;
    background: rgba(255,255,255,0.1);
    margin: 0 3px;
}

.view-controls { display: flex; gap: 3px; }

.view-controls button {
    border: none;
    background: transparent;
    padding: 7px 12px;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    color: rgba(255,255,255,0.55);
    font-size: 11px;
    transition: 0.2s;
    white-space: nowrap;
}
.view-controls button:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.85); }
.view-controls button.active { background: var(--accent); color: white; }

/* --- STATS BAR --- */
.stats-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(11, 26, 62, 0.92);
    backdrop-filter: blur(12px);
    padding: 10px 16px;
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid rgba(255,255,255,0.08);
}

.stat-box {
    display: flex;
    flex-direction: column;
    min-width: 72px;
    text-align: center;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    position: relative;
}
.stat-box:hover { background: rgba(255,255,255,0.08); }
.stat-label {
    font-size: 8px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.45);
    font-weight: 700;
    letter-spacing: 0.8px;
    margin-bottom: 3px;
}
.stat-value {
    font-size: 17px;
    font-weight: 800;
    color: #fff;
    font-family: 'Inter', monospace;
}
/* Utilization bar under volume/weight stats */
.stat-bar {
    height: 3px;
    border-radius: 2px;
    background: rgba(255,255,255,0.1);
    margin-top: 4px;
    overflow: hidden;
}
.stat-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease, background 0.3s;
    background: var(--accent);
}
.stat-bar-fill.high { background: #ff9800; }
.stat-bar-fill.critical { background: #f44336; }
/* Weight distribution mini-chart */
.weight-dist {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
}
.weight-dist-label {
    font-size: 7px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.35);
    font-weight: 700;
    letter-spacing: 0.5px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
}
.weight-dist-bars {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.weight-dist-row {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 8px;
    font-weight: 700;
    color: rgba(255,255,255,0.5);
}
.weight-dist-row span { min-width: 14px; text-align: center; }
.wd-bar {
    width: 56px;
    height: 6px;
    border-radius: 3px;
    background: rgba(255,255,255,0.08);
    overflow: hidden;
    display: flex;
}
.wd-fill-left {
    height: 100%;
    background: #42a5f5;
    transition: width 0.5s ease;
}
.wd-fill-right {
    height: 100%;
    background: #ef5350;
    transition: width 0.5s ease;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 12px;
    margin-left: 4px;
    border-left: 1px solid rgba(255,255,255,0.1);
}

.divider { display: none; }

.nav-btn {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.06);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: 0.2s;
    color: rgba(255,255,255,0.6);
}
.nav-btn:hover {
    border-color: var(--accent);
    color: #fff;
    background: rgba(0,137,123,0.3);
}
.nav-text { color: rgba(255,255,255,0.8); font-size: 11px; font-weight: 700; }

/* --- DOOR INDICATOR --- */
.door-indicator {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(11, 26, 62, 0.85);
    backdrop-filter: blur(8px);
    color: rgba(255,255,255,0.8);
    padding: 14px 10px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 10px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.08);
}

/* --- DIMENSION LEGEND --- */
.dimension-legend {
    position: absolute;
    top: 80px;
    right: 16px;
    background: rgba(11, 26, 62, 0.85);
    backdrop-filter: blur(8px);
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    font-size: 11px;
    min-width: 160px;
}

.legend-title {
    font-weight: 700;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: rgba(255,255,255,0.5);
    margin-bottom: 6px;
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    color: rgba(255,255,255,0.7);
    font-size: 11px;
}

.legend-color {
    width: 16px;
    height: 10px;
    border-radius: 2px;
}

.legend-note {
    font-size: 9px;
    color: #94a3b8;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid #e2e8f0;
    font-style: italic;
}

/* --- CTU BADGE --- */
.ctu-pass {
    color: #4caf50 !important;
    background: rgba(76,175,80,0.15) !important;
    padding: 2px 8px !important;
    border-radius: 6px !important;
    font-size: 13px !important;
}
.ctu-warning {
    color: #ff9800 !important;
    background: rgba(255,152,0,0.15) !important;
    padding: 2px 8px !important;
    border-radius: 6px !important;
    font-size: 13px !important;
    animation: ctu-pulse 2s ease-in-out infinite;
}
.ctu-fail {
    color: #f44336 !important;
    background: rgba(244,67,54,0.15) !important;
    padding: 2px 8px !important;
    border-radius: 6px !important;
    font-size: 13px !important;
    animation: ctu-pulse 1.5s ease-in-out infinite;
}
@keyframes ctu-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* --- CTU MODAL --- */
.ctu-modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); z-index: 99999;
    display: flex; align-items: center; justify-content: center;
}
.ctu-modal-content {
    background: #fff; border-radius: 12px; max-width: 520px; width: 90%;
    max-height: 85vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.ctu-modal-header {
    padding: 18px 24px; color: white; display: flex;
    justify-content: space-between; align-items: center;
    border-radius: 12px 12px 0 0;
}
.ctu-modal-header h3 { margin: 0; font-size: 16px; }
.ctu-status-badge {
    font-size: 11px; font-weight: 800; padding: 4px 12px;
    border-radius: 20px; background: rgba(255,255,255,0.25);
}
.ctu-modal-body { padding: 20px 24px; }
.ctu-section { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid #eee; }
.ctu-section:last-child { border-bottom: none; }
.ctu-section h4 { font-size: 13px; color: #333; margin: 0 0 10px; }
.ctu-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 13px; }
.ctu-row span { color: #666; }
.ctu-row b { font-family: monospace; color: #1a1a1a; }
.ctu-row small { color: #999; font-size: 11px; }
.ctu-bar-container { display: flex; height: 24px; border-radius: 4px; overflow: hidden; margin-top: 8px; }
.ctu-bar { display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: white; }
.ctu-bar-left { background: #42a5f5; }
.ctu-bar-right { background: #ef5350; }
.ctu-violations { }
.ctu-violation-item { padding: 6px 10px; background: #fff3e0; border-radius: 6px; margin-bottom: 6px; font-size: 12px; color: #e65100; }
.ctu-modal-footer { padding: 16px 24px; border-top: 1px solid #eee; text-align: right; }
.ctu-modal-footer button {
    padding: 10px 24px; border: none; border-radius: 6px;
    background: var(--primary); color: white; font-weight: 600; cursor: pointer;
}

/* --- ADVANCED CARGO ROW --- */
.advanced-cargo-row {
    display: flex; gap: 12px; align-items: center;
    margin-top: 8px; padding: 8px 10px;
    background: #f0f4f8; border-radius: 6px; border: 1px solid #e2e8f0;
}
.adv-option { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.adv-option label { font-size: 11px; color: #475569; font-weight: 600; cursor: pointer; white-space: nowrap; }
.adv-option input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.stack-input {
    width: 70px; padding: 4px 6px; border: 1px solid #d1d5db;
    border-radius: 4px; font-size: 11px; font-family: monospace; text-align: center;
}

/* --- ALGORITHM SELECTOR --- */
.algorithm-row { display: flex; gap: 8px; margin-bottom: 8px; }
.algo-select {
    padding: 10px 12px; border: 2px solid var(--border); border-radius: 8px;
    font-size: 12px; font-weight: 600; background: #fff; cursor: pointer;
    min-width: 160px;
}
.algo-select:focus { border-color: var(--accent); outline: none; }

/* --- EXPORT BUTTONS --- */
.export-row { display: flex; gap: 6px; margin-bottom: 8px; }
.btn-export {
    flex: 1; padding: 10px; border: 2px solid var(--border);
    border-radius: 8px; background: #f8fafc; color: #374151;
    font-weight: 700; font-size: 12px; cursor: pointer; transition: 0.2s;
    text-align: center;
}
.btn-export:hover { border-color: var(--accent); background: #e8f5f5; color: var(--primary); }

/* --- AUTO-SELECT BUTTON --- */
.btn-auto-select {
    width: 100%; padding: 10px; margin-top: 8px;
    border: 2px dashed var(--accent); border-radius: 8px;
    background: transparent; color: var(--accent);
    font-weight: 700; font-size: 11px; cursor: pointer; transition: 0.2s;
}
.btn-auto-select:hover { background: rgba(0,137,123,0.06); border-style: solid; }

/* --- RESPONSIVE --- */
@media (max-width: 1200px) {
    .sidebar { width: 360px; }
    .overlay-top { flex-wrap: wrap; justify-content: center; }
}
