/* ── Google Fonts ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

/* ── Theme tokens ─────────────────────────────────────────────────────────── */
:root, [data-theme="dark"] {
  --bg:        #0f1117;
  --surface:   #1a1f2e;
  --surface2:  #222840;
  --border:    #2d3348;
  --border2:   #3d4468;
  --text:      #e2e8f0;
  --text2:     #94a3b8;
  --text3:     #64748b;
  --accent:    #f59e0b;
  --accent2:   #fbbf24;
  --danger:    #ef4444;
  --success:   #22c55e;
  --warning:   #f59e0b;
  --info:      #3b82f6;
}

[data-theme="medium"] {
  --bg:        #1e2433;
  --surface:   #28304a;
  --surface2:  #323c5a;
  --border:    #3d4868;
  --border2:   #4d5880;
  --text:      #e8edf5;
  --text2:     #9dacc4;
  --text3:     #6b7fa0;
  --accent:    #f59e0b;
  --accent2:   #fbbf24;
}

[data-theme="light"] {
  --bg:        #f0f4f8;
  --surface:   #ffffff;
  --surface2:  #f8fafc;
  --border:    #e2e8f0;
  --border2:   #cbd5e1;
  --text:      #1e293b;
  --text2:     #475569;
  --text3:     #94a3b8;
  --accent:    #d97706;
  --accent2:   #f59e0b;
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
code, .mono { font-family: 'JetBrains Mono', monospace; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 220px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { height: 52px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 12px; flex-shrink: 0; }
.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar-logo { padding: 20px 16px 12px; border-bottom: 1px solid var(--border); }
.sidebar-logo { flex-shrink: 0; }
.sidebar-header { flex-shrink: 0; }
.sidebar-footer { flex-shrink: 0; }
.sidebar-version { font-size: 10px; color: var(--text3); text-align: center; padding: 6px 8px 2px; letter-spacing: .03em; }
.sidebar-logo .product { font-weight: 700; font-size: 15px; color: var(--accent); letter-spacing: .02em; }
.sidebar-logo .sub { font-size: 11px; color: var(--text3); font-weight: 400; }
.nav-items { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--text2); font-size: 13.5px; font-weight: 500; transition: background .12s, color .12s; user-select: none; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(245,158,11,.12); color: var(--accent); }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); }
.user-pill { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.user-pill:hover { background: var(--surface2); }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #000; flex-shrink: 0; }
.user-name { font-size: 13px; font-weight: 500; color: var(--text); }
.user-role { font-size: 11px; color: var(--text3); }

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar-title { font-size: 15px; font-weight: 600; color: var(--text); flex: 1; }
.barcode-input { background: var(--surface2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 5px 10px; font-size: 13px; width: 200px; font-family: 'JetBrains Mono', monospace; }
.barcode-input::placeholder { color: var(--text3); }
.barcode-input:focus { outline: none; border-color: var(--accent); }

/* ── Status badges (indicator lights) ─────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 100px; text-transform: uppercase; letter-spacing: .04em; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; display: block; flex-shrink: 0; }
.badge-open { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-open::before { background: #3b82f6; }
.badge-progress { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-progress::before { background: #f59e0b; animation: pulse-amber 1.8s infinite; }
.badge-hold { background: rgba(148,163,184,.1); color: #94a3b8; }
.badge-hold::before { background: #94a3b8; }
.badge-closed { background: rgba(34,197,94,.12); color: #4ade80; }
.badge-closed::before { background: #22c55e; }
@keyframes pulse-amber {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,.5); }
  50% { box-shadow: 0 0 0 4px rgba(245,158,11,0); }
}

/* ── Cards + panels ───────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 13.5px; font-weight: 600; color: var(--text); }
.card-body { padding: 18px; }

/* ── Stat tiles ───────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 18px; }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text3); }
.stat-value { font-size: 30px; font-weight: 700; color: var(--text); margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.stat-value.amber { color: var(--accent); }
.stat-value.red { color: var(--danger); }
.stat-sub { font-size: 11.5px; color: var(--text3); }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th { text-align: left; padding: 8px 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text3); border-bottom: 1px solid var(--border); }
.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); color: var(--text2); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); cursor: pointer; }
.data-table .id-cell { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--text3); }
.data-table .title-cell { color: var(--text); font-weight: 500; }
.data-table .pt-name-cell { max-width: 25vw; white-space: normal; word-break: break-word; line-height: 1.35; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; border: none; transition: opacity .12s; font-family: inherit; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover:not(:disabled) { background: var(--accent2); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--border2); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--danger); border: 1px solid rgba(239,68,68,.2); }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,.25); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text2); }
.form-input, .form-select, .form-textarea {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 7px 10px; font-size: 13px; font-family: inherit; width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: min(520px, 92vw); max-height: 85vh; overflow-y: auto; }
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15px; font-weight: 700; color: var(--text); }
.modal-close { color: var(--text3); font-size: 18px; cursor: pointer; background: none; border: none; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
#fleet-form-modal .modal { width: min(1280px, 97vw) !important; max-width: 1280px !important; max-height: 95vh; box-sizing: border-box; }
#fleet-form-modal .modal-header { padding: 24px 36px; }
#fleet-form-modal .modal-title { font-size: 21px; font-weight: 800; }
#fleet-form-modal .modal-body { padding: 14px 36px 36px; box-sizing: border-box; overflow-x: hidden; }
#fleet-form-modal .modal-body > div { box-sizing: border-box; width: 100%; max-width: 100%; }
#fleet-form-modal .form-group { margin-bottom: 22px; min-width: 0; }
#fleet-form-modal .form-label { font-size: 14.5px; font-weight: 700; color: var(--text); margin-bottom: 8px; letter-spacing: .01em; }
#fleet-form-modal input.form-control,
#fleet-form-modal select.form-control,
#fleet-form-modal textarea.form-control { width: 100% !important; box-sizing: border-box !important; height: 50px; font-size: 16px; padding: 0 14px; background: #1a2233 !important; border: 1px solid var(--border) !important; border-radius: 8px; color: var(--text) !important; }
#fleet-form-modal input.form-control:focus,
#fleet-form-modal select.form-control:focus { background: #222c40 !important; border-color: #4a90d9 !important; outline: none; }
#fleet-form-modal .fleet-section-title { font-size: 16px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; color: var(--text); border-bottom: 2px solid var(--border); padding-bottom: 10px; margin: 30px 0 22px; grid-column: 1 / -1; }
#fleet-form-modal .modal-footer { padding: 20px 36px; }
#fleet-form-modal .btn { height: 46px; font-size: 15px; padding: 0 24px; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 40px; width: min(400px, 92vw); }
.login-logo { font-size: 22px; font-weight: 800; color: var(--accent); margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--text3); margin-bottom: 28px; }

/* ── Toasts ───────────────────────────────────────────────────────────────── */
.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--surface2); border: 1px solid var(--border2); border-radius: 8px; padding: 10px 16px; font-size: 13px; font-weight: 500; color: var(--text); display: flex; align-items: center; gap: 8px; pointer-events: all; }
.toast.error { border-color: rgba(239,68,68,.4); color: #fca5a5; }
.toast.success { border-color: rgba(34,197,94,.3); color: #86efac; }

/* ── Detail section ───────────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.detail-field { }
.detail-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text3); }
.detail-value { font-size: 14px; color: var(--text); margin-top: 3px; }
.detail-value.mono { font-family: 'JetBrains Mono', monospace; font-size: 13px; }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-title { font-size: 20px; font-weight: 700; color: var(--text); }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text3); margin-bottom: 12px; }
.empty-state { padding: 48px 24px; text-align: center; color: var(--text3); font-size: 14px; }
.priority-critical { color: #f87171; }
.priority-high { color: #fbbf24; }
.priority-medium { color: #60a5fa; }
.priority-low { color: #64748b; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text3); cursor: pointer; margin-bottom: 16px; }
.back-link:hover { color: var(--accent); }
.theme-toggle { display: flex; gap: 4px; background: var(--surface2); border-radius: 6px; padding: 3px; }
.theme-btn { padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; cursor: pointer; border: none; background: none; color: var(--text3); font-family: inherit; }
.theme-btn.active { background: var(--accent); color: #000; }
[x-cloak] { display: none !important; }

/* Searchable dropdown */
.ss-option { padding: 8px 12px; font-size: 13px; cursor: pointer; color: var(--text2); }
.ss-option:hover { background: var(--surface3); color: var(--text1); }

.tenant-card { transition: border-color .15s; }
.tenant-card:hover { border-color: var(--accent) !important; }

/* ── Kiosk / presentation mode (dashboard rotation full-screen) ───────────── */
body.kiosk-mode .sidebar { display: none !important; }
body.kiosk-mode .topbar  { display: none !important; }
body.kiosk-mode .main    { width: 100vw; }
body.kiosk-mode .content { padding-top: 8px; }

/* ── MOBILE LAYOUT ────────────────────────────────────────────────────────── */
.hamburger-btn { display: none; background: none; border: none; color: var(--text); font-size: 22px; cursor: pointer; padding: 4px 10px 4px 0; line-height: 1; }
.mobile-backdrop { display: none; }

@media (max-width: 820px) {
  .app-shell { position: relative; }

  /* sidebar -> off-canvas drawer */
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100%; width: 270px; max-width: 84vw;
    z-index: 999; transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,.45); overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .mobile-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 998; }
  body.nav-open .mobile-backdrop { display: block; }

  .hamburger-btn { display: inline-block; }

  .main { width: 100%; }
  .content { padding: 14px; }
  .topbar { padding: 0 12px; height: 50px; }
  .topbar-title { font-size: 15px; }

  /* stack form/detail grids to one column */
  .form-grid, .detail-grid { grid-template-columns: 1fr !important; }
  /* 16px inputs prevent iOS auto-zoom on focus */
  .form-input, .form-select, .form-textarea { font-size: 16px; }

  .page-header { flex-wrap: wrap; gap: 8px; }
  .page-title { font-size: 20px; }
  .card { margin-bottom: 12px; }

  /* ── tables -> stacked cards (CSS-only) ────────────────────────────────── */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    margin-bottom: 10px; border: 1px solid var(--border); border-radius: 8px;
    padding: 8px 12px; background: var(--surface);
  }
  .data-table tr:hover td { background: none; }
  .data-table td { border: none; padding: 4px 0; color: var(--text2); }
  .data-table td.id-cell { font-size: 11px; color: var(--text3); padding-bottom: 2px; }
  .data-table td.title-cell { font-size: 16px; font-weight: 600; color: var(--text); padding-bottom: 4px; }

  /* ── wo-table compact mobile rows (override the stacked-card rule) ─────── */
  .data-table.wo-table, .data-table.wo-table tbody { display: block; width: 100%; }
  .data-table.wo-table tr {
    display: flex; align-items: baseline; gap: 8px;
    margin-bottom: 0; border: none; border-bottom: 1px solid var(--border);
    border-radius: 0; padding: 10px 4px; background: none;
  }
  .data-table.wo-table td { display: none; padding: 0; line-height: 1.3; }
  .data-table.wo-table td.id-cell {
    display: block; flex: 0 0 auto; font-size: 12px; color: var(--text3);
    padding-bottom: 0; white-space: nowrap;
  }
  .data-table.wo-table td.title-cell {
    display: block; flex: 1 1 auto; font-size: 14px; font-weight: 600; color: var(--text);
    padding-bottom: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  /* priority cell = col 3, due = last col; show both as small trailing meta */
  .data-table.wo-table td:nth-child(3) {
    display: block; flex: 0 0 auto; font-size: 11px; font-weight: 700; text-transform: uppercase;
  }
  .data-table.wo-table td:last-child {
    display: block; flex: 0 0 auto; font-size: 11px; color: var(--text3); white-space: nowrap;
  }

  /* drawer nav: bigger tap targets */
  .nav-item { padding: 12px 16px; font-size: 15px; }
}

/* ── FACILITY MAP MOBILE ──────────────────────────────────────────────────── */
.map-layers-toggle { display: none; }
@media (max-width: 820px) {
  .map-layers-toggle { display: inline-block; }
  /* stack: layers panel on top (collapsible), map full-width below */
  .map-row { flex-direction: column !important; }
  #map-layers { flex: 1 1 auto !important; width: 100%; display: none; }  /* collapsed by default; toggle shows it */
  #leaflet-map { flex: none !important; width: 100% !important; height: 70vh !important; min-height: 380px !important; }
}

.pt-subtotal-row td{background:var(--surface2);padding-top:2px;padding-bottom:6px}
