/* ─── Variables ────────────────────────────────────────────────────── */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #1e2130;
    --bg-hover: #252838;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-muted: #6b7280;
    --border: #2d3140;
    --accent: #4a9eff;
    --accent-hover: #3d8ce6;

    /* Urgency colors */
    --urgency-critical: #ef4444;
    --urgency-critical-bg: rgba(239, 68, 68, 0.15);
    --urgency-stock-morning: #fb923c;
    --urgency-stock-midday: #f97316;
    --urgency-stock-afternoon: #ea580c;
    --urgency-stock-unknown: #c2410c;
    --urgency-stock-bg: rgba(249, 115, 22, 0.12);
    --urgency-time: #eab308;
    --urgency-time-bg: rgba(234, 179, 8, 0.12);
    --urgency-rush: #3b82f6;
    --urgency-rush-bg: rgba(59, 130, 246, 0.10);

    /* Refresh indicator */
    --refresh-fresh: #22c55e;
    --refresh-stale: #eab308;
    --refresh-dead: #ef4444;

    --header-height: 52px;
    --filter-height: auto;
    --panel-width: 420px;
}

/* ─── Reset & Base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.4;
    overflow-x: hidden;
}

/* ─── Header ──────────────────────────────────────────────────────── */
/* base.html's <main> had no rule at all, so content sat flush against the
   window edge on any page whose own containers didn't pad themselves. The
   horizontal gutter lives here now; .filter-bar/.kpi-row/.table-container
   below keep only their vertical padding so those pages don't double up. */
.main-content {
    padding: 0 16px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--header-height);
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 24px; }
.header-right { display: flex; align-items: center; gap: 16px; }
.current-user { color: var(--text-muted); font-size: 13px; }
.logout-link { color: var(--text-muted); font-size: 12px; text-decoration: none; opacity: 0.7; }
.logout-link:hover { opacity: 1; text-decoration: underline; }
.tracking-link { color: #fbbf24; text-decoration: underline; font-weight: 500; }
.tracking-link:hover { color: #fde68a; }
.note-author-display { color: var(--text-primary); font-size: 13px; font-weight: 500; }

.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    opacity: 0.9;
    flex-shrink: 0;
}
.logo:hover { opacity: 1; }

.nav-tabs { display: flex; align-items: center; gap: 4px; }
.nav-section { display: flex; align-items: center; gap: 4px; }
.nav-section-label {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-primary);
    letter-spacing: 0.5px;
    padding-right: 2px;
    white-space: nowrap;
}
.nav-tab {
    padding: 6px 14px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}
.nav-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.nav-tab.active { color: var(--text-primary); background: var(--accent); }
.nav-separator { width: 1px; height: 20px; background: var(--border); margin: 0 8px; }
.nav-philly .nav-section-label { color: #6366f1; }
.nav-mach6  .nav-section-label { color: #14b8a6; }
.nav-analytics .nav-section-label { color: var(--text-muted); }
.nav-philly .nav-tab.active { background: #6366f1; color: #fff; }
.nav-mach6  .nav-tab.active { background: #14b8a6; color: #fff; }

/* Mode toggle (Live | Sweeper) — sweeper is a mode of each dashboard */
.mode-bar {
    display: flex; align-items: center;
    padding: 8px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}
.mode-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.mode-seg {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 14px;
    font-size: 12px; font-weight: 500;
    color: var(--text-secondary); text-decoration: none;
}
.mode-seg + .mode-seg { border-left: 1px solid var(--border); }
.mode-seg:hover { background: var(--bg-hover); color: var(--text-primary); }
.mode-seg.active { background: var(--accent); color: #fff; }
.mode-warn { color: #f59e0b; }
.mode-seg-sweeper.active { background: #f59e0b; color: #1a1d27; }
.mode-seg-sweeper.active .mode-warn { color: #1a1d27; }

/* Refresh indicator */
.refresh-indicator { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.refresh-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--refresh-fresh);
    transition: background 0.3s;
}
.refresh-dot.stale { background: var(--refresh-stale); }
.refresh-dot.dead { background: var(--refresh-dead); }

/* ─── Filter Bar ──────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 10px 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.filter-toggles { display: flex; gap: 3px; flex-wrap: wrap; }
.filter-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.filter-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.filter-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.filter-select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    min-width: 150px;
}
.filter-select[multiple] {
    height: 80px;
    padding: 2px 4px;
    overflow-y: auto;
}
.filter-select:focus { outline: none; border-color: var(--accent); }

.filter-clear-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
}
.filter-clear-btn:hover { border-color: var(--urgency-critical); color: var(--urgency-critical); }

/* ─── KPI Cards ───────────────────────────────────────────────────── */
.kpi-row {
    display: flex;
    gap: 8px;
    padding: 12px 0;
    overflow-x: auto;
}

.kpi-card {
    flex: 1;
    min-width: 100px;
    padding: 12px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-align: center;
}

.kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}

.kpi-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-top: 4px;
    letter-spacing: 0.3px;
}

.kpi-card.kpi-filterable {
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.kpi-card.kpi-filterable:hover {
    border-color: var(--accent);
}
.kpi-card.kpi-filterable.active {
    border-color: var(--accent);
    background: rgba(74, 158, 255, 0.12);
}
.kpi-card.kpi-filterable.active .kpi-value {
    color: var(--accent);
}
.kpi-card.kpi-filterable.active .kpi-label {
    color: var(--accent);
}

/* ─── Table Container ─────────────────────────────────────────────── */
.table-container {
    padding: 0 0 16px;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

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

.btn-download-csv {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
}
.btn-download-csv:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Tabulator overrides for urgency rows */
.tabulator {
    border: 1px solid var(--border) !important;
    border-radius: 8px;
    overflow: hidden;
}

.tabulator .tabulator-header { background: var(--bg-secondary) !important; }
.tabulator .tabulator-header .tabulator-col { border-color: var(--border) !important; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content .tabulator-col-title {
    white-space: normal !important;
    text-overflow: clip !important;
    line-height: 1.2;
}

.tabulator-row { cursor: pointer; transition: background 0.1s; }
.tabulator-row:hover { background: var(--bg-hover) !important; }
.tabulator-row.active-row,
.tabulator-row.urgency-STOCK_ALERT.active-row,
.tabulator-row.urgency-CRITICAL.active-row,
.tabulator-row.urgency-STOCK_RISK.active-row,
.tabulator-row.urgency-TIME_RISK.active-row,
.tabulator-row.urgency-RUSH.active-row {
    box-shadow: inset 4px 0 0 var(--accent) !important;
    background: rgba(74, 158, 255, 0.18) !important;
}
.tabulator-row.active-row:hover,
.tabulator-row.urgency-STOCK_ALERT.active-row:hover,
.tabulator-row.urgency-CRITICAL.active-row:hover,
.tabulator-row.urgency-STOCK_RISK.active-row:hover,
.tabulator-row.urgency-TIME_RISK.active-row:hover,
.tabulator-row.urgency-RUSH.active-row:hover {
    background: rgba(74, 158, 255, 0.25) !important;
}

/* Urgency row backgrounds */
.tabulator-row.urgency-STOCK_ALERT { background: rgba(127, 29, 29, 0.5) !important; }
.tabulator-row.urgency-STOCK_ALERT:hover { background: rgba(127, 29, 29, 0.65) !important; }

.tabulator-row.urgency-CRITICAL { background: var(--urgency-critical-bg) !important; }
.tabulator-row.urgency-CRITICAL:hover { background: rgba(239, 68, 68, 0.25) !important; }

.tabulator-row.urgency-STOCK_RISK { background: var(--urgency-stock-bg) !important; }
.tabulator-row.urgency-STOCK_RISK:hover { background: rgba(249, 115, 22, 0.22) !important; }

.tabulator-row.urgency-TIME_RISK { background: var(--urgency-time-bg) !important; }
.tabulator-row.urgency-TIME_RISK:hover { background: rgba(234, 179, 8, 0.22) !important; }

.tabulator-row.urgency-RUSH { background: var(--urgency-rush-bg) !important; }
.tabulator-row.urgency-RUSH:hover { background: rgba(59, 130, 246, 0.18) !important; }

/* Transfers brand row tints */
.tabulator-row.brand-cricut         { background: rgba(34, 197, 94, 0.12) !important; }
.tabulator-row.brand-cricut:hover   { background: rgba(34, 197, 94, 0.22) !important; }
.tabulator-row.brand-ss             { background: rgba(59, 130, 246, 0.12) !important; }
.tabulator-row.brand-ss:hover       { background: rgba(59, 130, 246, 0.22) !important; }

/* ── Transfers ship-bucket group headers (Mach 6) ───────────────── */
.tabulator .tabulator-group {
    background: var(--bg-secondary) !important;
    border-top: 1px solid var(--border) !important;
    border-bottom: 1px solid var(--border) !important;
    color: var(--text-primary) !important;
    font-weight: 700;
    padding: 6px 10px !important;
}
.tabulator .tabulator-group .ship-group-count {
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 4px;
}

/* Urgency badge */
.urgency-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.urgency-badge.STOCK_ALERT { background: #7f1d1d; color: #fff; }
.urgency-badge.CRITICAL { background: var(--urgency-critical); color: #fff; }
.urgency-badge.STOCK_RISK { background: var(--urgency-stock-midday); color: #fff; }
.urgency-badge.TIME_RISK { background: var(--urgency-time); color: #000; }
.urgency-badge.RUSH { background: var(--urgency-rush); color: #fff; }
.urgency-badge.NORMAL { background: var(--border); color: var(--text-secondary); }

/* Department tag pills */
.dept-tags { display: flex; flex-wrap: wrap; gap: 2px; }
.dept-tag {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 600;
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

/* Order link */
.order-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
.order-link:hover { text-decoration: underline; }

/* Note indicator */
.note-indicator {
    display: inline-block;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}
.note-indicator.has-notes { color: var(--text-secondary); }
.note-indicator.has-unresolved { color: #fca5a5; font-weight: 600; }

/* ─── Side Panel ──────────────────────────────────────────────────── */
.side-panel {
    position: fixed;
    top: 0;
    right: -480px;
    width: var(--panel-width);
    max-width: 90vw;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 200;
    transition: right 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.side-panel.open { right: 0; }

.side-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.side-panel-header h2 { font-size: 15px; font-weight: 600; }
.panel-customer { font-size: 13px; font-weight: 400; color: #fff; margin-top: 2px; }
.panel-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.panel-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.side-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.side-panel-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 199;
}
.side-panel-overlay.open { display: block; }

/* Panel sections */
.panel-section { margin-bottom: 20px; }
.panel-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.panel-field { margin-bottom: 6px; display: flex; gap: 8px; }
.panel-field-label { color: var(--text-muted); font-size: 12px; min-width: 90px; }
.panel-field-value { color: var(--text-primary); font-size: 12px; font-weight: 500; }

/* Status timeline */
.status-timeline { list-style: none; }
.status-timeline li {
    padding: 6px 0;
    border-left: 2px solid var(--border);
    padding-left: 12px;
    position: relative;
    font-size: 12px;
}
.status-timeline li::before {
    content: '';
    position: absolute;
    left: -5px; top: 10px;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent);
}
.status-timeline li:first-child::before { background: var(--refresh-fresh); }
.status-time { color: var(--text-muted); font-size: 11px; }
.status-employee { color: var(--text-muted); font-size: 11px; font-style: italic; }
.btn-expand-statuses {
    background: none; border: none; color: var(--accent); cursor: pointer;
    font-size: 12px; padding: 4px 0; margin-top: 4px;
}
.btn-expand-statuses:hover { text-decoration: underline; }

/* Notes */
.note-item {
    padding: 8px 10px;
    background: var(--bg-primary);
    border-radius: 6px;
    margin-bottom: 6px;
    border-left: 3px solid var(--accent);
}
.note-item.resolved { border-left-color: var(--text-muted); opacity: 0.6; }
.note-author { font-size: 11px; font-weight: 600; color: var(--accent); }
.note-dept { font-size: 10px; color: var(--text-muted); }
.note-text { font-size: 12px; margin-top: 4px; }
.note-time { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

/* Slack mentions */
.slack-mention {
    padding: 10px 12px;
    background: var(--bg-primary);
    border-radius: 6px;
    margin-bottom: 8px;
    border-left: 3px solid #4a154b; /* Slack aubergine */
}
.slack-mention-meta { display: flex; align-items: center; gap: 8px; }
.slack-mention-author {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}
.slack-mention-channel {
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border-radius: 10px;
    padding: 1px 8px;
}
.slack-mention-link {
    font-size: 11px;
    margin-left: auto;
    text-decoration: none;
    color: var(--accent);
    flex-shrink: 0;
}
.slack-mention-link:hover { text-decoration: underline; }
.slack-mention-text {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    margin-top: 6px;
    white-space: pre-wrap;
    word-break: break-word;
}
.slack-mention-time { font-size: 10px; color: var(--text-muted); margin-top: 6px; }

/* Note form */
.note-form { margin-top: 12px; }
.note-form textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 12px;
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
}
.note-form textarea:focus { outline: none; border-color: var(--accent); }

.note-form-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}
.note-form-actions select,
.note-form-actions input[type="text"] {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 12px;
}

.btn-primary {
    padding: 6px 14px;
    background: var(--accent);
    border: none;
    border-radius: 4px;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.slack-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

/* Stock tracking */
.stock-item {
    padding: 6px 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    margin-bottom: 4px;
    font-size: 12px;
}
.stock-po { font-weight: 600; color: var(--accent); }
.stock-status { color: var(--text-muted); }
.stock-tracking { font-size: 11px; color: var(--text-secondary); }

/* Truck expectation badges */
.truck-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.2px;
    margin-top: 3px;
}
.truck-badge.overdue   { background: #7f1d1d; color: #fca5a5; }
.truck-badge.morning   { background: #78350f; color: #fde68a; }
.truck-badge.afternoon { background: #1e3a5f; color: #93c5fd; }
.truck-badge.ups       { background: #713f12; color: #fbbf24; }
.truck-badge.ups-overdue { background: #7f1d1d; color: #fbbf24; }

/* ─── Mobile Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .filter-bar { flex-direction: column; gap: 8px; }
    .kpi-row { gap: 6px; padding: 8px 10px; }
    .kpi-card { min-width: 80px; padding: 8px 6px; }
    .kpi-value { font-size: 18px; }
    .table-container { padding: 0 0 8px; }
    .side-panel { width: 100vw; max-width: 100vw; }
    .header { padding: 0 10px; }
    .main-content { padding: 0 10px; }
    .logo svg { width: 28px; height: 28px; }
    .nav-tab { padding: 4px 10px; font-size: 12px; }
}

@media (max-width: 480px) {
    .kpi-row { flex-wrap: wrap; }
    .kpi-card { min-width: calc(33% - 6px); }
}
