/* Staff app styles (admin, agency, business, staff screens, client reports) */
:root {
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --accent: #f59e0b;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e4e7ee;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info-bg: #e0e7ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
img { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; } .mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }

/* Shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: #111827; color: #d1d5db; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 700; font-size: 1.1rem; padding: .25rem .5rem 1rem; }
.sidebar .brand img { max-height: 32px; max-width: 120px; }
.sidebar nav a { display: block; color: #d1d5db; padding: .5rem .75rem; border-radius: 8px; margin-bottom: 2px; }
.sidebar nav a:hover { background: #1f2937; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar .nav-label { text-transform: uppercase; font-size: .7rem; letter-spacing: .08em; color: #6b7280; margin: 1rem .75rem .35rem; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .who { color: var(--muted); font-size: .9rem; }
.content { padding: 1.5rem; max-width: 1200px; }
.menu-toggle { display: none; background: none; border: 0; font-size: 1.5rem; cursor: pointer; }
.impersonation-bar { background: #b91c1c; color: #fff; padding: .5rem 1.5rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.impersonation-bar button { background: #fff; color: #b91c1c; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; width: 250px; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-toggle { display: block; }
  .content { padding: 1rem; }
}

/* Page header */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin-top: .25rem; }
.breadcrumbs { font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }
.breadcrumbs a { color: var(--muted); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Cards and grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .75rem; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.stat .hint { color: var(--muted); font-size: .8rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfd; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #fafbff; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* Forms */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }
.field .help { color: var(--muted); font-size: .82rem; margin-top: .25rem; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=tel],
input[type=date], input[type=datetime-local], input[type=search], input[type=color], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid #cfd4de; border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input[type=color] { padding: .2rem; height: 2.4rem; width: 4rem; }
textarea { min-height: 6rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
.check { display: flex; gap: .5rem; align-items: flex-start; font-weight: 400; }
.check input { margin-top: .25rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > .field { flex: 1 1 200px; }
.inline-form { display: inline; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .4rem; }
.error-text { color: var(--bad); font-size: .85rem; }

/* Buttons */
.btn, button { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; background: var(--brand); color: var(--brand-ink); text-decoration: none; line-height: 1.2; }
.btn:hover, button:hover { filter: brightness(1.06); text-decoration: none; }
.btn:disabled, button:disabled { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--ink); border-color: #cfd4de; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-link { background: none; color: var(--brand); padding: 0; border: 0; font-weight: 500; }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1.05rem; }
.btn-block { width: 100%; }

/* Badges and alerts */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eef0f4; color: #374151; text-transform: capitalize; white-space: nowrap; }
.badge-active, .badge-approved, .badge-verified, .badge-redeemed, .badge-sent, .badge-ok, .badge-granted, .badge-claimed, .badge-finalized, .badge-delivered, .badge-cleared { background: var(--ok-bg); color: var(--ok); }
.badge-draft, .badge-pending, .badge-scheduled, .badge-trial, .badge-queued, .badge-preview, .badge-issued, .badge-selected, .badge-notified { background: var(--info-bg); color: #3730a3; }
.badge-paused, .badge-open, .badge-flagged, .badge-warn, .badge-alternate, .badge-dev_blocked { background: var(--warn-bg); color: var(--warn); }
.badge-ended, .badge-archived, .badge-expired, .badge-void, .badge-inactive, .badge-none, .badge-cancelled { background: #eef0f4; color: #4b5563; }
.badge-suspended, .badge-blocked, .badge-rejected, .badge-failed, .badge-disqualified, .badge-confirmed, .badge-forfeited, .badge-revoked, .badge-suppressed, .badge-bad { background: var(--bad-bg); color: var(--bad); }
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: #14532d; border-color: #bbf7d0; }
.alert-error { background: var(--bad-bg); color: #7f1d1d; border-color: #fecaca; }
.alert-info { background: var(--info-bg); color: #312e81; border-color: #c7d2fe; }
.alert-warn { background: var(--warn-bg); color: #713f12; border-color: #fde68a; }

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; overflow-x: auto; }
.tabs a { padding: .6rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }

/* Toasts */
#toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 1000; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: #111827; color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { background: var(--bad); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17, 24, 39, .5); display: flex; align-items: center; justify-content: center; z-index: 900; padding: 1rem; }
.modal { background: #fff; border-radius: var(--radius); max-width: 520px; width: 100%; padding: 1.5rem; box-shadow: 0 20px 50px rgba(0,0,0,.25); max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-top: 0; }
.modal .actions { justify-content: flex-end; margin-top: 1rem; }

/* Auth pages */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .logo { text-align: center; font-size: 1.6rem; font-weight: 800; margin-bottom: 1rem; color: var(--brand); }
.narrow { max-width: 560px; margin: 3rem auto; padding: 0 1rem; }

/* Misc components */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.list-plain li:last-child { border-bottom: 0; }
.checklist li { display: flex; gap: .5rem; align-items: center; }
.checklist .ok { color: var(--ok); } .checklist .no { color: var(--bad); }
.pill-choice { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.choice-card { border: 2px solid var(--line); border-radius: var(--radius); padding: 1rem; background: #fff; cursor: pointer; display: block; color: inherit; }
.choice-card:hover { border-color: var(--brand); text-decoration: none; }
.choice-card h3 { margin-bottom: .3rem; }
.swatch { display: inline-block; width: 1rem; height: 1rem; border-radius: 4px; vertical-align: middle; border: 1px solid rgba(0,0,0,.1); }
.thumb { width: 48px; height: 48px; object-fit: contain; border-radius: 6px; background: #f3f4f6; }
.copy-field { display: flex; gap: .5rem; }
.copy-field input { flex: 1; }
.sortable-handle { cursor: grab; color: var(--muted); }
.task-row { display: flex; align-items: center; gap: .75rem; }
.bar { height: 8px; background: #eef0f4; border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.split { display: grid; grid-template-columns: 380px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }
.preview-frame-wrap { background: #e5e7eb; border-radius: var(--radius); padding: 1rem; display: flex; justify-content: center; position: sticky; top: 1rem; }
.preview-frame-wrap iframe { border: 0; background: #fff; border-radius: 8px; box-shadow: var(--shadow); width: 100%; height: 80vh; transition: width .2s; }
.preview-frame-wrap.mobile iframe { width: 390px; }
.timeline { border-left: 2px solid var(--line); padding-left: 1rem; }
.timeline .item { margin-bottom: .75rem; }
.timeline .when { color: var(--muted); font-size: .8rem; }
.heatmap td { width: 2.2rem; height: 1.6rem; text-align: center; font-size: .7rem; }
.chart { width: 100%; }

/* Staff screen (mobile-first) */
.staff-screen { max-width: 640px; margin: 0 auto; padding: 1rem; }
.staff-screen .big-input { font-size: 1.2rem; padding: .8rem; }
.scanner-box { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 1 / 1; max-height: 60vh; margin: 0 auto 1rem; }
.scanner-box video { width: 100%; height: 100%; object-fit: cover; }
.scanner-box .frame { position: absolute; inset: 15%; border: 3px solid rgba(255,255,255,.8); border-radius: 12px; }
.pin-display { font-size: 4rem; font-weight: 800; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }

/* Print */
@media print {
  .sidebar, .topbar, .no-print, .impersonation-bar { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
