/* ============================================================
   Wilson TraX — Shared Stylesheet v14
   Single source of truth for tokens, layout, topbar, sidebar,
   responsive breakpoints, and reusable components.
   ============================================================ */

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
*:focus { outline: none; }

/* ── Tokens ── */
:root {
  --bg:        #0b1220;
  --bg-soft:   #111827;
  --soft:      #111827;
  --card:      #172033;
  --card2:     #1d2940;
  --card-2:    #1d2940;
  --border:    #2b3750;
  --text:      #e5ecf6;
  --muted:     #94a3b8;
  --green:     #22c55e;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --blue:      #3b82f6;
  --purple:    #a78bfa;
  --teal:      #0d9488;
  --topbar-h:  52px;
  --sidebar-w: 260px;
}

[data-theme="light"] {
  --bg:      #f1f5f9;
  --bg-soft: #ffffff;
  --soft:    #ffffff;
  --card:    #ffffff;
  --card2:   #f8fafc;
  --card-2:  #f8fafc;
  --border:  #e2e8f0;
  --text:    #1e293b;
  --muted:   #64748b;
  --blue:    #2563eb;
  --green:   #16a34a;
  --amber:   #d97706;
  --red:     #dc2626;
  --purple:  #7c3aed;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* ── Page Layouts ─────────────────────────────────────────────────────────── */

/* Two-column: sidebar + main (Dashboard, Vault, Diagnostics) */
.shell-2col {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.shell-2col > .topbar   { grid-column: 1 / -1; grid-row: 1; }
.shell-2col > .sidebar  { grid-column: 1;      grid-row: 2; }
.shell-2col > .main     { grid-column: 2;      grid-row: 2; }

/* One-column: topbar + full-width main (Financials, Admin, Audit Log) */
.shell-1col {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.shell-1col > .topbar { grid-column: 1; grid-row: 1; }
.shell-1col > .main   { grid-column: 1; grid-row: 2; }

/* Legacy compat — .app-shell = .shell-2col */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.app-shell > .topbar     { grid-column: 1 / -1; grid-row: 1; }
.app-shell > .sidebar    { grid-column: 1;      grid-row: 2; }
.app-shell > .main-panel { grid-column: 2;      grid-row: 2; }
.app-shell > .main       { grid-column: 2;      grid-row: 2; }

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  height: var(--topbar-h);
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding: 0 0 0 16px;
  flex-shrink: 0;
  z-index: 100;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 16px;
  border-right: 1px solid var(--border);
  margin-right: 0;
  flex-shrink: 0;
  white-space: nowrap;
}

.brand-name {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.brand-x { color: var(--red); }

.brand-ver {
  font-size: 10px;
  color: var(--muted);
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ── Tab Navigation ───────────────────────────────────────────────────────── */
.tab-nav {
  flex: 1;
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
}

.tab-nav::-webkit-scrollbar { display: none; }

.tab-nav a {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 13px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.12s, border-color 0.12s;
}

.tab-nav a:hover  { color: var(--text); }
.tab-nav a.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-nav a.hidden { display: none; }

/* ── Topbar Right ─────────────────────────────────────────────────────────── */
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  flex-shrink: 0;
}

.topbar-right img { height: 22px; opacity: 0.85; }
#logoDark  { display: inline; }
#logoLight { display: none; }
[data-theme="light"] #logoDark  { display: none !important; }
[data-theme="light"] #logoLight { display: inline !important; }

/* Mobile menu button — hidden on desktop */
.mobile-menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  margin-right: 8px;
  align-items: center;
  justify-content: center;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  grid-column: 1;
  grid-row: 2;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-search input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}

.sidebar-search input:focus { border-color: var(--blue); }

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.sidebar-item {
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  transition: background 0.1s;
}

.sidebar-item:hover  { background: var(--card2); }
.sidebar-item.active { background: var(--card2); border-left-color: var(--blue); }
.sidebar-item-name   { font-size: 13px; font-weight: 600; }
.sidebar-item-sub    { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Trailer List Cards (shared across Dashboard / Vault / Diagnostics) ──── */
.trailer-list {
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 10px 12px 14px;
  min-height: 0;
  flex: 1;
}

.trailer-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: 0.2s ease;
  font-weight: 400;
}

.trailer-item:hover {
  background: var(--card2);
  transform: translateY(-1px);
}

.trailer-item.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px rgba(59,130,246,0.35);
  background: #19263d;
}

.trailer-title {
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 5px;
  color: var(--text);
}

.trailer-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

/* Left-border status strips */
.row-healthy  { border-left: 4px solid var(--green); }
.row-warning  { border-left: 4px solid var(--amber); }
.row-critical { border-left: 4px solid var(--red); }

/* Last-seen age pill */
.trailer-age {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}
.trailer-age.online  { background: rgba(34,197,94,0.15);  color: var(--green); }
.trailer-age.stale   { background: rgba(245,158,11,0.15); color: var(--amber); }
.trailer-age.offline { background: rgba(239,68,68,0.15);  color: var(--red); }

/* Source status badges (SOLAR / ROUTER / GPS) */
.trailer-src-row {
  display: flex;
  gap: 5px;
  margin-top: 5px;
  flex-wrap: wrap;
}

.src-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.src-ok   { background: rgba(34,197,94,0.15);   color: #22c55e; border: 1px solid rgba(34,197,94,0.3); }
.src-warn { background: rgba(245,158,11,0.15);  color: #f59e0b; border: 1px solid rgba(245,158,11,0.3); }
.src-bad  { background: rgba(239,68,68,0.15);   color: #ef4444; border: 1px solid rgba(239,68,68,0.3); }
.src-none { background: rgba(148,163,184,0.08); color: #4b5c7a; border: 1px solid rgba(148,163,184,0.12); }

/* Light theme */
[data-theme="light"] .trailer-item {
  background: #f8fafc;
  border-color: #e2e8f0;
}
[data-theme="light"] .trailer-item:hover {
  background: #f1f5f9;
}
[data-theme="light"] .trailer-item.selected,
[data-theme="light"] .trailer-item.active {
  background: #eff6ff;
  border-left-color: var(--blue);
}

/* ── Mobile Trailer Picker (hidden on desktop) ───────────────────────────── */
.mobile-trailer-picker-wrap {
  display: none;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.mobile-trailer-picker {
  width: 100%;
  padding: 10px 36px 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background-color: var(--card2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.mobile-trailer-picker:focus { border-color: var(--blue); outline: none; }

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  min-width: 0;
}

.main-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  min-height: 200px;
}

.empty-state .icon { font-size: 40px; opacity: 0.4; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  padding: 6px 13px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
  white-space: nowrap;
}

.btn:hover    { background: var(--card); }
.btn.primary  { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { opacity: 0.9; }
.btn.danger   { background: rgba(239,68,68,0.1); border-color: var(--red); color: var(--red); }
.btn.sm       { padding: 3px 9px; font-size: 11px; }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  font-family: inherit;
  transition: background 0.12s;
}

.btn-icon:hover { background: var(--card2); color: var(--text); }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.detail-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.detail-table td { padding: 6px; border-bottom: 1px solid var(--border); vertical-align: middle; word-break: break-word; font-size: 13px; }
.detail-table td:first-child { width: 38%; color: var(--muted); font-size: 12px; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Light Theme Global ───────────────────────────────────────────────────── */
[data-theme="light"] .shell-2col,
[data-theme="light"] .shell-1col,
[data-theme="light"] .app-shell {
  background: var(--bg);
}

[data-theme="light"] .sidebar {
  background: #ffffff;
}

[data-theme="light"] .topbar {
  background: #ffffff;
}

[data-theme="light"] .sidebar-item:hover {
  background: #f1f5f9;
}

[data-theme="light"] .sidebar-item.active {
  background: #eff6ff;
  border-left-color: var(--blue);
}


/* ════════════════════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET  (≤ 900px)
   ════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  :root { --sidebar-w: 220px; }

  .tab-nav a {
    padding: 0 10px;
    font-size: 11px;
  }
}


/* ════════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE  (≤ 768px)
   ════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  html, body {
    overflow: auto;
    height: auto;
  }

  /* ── Show hamburger button ── */
  .mobile-menu-btn { display: flex; }

  /* ── All shell layouts become single-column stacked ── */
  .shell-2col,
  .shell-1col,
  .app-shell {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    overflow: visible;
  }

  /* ── Topbar: sticky at top ── */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 200;
    height: auto;
    min-height: var(--topbar-h);
    flex-wrap: nowrap;
    padding: 0 8px 0 12px;
  }

  /* ── Tab nav: dropdown menu ── */
  .tab-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 8px 0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    z-index: 199;
  }

  [data-theme="light"] .tab-nav {
    background: #ffffff;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  }

  .tab-nav.mobile-open {
    display: flex;
  }

  .tab-nav a {
    padding: 12px 20px;
    font-size: 14px;
    border-bottom: none;
    border-left: 3px solid transparent;
  }

  .tab-nav a.active {
    border-bottom: none;
    border-left-color: var(--blue);
    background: var(--card);
  }

  .tab-nav a:hover { background: var(--card2); }

  /* ── Sidebar: dropdown-only on mobile ── */
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
    overflow: visible;
    padding: 0;
  }

  /* Show the native picker */
  .mobile-trailer-picker-wrap { display: block; }

  /* Hide the full list + desktop filters/search on mobile */
  .sidebar-list,
  .trailer-list,
  .sidebar-search,
  .sidebar .filters {
    display: none !important;
  }

  /* ── Main: scrollable ── */
  .main,
  .main-panel {
    flex: 1;
    overflow: visible;
    min-height: 0;
  }

  /* ── Brand: tighter ── */
  .brand-name { font-size: 15px; }
  .brand-ver  { font-size: 9px; }
  .brand { padding-right: 10px; gap: 6px; }
}


/* ════════════════════════════════════════════════════════════════════════════
   RESPONSIVE — SMALL PHONE  (≤ 480px)
   ════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .brand-ver { display: none; }
  .topbar-right img { height: 18px; }
  .topbar-right { gap: 4px; padding: 0 6px; }
  .btn-icon { font-size: 12px; padding: 3px 6px; }
  .sidebar { padding: 8px; }
  .sidebar-list,
  .trailer-list { max-height: none; }
}
