:root{--admin-tabbar-h:0px;}
.admin-shell{display:flex;min-height:calc(100vh - 90px);}
.sidebar{
  width:220px;background:var(--surface);border-right:1px solid var(--border);
  padding:20px 14px;flex-shrink:0;
  position:sticky;top:90px;align-self:flex-start;
  max-height:calc(100vh - 90px);overflow-y:auto;z-index:20;
}
.side-link{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:8px;font-size:14px;font-weight:600;color:var(--muted);cursor:pointer;margin-bottom:2px;text-decoration:none;transition:background .15s,color .15s;}
.side-link svg{width:17px;height:17px;stroke:currentColor;flex-shrink:0;}
.side-link i{width:17px;font-size:15px;text-align:center;flex-shrink:0;}
.side-link.active{background:var(--orange-light);color:var(--orange-dark);}
.side-link:hover:not(.active){background:var(--surface-2);}
.side-group-label{font-family:var(--font-mono);font-size:10.5px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin:18px 0 6px 12px;}
.admin-main{flex:1;padding:26px 30px;min-width:0;animation:fadeIn .2s ease;}
.admin-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:22px;flex-wrap:wrap;gap:12px;}
.admin-head h1{font-family:var(--font-display);font-size:23px;margin:0;}

.stat-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:16px;margin-bottom:20px;}
.stat-card{background:var(--surface);border:1px solid var(--border);border-radius:12px;padding:18px 20px;animation:fadeUp .25s ease backwards;}
.stat-label{font-size:12.5px;color:var(--muted);font-weight:600;margin:0 0 8px;}
.stat-value{font-family:var(--font-mono);font-size:30px;font-weight:700;margin:0 0 6px;}
.stat-foot{font-size:11.5px;color:var(--muted);display:flex;align-items:center;gap:5px;}
.stat-foot svg{width:12px;height:12px;stroke:currentColor;}
.stat-foot i{font-size:11px;}
.stat-dots{display:none;}

/* Hidden at every width by default, not just below the mobile
   breakpoint — the button that opens it (inside .admin-tabbar) only
   ever renders on mobile, but this markup is always present in the
   page, so its own default state must be "closed" regardless of
   viewport rather than relying on the tab bar being hidden to keep it
   off-screen. Combined with .modal-overlay (from style.css) for the
   backdrop/position/animation; only display is overridden here. */
.more-sheet-overlay{display:none;}
.more-sheet-overlay.open{display:flex;}
.admin-tabbar{display:none;}

/* Pull-to-refresh indicator (see initPullToRefresh in ui-helpers.js).
   Sits just below the sticky topbar; hidden/collapsed until a touch
   drag pulls it into view, so it costs nothing visually on desktop or
   whenever the page isn't scrolled to the very top. */
.ptr-indicator{
  position:fixed;top:90px;left:50%;width:38px;height:38px;margin-left:-19px;
  background:var(--surface);border:1px solid var(--border);border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  box-shadow:0 4px 14px rgba(0,0,0,.16);
  opacity:0;transform:translateY(-46px);z-index:40;pointer-events:none;
  transition:transform .25s ease,opacity .25s ease;
}
.ptr-indicator.dragging{transition:none;}
.ptr-indicator .ptr-spinner{display:flex;color:var(--orange-dark);font-size:15px;}
.ptr-indicator.spinning .ptr-spinner{animation:ptrSpin .7s linear infinite;}
@keyframes ptrSpin{to{transform:rotate(360deg);}}
@media (prefers-reduced-motion: reduce){
  .ptr-indicator{transition-duration:.001ms !important;}
  .ptr-indicator.spinning .ptr-spinner{animation-duration:.001ms !important;}
}

.panel-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:20px;}
.panel{background:var(--surface);border:1px solid var(--border);border-radius:12px;padding:20px;}
.panel h3{font-family:var(--font-display);font-size:15px;margin:0 0 16px;}
.legend{display:flex;flex-wrap:wrap;gap:10px;margin-top:14px;font-size:12px;color:var(--muted);}
.legend span{display:inline-flex;align-items:center;gap:5px;}
.dot{width:8px;height:8px;border-radius:50%;}

.table-wrap{background:var(--surface);border:1px solid var(--border);border-radius:12px;overflow:hidden;}
.table-head{display:flex;justify-content:space-between;align-items:center;padding:16px 20px;border-bottom:1px solid var(--border);gap:12px;flex-wrap:wrap;}
.table-head h3{font-family:var(--font-display);font-size:15px;margin:0;}
.filters{display:flex;gap:8px;flex-wrap:wrap;}
.filters input,.filters select{border:1px solid var(--border);border-radius:7px;padding:7px 10px;font-size:13px;font-family:var(--font-body);}
.table-scroll{overflow-x:auto;}
table{width:100%;border-collapse:collapse;font-size:13.5px;}
th{text-align:left;padding:10px 20px;color:var(--muted);font-weight:600;font-size:11.5px;text-transform:uppercase;letter-spacing:.03em;background:var(--surface-2);font-family:var(--font-mono);white-space:nowrap;}
td{padding:12px 20px;border-top:1px solid var(--border);vertical-align:top;}
.cust-name{font-weight:700;margin:0;}
.cust-sub{color:var(--muted);font-size:12px;margin:2px 0 0;}
.ref-mono{font-family:var(--font-mono);font-weight:700;font-size:12.5px;}
.status-pill{font-size:11.5px;font-weight:700;padding:3px 10px;border-radius:999px;display:inline-block;border:none;cursor:pointer;font-family:inherit;}
.status-pending{background:var(--amber-light);color:var(--amber);}
.status-confirmed{background:var(--teal-light);color:var(--teal);}
.status-declined{background:var(--red-light);color:var(--red);}
.status-in_progress{background:#EBE3FA;color:#6B3FD4;}
.status-completed{background:var(--green-light);color:var(--green);}
.status-cancelled{background:var(--red-light);color:var(--red);}
.empty-row td{text-align:center;color:var(--muted);padding:34px 20px;}
.row-actions{display:flex;gap:6px;}
.icon-btn{width:30px;height:30px;border-radius:7px;border:1px solid var(--border);background:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:border-color .15s,background .15s;}
.icon-btn:hover{border-color:var(--border-strong);background:var(--surface-2);}
.icon-btn svg{width:15px;height:15px;stroke:var(--muted);}
.icon-btn i{font-size:13px;color:var(--muted);}
.icon-btn.danger:hover{border-color:var(--red);background:var(--red-light);}
.icon-btn.danger:hover svg{stroke:var(--red);}
.icon-btn.danger:hover i{color:var(--red);}

/* admin modal (reuses .modal-overlay/.modal-box from style.css) */
.admin-modal-box{max-width:640px;}
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px;}
.form-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:18px;padding-top:16px;border-top:1px solid var(--border);}
.toggle-active{display:flex;align-items:center;gap:10px;font-size:13.5px;font-weight:600;margin-top:4px;}

/* login page */
.login-shell{min-height:100vh;display:flex;align-items:center;justify-content:center;background:var(--ink);padding:20px;}
.login-card{background:var(--surface);border-radius:16px;padding:36px 32px;width:100%;max-width:380px;animation:popIn .3s ease;}
.login-card .brand{justify-content:center;margin-bottom:26px;}
.login-card .brand-name{color:var(--ink);}
.login-card h1{font-family:var(--font-display);font-size:20px;text-align:center;margin:0 0 4px;}
.login-card p.hint{text-align:center;color:var(--muted);font-size:13px;margin:0 0 24px;}
.login-error{background:var(--red-light);color:var(--red);font-size:13px;padding:10px 12px;border-radius:8px;margin-bottom:16px;display:none;}
.login-error.show{display:block;animation:fadeUp .2s ease;}
.demo-note{margin-top:18px;text-align:center;font-size:12px;color:var(--muted);}
.demo-note code{background:var(--surface-2);padding:2px 6px;border-radius:4px;font-family:var(--font-mono);}
.demo-note a{color:var(--muted);text-decoration:underline;text-underline-offset:2px;}
.demo-note a:hover{color:var(--orange-dark);}

@media(max-width:900px){
  .stat-grid,.panel-grid{grid-template-columns:1fr;}
  .form-grid{grid-template-columns:1fr;}
}
@media(max-width:760px){
  /* The sidebar (and, on the garage dashboard, the hamburger menu) is
     replaced by a fixed bottom tab bar below — see .admin-tabbar further
     down — so both are hidden here rather than left as a second, redundant
     nav. .topbar--app reuses the same modifier booking/account/track pages
     use in style.css for the same purpose, just at admin's own 760px
     breakpoint instead of that one's 640px, so there's no window where
     both the old nav and the new tab bar show at once. */
  :root{--admin-tabbar-h:calc(60px + env(safe-area-inset-bottom,0px));}
  .admin-shell{flex-direction:column;}
  .sidebar{display:none;}
  .topbar--app .topbar-toggle,.topbar--app .topbar-links{display:none;}
  .admin-main{padding:18px 16px calc(18px + var(--admin-tabbar-h));}
  table{font-size:12.5px;}
  th,td{padding:10px 12px;}

  /* Stat cards become a horizontally-swipeable row instead of a stack
     of full-width cards — the stack ate a whole screen of scrolling
     before you reached the actual table on some pages (up to 6 cards
     on the garage dashboard). This also neutralizes the inline
     grid-template-columns some pages set on .stat-grid (e.g.
     repeat(6,1fr)), since a flex row ignores that property entirely —
     those were rendering as 4-6 cramped columns on an actual phone
     screen before this rule existed, not the single stacked column
     the 900px breakpoint above intended. Cards bleed to the screen
     edges (negative margin matching .admin-main's own padding) with
     the next card peeking in, a plain visual cue that there's more to
     scroll to. */
  .stat-grid{
    display:flex;overflow-x:auto;scroll-snap-type:x mandatory;
    -webkit-overflow-scrolling:touch;gap:12px;
    margin:0 -16px 6px;padding:2px 16px 12px;scrollbar-width:none;
  }
  .stat-grid::-webkit-scrollbar{display:none;}
  .stat-card{scroll-snap-align:start;flex:0 0 154px;}
  .stat-dots{display:flex;justify-content:center;gap:6px;margin:0 0 18px;}
  .stat-dot{width:6px;height:6px;border-radius:50%;background:var(--border-strong);border:none;padding:0;cursor:pointer;-webkit-tap-highlight-color:transparent;transition:width .15s,background .15s;}
  .stat-dot.active{background:var(--orange);width:16px;border-radius:3px;}

  /* Card layout for data tables: a wide multi-column table is either
     cramped or requires horizontal scrolling on a phone — neither is
     great. Below this width, each row becomes its own card with
     label/value pairs stacked vertically instead. Driven by a
     data-label attribute on each <td>; tables that don't set one just
     silently keep working (attr() on a missing attribute is an empty
     string, not an error), so this degrades gracefully. */
  .table-scroll{overflow-x:visible;}
  table.card-table{border-spacing:0;}
  table.card-table thead{display:none;}
  table.card-table, table.card-table tbody, table.card-table tr, table.card-table td{display:block;width:100%;}
  table.card-table{padding:12px;}
  table.card-table tr{background:var(--surface);border:1px solid var(--border);border-radius:10px;padding:14px 16px;margin-bottom:12px;}
  table.card-table tr:last-child{margin-bottom:0;}
  table.card-table td{padding:8px 0;border-bottom:1px solid var(--border);text-align:left;}
  table.card-table td:first-child{padding-top:0;}
  table.card-table td:last-child{border-bottom:none;padding-bottom:0;}
  table.card-table td::before{content:attr(data-label);display:block;font-family:var(--font-mono);font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.05em;color:var(--muted);margin-bottom:5px;}
  table.card-table tr.empty-row{background:none;border:none;padding:0;}
  table.card-table tr.empty-row td{border:none;text-align:center;padding:34px 20px;}
  table.card-table tr.empty-row td::before{content:none;}
  table.card-table .row-actions{flex-wrap:wrap;}

  /* Collapsed by default: only fields marked card-summary show, so more
     rows fit on screen at once. Tapping anywhere on the card (outside an
     actual interactive control) reveals every field — handled by a
     single delegated listener in ui-helpers.js, so this works on every
     card-table automatically without per-page wiring. */
  table.card-table tbody tr:not(.empty-row){position:relative;cursor:pointer;padding-right:36px;}
  table.card-table tbody tr:not(.empty-row)::after{
    content:'▾';position:absolute;top:16px;right:16px;color:var(--muted);
    font-size:13px;line-height:1;transition:transform .15s ease;pointer-events:none;
  }
  table.card-table tbody tr.expanded::after{transform:rotate(180deg);}
  table.card-table td{display:none;}
  table.card-table td.card-summary{display:block;}
  table.card-table tr.expanded td{display:block;}
  table.card-table tr:not(.expanded) td.card-summary:last-of-type{border-bottom:none;padding-bottom:0;}

  /* ---------- bottom tab bar (admin + garage app-shell nav) ----------
     Same treatment as the customer-facing booking/account/track pages:
     a fixed row of icon tabs replaces the sidebar (admin) or the
     hamburger's links (garage) as primary mobile nav. Admin has more
     destinations than fit in a tab bar, so a "More" tab opens the
     remaining ones in a bottom sheet (reusing .modal-overlay/.modal-box
     from style.css) rather than cramming in a 6th or 7th icon. */
  .admin-tabbar{
    display:flex;position:fixed;left:0;right:0;bottom:0;z-index:35;
    background:var(--ink);border-top:1px solid rgba(255,255,255,.08);
    padding:7px 4px calc(7px + env(safe-area-inset-bottom,0px));
    box-shadow:0 -2px 16px rgba(0,0,0,.18);
  }
  .admin-tabbar-item{
    flex:1;display:flex;flex-direction:column;align-items:center;gap:3px;
    text-decoration:none;color:#82868F;padding:5px 2px 4px;border-radius:12px;
    background:none;border:none;font-family:inherit;cursor:pointer;
    -webkit-tap-highlight-color:transparent;transition:color .15s,transform .1s;
  }
  .admin-tabbar-item i{font-size:18px;line-height:1;transition:transform .15s;}
  .admin-tabbar-item span{font-size:10px;font-weight:700;font-family:var(--font-mono);letter-spacing:.02em;}
  .admin-tabbar-item:active{transform:scale(.93);background:rgba(255,255,255,.06);}
  .admin-tabbar-item.active{color:#fff;}
  .admin-tabbar-item.active i{color:var(--orange);transform:translateY(-1px);}
  /* Garage dashboard's own Bookings/Commissions pill buttons become
     redundant once the bottom tab bar covers the same switch. */
  .view-tabs{display:none;}

  .more-sheet-group-label{font-family:var(--font-mono);font-size:10.5px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin:14px 0 4px 6px;}
  .more-sheet-group-label:first-child{margin-top:0;}
  .more-sheet-item{display:flex;align-items:center;gap:14px;padding:13px 6px;border-radius:12px;text-decoration:none;color:var(--ink);font-size:14.5px;font-weight:600;transition:background .1s;}
  .more-sheet-item:active{background:var(--surface-2);}
  .more-sheet-item i{width:20px;text-align:center;color:var(--muted);font-size:15px;flex-shrink:0;}
  .more-sheet-item.danger{color:var(--red);}
  .more-sheet-item.danger i{color:var(--red);}
  .more-sheet-divider{border-top:1px solid var(--border);margin:10px 0;}
}
