/* Nighthawk-6 — 6666 Ranch Palette
   Steel doesn't sleep. */

:root {
    --branded-iron:     #1A1210;
    --sixes-red:        #8B2500;
    --burnt-saddle:     #6B3A2A;
    --ranch-leather:    #A0764A;
    --fence-post:       #3B3230;
    --dust-trail:       #D4C4A8;
    --bone-white:       #F2EDE4;
    --signal-amber:     #D4A017;
    --clearance-green:  #4A7C59;
    --theft-red:        #C41E3A;

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --navbar-height: 56px;
    --sidebar-width: 260px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
    font-family: var(--font-sans);
    background: var(--branded-iron);
    color: var(--bone-white);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--branded-iron); }
::-webkit-scrollbar-thumb { background: var(--fence-post); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--burnt-saddle); }

/* ── Navigation ─────────────────────────────────────── */
.navbar {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--navbar-height);
    background: rgba(26, 18, 16, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(107, 58, 42, 0.3);
    display: flex; align-items: center;
    padding: 0 1.5rem;
    z-index: 1000;
    gap: 2rem;
}

.nav-brand {
    display: flex; align-items: center; gap: 0.5rem;
    font-weight: 800; font-size: 1.1rem;
    letter-spacing: 0.12em; color: var(--sixes-red);
}
.brand-icon { font-size: 1.4rem; }
.nav-links { display: flex; gap: 0.25rem; }
.nav-link {
    padding: 0.5rem 1rem; border-radius: 6px;
    color: var(--dust-trail); text-decoration: none;
    font-size: 0.85rem; font-weight: 500;
    transition: all 0.15s;
}
.nav-link:hover { background: var(--fence-post); color: var(--bone-white); }
.nav-link.active { background: rgba(139,37,0,0.2); color: var(--sixes-red); }
.nav-actions { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.nav-status { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--dust-trail); }

/* ── Layout ─────────────────────────────────────────── */
.app-layout { display: flex; padding-top: var(--navbar-height); min-height: 100vh; }

.sidebar {
    position: fixed; top: var(--navbar-height); left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: rgba(26, 18, 16, 0.6);
    border-right: 1px solid rgba(107, 58, 42, 0.2);
    overflow-y: auto; padding: 1rem;
}
.sidebar-section { margin-bottom: 1.5rem; }
.sidebar-title {
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--dust-trail); margin-bottom: 0.75rem;
}
.stat-list { display: flex; flex-direction: column; gap: 0.5rem; }
.stat-item { display: flex; justify-content: space-between; font-size: 0.85rem; }
.stat-label { color: var(--dust-trail); }
.stat-value { font-weight: 700; font-family: var(--font-mono); }
.stat-alert { color: var(--theft-red); }

.app-main { margin-left: var(--sidebar-width); flex: 1; }
.app-content { padding: 1.5rem; max-width: 1400px; }

/* ── Cards ──────────────────────────────────────────── */
.card {
    background: var(--fence-post);
    border: 1px solid rgba(107, 58, 42, 0.25);
    border-radius: 10px;
    overflow: hidden;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(107, 58, 42, 0.15);
}
.card-title { font-size: 0.95rem; font-weight: 700; }
.card-body { padding: 1rem 1.25rem; }

.stat-card { padding: 1.25rem; text-align: center; }
.stat-card-label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dust-trail); margin-bottom: 0.5rem; }
.stat-card-value { font-size: 2rem; font-weight: 800; font-family: var(--font-mono); line-height: 1; }
.stat-card-sub { font-size: 0.75rem; color: var(--dust-trail); margin-top: 0.5rem; display: flex; align-items: center; justify-content: center; gap: 0.3rem; }

/* ── Status Dots ────────────────────────────────────── */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.status-dot.dot-green { background: var(--clearance-green); box-shadow: 0 0 6px rgba(74,124,89,0.5); }
.status-dot.dot-amber { background: var(--signal-amber); box-shadow: 0 0 6px rgba(212,160,23,0.5); }
.status-dot.dot-red { background: var(--theft-red); box-shadow: 0 0 6px rgba(196,30,58,0.5); animation: pulse-red 1.5s ease-in-out infinite; }

@keyframes pulse-red {
    0%, 100% { box-shadow: 0 0 6px rgba(196,30,58,0.5); }
    50% { box-shadow: 0 0 14px rgba(196,30,58,0.9); }
}

/* ── Badges ─────────────────────────────────────────── */
.badge {
    display: inline-flex; padding: 2px 8px; border-radius: 10px;
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge-info { background: rgba(160,118,74,0.2); color: var(--ranch-leather); }
.badge-warning { background: rgba(212,160,23,0.15); color: var(--signal-amber); }
.badge-critical { background: rgba(196,30,58,0.15); color: var(--theft-red); animation: badge-pulse 2s infinite; }
.badge-success { background: rgba(74,124,89,0.15); color: var(--clearance-green); }

@keyframes badge-pulse { 0%,100% { opacity:1; } 50% { opacity:0.7; } }

/* ── Dashboard Grid ─────────────────────────────────── */
.dashboard-grid { display: grid; gap: 1.25rem; }
.dashboard-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.dashboard-map { grid-column: 1 / -1; }
.dashboard-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* ── Map ────────────────────────────────────────────── */
.map-container { position: relative; width: 100%; height: 500px; border-radius: 10px; overflow: hidden; }
.map-legend {
    position: absolute; bottom: 12px; left: 12px; z-index: 10;
    background: rgba(26,18,16,0.9); backdrop-filter: blur(8px);
    border: 1px solid rgba(107,58,42,0.3); border-radius: 6px;
    padding: 6px 12px; display: flex; gap: 12px; font-size: 0.75rem;
}
.map-legend-item { display: flex; align-items: center; gap: 4px; color: var(--dust-trail); }

/* Mapbox popup overrides */
.mapboxgl-popup-content {
    background: var(--fence-post) !important; color: var(--bone-white) !important;
    border-radius: 8px !important; padding: 14px !important;
    border: 1px solid rgba(107,58,42,0.3) !important;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5) !important; min-width: 200px;
}
.mapboxgl-popup-tip { border-top-color: var(--fence-post) !important; }
.mapboxgl-popup-close-button { color: var(--dust-trail) !important; font-size: 18px; }
.popup-trailer-id { font-family: var(--font-mono); font-weight: 700; font-size: 0.95rem; margin-bottom: 8px; }
.popup-row { display: flex; justify-content: space-between; font-size: 0.8rem; padding: 2px 0; color: var(--dust-trail); }
.popup-value { font-weight: 600; color: var(--bone-white); }

/* ── Alerts ─────────────────────────────────────────── */
.alert-item {
    display: flex; gap: 12px; padding: 12px; border-radius: 8px;
    border: 1px solid rgba(107,58,42,0.15); margin-bottom: 8px; transition: background 0.15s;
}
.alert-item:hover { background: rgba(160,118,74,0.06); }
.alert-item.alert-critical { border-left: 3px solid var(--theft-red); background: rgba(196,30,58,0.06); }
.alert-item.alert-warning-item { border-left: 3px solid var(--signal-amber); }
.alert-item.alert-info-item { border-left: 3px solid var(--ranch-leather); }

.alert-severity {
    width: 36px; height: 36px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-weight: 700;
}
.severity-critical { background: rgba(196,30,58,0.2); color: var(--theft-red); }
.severity-warning { background: rgba(212,160,23,0.15); color: var(--signal-amber); }
.severity-info { background: rgba(160,118,74,0.2); color: var(--ranch-leather); }

.alert-content { flex: 1; min-width: 0; }
.alert-title { font-size: 0.85rem; font-weight: 600; }
.alert-meta { font-size: 0.75rem; color: var(--dust-trail); }
.alert-time { font-size: 0.75rem; color: rgba(212,196,168,0.5); white-space: nowrap; }

/* ── Toasts ─────────────────────────────────────────── */
.toast-container {
    position: fixed; top: calc(var(--navbar-height) + 12px); right: 12px;
    z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
    min-width: 300px; max-width: 400px;
    background: var(--fence-post); border: 1px solid rgba(107,58,42,0.3); border-radius: 8px;
    padding: 12px; display: flex; align-items: flex-start; gap: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5); pointer-events: auto;
    animation: toast-in 0.3s ease;
}
.toast.toast-exiting { opacity: 0; transform: translateX(100%); transition: all 0.3s; }
.toast.toast-critical { border-left: 3px solid var(--theft-red); }
.toast.toast-warning { border-left: 3px solid var(--signal-amber); }
.toast-icon { font-size: 1.1rem; flex-shrink: 0; }
.toast-body { flex: 1; }
.toast-title { font-size: 0.85rem; font-weight: 600; }
.toast-message { font-size: 0.75rem; color: var(--dust-trail); margin-top: 2px; }
.toast-close { background: none; border: none; color: var(--dust-trail); cursor: pointer; font-size: 1rem; }

@keyframes toast-in { from { opacity:0; transform:translateX(50px); } to { opacity:1; transform:translateX(0); } }

/* ── Buttons ────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px; border-radius: 6px; font-family: var(--font-sans);
    font-size: 0.85rem; font-weight: 600; cursor: pointer; border: none; transition: all 0.15s;
    text-decoration: none;
}
.btn-primary { background: var(--sixes-red); color: var(--bone-white); }
.btn-primary:hover { background: #A02D00; box-shadow: 0 0 16px rgba(139,37,0,0.4); }
.btn-secondary { background: var(--fence-post); color: var(--dust-trail); border: 1px solid rgba(107,58,42,0.3); }
.btn-secondary:hover { color: var(--bone-white); }
.btn-ghost { background: transparent; color: var(--dust-trail); }
.btn-ghost:hover { background: var(--fence-post); color: var(--bone-white); }
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }
.btn-danger { background: var(--theft-red); color: var(--bone-white); }

/* ── Tables ─────────────────────────────────────────── */
table.ts-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.ts-table thead { background: rgba(26,18,16,0.5); }
table.ts-table thead th {
    padding: 8px 12px; text-align: left; font-weight: 600; font-size: 0.7rem;
    text-transform: uppercase; letter-spacing: 0.06em; color: var(--dust-trail);
    border-bottom: 1px solid rgba(107,58,42,0.15);
}
table.ts-table tbody tr { border-bottom: 1px solid rgba(107,58,42,0.1); transition: background 0.15s; }
table.ts-table tbody tr:hover { background: rgba(160,118,74,0.06); }
table.ts-table tbody td { padding: 8px 12px; color: var(--dust-trail); }
.cell-primary { color: var(--bone-white); font-weight: 500; text-decoration: none; }
.cell-primary:hover { color: var(--ranch-leather); }
.cell-mono { font-family: var(--font-mono); font-size: 0.8rem; }

/* ── Forms ──────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--dust-trail); margin-bottom: 4px; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 8px 12px;
    background: var(--branded-iron); border: 1px solid rgba(107,58,42,0.3); border-radius: 6px;
    color: var(--bone-white); font-family: var(--font-sans); font-size: 0.85rem; transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--ranch-leather); box-shadow: 0 0 0 3px rgba(160,118,74,0.15); }
.form-input::placeholder { color: rgba(212,196,168,0.35); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-upload {
    border: 2px dashed rgba(160,118,74,0.3); border-radius: 10px; padding: 2rem;
    text-align: center; color: var(--dust-trail); cursor: pointer; transition: all 0.15s;
}
.form-upload:hover { border-color: var(--ranch-leather); background: rgba(160,118,74,0.05); }

/* ── Spinner ────────────────────────────────────────── */
.spinner {
    width: 28px; height: 28px;
    border: 3px solid rgba(139,37,0,0.2); border-top-color: var(--sixes-red);
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
.spinner-center { display: flex; align-items: center; justify-content: center; padding: 2rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pressure Grid ──────────────────────────────────── */
.pressure-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 12px; background: var(--branded-iron); border-radius: 8px; border: 1px solid rgba(107,58,42,0.25); }
.pressure-cell { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 4px; font-size: 0.7rem; font-family: var(--font-mono); font-weight: 600; }
.zone-label { font-size: 0.55rem; opacity: 0.6; }
.zone-empty { background: rgba(59,50,48,0.5); color: rgba(212,196,168,0.3); }
.zone-normal { background: rgba(74,124,89,0.3); color: var(--clearance-green); }
.zone-heavy { background: rgba(212,160,23,0.25); color: var(--signal-amber); }

/* ── Sensor Grid ────────────────────────────────────── */
.sensor-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.sensor-card { background: var(--branded-iron); border: 1px solid rgba(107,58,42,0.25); border-radius: 8px; padding: 12px; text-align: center; }
.sensor-label { font-size: 0.7rem; color: var(--dust-trail); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.sensor-value { font-size: 1.6rem; font-weight: 800; font-family: var(--font-mono); line-height: 1; }
.sensor-unit { font-size: 0.7rem; color: var(--dust-trail); margin-top: 4px; }
.sensor-card.sensor-ok { border-bottom: 3px solid var(--clearance-green); }
.sensor-card.sensor-caution { border-bottom: 3px solid var(--signal-amber); }
.sensor-card.sensor-critical { border-bottom: 3px solid var(--theft-red); }

/* ── Weight Reconciliation ──────────────────────────── */
.weight-comparison { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: center; padding: 1.25rem; background: var(--branded-iron); border-radius: 8px; border: 1px solid rgba(107,58,42,0.25); }
.weight-block { text-align: center; }
.weight-label { font-size: 0.7rem; color: var(--dust-trail); text-transform: uppercase; margin-bottom: 4px; }
.weight-value { font-size: 1.8rem; font-weight: 800; font-family: var(--font-mono); }
.weight-delta { font-size: 1.2rem; font-weight: 700; font-family: var(--font-mono); padding: 6px 12px; border-radius: 6px; }
.delta-ok { background: rgba(74,124,89,0.15); color: var(--clearance-green); }
.delta-warn { background: rgba(212,160,23,0.15); color: var(--signal-amber); }
.delta-alert { background: rgba(196,30,58,0.15); color: var(--theft-red); }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 768px) {
    :root { --sidebar-width: 0px; }
    .sidebar { display: none; }
    .app-main { margin-left: 0; }
    .navbar { padding: 0 0.75rem; }
    .dashboard-panels { grid-template-columns: 1fr; }
    .map-container { height: 350px; }
}

/* ── Utilities ──────────────────────────────────────── */
.text-muted { color: rgba(212,196,168,0.5); }
.text-center { text-align: center; }
.mt-sm { margin-top: 0.5rem; }
.mt-md { margin-top: 1rem; }
.mb-md { margin-bottom: 1rem; }
.hidden { display: none !important; }
