:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #5c6578; --line: #dfe3ea;
  --accent: #1f5fd6; --accent-text: #fff; --ok: #14733a; --okbg: #e3f5ea;
  --warn: #8a5a00; --warnbg: #fff1d6; --fail: #a4262c; --failbg: #fde7e9;
  --radius: 8px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --card: #1c2029; --text: #e6e9ef; --muted: #99a2b5; --line: #2d3342;
    --accent: #5b8def; --accent-text: #0b1220; --ok: #6fd69a; --okbg: #123322;
    --warn: #f0c26a; --warnbg: #3a2c0c; --fail: #f19097; --failbg: #3b1a1d;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .92em; }

.topbar { display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { font-size: 1.05rem; letter-spacing: .02em; }
.spacer { flex: 1; }
nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.tab { background: none; border: 0; padding: .45rem .8rem; border-radius: var(--radius); color: var(--muted); font: inherit; cursor: pointer; }
.tab:hover { background: var(--bg); color: var(--text); }
.tab.active { background: var(--accent); color: var(--accent-text); }
.content { max-width: 1080px; margin: 1.25rem auto; padding: 0 1rem 3rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .75rem; }
.row .spacer { flex: 1; }

.btn { font: inherit; padding: .4rem .85rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--fail); }
.btn.small { padding: .2rem .55rem; font-size: .86rem; }
.btn:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=password], input[type=email], input[type=number], input:not([type]), select, textarea {
  font: inherit; width: 100%; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); color: var(--text);
}
textarea { font-family: var(--mono); font-size: .9rem; min-height: 55vh; resize: vertical; }
label { display: block; margin-bottom: .7rem; font-weight: 500; }
label.inline { display: flex; align-items: center; gap: .5rem; font-weight: 400; margin-bottom: .4rem; }
label.inline input { width: auto; }
.hint { font-weight: 400; color: var(--muted); font-size: .86rem; display: block; margin-top: .2rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
.tablewrap { overflow-x: auto; }

.chip { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .8rem; font-weight: 600; background: var(--bg); border: 1px solid var(--line); }
.chip.ok { background: var(--okbg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warnbg); color: var(--warn); border-color: transparent; }
.chip.fail { background: var(--failbg); color: var(--fail); border-color: transparent; }

.error { color: var(--fail); min-height: 1.2em; margin: .25rem 0 .5rem; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(380px, 100%); }
.login-card .btn { width: 100%; margin-top: .25rem; }

.crumbs { display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; }
.crumbs button { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: .1rem .2rem; }
.crumbs span { color: var(--muted); }
.namebtn { background: none; border: 0; padding: 0; font: inherit; color: var(--text); cursor: pointer; text-align: left; }
.namebtn.dir { color: var(--accent); font-weight: 600; }
.namebtn:hover { text-decoration: underline; }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: .9rem; text-align: center; color: var(--muted); margin-bottom: 1rem; }
.dropzone.over { border-color: var(--accent); background: var(--card); color: var(--text); }
progress { width: 100%; height: .8rem; }

.checkline { display: flex; gap: .5rem; align-items: baseline; padding: .25rem 0; }
.checkline .chip { min-width: 4.2rem; text-align: center; flex: none; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 1.25rem; width: min(640px, 94vw); max-height: 92vh; overflow: auto; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog.wide { width: min(900px, 96vw); }
.dlg-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 .8rem; padding: .6rem .8rem; }
legend { font-weight: 600; padding: 0 .3rem; }

#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; max-width: min(420px, 92vw); }
.toast { white-space: pre-line; cursor: pointer; background: var(--text); color: var(--bg); padding: .6rem .9rem; border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.error { background: var(--fail); color: #fff; }
.toast.ok { background: var(--ok); color: var(--bg); }

@media (max-width: 640px) {
  th:nth-child(n+4), td:nth-child(n+4) { white-space: normal; }
  .topbar { gap: .4rem; }
}
