:root {
  color-scheme: dark;
  --bg: #14161a;
  --panel: #1c1f26;
  --border: #2a2e37;
  --text: #e6e8eb;
  --muted: #8a919e;
  --accent: #4a9eff;
  --green: #3ecf6e;
  --red: #e5484d;
  --orange: #e58e26;
  --blue: #4a9eff;
  --gray: #8a919e;
  --topbar-h: 56px;
  --sidebar-w: 210px;
  /* Row hover tint, shared by every data table (was the raw #22252d, repeated
     in ten separate page <style> blocks before the table rules moved here). */
  --row-hover: #22252d;
}

* { box-sizing: border-box; }

/* Stops Android Chrome auto-inflating text inside the horizontally-scrolling
   data tables, which throws their column widths out. */
html { -webkit-text-size-adjust: 100%; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 20;
}

.auth-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  width: 200px;
  font-family: inherit;
}

.auth-input:focus { outline: none; border-color: var(--accent); }

.auth-submit, .auth-logout {
  background: var(--accent);
  color: #0c0f13;
  border: none;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.auth-submit:hover, .auth-logout:hover { opacity: 0.9; }

.auth-logout {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}

.auth-welcome {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
}

.auth-error {
  font-size: 12px;
  color: var(--red);
  max-width: 340px;
  line-height: 1.3;
  /* Sign-out reasons (e.g. "no longer a member of this faction") are a full
     sentence, so let them wrap rather than clip. */
  white-space: normal;
}

.auth-info {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

.auth-info:hover { color: var(--text); border-color: var(--accent); }

/* Collapsed by default so the notice is available without shouting; the "?"
   next to the login box opens it. */
.consent-panel {
  display: none;
  position: fixed;
  top: calc(var(--topbar-h) + 8px);
  right: 20px;
  z-index: 30;
  width: 380px;
  max-width: calc(100vw - 40px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 12px;
  color: var(--muted);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}

.consent-panel.open { display: block; }
.consent-panel strong { color: var(--text); }
.consent-panel ul { margin: 8px 0 0; padding-left: 18px; }
.consent-panel li { margin-bottom: 6px; line-height: 1.45; }
.consent-note {
  display: block;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--orange);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar .brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar .brand .brand-logo {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  display: block;
  flex: none;
}

/* Toggles .sidebar-collapsed on <body> — stays put in the topbar regardless
   of sidebar state, so the same icon both hides and brings the sidebar back. */
.sidebar-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.sidebar-toggle:hover { color: var(--text); border-color: var(--accent); }
.sidebar-toggle svg { width: 18px; height: 18px; }

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  overflow-y: auto;
  z-index: 10;
  transition: transform 0.18s ease;
}

/* Slid fully off-screen rather than display:none, so the toggle animates
   instead of snapping — and .main's own margin-left transition (below) stays
   in step with it. */
body.sidebar-collapsed .sidebar { transform: translateX(-100%); }

/* Only ever visible behind the mobile drawer; inert at desktop widths. */
.sidebar-backdrop { display: none; }
.sidebar-head { display: none; }

.sidebar nav {
  display: flex;
  flex-direction: column;
}

/* Purely a visual grouping label — not a link, not clickable. Icon + text
   sized down and muted so it reads as a heading over the links below it. */
.sidebar .nav-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.sidebar .nav-section-header svg { width: 14px; height: 14px; flex-shrink: 0; }

.sidebar a.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  padding: 10px 20px;
  border-left: 3px solid transparent;
}

.sidebar a.nav-link:hover {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}

.sidebar a.nav-link.active {
  color: var(--text);
  background: rgba(74,158,255,0.08);
  border-left-color: var(--accent);
  font-weight: 600;
}

.main {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 24px;
  min-height: calc(100vh - var(--topbar-h));
  transition: margin-left 0.18s ease;
}

body.sidebar-collapsed .main { margin-left: 0; }

/* Sits at the end of .main's own content, not fixed — a normal footer,
   present on every page since shared/nav.js injects it into whichever
   .main the current page already has. */
.app-footer {
  margin-top: 40px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
}
.app-footer .footer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 10px;
  line-height: 1.6;
}
.app-footer .footer-row + .footer-row { margin-top: 4px; }
.app-footer .sep { opacity: 0.45; }
.app-footer .footer-label { color: #565d6c; }

/* A player name that links out to their Torn profile — used anywhere a
   member/attacker/entrant's name is rendered, across every page. Deliberately
   NOT default link-blue: inherits whatever color the surrounding text/badge
   already uses, and only hints "this is clickable" on hover. */
a.profile-link {
  color: inherit;
  text-decoration: none;
}
a.profile-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ---------------------------------------------------------------------------
   Tables — the shape every data page shares. Only declarations that were
   byte-identical across all ten page <style> blocks live here. The parts that
   genuinely differ per page stay in those pages: cell padding (four variants),
   the table's own background/border-radius, `white-space: nowrap`, and whether
   the sort target is a bare `th` or `th.sortable`.

   CASCADE NOTE, load-bearing: theme.css is <link>ed on line 6 of every page and
   that page's own <style> follows on line 7, so at EQUAL specificity the page
   wins — and a media query adds no specificity at all. That's why the mobile
   overrides at the bottom of this file are scoped `.main th` rather than bare
   `th`; simplifying them back would silently stop them applying.
   --------------------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sorted {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}
th.num { text-align: right; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--row-hover); }

.table-wrap { overflow-x: auto; }

/* Identity column pinned while the rest of a wide table scrolls under it —
   Member Stats (~32 columns) and Performance (~27) both rely on it. */
.name-col { position: sticky; left: 0; background: var(--panel); z-index: 1; }
tr:hover td.name-col { background: var(--row-hover); }

/* ---------------------------------------------------------------------------
   Mobile shell. Two breakpoints:

     760px — structural. Below this the fixed 210px sidebar is eating over a
             quarter of the screen. Deliberately under 768 so an iPad in
             portrait keeps the desktop layout, where .main still gets 510px —
             comfortably more than the widest fixed-width thing in the app
             (War's 260px score bar).
     560px — cosmetic only, see that block.

   Anything a page's own <style> also declares has to be over-specified here;
   see the cascade note above the table rules.
   --------------------------------------------------------------------------- */
@media (max-width: 760px) {
  /* The topbar holds ~590px of unshrinkable content, so it has to wrap. A fixed
     bar can't grow into the page (.main clears it with a fixed margin-top), so
     it becomes sticky and takes real space in the flow instead. Sticky needs a
     body that scrolls rather than one exactly 100% tall, or the bar comes
     unstuck after a single viewport of scroll. The background is unaffected —
     html paints it and propagates to the canvas. */
  html, body { height: auto; min-height: 100%; }

  .topbar {
    position: sticky;
    height: auto;
    min-height: var(--topbar-h);
    flex-wrap: wrap;
    padding: 8px 12px;
    row-gap: 8px;
  }
  .topbar-left { gap: 10px; }
  .topbar .brand { font-size: 14px; min-width: 0; }

  /* Full width drops the auth controls onto their own row; the input then takes
     whatever the button and the "?" leave it. */
  .auth-box { width: 100%; flex-wrap: wrap; }
  .auth-input { flex: 1 1 auto; width: auto; min-width: 0; }
  .auth-welcome { flex: 1 1 auto; min-width: 0; white-space: normal; }
  /* Claims a row of its own only when it actually carries a message. */
  .auth-error { flex-basis: 100%; max-width: none; }

  /* Sidebar becomes an overlay drawer — full height, so it doesn't depend on
     the now-variable topbar height. */
  .sidebar {
    top: 0;
    width: min(80vw, 260px);
    padding-top: 0;
    z-index: 40;
    transform: translateX(-100%);
  }

  /* The drawer sits over the topbar, so the toggle is underneath it while open.
     This strip is exactly one topbar tall and its close button is aligned to the
     toggle`s own position, so tapping the menu button a second time closes the
     drawer rather than hitting whatever nav link happens to be up there. */
  .sidebar-head {
    display: flex;
    align-items: center;
    min-height: var(--topbar-h);
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-close {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 6px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
  }
  .sidebar-close svg { width: 18px; height: 18px; }
  body.sidebar-open .sidebar { transform: none; }
  /* Covers the topbar as well as the page, so a tap on the toggle while the
     drawer is open lands here and closes it. */
  body.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 35;
  }

  .main {
    margin-left: 0;
    margin-top: 0;
    padding: 16px 12px;
    min-height: auto;
  }

  /* A 380px panel hung off a variable-height topbar doesn't work on a phone. */
  .consent-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    max-height: 70vh;
    overflow-y: auto;
    border-radius: 12px 12px 0 0;
    z-index: 50;
  }

  /* Scoped .main so it beats each page's own `th, td` padding. Tighter across,
     to fit more columns on screen; taller down, because the sort target is the
     header cell itself. */
  .main th, .main td { padding: 11px 8px; }
  .main th { padding-top: 14px; padding-bottom: 14px; }

  /* Two signals that a table scrolls, because iOS Safari paints no scrollbar at
     all for a touch-scrolled element. The text hint is unconditional: telling
     whether a given table actually overflows needs JS, and these tables run to
     16-32 columns, so it is honest nearly everywhere it appears. */
  .table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }
  .table-wrap::-webkit-scrollbar { height: 6px; -webkit-appearance: none; }
  .table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
  .table-wrap::-webkit-scrollbar-track { background: transparent; }
  .table-wrap::after {
    content: "swipe table sideways for more \2192";
    position: sticky;   /* pinned to the left edge as the table scrolls under it */
    left: 0;
    display: block;
    width: fit-content;
    padding: 6px 8px 2px;
    font-size: 11px;
    color: var(--muted);
  }

  /* Touch targets. Nothing in this app reached 44px; these are the controls
     shared widely enough to be worth fixing centrally. */
  .sidebar a.nav-link { padding: 14px 20px; font-size: 14px; }
  .sidebar-toggle { width: 40px; height: 40px; }
  .auth-submit, .auth-logout { min-height: 40px; padding: 10px 16px; }
  .main .btn-sm, .main .tab-btn, .main .war-refresh-btn,
  .main .chain-refresh-btn, .main .race-btn { min-height: 40px; padding: 10px 14px; }
  /* Keeps its 24px circle, gains a 44px hit area. */
  .auth-info { position: relative; }
  .auth-info::after { content: ""; position: absolute; inset: -10px; }

  /* iOS Safari zooms the page whenever a focused control is under 16px, and
     every input in this app is 12-15px. A platform workaround rather than a
     design choice, and the one !important here: the page rules this has to beat
     (members.html's input[type="text"], personalstats.html's .threshold-field
     input, warpayout.html's table.costs input) tie with or out-specify anything
     theme.css can say about an input. */
  input, select, textarea { font-size: 16px !important; }
  .main select { max-width: 100%; }
}

@media (max-width: 560px) {
  /* Logged out, the topbar's unshrinkable content is ~533px, so it wraps to two
     rows just under 600. Dropping the wordmark pulls it back to one row, and
     the faction logo still reads as the brand. */
  .brand-label { display: none; }
  .main { padding: 14px 10px; }
}
