:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #16181d;
  --muted: #646b78;
  --line: #e2e5ea;
  --accent: #1565c0;
  --ok: #1e8e3e;
  --warn: #b26a00;
  --bad: #c62828;
  --wait: #5e6ad2;
  --idle: #8a919e;
  --code: #f0f2f5;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1a1d23;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --line: #2c3038;
    --accent: #6ea8fe;
    --ok: #4cc06a;
    --warn: #e0a030;
    --bad: #ef6b6b;
    --wait: #8f98f0;
    --idle: #7c8390;
    --code: #22262d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
h3 { font-size: 13px; margin: 18px 0 6px; color: var(--muted); font-weight: 600; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select {
  width: 100%;
  padding: 7px 9px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
}
textarea { resize: vertical; }
button {
  cursor: pointer;
  padding: 6px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
}
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--bad); }
button.quiet { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
pre, code { font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
details { margin-top: 12px; }
pre { margin: 0; padding: 10px; background: var(--code); border-radius: 6px; overflow: auto; max-height: 420px; white-space: pre-wrap; word-break: break-word; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.start { justify-content: flex-start; flex-wrap: wrap; }

.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 17px; color: var(--accent); }
.bar h1 span { color: var(--muted); font-weight: 500; }
.access { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-wrap: wrap; }
.operator { display: flex; align-items: center; gap: 8px; }
.operator-name { font-weight: 600; }
.token { display: flex; align-items: center; gap: 8px; }
.token label { color: var(--muted); white-space: nowrap; }
.token input { width: 180px; }
.token-state { font-size: 12px; white-space: nowrap; }
.token-state.ok { color: var(--ok); }
.token-state.bad { color: var(--bad); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--idle); }
.chip.ok::before { background: var(--ok); }
.chip.bad::before { background: var(--bad); }
.chip.plain::before { display: none; }
.arrow { color: var(--muted); }

.setup { margin: 0; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.setup summary { cursor: pointer; color: var(--muted); }
.setup-grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 10px 0 4px; align-items: center; }

.notice { margin: 12px 16px 0; padding: 8px 12px; border-radius: 6px; background: var(--code); border-left: 3px solid var(--accent); }
.notice.bad { border-left-color: var(--bad); }

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
.layout.wide { grid-template-columns: minmax(0, 1fr); }

.sections { display: flex; gap: 4px; padding: 10px 16px 0; flex-wrap: wrap; }
.sections button { border: 1px solid var(--line); background: var(--card); padding: 6px 14px; border-radius: 999px; color: var(--muted); }
.sections button[aria-selected="true"] { background: var(--code); color: var(--text); font-weight: 600; border-color: var(--accent); }
.lookup { grid-template-columns: 1fr auto; margin-bottom: 8px; }
.users li a.label { color: inherit; text-decoration: none; }
.users li a.label:hover, .users li a.label[aria-current="true"] { text-decoration: underline; }
.detail h3 { margin: 16px 0 6px; font-size: 14px; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.events li { padding: 4px 0; overflow-wrap: anywhere; }
.stats-chips { flex-wrap: wrap; margin-bottom: 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; }
#stats { overflow-x: auto; }
.side { display: grid; gap: 16px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; min-width: 0; }
.card > h2 { margin-bottom: 8px; }

.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tabs button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--code); color: var(--text); font-weight: 600; }
.panel { display: grid; gap: 8px; }
#link-form, #file-form { grid-template-columns: 1fr auto; }

.list { list-style: none; margin: 0; padding: 0; max-height: 46vh; overflow: auto; }
.list li button {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 6px;
  background: none;
  padding: 6px;
}
.list li button:hover, .list li button[aria-current="true"] { background: var(--code); }
.list .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .when { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 6px; }

.grants { margin-top: 10px; }
.grants li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 6px; }
.grants .danger { color: var(--bad); }
.users { margin-top: 10px; }
.users li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; padding: 6px; }
.users li.gone .label { color: var(--muted); }
.users .sub { grid-column: 1; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.users select { width: auto; grid-row: span 2; }
#grant-form select, #account-form select { width: auto; flex: 1; }
.account { margin-top: 10px; }
.account summary { cursor: pointer; color: var(--accent); }
.account form { margin-top: 8px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.check input { width: auto; }
.account-result { margin-top: 8px; padding: 8px 10px; border-radius: 6px; background: var(--code); display: grid; gap: 4px; }
.account-result code { user-select: all; font-size: 14px; }
.hint { margin: 0; font-size: 12px; }
.badge.g-pro { background: var(--accent); }
.badge.g-unlimited { background: var(--ok); }
.badge.g-operator { background: var(--warn); }
.badge.g-free { background: var(--idle); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--idle); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; background: var(--idle); }
.s-ready { background: var(--ok); }
.s-partial, .s-withheld { background: var(--warn); }
.s-failed { background: var(--bad); }
.s-saved, .s-queued, .s-processing { background: var(--wait); }

.detail { min-height: 300px; }
.detail header { display: grid; gap: 6px; margin-bottom: 4px; }
.detail .title { font-size: 18px; font-weight: 650; word-break: break-word; }
.source { word-break: break-all; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 13px; align-items: center; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.timeline li { display: grid; grid-template-columns: 64px auto 1fr; gap: 10px; align-items: baseline; }
.timeline .t { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.timeline .note { color: var(--muted); word-break: break-word; }

.bars { display: grid; grid-template-columns: max-content 1fr max-content; gap: 4px 10px; align-items: center; }
.bars .track { height: 10px; background: var(--code); border-radius: 3px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--accent); }
.bars .v { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.kv ul, .kv ol { margin: 0; padding-left: 18px; }
.thumb { max-width: 160px; max-height: 120px; border-radius: 6px; border: 1px solid var(--line); }

.progress { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--code); margin: 8px 0; }
.progress span { height: 100%; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: 6px; }
.table td { border-bottom: 1px solid var(--line); padding: 6px; vertical-align: top; }
.table td.link { max-width: 0; width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table tr.open { cursor: pointer; }
.table tr.open:hover td { background: var(--code); }
.table-wrap { overflow-x: auto; }

.activity li { display: grid; gap: 2px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.activity .what { font-weight: 600; }
.activity .detail-line { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
