/* MSC Autopilot: palette from the logo (anthracite #222a37, gold #d2ae62, white). Dark by default, light on request.
   Narrow screens (cover display): bottom navigation. Wide screens (Fold unfolded, >= 720px): side rail and list + detail. */
:root {
  color-scheme: dark light;
  --bg: #171c26; --panel: #222a37; --panel-2: #2c3647; --line: #374157; --text: #f3f5f8; --muted: #a8b1c0;
  --accent: #d2ae62; --accent-ink: #1b212c; --accent-text: #e3c481;
  --ok: #62c48e; --warn: #e6b94a; --bad: #f28585; --info: #82b4ff; --danger-bg: #c0392b;
  --radius: 14px; --nav-h: 64px; --bar-h: 56px; --gap: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 16px; line-height: 1.4;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f3f6; --panel: #ffffff; --panel-2: #eceef3; --line: #d9dde6; --text: #1d2431; --muted: #566074;
    --accent: #c9a24f; --accent-ink: #1d2431; --accent-text: #86601b;
    --ok: #17744a; --warn: #8f6200; --bad: #bb3326; --info: #1a5dc0;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; -webkit-text-size-adjust: 100%; overscroll-behavior-y: contain; }
a { color: var(--accent-text); text-decoration: none; }
h1 { font-size: 20px; margin: 0; line-height: 1.25; }
h2 { font-size: 16px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
img, video { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.ok-text { color: var(--ok); } .warn-text { color: var(--warn); } .bad-text { color: var(--bad); }
.row { display: flex; align-items: center; gap: 8px; } .row.wrap { flex-wrap: wrap; }
.boot { display: grid; place-items: center; min-height: 100dvh; } .boot-text { color: var(--muted); }

/* ---- tones ------------------------------------------------------------------------------------------------ */
.ok { --tone: var(--ok); } .warn { --tone: var(--warn); } .bad, .fail { --tone: var(--bad); } .info { --tone: var(--info); }
.gold { --tone: var(--accent-text); } .chip.muted { --tone: var(--muted); }

/* ---- shell ------------------------------------------------------------------------------------------------ */
.shell { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.appbar { position: sticky; top: 0; z-index: 20; height: var(--bar-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 0 16px; padding-top: env(safe-area-inset-top); background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; }
.brand img { border-radius: 7px; background: #fff; }
.appbar-right { display: flex; align-items: center; gap: 8px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.fail { background: var(--bad); }
.iconbtn { position: relative; display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: transparent; color: var(--text); cursor: pointer; flex: none; }
.iconbtn:hover { background: var(--panel-2); }
.badge { position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger-bg);
  color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--panel); border-top: 1px solid var(--line); }
.tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tab.on { color: var(--accent-text); }
.tab .badge { top: 6px; right: calc(50% - 26px); }
.view { outline: none; }
.page { width: 100%; max-width: 760px; margin: 0 auto; padding: 14px 16px 28px; display: flex; flex-direction: column; gap: var(--gap); }

/* ---- cards and rows --------------------------------------------------------------------------------------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.card.accent { border-color: var(--accent); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.banner { border-left: 4px solid var(--tone, var(--line)); }
.banner-head { display: flex; align-items: center; gap: 12px; color: var(--tone, var(--text)); }
.banner-head strong { color: var(--text); display: block; }
.banner-head .muted { color: var(--muted); }
.note { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; font-size: 14px;
  background: color-mix(in srgb, var(--tone, var(--muted)) 14%, transparent); color: var(--text); border: 1px solid color-mix(in srgb, var(--tone, var(--muted)) 40%, transparent); }
.note .icon { flex: none; color: var(--tone, var(--muted)); margin-top: 1px; }
.problem { display: flex; flex-direction: column; padding: 8px 0 0; border-top: 1px solid var(--line); color: var(--text); }
.problem-title { font-weight: 600; } .problem-detail { color: var(--muted); font-size: 13px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.post-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; padding: 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; color: var(--text); }
.post-row.selected { border-color: var(--accent); background: var(--panel-2); }
.post-row.static { grid-template-columns: auto 1fr auto; }
.post-main .chip { align-self: flex-start; margin-top: 4px; }
.card .post-row { background: var(--panel-2); }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; background: #fff; flex: none; }
.thumb.ph { display: grid; place-items: center; background: var(--panel-2); color: var(--muted); }
.post-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.post-title { font-weight: 650; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; color: var(--text); }
.note-line { color: var(--accent-text); }
.kv { display: flex; justify-content: space-between; gap: 12px; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 36px 12px; color: var(--muted); text-align: center; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; } .stats.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { display: flex; flex-direction: column; min-width: 90px; } .stat.link { align-items: center; justify-content: center; color: var(--accent-text); }
.stat-n { font-size: 26px; font-weight: 750; letter-spacing: -0.5px; }
.stat-card { background: var(--panel-2); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.spark { color: var(--accent-text); } .spark svg { width: 100%; height: 56px; display: block; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.metric { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; } .metric-n { font-size: 20px; font-weight: 700; }
.meter { height: 10px; border-radius: 99px; background: var(--panel-2); overflow: hidden; --tone: var(--accent); }
.meter span { display: block; height: 100%; width: var(--w, 0); background: var(--tone); border-radius: inherit; transition: width 0.2s; }
.fold summary { cursor: pointer; font-weight: 650; padding: 4px 0; list-style-position: inside; }
.history { display: flex; flex-direction: column; gap: 6px; padding-top: 6px; }
.hist-row { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; border-top: 1px solid var(--line); padding-top: 6px; }
.checks { display: flex; flex-direction: column; gap: 10px; }
.check-row { display: flex; gap: 10px; align-items: flex-start; } .check-row .dot { margin-top: 6px; } .check-name { font-weight: 600; }
.notice { position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; padding: 12px; border-radius: 12px; background: var(--panel);
  border: 1px solid var(--line); color: var(--text); align-items: start; }
.notice.unread { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.notice-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--tone, var(--muted)) 18%, transparent); color: var(--tone, var(--muted)); }
.notice-title { font-weight: 650; } .unread-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-top: 6px; }
.device { display: flex; align-items: center; gap: 4px; padding: 6px 0; border-top: 1px solid var(--line); } .device-main { flex: 1; min-width: 0; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.setting.stack { flex-direction: column; align-items: stretch; } .setting-title { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.setting-text { min-width: 0; }

/* ---- controls --------------------------------------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 650; font-size: 15px; cursor: pointer; text-align: center; color: var(--text); background: var(--panel-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--panel-2); border-color: var(--line); }
.btn.danger { background: var(--danger-bg); color: #fff; }
.btn.danger-ghost { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.wide { width: 100%; } .btn.grow { flex: 1; } .btn.small-btn { min-height: 36px; font-size: 13px; padding: 0 12px; align-self: flex-start; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--accent-ink); border-top-color: transparent; animation: spin 0.7s linear infinite; }
.btn.ghost.loading::after { border-color: var(--text); border-top-color: transparent; }
.iconbtn-wide { padding: 0 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 650; white-space: nowrap;
  color: var(--tone, var(--muted)); background: color-mix(in srgb, var(--tone, var(--muted)) 16%, transparent); border: 1px solid color-mix(in srgb, var(--tone, var(--muted)) 38%, transparent); }
.chip.link { --tone: var(--accent-text); } .chip.choice { --tone: var(--muted); cursor: pointer; font: inherit; font-size: 13px; padding: 6px 14px; }
.chip.choice.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.segmented { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--panel-2); border-radius: 12px; }
.seg { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 10px; border-radius: 9px; font: inherit; font-size: 13px; font-weight: 650;
  white-space: nowrap; color: var(--muted); background: transparent; border: 0; cursor: pointer; min-height: 38px; }
.seg.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }
.seg .count { min-width: 18px; padding: 0 5px; height: 18px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; display: grid; place-items: center; }
.small-seg { min-width: 180px; }
.input { width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; }
.input.time { width: auto; } .input.code { font-size: 20px; letter-spacing: 2px; text-transform: uppercase; text-align: center; }
textarea.input { resize: vertical; min-height: 64px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; } .field > span { font-size: 13px; color: var(--muted); }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.slider { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background 0.15s; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + .slider { background: var(--accent); } .switch input:checked + .slider::after { transform: translateX(20px); }
.switch input:disabled + .slider { opacity: 0.5; } .switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- post detail ------------------------------------------------------------------------------------------ */
.detail-head { display: flex; gap: 4px; align-items: center; } .detail-title { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.gallery { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--panel-2); border: 1px solid var(--line); }
.gallery-track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.gallery-track::-webkit-scrollbar { display: none; }
.gallery-track > * { flex: 0 0 100%; scroll-snap-align: center; aspect-ratio: 4 / 5; max-height: 64dvh; width: 100%; object-fit: contain; background: #fff; cursor: zoom-in; }
.media-missing { display: grid; place-items: center; gap: 6px; background: var(--panel-2) !important; color: var(--bad); }
.gallery-count { position: absolute; right: 10px; bottom: 10px; padding: 3px 10px; border-radius: 99px; background: rgba(0, 0, 0, 0.62); color: #fff; font-size: 12px; font-weight: 650; }
.caption-text { white-space: pre-wrap; font: inherit; background: var(--panel-2); padding: 12px; border-radius: 10px; margin: 0; line-height: 1.5; word-break: break-word; }
.actionbar { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 10; display: flex; gap: 8px; margin: 0 -16px -28px; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 94%, transparent); border-top: 1px solid var(--line); backdrop-filter: blur(10px); }

/* ---- dialogs and toast ------------------------------------------------------------------------------------ */
dialog.sheet { border: 0; padding: 20px; width: min(100%, 540px); max-width: 100%; margin: auto auto 0; border-radius: 20px 20px 0 0; background: var(--panel); color: var(--text);
  max-height: 88dvh; overflow: auto; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
dialog::backdrop { background: rgba(5, 8, 14, 0.62); }
.sheet h2 { font-size: 18px; margin-bottom: 10px; } .sheet-body { display: flex; flex-direction: column; gap: 4px; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; } .sheet-actions .btn { flex: 1 1 auto; }
dialog.lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #000; }
dialog.lightbox[open] { display: grid; place-items: center; }
.lightbox img { max-width: 100%; max-height: 100dvh; object-fit: contain; }
.lightbox .close { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 8px; color: #fff; background: rgba(0, 0, 0, 0.5); z-index: 2; }
.lightbox-nav { position: absolute; left: 0; right: 0; bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; justify-content: center; align-items: center; gap: 16px; color: #fff; }
.lightbox-nav .iconbtn { color: #fff; background: rgba(0, 0, 0, 0.5); }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px); max-width: min(92vw, 520px); z-index: 100;
  padding: 12px 16px; border-radius: 12px; background: #11151d; color: #fff; border: 1px solid var(--line); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; font-size: 14px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); } #toast.ok { border-color: var(--ok); } #toast.bad { border-color: var(--bad); }

/* ---- pairing ---------------------------------------------------------------------------------------------- */
.pair-page { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.pair-card { width: min(100%, 420px); align-items: stretch; padding: 24px 20px; gap: 12px; text-align: center; }
.pair-logo { align-self: center; border-radius: 16px; background: #fff; }

/* ---- wide screens: the unfolded Fold ---------------------------------------------------------------------- */
@media (min-width: 720px) {
  .shell { display: grid; grid-template-columns: 92px 1fr; grid-template-rows: var(--bar-h) 1fr; grid-template-areas: "nav bar" "nav view"; padding-bottom: 0; }
  .appbar { grid-area: bar; } .view { grid-area: view; min-width: 0; }
  .nav { position: sticky; top: 0; grid-area: nav; height: 100dvh; grid-template-columns: 1fr; grid-auto-rows: 72px; align-content: start; padding: 12px 0; border-top: 0; border-right: 1px solid var(--line); }
  .tab .badge { top: 8px; right: 18px; }
  .actionbar { bottom: 0; margin-bottom: -28px; }
  #toast { bottom: 24px; }
  dialog.sheet { margin: auto; border-radius: 20px; }
  .split { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; height: calc(100dvh - var(--bar-h)); }
  .split-list, .split-detail { overflow-y: auto; overflow-x: hidden; height: 100%; }
  .split-list { border-right: 1px solid var(--line); }
  .split-list .page, .split-detail .page { max-width: none; }
  .split-detail .page { padding-bottom: 0; }
  .split-detail .actionbar { margin-bottom: 0; }
  .gallery-track > * { max-height: 58dvh; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 0.01ms !important; } }
