/* ==========================================================================
   Main Street — design system
   Black ground, warm bone/silver type (from the logo), measured purple accent.
   Brand values below are overridden at runtime from Settings → Branding.
   ========================================================================== */

:root {
  --bg: #0a0a0b;
  --bg-2: #0f0f11;
  --surface: #141416;
  --surface-2: #1a1a1d;
  --surface-3: #222226;
  --line: rgba(236, 229, 216, 0.08);
  --line-2: rgba(236, 229, 216, 0.14);
  --line-3: rgba(236, 229, 216, 0.24);

  --text: #ece5d8;
  --text-2: #a8a197;
  --text-3: #6e6962;
  --text-inv: #0a0a0b;

  --accent: #8b5cf6;
  --accent-2: #a78bfa;
  --accent-soft: rgba(139, 92, 246, 0.14);
  --accent-line: rgba(139, 92, 246, 0.45);
  --on-accent: #ffffff;

  --ok: #9ae6b4;
  --warn: #f6d58b;
  --danger: #f2a0a0;
  --danger-soft: rgba(242, 160, 160, 0.12);

  --font-head: 'Montserrat', 'Helvetica Neue', Arial, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --r-xl: 26px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 30px 80px rgba(0, 0, 0, 0.6);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --t: 180ms var(--ease);

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg, video { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--accent); color: #fff; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }

/* ---------- Typography ---------- */
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; line-height: 1.1; margin: 0; letter-spacing: -0.01em; }
.display { font-size: clamp(2.4rem, 6vw, 5.2rem); font-weight: 600; letter-spacing: -0.02em; line-height: 1.02; }
.h1 { font-size: clamp(2rem, 4.2vw, 3.4rem); }
.h2 { font-size: clamp(1.6rem, 3vw, 2.4rem); }
.h3 { font-size: 1.25rem; }
.h4 { font-size: 1.05rem; }
.eyebrow {
  font-family: var(--font-head); font-size: 0.72rem; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.32em; color: var(--text-2);
}
.eyebrow.accent { color: var(--accent-2); }
.wordmark { font-family: var(--font-head); font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; }
.serif { font-family: var(--font-serif); font-weight: 400; }
.lead { font-size: 1.12rem; color: var(--text-2); max-width: 60ch; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.75rem; }
.num { font-variant-numeric: tabular-nums; }
.accent-text { color: var(--accent-2); }
.rule { display: flex; align-items: center; gap: 16px; }
.rule::before, .rule::after { content: ''; flex: 1; height: 1px; background: var(--line-3); }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding-inline: 20px; }
.container.narrow { max-width: 760px; }
.stack > * + * { margin-top: var(--gap, 16px); }
.row { display: flex; align-items: center; gap: var(--gap, 12px); }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: var(--gap, 16px); }
.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)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(var(--min, 240px), 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; } .grid-4.keep-2, .grid-3.keep-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; } .mt-4 { margin-top: 40px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.w-full { width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface-2); --btn-fg: var(--text); --btn-bd: var(--line-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: 999px; border: 1px solid var(--btn-bd);
  background: var(--btn-bg); color: var(--btn-fg);
  font-family: var(--font-head); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase;
  transition: background var(--t), border-color var(--t), color var(--t), transform var(--t), box-shadow var(--t);
  white-space: nowrap; user-select: none; -webkit-tap-highlight-color: transparent;
}
.btn:hover { --btn-bd: var(--line-3); background: var(--surface-3); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn[disabled], .btn.is-loading { opacity: .55; pointer-events: none; }
.btn.primary { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-bd: var(--accent); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); box-shadow: 0 8px 30px var(--accent-soft); }
.btn.light { --btn-bg: var(--text); --btn-fg: var(--text-inv); --btn-bd: var(--text); }
.btn.light:hover { background: #fff; }
.btn.ghost { --btn-bg: transparent; --btn-bd: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.outline { --btn-bg: transparent; }
.btn.danger { --btn-fg: var(--danger); --btn-bd: rgba(242,160,160,.3); --btn-bg: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { min-height: 34px; padding: 0 14px; font-size: 0.7rem; }
.btn.lg { min-height: 54px; padding: 0 30px; font-size: 0.84rem; }
.btn.block { width: 100%; }
.btn.icon { width: 40px; min-height: 40px; padding: 0; border-radius: 50%; }
.btn.icon.sm { width: 32px; min-height: 32px; }
.btn.is-loading::after { content: ''; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { color: var(--accent-2); border-bottom: 1px solid transparent; transition: border-color var(--t); }
.link:hover { border-color: currentColor; }
.icon-svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .label { font-size: 0.72rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.14em; color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 11px 14px; border-radius: var(--r);
  background: var(--bg-2); border: 1px solid var(--line-2); color: var(--text);
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
  font-size: 16px; /* prevents iOS zoom */
}
.input.sm, .select.sm { min-height: 36px; padding: 6px 10px; font-size: 14px; border-radius: var(--r-sm); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23a8a197' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px; }
.input[type="color"] { padding: 4px; width: 56px; cursor: pointer; }
.input[type="date"], .input[type="time"], .input[type="datetime-local"] { color-scheme: dark; }
.field-hint { font-size: 0.8rem; color: var(--text-3); }
.field-error { font-size: 0.82rem; color: var(--danger); }
.form-error { padding: 12px 14px; border-radius: var(--r); background: var(--danger-soft); color: var(--danger); font-size: .9rem; }
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: .92rem; }
.check input { appearance: none; width: 20px; height: 20px; border-radius: 6px; border: 1px solid var(--line-3); background: var(--bg-2); display: grid; place-items: center; transition: var(--t); flex: none; margin: 0; }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ''; width: 10px; height: 6px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 12px; cursor: pointer; font-size: .92rem; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--line-2); position: relative; transition: var(--t); margin: 0; flex: none; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--text-2); transition: var(--t); }
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::after { left: 20px; background: #fff; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--r) 0 0 var(--r); }
.input-group .addon { display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--line-2); border-left: 0; border-radius: 0 var(--r) var(--r) 0; color: var(--text-2); background: var(--surface); font-size: .9rem; }

/* ---------- Cards / surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; }
.card.flat { background: transparent; }
.card.pad-sm { padding: 14px; }
.card.pad-0 { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-title { font-family: var(--font-head); font-size: 0.78rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-2); font-weight: 500; }
.hover-lift { transition: transform var(--t), border-color var(--t), background var(--t); }
.hover-lift:hover { transform: translateY(-2px); border-color: var(--line-3); }
.divider { height: 1px; background: var(--line); margin: 18px 0; border: 0; }

/* Stat tiles */
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat-label { font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-2); }
.stat-value { font-family: var(--font-head); font-size: clamp(1.5rem, 2.4vw, 2rem); font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat-value.accent { color: var(--accent-2); }
.stat-sub { font-size: 0.8rem; color: var(--text-3); }
.meter { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 600ms var(--ease); }
.meter.light > i { background: var(--text); }

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 99px;
  font-size: 0.7rem; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.accent { background: var(--accent-soft); color: var(--accent-2); border-color: var(--accent-line); }
.badge.light { background: var(--text); color: var(--text-inv); border-color: var(--text); }
.chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 16px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line-2); color: var(--text-2); font-size: 0.88rem;
  transition: var(--t); cursor: pointer; user-select: none; white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--line-3); }
.chip.active, .chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips.scroll::-webkit-scrollbar { display: none; }

/* Segmented control */
.segmented { display: inline-flex; padding: 3px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line-2); }
.segmented button { min-height: 32px; padding: 0 14px; border-radius: 99px; font-size: 0.78rem; color: var(--text-2); transition: var(--t); white-space: nowrap; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--text); color: var(--text-inv); font-weight: 600; }

/* Avatar */
.avatar {
  --size: 40px; width: var(--size); height: var(--size); border-radius: 50%; flex: none; overflow: hidden;
  background: linear-gradient(145deg, var(--surface-3), var(--surface)); border: 1px solid var(--line-2);
  display: grid; place-items: center; font-family: var(--font-head); font-weight: 600; font-size: calc(var(--size) * 0.36);
  color: var(--text); letter-spacing: 0.04em; object-fit: cover;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { --size: 64px; } .avatar.xl { --size: 96px; } .avatar.sm { --size: 30px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; font-size: 0.68rem; font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-3); padding: 14px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--bg-2); position: sticky; top: 0; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--t); }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr:hover { background: rgba(236,229,216,0.025); }
.table .r { text-align: right; }
.table input.input { min-height: 36px; padding: 6px 10px; font-size: 14px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button, .tabs a { padding: 12px 14px; font-size: 0.82rem; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; transition: var(--t); }
.tabs button:hover, .tabs a:hover { color: var(--text); }
.tabs .active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 900; opacity: 0; transition: opacity 200ms var(--ease); }
.overlay.open { opacity: 1; }
.modal {
  position: fixed; left: 50%; top: 50%; z-index: 901; width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg); transform: translate(-50%, -48%) scale(.98); opacity: 0; transition: transform 220ms var(--ease), opacity 220ms var(--ease);
}
.modal.wide { width: min(860px, calc(100vw - 32px)); }
.modal.open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 22px 12px; }
.modal-title { font-family: var(--font-head); font-size: 1.1rem; font-weight: 600; }
.modal-body { padding: 8px 22px 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 22px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
/* Bottom sheet on phones */
@media (max-width: 640px) {
  .modal { left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-height: 92dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; transform: translateY(100%); padding-bottom: var(--safe-b); }
  .modal.wide { width: 100%; }
  .modal.open { transform: translateY(0); }
  .modal::before { content: ''; width: 40px; height: 4px; border-radius: 4px; background: var(--line-3); margin: 10px auto 0; flex: none; }
  .modal-foot .btn { flex: 1; }
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 901; width: min(520px, 100vw); background: var(--surface);
  border-left: 1px solid var(--line-2); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 260ms var(--ease);
}
.drawer.open { transform: none; }
.drawer .modal-body { flex: 1; }
@media (max-width: 640px) { .drawer { top: auto; height: 94dvh; width: 100%; border-left: 0; border-radius: var(--r-xl) var(--r-xl) 0 0; transform: translateY(100%); padding-bottom: var(--safe-b); } .drawer.open { transform: none; } }

/* Toasts */
.toasts { position: fixed; z-index: 1000; left: 50%; transform: translateX(-50%); bottom: calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(420px, calc(100vw - 32px)); }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: center; padding: 12px 18px; border-radius: 99px; background: var(--text); color: var(--text-inv); font-size: .9rem; font-weight: 500; box-shadow: var(--shadow); animation: toastIn 260ms var(--ease); max-width: 100%; }
.toast.error { background: #2a1414; color: var(--danger); border: 1px solid rgba(242,160,160,.3); }
.toast.accent { background: var(--accent); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ---------- Loading ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; border-radius: var(--r); min-height: 16px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-3); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.loading-block { display: grid; place-items: center; padding: 60px 0; }
.empty { text-align: center; padding: 48px 20px; color: var(--text-2); }
.empty .icon-svg { width: 34px; height: 34px; margin: 0 auto 12px; color: var(--text-3); }
.fade-in { animation: fadeIn 380ms var(--ease) both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } }
.reveal { opacity: 0; transform: translateY(18px); transition: opacity 700ms var(--ease), transform 700ms var(--ease); }
.reveal.in { opacity: 1; transform: none; }

/* ---------- Misc ---------- */
.kbd { font-family: ui-monospace, Menlo, monospace; font-size: .8em; padding: 2px 6px; border-radius: 5px; background: var(--surface-3); border: 1px solid var(--line-2); }
.list { list-style: none; padding: 0; margin: 0; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.dot-sep::before { content: '·'; margin: 0 8px; color: var(--text-3); }
.scroll-y { overflow-y: auto; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.stat-value { white-space: nowrap; }
@media (max-width: 480px) { .stat-value { font-size: 1.35rem; } }
