@font-face { font-family: 'Barlow'; font-weight: 400; font-display: swap; src: url(../fonts/Barlow-400.woff2) format('woff2'); }
@font-face { font-family: 'Barlow'; font-weight: 500; font-display: swap; src: url(../fonts/Barlow-500.woff2) format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 500; font-display: swap; src: url(../fonts/BarlowCondensed-500.woff2) format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-display: swap; src: url(../fonts/BarlowCondensed-600.woff2) format('woff2'); }

:root {
  --dot: #ffe0a8;
  --bg: #1a2029; --panel: #222a34; --panel-2: #2a333f; --line: #36414e; --line-strong: #4a5664;
  --text: #e6eaef; --muted: #97a3b0; --faint: #6d7986;
  --ficsit: #f59b2e; --ficsit-ink: #1a2029; --flow: #f59b2e;
  --ok: #3fae8c; --tight: #e3b43a; --full: #e0524f; --over: #e0524f; --idle: #3a4552;
  --error-bg: rgba(224, 82, 79, .14); --warning-bg: rgba(227, 180, 58, .14); --notice-bg: rgba(151, 163, 176, .12); --ok-bg: rgba(63, 174, 140, .14);
  --radius: 6px;
  --display: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', sans-serif;
  --body: 'Barlow', 'Segoe UI', Roboto, Arial, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --dot: #8a4a00;
  --bg: #edf0f3; --panel: #ffffff; --panel-2: #f4f6f8; --line: #d6dce2; --line-strong: #b9c2cc;
  --text: #1c242e; --muted: #56616d; --faint: #7d8894;
  --ficsit: #d9790f; --ficsit-ink: #ffffff; --flow: #e08718;
  --ok: #23916f; --tight: #b8860b; --full: #c93b38; --over: #c93b38; --idle: #dfe4e9;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 15px/1.55 var(--body); font-variant-numeric: tabular-nums; }
a { color: inherit; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
a:hover { color: var(--ficsit); text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--ficsit); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: .01em; }
h1 { font-size: 34px; }
h2 { font-size: 22px; margin-bottom: 12px; }
h3 { font-size: 18px; }

.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); overflow-x: clip; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 0 0 20px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.stripe { height: 10px; background: repeating-linear-gradient(-45deg, var(--ficsit) 0 12px, var(--panel) 12px 24px); }
.brand { padding: 18px 20px 22px; }
.brand-name { font-family: var(--display); font-weight: 600; font-size: 24px; line-height: 1.05; }
.brand-sub { color: var(--muted); font-size: 13px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.nav a { text-decoration: none; padding: 9px 12px; border-radius: var(--radius); color: var(--muted); font-weight: 500; border-left: 3px solid transparent; }
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a.active { color: var(--text); background: var(--panel-2); border-left-color: var(--ficsit); border-radius: 0 var(--radius) var(--radius) 0; }
.nav .count { float: right; font-size: 12px; background: var(--full); color: #fff; border-radius: 9px; padding: 0 7px; line-height: 18px; margin-top: 2px; }
.side-foot { margin-top: auto; padding: 0 20px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 10px; }
.side-foot .row { display: flex; gap: 8px; }
button, select, input { font: inherit; color: inherit; }
button, .btn { background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--ficsit); }
button.primary, .btn.primary { background: var(--ficsit); color: var(--ficsit-ink); border-color: var(--ficsit); font-weight: 500; }
input[type="text"], input[type="number"], input[type="search"], select { background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 7px 10px; min-width: 0; }
input[type="checkbox"] { accent-color: var(--ficsit); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; }
.dot.stale { background: var(--tight); }

main { padding: 32px 40px 60px; max-width: 1280px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.back { font-size: 14px; color: var(--muted); display: inline-block; margin-bottom: 8px; }
.banner { border: 1px solid var(--full); background: var(--error-bg); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; }
.banner strong { display: block; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 28px; }
.tile { padding: 14px 18px; outline: 1px solid var(--line); }
.tile-value { font-family: var(--display); font-weight: 600; font-size: 36px; line-height: 1; }
.tile-label { color: var(--muted); font-size: 13px; margin-top: 6px; }
.tile.error .tile-value { color: var(--full); }
.tile.good .tile-value { color: var(--ok); }
.unit { color: var(--faint); font-size: .85em; margin-left: 1px; }

.cols { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 28px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.panel + .panel { margin-top: 20px; }
.cols > .panel { margin-top: 0; }
.empty { color: var(--muted); margin: 0; }

.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alert { display: grid; grid-template-columns: 4px minmax(0, 1fr) auto; align-items: start; gap: 12px; padding: 10px 12px; border-radius: var(--radius); }
.alert-mark { border-radius: 2px; align-self: stretch; }
.alert.error { background: var(--error-bg); } .alert.error .alert-mark { background: var(--full); }
.alert.warning { background: var(--warning-bg); } .alert.warning .alert-mark { background: var(--tight); }
.alert.notice { background: var(--notice-bg); } .alert.notice .alert-mark { background: var(--faint); }
.alert-msg { font-weight: 500; }
.alert-detail { color: var(--muted); font-size: 14px; }

.bar { height: 8px; background: var(--idle); border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar span { display: block; height: 100%; }
.lvl-ok { background: var(--ok); } .lvl-tight { background: var(--tight); } .lvl-full { background: var(--full); }
.lvl-over { background: repeating-linear-gradient(-45deg, var(--over) 0 5px, #ffffff66 5px 8px); animation: hazard .9s linear infinite; }
.lvl-idle { background: transparent; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

.badge { display: inline-block; font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 10px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.error { background: var(--error-bg); color: var(--full); }
.badge.warning { background: var(--warning-bg); color: var(--tight); }
.badge.muted { background: var(--notice-bg); color: var(--muted); }

.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar label { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 14px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 12px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.card-head h3 a { text-decoration: none; }
.card-meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.prow { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, .8fr) 72px; gap: 10px; align-items: center; font-size: 14px; padding: 3px 0; }
.prow .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .left { text-align: right; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--panel-2); }
th button.sort { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; }
th button.sort[data-active] { color: var(--text); }
.neg { color: var(--full); font-weight: 500; }
.sub { color: var(--muted); font-size: 13px; }

/* Supply-chain map */
.map-wrap { position: relative; overflow: hidden; height: min(72vh, 680px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); touch-action: none; cursor: grab;
  background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 24px 24px; }
.map-wrap.grabbing { cursor: grabbing; }
.map-wrap svg { display: block; user-select: none; }
.node rect { fill: var(--panel-2); stroke: var(--line-strong); stroke-width: 1; }
.node.external rect { fill: transparent; stroke-dasharray: 4 3; }
.node.has-error rect { stroke: var(--full); stroke-width: 2; }
.node .n-name { fill: var(--text); font: 600 16px var(--display); }
.node .n-sub { fill: var(--muted); font: 400 12px var(--body); }
.node { cursor: pointer; }
.node.dim, .link.dim { opacity: .12; }
.node.focus rect { stroke: var(--ficsit); stroke-width: 2; }
.link { fill: none; stroke: var(--flow); stroke-opacity: .45; transition: opacity .15s; }
.link.on { stroke-opacity: .9; }
.link.over { stroke: var(--over); }
.tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 8px 10px; font-size: 13px; max-width: 280px; z-index: 5; display: none; }
.tip b { font-weight: 500; }

/* Planner */
.plan-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.plan-row { display: grid; grid-template-columns: minmax(0, 2fr) 120px auto; gap: 8px; }
.plan-result { border-left: 3px solid var(--ok); padding: 10px 14px; background: var(--panel-2); border-radius: 0 var(--radius) var(--radius) 0; margin-bottom: 10px; }
.plan-result.short { border-left-color: var(--full); }
.plan-result.none { border-left-color: var(--faint); }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .nav .count { float: none; margin-left: 6px; }
  .side { position: static; height: auto; }
  .brand { padding: 12px 16px; }
  .nav { flex-direction: row; overflow-x: auto; padding: 0 8px 8px; }
  .nav a { white-space: nowrap; border-left: 0; border-bottom: 3px solid transparent; border-radius: var(--radius); }
  .nav a.active { border-bottom-color: var(--ficsit); border-radius: var(--radius) var(--radius) 0 0; }
  .side-foot { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; padding: 8px 16px 0; }
  main { padding: 20px 16px 48px; }
  .cols { grid-template-columns: 1fr; }
  h1 { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* Editing */
#toast { position: fixed; right: 20px; bottom: 20px; max-width: 420px; padding: 12px 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line-strong); border-left: 4px solid var(--ok); opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; }
#toast.show { opacity: 1; transform: none; }
#toast.error { border-left-color: var(--full); }
button.danger { color: var(--full); border-color: var(--full); background: transparent; }
button.danger:hover { background: var(--error-bg); }
button.small { padding: 3px 9px; font-size: 13px; }
.edit-table td { padding: 5px 6px; }
.edit-table input, .edit-table select { width: 100%; }
.edit-table td.act { width: 1%; white-space: nowrap; }
.edit-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 20px; }
.edit-actions .spacer { flex: 1; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; max-width: 420px; }
.field label { color: var(--muted); font-size: 14px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; padding: 0; list-style: none; }
.chips li { display: flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 2px 4px 2px 12px; font-size: 14px; }
.chips button { border: 0; background: transparent; padding: 0 6px; color: var(--muted); font-size: 16px; line-height: 1; }
.chips button:hover { color: var(--full); }

.alert.dismissed { opacity: .6; }
.dismissed-list { margin-top: 14px; }
.dismissed-list summary { cursor: pointer; color: var(--muted); font-size: 14px; margin-bottom: 8px; }

/* Edit mode */
body.locked .edit-only { display: none !important; }
#editmode { width: 100%; }
#editmode:disabled { opacity: .6; cursor: not-allowed; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 22px 24px; width: min(400px, 90vw); }
dialog::backdrop { background: rgba(10, 14, 20, .6); }
dialog input[type="password"] { width: 100%; margin-top: 8px; }
#unlock-error { min-height: 1.4em; margin: 8px 0; }

/* Motion */
.bar span { transition: width .7s cubic-bezier(.2, .8, .2, 1), background-color .4s; }
.lvl-full { animation: pulse 2.6s ease-in-out infinite; }
@keyframes hazard { to { background-position: 11.31px 0; } }
@keyframes pulse { 50% { opacity: .6; } }

.changed { animation: glow 1.8s ease-out; border-radius: 3px; }
@keyframes glow { 0%, 25% { background: color-mix(in srgb, var(--ficsit) 35%, transparent); color: var(--text); } 100% { background: transparent; } }

main.page-enter { animation: fade .25s ease-out; }
main.page-enter .tile, main.page-enter .card, main.page-enter .panel, main.page-enter .map-wrap, main.page-enter .cols > section {
  animation: rise .4s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i, 0) * 35ms);
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.dots circle { fill: var(--dot); pointer-events: none; }
.dotgroup { transition: opacity .15s; }
.dotgroup.dim { opacity: .1; }
.map-controls { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 4; }
.map-controls button { background: var(--panel); min-width: 34px; }
.node.dragging rect { stroke: var(--ficsit); }
