/* ============================================================
   FHG AAUA — design system
   Blue + white brand: deep-blue ink, blue actions, gold reserved
   for raffle moments; monospaced numerals so counts & money read
   like a ledger.
   ============================================================ */

:root {
  --ink:        #0C2E66;
  --ink-soft:   #1E4487;
  --paper:      #FFFFFF;
  --workspace:  #EDF1F8;
  --line:       #D3DEEC;
  --muted:      #5C6B7C;
  --blue:      #2563EB;
  --blue-deep: #1D4ED8;
  --blue-tint: #E7EEFC;
  --gold:       #B8901F;
  --gold-soft:  #FBF1D2;
  --red:        #B23A48;
  --red-tint:   #F8E7E9;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,35,58,.06), 0 4px 16px rgba(20,35,58,.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--workspace);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--blue-deep); }

/* ---------- shell: sidebar + content ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--ink); color: #fff;
  padding: 22px 16px;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
  display: flex; flex-direction: column;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 0 8px 20px; }
.brand-mark { color: #fff; font-size: 1rem; }
.brand-name { font-weight: 650; font-size: .98rem; letter-spacing: -.2px; }

/* The mark in the sidebar and top bar. Both are deep blue, and the mark's
   own blues would sink into it, so it sits on a small white chip that keeps
   the brand colours true. Height-constrained, so any shape — square,
   wide wordmark, tall crest — lands at a sensible size. */
.brand-logo {
  height: 32px; width: auto; max-width: 116px;
  object-fit: contain; display: block;
  background: #fff; border-radius: 7px; padding: 3px 5px;
}

/* On white surfaces the logo needs no chip. */
.login-logo { height: 74px; width: auto; max-width: 210px; object-fit: contain; display: block; margin: 0 auto; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-label { text-transform: uppercase; letter-spacing: .1em; font-size: .64rem; font-weight: 700; color: #6E7E92; padding: 16px 12px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: #C3CEDC; text-decoration: none;
  font-size: .9rem; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--blue); color: #fff; }
.nav .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .5; }

.nav-foot { border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.nav-foot .who { font-size: .82rem; color: #9DAABB; padding: 0 12px; }
.nav-foot .signout { color: #C3CEDC; text-decoration: none; font-size: .85rem; padding: 6px 12px; border-radius: 8px; }
.nav-foot .signout:hover { background: rgba(255,255,255,.06); color: #fff; }

/* ---------- mobile top bar + drawer (hidden on desktop) ---------- */

.topbar { display: none; }
.nav-scrim { display: none; }
.hamburger { display: none; }

.content { flex: 1; padding: 32px 36px 64px; max-width: 1000px; }
.page-tools { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.export-group { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.export-group a { margin-left: 8px; font-weight: 600; }

/* ---------- headings ---------- */

.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .7rem; font-weight: 700; color: var(--blue-deep); margin: 0 0 6px; }
h1 { font-size: 1.7rem; letter-spacing: -.6px; margin: 0 0 4px; }
h2 { font-size: 1.1rem; letter-spacing: -.3px; margin: 0 0 14px; }
.lede { color: var(--muted); margin: 0 0 26px; max-width: 64ch; }

/* ---------- cards ---------- */

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-head h2 { margin: 0; }

.note { background: var(--gold-soft); border: 1px solid #E9D9A6; color: #6b551a; border-radius: var(--radius); padding: 13px 16px; margin-bottom: 22px; font-size: .9rem; }

/* ---------- stat strip ---------- */

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.stat .num { font-family: var(--mono); font-size: 2rem; font-weight: 700; letter-spacing: -1px; margin-top: 4px; }
.stat.accent .num { color: var(--blue-deep); }
.stat.gold .num { color: var(--gold); }

/* ---------- standings (bars) ---------- */

.standings { display: flex; flex-direction: column; gap: 10px; }
.rank-row { display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 14px; }
.rank-num { font-family: var(--mono); color: var(--muted); font-size: .85rem; text-align: right; }
.rank-body { min-width: 0; }
.rank-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.rank-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-count { font-family: var(--mono); font-weight: 700; }
.rank-count .sub { color: var(--muted); font-weight: 500; font-size: .78rem; margin-left: 6px; }
.bar { height: 9px; border-radius: 5px; background: var(--workspace); overflow: hidden; margin-top: 6px; display: flex; }
.bar .members { background: var(--blue); height: 100%; }
.bar .distributors { background: var(--ink-soft); height: 100%; }
.legend { display: flex; gap: 18px; font-size: .78rem; color: var(--muted); margin-top: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.swatch.m { background: var(--blue); }
.swatch.d { background: var(--ink-soft); }

/* ---------- forms ---------- */

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 5px; color: var(--ink-soft); }
input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }

/* ---------- buttons ---------- */

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border: 1px solid transparent; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; background: var(--blue); color: #fff; }
.btn:hover { background: var(--blue-deep); }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: var(--workspace); }
.btn.gold { background: var(--gold); color: #fff; }
.btn.gold:hover { filter: brightness(.94); }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn.danger:hover { background: var(--red-tint); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn-link { background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; padding: 4px; text-decoration: underline; }
.btn-link:hover { color: var(--red); }

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 0 12px 8px; border-bottom: 1px solid var(--line); }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { font-family: var(--mono); text-align: right; }

/* ---------- tags ---------- */

.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.tag.member { background: var(--blue-tint); color: var(--blue-deep); }
.tag.distributor { background: #E7ECF3; color: var(--ink-soft); }

/* ---------- winner cards ---------- */

.winners-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.winner { border: 1px solid var(--gold); background: linear-gradient(180deg, var(--gold-soft), #fff); border-radius: var(--radius); padding: 16px; animation: pop .45s cubic-bezier(.2,.8,.25,1) both; }
.winner .incentive { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--gold); font-weight: 700; }
.winner .wname { font-size: 1.15rem; font-weight: 700; letter-spacing: -.3px; margin: 4px 0 2px; }
.winner .wmeta { font-size: .82rem; color: var(--muted); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }

/* ---------- flash ---------- */

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-weight: 500; }
.flash.ok { background: var(--blue-tint); color: var(--blue-deep); }
.flash.error { background: var(--red-tint); color: var(--red); }

/* ---------- login ---------- */

.login-page { background: var(--ink); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { width: 100%; max-width: 380px; padding: 24px; }
.login-card { background: var(--paper); border-radius: 14px; padding: 30px 28px; box-shadow: 0 18px 50px rgba(0,0,0,.35); }
.login-brand { padding: 0 0 18px; justify-content: center; }
.login-brand .brand-name { color: var(--ink); }
.login-card h1 { margin-bottom: 20px; }
.login-foot { text-align: center; margin: 16px 0 0; font-size: .78rem; color: #8FA3BE; }

/* ---------- misc ---------- */

.muted { color: var(--muted); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form { display: inline; }
.spacer { height: 8px; }
hr.rule { border: none; border-top: 1px solid var(--line); margin: 22px 0; }

/* ---------- sponsor tree ---------- */

.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: 14px; padding-left: 16px; border-left: 1px solid var(--line); }
.tree li { margin: 2px 0; }
.tree-row { display: inline-flex; align-items: baseline; gap: 10px; padding: 5px 0; }
.tree-name { font-weight: 600; }
.tree-status { font-size: .72rem; font-weight: 600; color: var(--blue-deep); background: var(--blue-tint); border-radius: 999px; padding: 1px 9px; }
.tree-office { font-size: .8rem; }

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  .shell { display: block; }

  /* Sticky top bar holds the menu button + brand. */
  .topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 30;
    background: var(--ink); color: #fff; padding: 12px 16px;
  }
  .topbar .brand-mark { color: #fff; }
  .topbar .brand-name { font-weight: 650; font-size: .98rem; letter-spacing: -.2px; }

  /* Hamburger button — three bars. */
  .hamburger {
    display: inline-flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 38px; height: 38px; padding: 8px;
    background: transparent; border: 1px solid rgba(255,255,255,.18);
    border-radius: 8px; cursor: pointer;
  }
  .hamburger span { display: block; height: 2px; background: #fff; border-radius: 2px; }

  /* Sidebar becomes an off-canvas drawer that slides in from the left. */
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 50;
    width: 264px; max-width: 84vw; height: 100vh;
    transform: translateX(-100%); transition: transform .25s ease;
    overflow-y: auto;
  }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }

  /* Dim the page behind the open drawer; tap it to close. */
  .nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 40;
    background: rgba(10,18,30,.5);
    opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility .25s ease;
  }
  body.nav-open .nav-scrim { opacity: 1; visibility: visible; }

  .content { padding: 22px 18px 56px; }
  .stats { grid-template-columns: repeat(2, 1fr); }

  /* Only cards holding a wide table or the tree scroll sideways — so the
     scroll stays contained and other cards don't get a stray scrollbar. */
  .card:has(table), .card:has(.tree) { overflow-x: auto; }
  .tree { min-width: max-content; }

  /* Card headers stack their title above any action button instead of
     cramming both onto one line. */
  .card-head { flex-wrap: wrap; gap: 6px 12px; }

  /* Action rows become a clean full-width stack — easier to tap. */
  .actions { flex-direction: column; align-items: stretch; }
  .actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) { .winner { animation: none; } }

/* ---------- letterhead, footer, print ---------- */

/* Anything marked print-only is for paper; the screen never shows it. */
.print-only { display: none; }

.print-head { display: flex; align-items: center; gap: 14px; }
.print-logo { height: 44px; width: auto; max-width: 170px; object-fit: contain; }
.print-name { font-weight: 700; font-size: 1.05rem; color: var(--ink); }
.print-contact { font-size: .78rem; color: var(--muted); }

.app-foot {
  margin-top: 32px; padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 7px;
  font-size: .76rem; color: var(--muted);
}
.foot-sep { opacity: .5; }
.foot-stamp { margin-left: auto; }

@media print {
  .sidebar, .no-print { display: none !important; }
  .content { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  body { background: #fff; }

  /* On paper the page leads with the letterhead and closes with the
     footer, so a printout stands on its own away from the screen. */
  .print-only { display: block; }
  .print-head {
    display: flex;
    margin-bottom: 18px; padding-bottom: 12px;
    border-bottom: 2px solid var(--ink);
  }
  .app-foot { display: flex; }
}
