/* REA Hub - one stylesheet for the Hub and its sign-in pages.
   Branding comes from the business: --hub-primary (sidebar, header) and
   --hub-accent (buttons, highlights), set by hub.js from /api/hub/me.
   Mobile first; sidebar layout from 960px. */

:root {
  --hub-primary: #0F2A44;
  --hub-on-primary: #FFFFFF;
  --hub-accent: #1F8A8A;
  --hub-on-accent: #FFFFFF;
  --text: #0B1120;
  --muted: #475569;
  --faint: #64748B;
  --border: #E2E8F0;
  --page: #F4F7FA;
  --card: #FFFFFF;
  --red: #B91C1C;
  --red-bg: #FEF2F2;
  --amber: #B45309;
  --amber-bg: #FFFBEB;
  --green: #15803D;
  --green-bg: #ECFDF5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 17, 32, 0.04), 0 4px 14px rgba(11, 17, 32, 0.04);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45; color: var(--text); background: var(--page); -webkit-font-smoothing: antialiased; }
a { color: var(--hub-accent); }
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
svg.ic { width: 20px; height: 20px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--hub-accent); outline-offset: 2px; }

/* Accent text on white: the accent color can be light, so text uses a darkened mix. */
.accent-text { color: color-mix(in srgb, var(--hub-accent) 75%, #000); }

/* ---------- Frame ---------- */
.hub { min-height: 100dvh; display: flex; flex-direction: column; }
.side { display: none; }
.mobile-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
}
.mobile-bar .logo-box { min-width: 0; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); cursor: pointer; }
.main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 16px 16px 40px; }

.top { display: none; }

/* Logo: uploaded image, or the business name in the brand color */
.logo-box { display: flex; flex-direction: column; gap: 2px; }
.logo-box img { display: block; max-height: 44px; max-width: 200px; object-fit: contain; }
.logo-name { font-weight: 800; font-size: 18px; letter-spacing: -0.01em; color: var(--hub-primary); line-height: 1.15; }
.powered { font-size: 11px; color: var(--faint); letter-spacing: 0.01em; }
.powered b { font-weight: 700; }

/* Drawer (phones) */
.drawer-back { position: fixed; inset: 0; background: rgba(11, 17, 32, 0.45); z-index: 40; display: none; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); z-index: 41; background: var(--hub-primary); color: var(--hub-on-primary); transform: translateX(-100%); transition: transform 0.2s ease; display: flex; flex-direction: column; padding: max(16px, env(safe-area-inset-top)) 12px 16px; }
.drawer-open .drawer { transform: none; }
.drawer-name { font-weight: 700; font-size: 16px; padding: 6px 12px 4px; }
.drawer-open .drawer-back { display: block; }
@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  color: var(--hub-on-primary); text-decoration: none; font-weight: 500; opacity: 0.86;
}
.nav a:hover { opacity: 1; background: color-mix(in srgb, var(--hub-on-primary) 10%, transparent); }
.nav a[aria-current="page"] { opacity: 1; background: var(--hub-accent); color: var(--hub-on-accent); font-weight: 600; }
.side-foot { margin-top: auto; font-size: 12px; opacity: 0.75; padding: 12px; }

@media (min-width: 960px) {
  .hub { flex-direction: row; }
  .mobile-bar, .drawer, .drawer-back { display: none !important; }
  .side { display: flex; flex-direction: column; width: 232px; flex: none; position: sticky; top: 0; height: 100dvh; background: var(--hub-primary); color: var(--hub-on-primary); }
  .side .side-logo { background: var(--card); padding: 18px 16px; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
  .side .nav { padding: 0 12px; margin-top: 16px; }
  .content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .top { display: flex; align-items: center; gap: 16px; background: var(--card); border-bottom: 1px solid var(--border); padding: 12px 28px; min-height: 64px; }
  .top .powered { font-size: 12px; }
  .top .spacer { flex: 1; }
  .main { padding: 24px 28px 48px; }
}

/* Month picker + account chip */
.month { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; padding: 8px 10px; border-radius: 8px; border: 1px solid transparent; background: none; }
.account { position: relative; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 8px 4px 4px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); cursor: pointer; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--hub-primary); color: var(--hub-on-primary); font-size: 12px; font-weight: 700; flex: none; }
.chip .chip-name { font-size: 14px; font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 260px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px rgba(11, 17, 32, 0.14); padding: 8px; }
.menu[hidden] { display: none; }
.menu .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu .who b { display: block; font-size: 14px; }
.menu .who span { font-size: 13px; color: var(--muted); word-break: break-all; }
.menu .label { font-size: 12px; color: var(--faint); padding: 6px 10px 2px; text-transform: uppercase; letter-spacing: 0.04em; }
.menu button, .menu a.item { display: flex; width: 100%; align-items: center; gap: 10px; min-height: 40px; padding: 8px 10px; border: 0; background: none; border-radius: 8px; text-align: left; cursor: pointer; color: var(--text); text-decoration: none; font-size: 14px; }
.menu button:hover, .menu a.item:hover { background: var(--page); }
.menu .current { font-weight: 700; }
.menu .tag { margin-left: auto; font-size: 11px; color: var(--muted); }

/* ---------- Page pieces ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.page-head p { color: var(--muted); font-size: 14px; margin-top: 2px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-head h2 .ic { color: var(--hub-accent); }
.card-head a { font-size: 13px; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; min-height: 32px; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.tile .ic { color: var(--hub-accent); }
.tile .num { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; line-height: 1.1; }
.tile .lbl { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--faint); margin-top: 4px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.needs { background: color-mix(in srgb, var(--hub-accent) 9%, #fff); border-color: color-mix(in srgb, var(--hub-accent) 28%, #fff); }
.grid4 { display: grid; gap: 14px; margin-top: 14px; }
.grid4 .card + .card { margin-top: 0; }
@media (min-width: 720px) { .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }
.empty.big { padding: 28px 8px; text-align: center; }
.empty.big .ic { width: 32px; height: 32px; color: var(--hub-accent); margin-bottom: 8px; }
.empty.big b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

.stage-list { list-style: none; margin: 0; padding: 0; }
.stage-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; }
.stage-list .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--hub-accent); flex: none; }
.stage-list .dot.won { background: var(--green); }
.stage-list .dot.lost { background: #94A3B8; }
.stage-list .n { margin-left: auto; font-weight: 600; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.rows li:first-child { border-top: 0; }
.rows .r-main { flex: 1; min-width: 0; }
.rows .r-main b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.rows .r-main span { font-size: 13px; color: var(--muted); word-break: break-all; }
.pill { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--page); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.accent { background: color-mix(in srgb, var(--hub-accent) 12%, #fff); color: color-mix(in srgb, var(--hub-accent) 70%, #000); border-color: color-mix(in srgb, var(--hub-accent) 30%, #fff); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 4px; vertical-align: -3px; margin-right: 6px; border: 1px solid rgba(0, 0, 0, 0.12); }

.notice { font-size: 14px; padding: 10px 12px; border-radius: 10px; background: var(--page); color: var(--muted); border: 1px solid var(--border); }
.notice.warn { background: var(--amber-bg); color: var(--amber); border-color: #FDE68A; }
.notice.err { background: var(--red-bg); color: var(--red); border-color: #FECACA; }
.demo-band { background: var(--amber-bg); color: var(--amber); border: 1px solid #FDE68A; border-radius: 10px; padding: 8px 12px; font-size: 13px; margin-bottom: 14px; }

/* ---------- Buttons and forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; background: var(--hub-accent); color: var(--hub-on-accent); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.ghost { background: var(--card); color: var(--text); border-color: var(--border); }
.btn.block { width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.field input { font: inherit; font-size: 16px; min-height: 48px; padding: 10px 12px; border: 1px solid #CBD5E1; border-radius: 10px; background: #fff; color: var(--text); }
.field input:focus { outline: 3px solid color-mix(in srgb, var(--hub-accent) 35%, transparent); border-color: var(--hub-accent); }

/* ---------- Sign-in pages ---------- */
.auth { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--page); }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 28px 24px; }
.auth-brand { font-size: 20px; font-weight: 800; color: var(--hub-primary); margin-bottom: 18px; }
.auth-brand span { font-weight: 500; color: var(--muted); }
.auth h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.auth .lead { color: var(--muted); margin-bottom: 18px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 13px; margin: 16px 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.g-btn { width: 100%; background: #fff; color: var(--text); border: 1px solid #CBD5E1; }
.g-btn svg { width: 18px; height: 18px; }
.auth .small { font-size: 13px; color: var(--muted); margin-top: 16px; }
.dev-link { margin-top: 14px; font-size: 13px; word-break: break-all; }

.skel { background: linear-gradient(90deg, #EEF2F6 25%, #F6F8FA 50%, #EEF2F6 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #0B1120; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: all 0.2s; z-index: 60; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%); }
