:root {
  --bg: #f4f6f9; --panel: #ffffff; --line: #e2e6ec; --text: #1c2430; --muted: #687385;
  --accent: #2563eb; --accent-ink: #ffffff; --danger: #c62828; --ok: #1b7f3b; --warn: #a15c00;
  --add-bg: #e8f6ec; --add-fg: #1b6b34; --del-bg: #fdecec; --del-fg: #a42020; --mod-bg: #fff6e0; --mod-fg: #8a5a00;
  --hunk: #eef2fb; --code: #f7f8fa;
  --t-baseline: #6d28d9; --t-service: #2563eb; --t-manual: #0f766e; --t-auto: #64748b; --t-pre-restore: #b45309; --t-imported: #be185d; --t-live: #15803d;
  font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --panel: #1a2029; --line: #2b3441; --text: #e3e8ef; --muted: #8c97a8;
    --accent: #4f8bff; --add-bg: #12301d; --add-fg: #7fd99a; --del-bg: #3a1618; --del-fg: #ff9a9a; --mod-bg: #3a2c0c; --mod-fg: #f3c56b;
    --hunk: #1e2a40; --code: #151a22;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
code, .mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.top { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 16px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.logo { background: var(--accent); color: #fff; border-radius: 6px; padding: 3px 6px; font-size: 12px; }
.machine { color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }

.layout { display: flex; min-height: calc(100vh - 53px); }
.side { width: 190px; flex: none; padding: 16px 10px; border-right: 1px solid var(--line); background: var(--panel); }
.side a { display: block; padding: 8px 12px; border-radius: 6px; color: var(--text); margin-bottom: 2px; }
.side a:hover { background: var(--bg); text-decoration: none; }
.side a.active { background: var(--accent); color: var(--accent-ink); }
body:not(.svc-on) .side a.svc { display: none; }
main { flex: 1; padding: 24px; min-width: 0; max-width: 1400px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.card + .card { margin-top: 16px; }
.grid .card + .card { margin-top: 0; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
.big { font-size: 28px; font-weight: 600; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 14px; border-radius: 7px; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--bg); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; color: #fff; white-space: nowrap; }
.t-baseline { background: var(--t-baseline); } .t-service { background: var(--t-service); } .t-manual { background: var(--t-manual); }
.t-auto { background: var(--t-auto); } .t-pre-restore { background: var(--t-pre-restore); } .t-imported { background: var(--t-imported); } .t-live { background: var(--t-live); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 12.5px; }
.pill.ok { background: var(--add-bg); color: var(--add-fg); } .pill.warn { background: var(--mod-bg); color: var(--mod-fg); } .pill.err { background: var(--del-bg); color: var(--del-fg); }

/* timeline */
.timeline { position: relative; }
.tl-row { display: grid; grid-template-columns: 28px 150px 1fr auto; gap: 12px; align-items: center; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.tl-row:hover { background: var(--bg); }
.dot { width: 12px; height: 12px; border-radius: 50%; margin-left: 8px; }
.tl-note { min-width: 0; }
.tl-note .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); border-radius: 14px; padding: 3px 12px; cursor: pointer; background: var(--panel); user-select: none; }
.chip.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* diff */
.diffhead { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.diffhead select { max-width: 380px; padding: 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; }
.stats { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.stat-add { color: var(--add-fg); } .stat-del { color: var(--del-fg); } .stat-mod { color: var(--mod-fg); }
.comp { margin-bottom: 18px; }
.comp > h2 { display: flex; align-items: center; gap: 10px; }
.change { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel); overflow: hidden; }
.change > .ch-head { display: flex; gap: 10px; align-items: center; padding: 7px 10px; cursor: pointer; }
.change > .ch-head:hover { background: var(--bg); }
.op { font-family: Consolas, monospace; font-weight: 700; width: 18px; text-align: center; border-radius: 4px; }
.op.added { background: var(--add-bg); color: var(--add-fg); } .op.removed { background: var(--del-bg); color: var(--del-fg); } .op.modified { background: var(--mod-bg); color: var(--mod-fg); }
.ch-path { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ch-body { border-top: 1px solid var(--line); padding: 0; }
.ch-body .pad { padding: 10px 12px; }
.kind { font-size: 11.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.ignored { opacity: .6; }

.udiff { width: 100%; border-collapse: collapse; font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
.udiff td { padding: 0 8px; border: 0; white-space: pre-wrap; word-break: break-all; }
.udiff td.ln { width: 1%; color: var(--muted); text-align: right; user-select: none; white-space: nowrap; }
.udiff tr.a td { background: var(--add-bg); } .udiff tr.d td { background: var(--del-bg); }
.udiff tr.h td { background: var(--hunk); color: var(--muted); padding: 3px 8px; }
.valdiff { display: grid; grid-template-columns: 70px 1fr; gap: 4px 10px; font-family: Consolas, monospace; font-size: 12.5px; }
.valdiff .o { background: var(--del-bg); color: var(--del-fg); padding: 2px 6px; border-radius: 4px; overflow-wrap: anywhere; }
.valdiff .n { background: var(--add-bg); color: var(--add-fg); padding: 2px 6px; border-radius: 4px; overflow-wrap: anywhere; }
.imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 10px; }
.imgs figure { margin: 0; } .imgs img { max-width: 100%; border: 1px solid var(--line); border-radius: 6px; }
.imgs figcaption { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
pre.text { margin: 0; padding: 10px 12px; background: var(--code); max-height: 420px; overflow: auto; font-size: 12.5px; }

.selbar { position: sticky; bottom: 0; background: var(--panel); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; box-shadow: 0 -4px 16px rgba(0,0,0,.08); margin-top: 12px; }

/* forms + modal */
label.f { display: block; margin-bottom: 12px; }
label.f span { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], textarea, select.f { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); font: inherit; }
textarea { min-height: 60px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; }
.modal { position: fixed; inset: 0; background: rgba(10,15,25,.45); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; z-index: 20; overflow: auto; }
.dialog { background: var(--panel); border-radius: 12px; padding: 22px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog .actions { justify-content: flex-end; margin-top: 18px; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 30; max-width: 480px; }
.toast.err { background: var(--danger); color: #fff; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: s 0.8s linear infinite; vertical-align: -2px; }
@keyframes s { to { transform: rotate(360deg); } }
.loading { padding: 30px; color: var(--muted); }
.warnbox { background: var(--mod-bg); color: var(--mod-fg); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.errbox { background: var(--del-bg); color: var(--del-fg); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.okbox { background: var(--add-bg); color: var(--add-fg); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .side { width: auto; display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .side a { white-space: nowrap; }
  main { padding: 16px; }
  .tl-row { grid-template-columns: 20px 1fr; }
  .tl-row > :nth-child(4) { grid-column: 1 / -1; }
  .imgs { grid-template-columns: 1fr; }
  .machine { display: none; }
}

@media print { .top, .side, .selbar, .diffhead, .actions, input[type=checkbox] { display: none !important; } main { padding: 0; } .change { break-inside: avoid; } }

/* central server */
.brand .sub { font-weight: 400; font-size: 12.5px; color: var(--muted); }
body[data-mode=server] .logo { background: #0f766e; }
.login { max-width: 380px; margin: 8vh auto; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.tile { color: var(--text); display: block; }
.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: 1px; }
.dot.on { background: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.18); }
.dot.off { background: #9ca3af; }
.tl-row .dot { margin-left: 0; }
.pill.info { background: var(--hunk); color: var(--muted); }
.fleet td { vertical-align: middle; }
.fleet .pill { margin: 1px 0; }
.codebox { font-family: Consolas, "Cascadia Mono", monospace; font-size: 34px; letter-spacing: 4px; text-align: center; padding: 14px; border: 2px dashed var(--accent); border-radius: 10px; margin: 10px 0; }
.diffhead .lbl { width: 22px; }
pre.text { white-space: pre-wrap; word-break: break-all; border-radius: 6px; }
input:disabled, select:disabled, textarea:disabled { opacity: .55; cursor: not-allowed; }
