/* Ninso App — mobile first.
   The floor staff live on a 390px phone; the owners occasionally open a laptop.
   So the phone layout is the base and the desktop sidebar is the enhancement,
   not the other way round. Breakpoint: 1024px. */

:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #99a0ad;
  --accent: #7c5cff;
  --accent-2: #36c5a8;
  --warn: #ffb02e;
  --bad: #ff5d5d;
  --ok: #36c5a8;
  --radius: 12px;
  --tabbar-h: 58px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; text-decoration: none; }

/* ── sidebar: desktop only ─────────────────────────────────────────────── */
.sidebar { display: none; }

@media (min-width: 1024px) {
  .sidebar {
    display: flex; flex-direction: column;
    width: 220px; flex-shrink: 0; background: var(--panel);
    border-right: 1px solid var(--border); height: 100vh; position: sticky; top: 0;
    padding: 18px 12px;
  }
  .brand { font-size: 20px; font-weight: 700; padding: 6px 10px 18px; }
  .brand span { color: var(--accent); }
  .sidebar nav { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
  .sidebar nav a {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px;
    border-radius: 9px; color: var(--muted); font-size: 14px;
  }
  .sidebar nav a:hover { background: var(--panel-2); color: var(--text); }
  .sidebar nav a.active { background: var(--accent); color: #fff; }
  .sidebar nav a .ico { width: 18px; text-align: center; }
  .sidebar-foot { margin-top: auto; font-size: 11px; color: var(--muted); padding: 10px; }
}

/* ── bottom tab bar: mobile only ───────────────────────────────────────── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--panel); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; color: var(--muted); font-size: 10.5px; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.tabbar a .ico { font-size: 19px; line-height: 1; }
.tabbar a.active { color: var(--accent); }
@media (min-width: 1024px) { .tabbar { display: none; } }

/* ── main column ───────────────────────────────────────────────────────── */
.main {
  flex: 1; min-width: 0;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
}
@media (min-width: 1024px) { .main { padding-bottom: 0; } }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
  background: rgba(15, 17, 21, .9); backdrop-filter: blur(6px);
}
.topbar h1 { font-size: 17px; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.current-user { font-size: 12px; color: var(--muted); max-width: 9ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.health { font-size: 12px; color: var(--muted); display: none; }
.health.ok { color: var(--ok); }
.health.bad { color: var(--bad); }
@media (min-width: 1024px) {
  .topbar { padding: 18px 28px; }
  .topbar h1 { font-size: 20px; }
  .health { display: inline; }
  .current-user { max-width: none; }
}

.view { padding: 16px 14px 40px; }
@media (min-width: 1024px) { .view { padding: 24px 28px 60px; } }
.loading { color: var(--muted); padding: 40px 0; }
.error-box { background: #3a1d1d; border: 1px solid var(--bad); color: #ffd5d5; padding: 12px 14px; border-radius: var(--radius); font-size: 13.5px; }

/* ── login ─────────────────────────────────────────────────────────────── */
.auth-body { display: flex; align-items: center; justify-content: center; padding: 24px; min-height: 100vh; }
.auth-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 26px 22px 24px; }
.auth-brand { font-size: 26px; font-weight: 700; text-align: center; }
.auth-brand span { color: var(--accent); }
.auth-sub { text-align: center; font-size: 12px; color: var(--muted); margin: 4px 0 22px; }
.auth-note { font-size: 13px; color: var(--warn); margin: 0 0 16px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.btn.block { width: 100%; padding: 13px; font-size: 15px; }

/* ── cards / KPI ───────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card + .card { margin-top: 12px; }
.kpi .kpi-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .kpi-value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi .kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── section heading + buttons ─────────────────────────────────────────── */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 12px; }
.section-head h2 { font-size: 15.5px; margin: 0; }
.btn {
  background: var(--accent); color: #fff; border: none; padding: 10px 15px; border-radius: 9px;
  font-size: 14px; cursor: pointer; font-weight: 600; min-height: 40px; /* thumb-sized */
  font-family: inherit;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .55; cursor: default; filter: none; }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn.small { padding: 6px 11px; font-size: 12.5px; min-height: 32px; }
.btn.primary-big { width: 100%; padding: 20px; font-size: 19px; border-radius: 14px; }

/* ── tables → cards on mobile ──────────────────────────────────────────── */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; padding: 11px 14px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); word-break: break-word; overflow-wrap: break-word; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* crudtable's card mode: one card per row, label/value pairs. */
.record-list { display: flex; flex-direction: column; gap: 10px; }
.record-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.record-card .rc-field { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 13.5px; }
.record-card .rc-label { color: var(--muted); flex: none; }
.record-card .rc-value { text-align: right; word-break: break-word; }
.record-card .row-actions { margin-top: 10px; justify-content: flex-end; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }
.pill.ok, .status-pill.approved { background: rgba(54,197,168,.15); color: var(--ok); }
.pill.warn, .status-pill.pending { background: rgba(255,176,46,.15); color: var(--warn); }
.pill.bad, .status-pill.rejected { background: rgba(255,93,93,.15); color: var(--bad); }
.pill.muted { background: var(--panel-2); color: var(--muted); }
.status-pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }

/* ── roster ────────────────────────────────────────────────────────────── */
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.week-nav .week-label { font-weight: 700; font-size: 15px; }
.day-list { display: flex; flex-direction: column; gap: 10px; }
.day-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.day-card.today { border-color: var(--accent); }
.day-card .day-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.day-card .day-name { font-weight: 600; font-size: 14px; }
.shift-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13.5px; border-top: 1px solid var(--border); }
.shift-row:first-of-type { border-top: none; }
.shift-time { font-variant-numeric: tabular-nums; color: var(--muted); flex: none; min-width: 11ch; }
.shift-name { font-weight: 600; }
.shift-row .row-actions { margin-left: auto; }
.day-empty { color: var(--muted); font-size: 13px; padding: 4px 0; }

.flag { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }
.flag.red { background: rgba(255,93,93,.15); color: var(--bad); }
.flag.orange { background: rgba(255,140,46,.15); color: #ff8c2e; }
.flag.yellow { background: rgba(255,214,64,.15); color: #ffd640; }
.flag-banner { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.flag-banner .flag { align-self: flex-start; padding: 8px 12px; font-size: 12.5px; line-height: 1.35; }

/* ── tasks ─────────────────────────────────────────────────────────────── */
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start; }
.task-card.done { opacity: .55; }
.task-card.overdue { border-color: var(--bad); }
.task-main { flex: 1; min-width: 0; }
.task-title { font-weight: 600; font-size: 14.5px; }
.task-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.task-desc { font-size: 13px; margin-top: 6px; color: var(--text); }

/* ── expenses / claims ─────────────────────────────────────────────────── */
.claim-form { display: flex; flex-direction: column; gap: 12px; }
.photo-input { display: flex; flex-direction: column; gap: 8px; }
.photo-preview { max-width: 100%; max-height: 240px; border-radius: 10px; border: 1px solid var(--border); object-fit: contain; background: var(--panel-2); }
.receipt-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); }
.claim-list { display: flex; flex-direction: column; gap: 10px; }
.claim-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 12px; align-items: center; }
.claim-card .claim-main { flex: 1; min-width: 0; }

/* ── cash ──────────────────────────────────────────────────────────────── */
.baseline-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.baseline-card.unlocked { border-color: var(--accent-2); }
.variance-live { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; }
.variance-live.over { color: var(--bad); }
.variance-live.ok { color: var(--ok); }
.ledger-day { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.ledger-list { display: flex; flex-direction: column; gap: 10px; }
.ledger-line { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; padding: 3px 0; }
.ledger-line .lbl { color: var(--muted); }
.ledger-line .val { font-variant-numeric: tabular-nums; }
.ledger-line.closing { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; font-weight: 700; }
.wa-preview { white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; line-height: 1.5; }
@media (min-width: 1024px) { .ledger-list.as-table { display: block; } }

/* ── clock ─────────────────────────────────────────────────────────────── */
.clock-state { text-align: center; margin-bottom: 18px; }
.clock-now { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.clock-btn { width: 100%; padding: 22px; font-size: 20px; border-radius: 16px; font-weight: 700; }
.clock-btn.in { background: var(--accent-2); color: #06231d; }
.clock-btn.out { background: var(--warn); color: #2b1c00; }
.clock-timeline { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.clock-event { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; display: flex; gap: 12px; align-items: center; }
.clock-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.clock-missing { color: var(--bad); }

/* ── forms ─────────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); } }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 11px 12px; border-radius: 9px; font-family: inherit;
  font-size: 16px; /* < 16px makes iOS Safari zoom on focus */
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.form-actions { display: flex; gap: 10px; margin-top: 14px; }
.form-actions .btn { flex: 1; }
@media (min-width: 640px) { .form-actions .btn { flex: none; } }

/* ── dialog ────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
  align-items: flex-end; justify-content: center; z-index: 50;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px 16px 0 0; padding: 20px;
  width: 100%; max-height: 90vh; overflow: auto;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .modal { border-radius: var(--radius); width: min(620px, 92vw); max-height: 88vh; padding-bottom: 20px; } }
.modal h3 { margin: 0 0 16px; font-size: 16px; }

/* ── chart ─────────────────────────────────────────────────────────────── */
.chart-card { height: 280px; }
.chart-card canvas { max-height: 230px; }

/* ── toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 14px; right: 14px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 10px; font-size: 13.5px; text-align: center;
  opacity: 0; transform: translateY(8px); transition: all .25s; z-index: 80;
}
@media (min-width: 640px) { .toast { left: auto; right: 24px; bottom: 24px; max-width: 420px; text-align: left; } }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok { border-color: var(--ok); }
.toast-bad { border-color: var(--bad); }

.muted { color: var(--muted); }
.row-actions { display: flex; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: 1fr 1fr; gap: 18px; } }
