/* FBR ORBAT: dark neutral chrome around sheets drawn like the team's ORBAT spreadsheets
   (coloured frame, serif title band, grey canvas with a gold edge, boxed tables). */
:root {
  --bg: #161617;
  --bar: #1f1f21;
  --line: #333336;
  --ink: #ececee;
  --quiet: #a3a3a8;
  --gold: #f1c232;
  --tbd: #b45f06;
  --vac: #cc0000;
  --serif: 'Merriweather', Georgia, serif;
  --sans: 'Lexend', 'Segoe UI', Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); }
body { min-height: 100vh; padding-bottom: 64px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; background: var(--bar); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: .04em; }
.brand img { width: 28px; height: 28px; border-radius: 50%; }
.bar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.btn {
  border: 1px solid var(--line); background: #262629; color: var(--ink);
  padding: 7px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;
}
.btn:hover { background: #2e2e32; }
a.btn { display: inline-block; text-decoration: none; }
.btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn.primary { background: #e8e8ea; color: #111; border-color: #e8e8ea; }
.btn.primary:hover { background: #fff; }
.btn.danger { color: #ff8a80; }
.viewers {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px;
  color: var(--quiet); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.viewers svg { color: #8fd18f; }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--quiet); }
.who img { width: 24px; height: 24px; border-radius: 50%; }

/* ---------------------------------------------------------------- search (top bar) */
.search { position: relative; flex: 1 1 320px; max-width: 460px; margin: 0 8px; }
.search input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: #121213; color: var(--ink); font-size: 14px;
}
.search input::placeholder { color: #8a8a90; }
.search input:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: transparent; }
.results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40; margin: 0; padding: 4px; list-style: none;
  max-height: min(60vh, 460px); overflow-y: auto; background: var(--bar); border: 1px solid #47474d; border-radius: 8px;
}
.results li { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 5px; cursor: pointer; }
.results li[aria-selected="true"], .results li:hover { background: #2a2a2e; }
.results .r-name { font-weight: 700; font-size: 14px; color: var(--ink); }
.results .r-meta { font-size: 12px; color: var(--quiet); }
.results .r-none { color: var(--quiet); font-size: 13px; cursor: default; }
td.hit, .award .v.hit { outline: 3px solid var(--gold); outline-offset: -2px; background: #fff2a8 !important; }
@media (prefers-reduced-motion: no-preference) { td.hit, .award .v.hit { transition: background-color .3s ease; } }

/* ---------------------------------------------------------------- landing */
.landing { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.landing-card { width: min(420px, 100%); text-align: center; }
.landing-card img { width: 112px; height: 112px; border-radius: 50%; }
.landing-card h1 { font-family: var(--serif); font-size: 28px; margin: 18px 0 8px; }
.landing-card p { color: var(--quiet); line-height: 1.5; margin: 0 0 20px; }
.landing-card .msg { color: #ffb4a9; }

/* ---------------------------------------------------------------- sheet */
.page { padding: 20px 16px 8px; }
.sheet {
  margin: 0 auto; max-width: 1180px;
  background: var(--frame); padding: 0 10px 10px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.4);
}
.sheet.wide { max-width: 1880px; }
.sheet-title {
  margin: 0; padding: 16px 8px 14px; text-align: center; color: #fff;
  font: 900 clamp(20px, 3vw, 30px)/1.2 var(--serif);
}
.canvas {
  position: relative; background: var(--canvas); border: 3px solid var(--gold);
  padding: 24px 20px 18px; color: #000; overflow-x: auto;
}
.corner { position: absolute; top: 18px; width: clamp(64px, 11vw, 150px); height: auto; border-radius: 50%; }
.corner.l { left: 18px; } .corner.r { right: 18px; }
.sheet-head {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 20px;
  max-width: 980px; margin: 0 auto 22px;
}
.sheet-head .icon { width: clamp(72px, 11vw, 140px); height: auto; border-radius: 50%; }
.sheet-head-mid { display: flex; flex-direction: column; align-items: center; gap: 12px; min-width: 0; overflow-x: auto; }
.sheet-head-mid .cmd { margin: 0; }
.sheet-head-mid .motto { margin: 0; }
.chart-head { max-width: none; margin-bottom: 12px; }
.motto { text-align: center; font: italic 700 18px var(--serif); color: #434343; margin: 4px 0 18px; }
.note { margin: 18px 0 0; font-size: 12px; color: #434343; line-height: 1.45; }
.viewing {
  max-width: 1180px; margin: 0 auto 12px; padding: 10px 14px; border-radius: 6px;
  background: #3a2f0b; color: #ffe599; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 14px;
}

/* command boxes (also the chart boxes) */
.cbox { border-collapse: collapse; border: 2px solid #000; font-size: 12px; font-weight: 700; background: #efefef; min-width: 300px; }
.cbox th { padding: 6px 10px; font-size: 13px; color: #fff; }
.cbox th.light { color: #000; }
.cbox td { border: 1px solid #000; padding: 4px 8px; text-align: center; height: 24px; }
.cbox td.b, .cbox td.r { background: var(--fa, #efefef); width: 22%; white-space: nowrap; }
.cbox td.n { background: var(--fb, #d9d9d9); }
.cbox input { width: 100%; min-width: 60px; border: 1px solid #888; background: #fff; color: #000; padding: 2px 4px; text-align: center; font-weight: 700; font-size: 12px; }
.center { display: flex; justify-content: center; }
.cmd { margin: 0 auto 22px; display: flex; justify-content: center; }
.name-tbd { color: var(--tbd); } .name-vac { color: var(--vac); }

/* rosters */
.roster { margin: 0 auto 22px; max-width: 980px; overflow-x: auto; }
.roster table { width: 100%; border-collapse: collapse; border: 2px solid #000; font-size: 12px; }
.roster caption {
  caption-side: top; background: #000; color: #fff; font-weight: 700; font-size: 15px;
  padding: 8px 12px; text-align: center; position: relative;
}
.roster caption .count { position: absolute; right: 14px; top: 8px; }
.roster th { background: var(--head); color: #fff; padding: 6px 8px; border: 1px solid #000; font-size: 12px; white-space: nowrap; }
.roster td { border: 1px solid #000; padding: 4px 6px; text-align: center; background: var(--fa); font-weight: 600; height: 26px; }
.roster td.wide { background: var(--fb); font-weight: 700; }
.roster td.zero { background: #ffe599; color: #cc0000; }
.roster td.red { color: #cc0000; font-weight: 700; }
.roster input, .roster select { width: 100%; min-width: 72px; border: 1px solid #888; background: #fff; color: #000; padding: 3px 4px; font-size: 12px; text-align: center; }
.roster select { min-width: 112px; }
.roster input[type=checkbox] { width: 16px; height: 16px; min-width: 0; }
.roster .del { border: 0; background: none; color: #990000; font-size: 16px; line-height: 1; padding: 2px 6px; }
.add { margin-top: 6px; border: 1px dashed #333; background: rgba(255,255,255,.5); color: #000; padding: 6px 12px; font-size: 12px; font-weight: 700; border-radius: 4px; }
.chip { display: inline-block; min-width: 92px; padding: 3px 6px; font-size: 10px; font-weight: 700; letter-spacing: .03em; }
.st-ACTIVE { background: #1e6b4a; color: #fff; } .st-LOA { background: #674ea7; color: #fff; }
.st-PROBATION { background: #ffe599; color: #7f6000; } .st-INACTIVE { background: #990000; color: #fff; }
.st-UNCHECKED { background: #b7b7b7; color: #000; } .st-N\/A { background: #ea9999; color: #cc0000; }
.ph-Basic { background: #b7e1cd; color: #0b5394; } .ph-Advanced { background: #ffe599; color: #7f6000; }
.ph-Graduated { background: #1e6b4a; color: #fff; } .ph-Failed { background: #990000; color: #fff; }

/* awards */
.awards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 28px; max-width: 760px; margin: 8px auto 0; }
.award { border: 2px solid #000; text-align: center; font-size: 12px; }
.award h3 { margin: 0; padding: 6px; background: #434343; color: #fff; font: 700 13px var(--serif); text-transform: uppercase; }
.award .k { background: #3d3b42; color: #fff; font-weight: 700; padding: 4px; }
.award .v { background: #b7b7b7; padding: 5px; min-height: 26px; }
.award input { width: 100%; border: 1px solid #888; padding: 3px; text-align: center; }

/* division info panel, sub-unit row, parent link */
.info {
  max-width: 980px; margin: 0 auto 22px; background: rgba(255,255,255,.55); border: 2px solid #000;
  padding: 14px 18px; font-size: 13px; line-height: 1.55; color: #111;
}
.info h2 { margin: 12px 0 4px; font: 700 12px var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--head); }
.info h2:first-child { margin-top: 0; }
.info p { margin: 0; max-width: 75ch; }
.info ul { margin: 0; padding-left: 20px; }
.info textarea { width: 100%; border: 1px solid #888; background: #fff; color: #000; padding: 6px 8px; font: 13px/1.45 var(--sans); resize: vertical; }
.subunits { margin: -8px auto 22px; }
.subunit { text-decoration: none; color: inherit; display: block; width: 100%; max-width: 300px; }
.subunit:hover .cbox, .subunit:focus-visible .cbox { outline: 2px solid var(--gold); outline-offset: 2px; }
.parent-link { text-align: center; margin: -10px 0 18px; font-size: 13px; font-weight: 600; color: #333; }
.parent-link a { color: var(--head); }

/* army structure tab: pastel headers, plain grey rows, regular-weight titles (matches the other services' sheets) */
.chart.army .cbox { background: #efefef; }
.chart.army .cbox th { font-weight: 600; }
.chart.army .cbox td.b, .chart.army .cbox td.r { background: #efefef; }
.chart.army .cbox td.n { background: #d9d9d9; }
.chart.army > .cbox { min-width: 340px; }
.chart.army { min-width: min(100%, 1180px); width: 100%; }
.chart.army .branch .cbox { max-width: 290px; }

/* charts: spine, bar, branches */
.chart { min-width: max-content; display: flex; flex-direction: column; align-items: center; padding-top: 4px; }
.vline { width: 2px; height: 16px; background: #000; flex: none; }
.unitbar { background: #000; color: #fff; font-weight: 700; font-size: 13px; padding: 8px 18px; min-width: 300px; text-align: center; border: 2px solid #000; }
.branches { position: relative; display: grid; grid-template-columns: repeat(var(--n), minmax(196px, 1fr)); width: 100%; }
.branches::before {
  content: ''; position: absolute; top: 0; height: 2px; background: #000;
  left: calc(100% / var(--n) / 2); right: calc(100% / var(--n) / 2);
}
.branch { display: flex; flex-direction: column; align-items: center; padding: 0 5px; }
.branch .cbox { min-width: 0; width: 100%; max-width: 300px; }
.chart .cbox { font-size: 11.5px; }
/* ownership: only two branches, kept close under the bar instead of at the page edges */
.chart.own .branches { width: min(100%, 760px); }

/* ---------------------------------------------------------------- bottom tabs (like sheet tabs) */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px; background: var(--bar); border-top: 1px solid var(--line);
  scrollbar-width: thin;
}
.tab {
  flex: none; border: 1px solid var(--line); background: #262629; color: var(--quiet);
  padding: 6px 12px; border-radius: 4px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
  box-shadow: inset 0 -3px 0 var(--c);
}
.tab[aria-current="page"] { background: #f1f1f2; color: #111; }
.tab .lock { margin-left: 6px; opacity: .55; font-size: 11px; }

/* ---------------------------------------------------------------- history drawer + toast */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; width: min(360px, 100%);
  background: var(--bar); border-left: 1px solid var(--line); padding: 16px; overflow-y: auto;
}
.drawer h2 { margin: 0 0 4px; font-size: 16px; }
.drawer p { margin: 0 0 14px; color: var(--quiet); font-size: 13px; }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { border-top: 1px solid var(--line); padding: 10px 0; display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: 13px; }
.hist .meta { color: var(--quiet); font-size: 12px; }
.toast {
  position: fixed; left: 50%; bottom: 70px; transform: translateX(-50%); z-index: 40;
  background: #f1f1f2; color: #111; padding: 10px 16px; border-radius: 6px; font-size: 14px; font-weight: 600; max-width: calc(100% - 32px);
}
.toast.err { background: #ffb4a9; }
.savebar {
  position: sticky; bottom: 56px; z-index: 15; max-width: 1180px; margin: 12px auto 0;
  display: flex; gap: 8px; justify-content: flex-end; padding: 10px; background: var(--bar); border: 1px solid var(--line); border-radius: 8px;
}
.savebar span { margin-right: auto; align-self: center; color: var(--quiet); font-size: 13px; }

@media (max-width: 640px) {
  .page { padding: 12px 8px 4px; }
  .canvas { padding: 16px 10px 14px; }
  .corner { position: static; display: inline-block; margin: 0 6px 12px; width: 64px; }
  .awards { grid-template-columns: 1fr; }
  .sheet-head { grid-template-columns: 1fr 1fr; gap: 12px; }
  .sheet-head .icon { width: 64px; }
  .sheet-head .icon:last-child { justify-self: end; }
  .sheet-head-mid { grid-column: 1 / -1; grid-row: 2; }
  .chart-head .sheet-head-mid { display: none; }
  .brand span { display: none; }
  .bar { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; margin: 4px 0 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .tab { transition: background-color .12s ease; }
}
