/* ==========================================================================
   RunLap Ops Hub — style.css
   Production styles. Adapted from wireframe design tokens.
   No handwritten fonts. Inter + JetBrains Mono only.
   ========================================================================== */

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

/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  /* Colours */
  --ink:        #1a1a1a;
  --ink-2:      #444;
  --ink-3:      #777;
  --ink-4:      #aaa;
  --line:       #d4cfc7;
  --line-soft:  #e4e0d8;
  --paper:      #f6f2ea;
  --paper-2:    #efeae0;
  --card:       #fdfbf5;
  --accent:     #BD2027;
  --accent-2:   #A81B21;
  --good:       #2e7d3a;
  --good-bg:    #d9ecd9;
  --warn:       #b08800;
  --warn-bg:    #fff3d6;
  --danger-bg:  #f7dcdd;

  /* Typography */
  --f-sans: 'Inter', system-ui, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* Spacing */
  --radius:    4px;
  --radius-lg: 8px;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

/* Auth guard — body starts hidden, revealed once auth is confirmed */
body.auth-pending { visibility: hidden; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   APP SHELL — Admin/Staff layout (sidebar + content)
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--paper-2);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.3px;
  padding: 2px 6px 14px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 8px;
}

.sidebar-brand .dot {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-brand .sub {
  font-family: var(--f-mono);
  font-size: 9px;
  color: var(--ink-3);
  letter-spacing: .06em;
  font-weight: 400;
  display: block;
  margin-top: 1px;
}

.sidebar-label {
  font-family: var(--f-mono);
  font-size: 9.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-4);
  padding: 12px 6px 4px;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 8px;
  margin: 1px 0;
  border-radius: var(--radius);
  color: var(--ink-2);
  font-size: 13.5px;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background .1s;
}

.sidebar nav a:hover {
  background: rgba(0,0,0,.04);
  color: var(--ink);
  text-decoration: none;
}

.sidebar nav a.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.sidebar nav a .badge {
  font-family: var(--f-mono);
  font-size: 10px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0 5px;
  border-radius: 8px;
  line-height: 1.6;
}

.sidebar nav a.active .badge {
  background: rgba(255,255,255,.15);
  color: var(--paper);
  border-color: transparent;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.sidebar-footer .user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}

.sidebar-footer .user-role {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--ink-3);
  margin-top: 2px;
}

.sidebar-footer .btn-logout {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-3);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: var(--f-sans);
}

.sidebar-footer .btn-logout:hover { color: var(--accent); }

/* Main content area */
.main {
  padding: 28px 32px 80px;
  min-width: 0;
  overflow-x: auto;
}

/* ============================================================
   TOP BAR — Coach/Customer layout (topbar + content)
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.3px;
  text-decoration: none;
  color: var(--ink);
}

.topbar-brand .dot {
  width: 9px;
  height: 9px;
  background: var(--accent);
  border-radius: 50%;
}

.topbar nav {
  display: flex;
  gap: 4px;
}

.topbar nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--ink-2);
  font-size: 13.5px;
  text-decoration: none;
  transition: background .1s;
}

.topbar nav a:hover { background: rgba(0,0,0,.05); color: var(--ink); text-decoration: none; }
.topbar nav a.active { background: var(--ink); color: var(--paper); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
}

.topbar-user .av {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
}

.topbar-content {
  padding: 24px 32px 80px;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  margin-bottom: 24px;
  border-bottom: 1.5px solid var(--line);
  flex-wrap: wrap;
}

.page-head h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 2px;
  letter-spacing: -.3px;
}

.page-head .crumb {
  font-family: var(--f-mono);
  font-size: 10.5px;
  color: var(--ink-3);
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.page-head p {
  margin: 4px 0 0;
  color: var(--ink-2);
  font-size: 13.5px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-family: var(--f-sans);
  font-size: 13px;
  font-weight: 500;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  box-shadow: 2px 2px 0 rgba(0,0,0,.06);
  transition: transform .05s, box-shadow .05s;
  white-space: nowrap;
}

.btn:hover {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 rgba(0,0,0,.06);
  text-decoration: none;
  color: var(--ink);
}

.btn:active { transform: translate(2px, 2px); box-shadow: none; }

.btn.primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  box-shadow: 2px 2px 0 rgba(0,0,0,.15);
}

.btn.red {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-2);
  box-shadow: 2px 2px 0 var(--accent-2);
}

.btn.ghost {
  border-style: dashed;
  box-shadow: none;
  background: transparent;
}

.btn.sm { padding: 4px 10px; font-size: 12px; box-shadow: 1px 1px 0 rgba(0,0,0,.06); }
.btn.xs { padding: 2px 8px; font-size: 11.5px; box-shadow: 1px 1px 0 rgba(0,0,0,.06); }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 5px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 8px 11px;
  font-size: 13.5px;
  font-family: var(--f-sans);
  color: var(--ink);
  outline: none;
  transition: border-color .15s;
  appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--ink-4); }

.form-textarea { resize: vertical; min-height: 80px; }

.form-hint {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 4px;
}

.form-error {
  font-size: 11.5px;
  color: var(--accent);
  margin-top: 4px;
}

/* Alert / error banner */
.alert {
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid;
}

.alert.error   { background: var(--danger-bg); border-color: var(--accent-2); color: var(--accent-2); }
.alert.success { background: var(--good-bg);   border-color: var(--good);     color: #1e5c27; }
.alert.warning { background: var(--warn-bg);   border-color: var(--warn);     color: #6b4f00; }

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th, .table td {
  padding: 9px 10px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line-soft);
}

.table th {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  border-bottom: 1.5px solid var(--line);
  background: var(--paper-2);
  white-space: nowrap;
}

.table tbody tr:hover td { background: rgba(0,0,0,.02); }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--f-mono); font-size: 12px; }
.table td.mono { font-family: var(--f-mono); font-size: 12px; }
.table td.muted { color: var(--ink-3); }

/* ============================================================
   STATUS PILLS
   ============================================================ */
.pill {
  display: inline-block;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  text-transform: uppercase;
  white-space: nowrap;
}

.pill.draft     { background: var(--paper-2);    color: var(--ink-3);  border-color: var(--line-soft); }
.pill.issued    { background: var(--warn-bg);     color: #6b4f00;       border-color: var(--warn); }
.pill.paid      { background: var(--good-bg);     color: #1e5c27;       border-color: var(--good); }
.pill.void      { background: #eee;               color: var(--ink-3);  text-decoration: line-through; }
.pill.pending   { background: var(--paper-2);     color: var(--ink-3);  border-color: var(--line-soft); }
.pill.confirmed { background: var(--good-bg);     color: #1e5c27;       border-color: var(--good); }
.pill.cancelled { background: #eee;               color: var(--ink-3);  text-decoration: line-through; }
.pill.approved  { background: var(--good-bg);     color: #1e5c27;       border-color: var(--good); }
.pill.rejected  { background: var(--danger-bg);   color: var(--accent-2); border-color: var(--accent-2); }
.pill.open      { background: #dff0ff;            color: #0a4a7a;       border-color: #5aa0d0; }
.pill.closed    { background: #eee;               color: var(--ink-3);  border-color: var(--line-soft); }
.pill.red       { background: var(--danger-bg);   color: var(--accent-2); border-color: var(--accent-2); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  border: 1.5px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--card);
  padding: 14px 16px;
}

.card-label {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 4px;
}

.card-value {
  font-size: 26px;
  font-weight: 600;
  line-height: 1;
  margin: 4px 0;
  letter-spacing: -.5px;
}

.card-sub {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 2px;
}

/* Stat card grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

/* ============================================================
   ROLE CHIPS
   ============================================================ */
.role-chip {
  display: inline-block;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  vertical-align: 1px;
}

.role-chip.coach      { background: #2a4d8f; }
.role-chip.customer   { background: #2e7d3a; }
.role-chip.accountant { background: #8a5200; }
.role-chip.staff      { background: #444; }
.role-chip.public     { background: #888; }

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.mono  { font-family: var(--f-mono); }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.tiny  { font-size: 11px; }
.right { text-align: right; }
.bold  { font-weight: 600; }
.good  { color: var(--good); }
.red   { color: var(--accent); }

.stack { display: flex; flex-direction: column; gap: 8px; }
.row   { display: flex; align-items: center; gap: 10px; }
.row.gap-sm { gap: 6px; }
.row.gap-lg { gap: 16px; }
.row.wrap   { flex-wrap: wrap; }
.between    { justify-content: space-between; }
.grow       { flex: 1; min-width: 0; }

.divider {
  border: none;
  border-top: 1px solid var(--line-soft);
  margin: 20px 0;
}

/* Bilingual label */
.zh {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--accent);
  border: 1px dashed var(--accent);
  padding: 0 4px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: 1px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-3);
  font-size: 13.5px;
}

.empty-state .empty-icon {
  font-size: 28px;
  margin-bottom: 10px;
  opacity: .4;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}

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

/* ============================================================
   HAMBURGER TOGGLE — hidden on desktop
   ============================================================ */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 36px;
  height: 36px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
  box-shadow: 1px 1px 0 rgba(0,0,0,.08);
}

.sidebar-toggle span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}

.sidebar-toggle.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.sidebar-toggle.open span:nth-child(2) { opacity: 0; }
.sidebar-toggle.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 149;
}

.sidebar-overlay.visible { display: block; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar-toggle {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 240px;
    z-index: 150;
    transform: translateX(-100%);
    transition: transform .25s ease;
    border-right: 1px solid var(--line);
    box-shadow: 4px 0 16px rgba(0,0,0,.12);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    padding: 60px 16px 60px;
  }

  .topbar-content { padding: 20px 16px 60px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: flex-start; }
}
