*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --surface-2: #f8fafd;
  --ink:       #16202e;
  --ink-soft:  #47566b;
  --muted:     #6b7a90;
  --line:      #e3e9f2;
  --line-soft: #eef2f8;
  --brand:     #2563eb;
  --brand-ink: #1d4ed8;
  --brand-bg:  #eaf1fe;
  --ok:        #0f7c4a;
  --ok-bg:     #e6f6ec;
  --warn:      #a55a06;
  --warn-bg:   #fdf3e3;
  --err:       #c02d24;
  --err-bg:    #fdecea;
  --info-bg:   #e9f0fb;
  --radius:    10px;
  --shadow:    0 1px 3px rgba(16,32,56,.07), 0 1px 2px rgba(16,32,56,.04);
  --sidebar-w: 232px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f151f;
    --surface:   #161f2c;
    --surface-2: #1b2534;
    --ink:       #e8eef7;
    --ink-soft:  #b3c1d4;
    --muted:     #8496ad;
    --line:      #26324356;
    --line-soft: #222d3d;
    --brand:     #5b93f7;
    --brand-ink: #7fabf9;
    --brand-bg:  #1a2740;
    --ok:        #56c98c;
    --ok-bg:     #14301f;
    --warn:      #e0a35a;
    --warn-bg:   #33240f;
    --err:       #f08279;
    --err-bg:    #3a1917;
    --info-bg:   #182337;
    --shadow:    0 1px 3px rgba(0,0,0,.4);
  }
}

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

a { color: var(--brand); }
a:hover { color: var(--brand-ink); }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: .6rem 1rem; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 1.1rem 1rem; border-bottom: 1px solid var(--line-soft);
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: .82rem; flex: none;
}
.brand-text {
  font-weight: 650; font-size: .94rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

.nav { padding: .6rem .55rem; flex: 1; }

.nav-link {
  display: flex; align-items: center; gap: .65rem;
  padding: .52rem .65rem; border-radius: 8px;
  color: var(--ink-soft); text-decoration: none; font-size: .89rem;
  margin-bottom: 1px;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.is-active { background: var(--brand-bg); color: var(--brand-ink); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; opacity: .85; flex: none; }

.nav-button {
  width: 100%; background: none; border: 0; font: inherit; cursor: pointer; text-align: left;
}

.sidebar-foot { padding: .55rem; border-top: 1px solid var(--line-soft); }
.version { margin: .5rem .65rem 0; font-size: .74rem; color: var(--muted); }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: .85rem;
  padding: .85rem 1.4rem; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.page-title { margin: 0; font-size: 1.08rem; font-weight: 650; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.role-chip {
  font-size: .74rem; font-weight: 600; padding: .2rem .55rem;
  border-radius: 20px; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line);
}

.menu-toggle {
  display: none; background: none; border: 1px solid var(--line);
  border-radius: 7px; padding: .3rem .55rem; font-size: 1.05rem;
  cursor: pointer; color: var(--ink);
}

.main { padding: 1.4rem; flex: 1; max-width: 1340px; width: 100%; }
.foot { padding: 1rem 1.4rem 1.6rem; color: var(--muted); font-size: .79rem; }

.banner { padding: .7rem 1.4rem; font-size: .88rem; border-bottom: 1px solid var(--line); }
.banner-warn { background: var(--warn-bg); color: var(--warn); }

.alert {
  padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem;
  font-size: .9rem; border: 1px solid transparent;
}
.alert-success { background: var(--ok-bg);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-error   { background: var(--err-bg);  color: var(--err);  border-color: color-mix(in srgb, var(--err) 25%, transparent); }
.alert-warning { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-info    { background: var(--info-bg); color: var(--ink-soft); border-color: var(--line); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.1rem;
}
.card-head {
  padding: .85rem 1.1rem; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: .96rem; font-weight: 650; flex: 1; }
.card-head .sub { color: var(--muted); font-size: .82rem; font-weight: 400; }
.card-body { padding: 1.1rem; }
.card-body.tight { padding: 0; }

.stats { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); margin-bottom: 1.1rem; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1rem; box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-value { font-size: 1.65rem; font-weight: 680; line-height: 1.15; margin-top: .3rem; letter-spacing: -.02em; }
.stat-note  { color: var(--muted); font-size: .79rem; margin-top: .15rem; }
.stat-value.ok   { color: var(--ok); }
.stat-value.warn { color: var(--warn); }
.stat-value.err  { color: var(--err); }

.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th, table.data td {
  text-align: left; padding: .62rem .8rem;
  border-bottom: 1px solid var(--line-soft); vertical-align: top;
}
table.data th {
  color: var(--muted); font-size: .74rem; text-transform: uppercase;
  letter-spacing: .04em; font-weight: 650; white-space: nowrap;
  background: var(--surface-2); position: sticky; top: 0;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .nowrap { white-space: nowrap; }
.cell-title { font-weight: 600; color: var(--ink); text-decoration: none; display: block; }
.cell-title:hover { color: var(--brand); }
.cell-sub { color: var(--muted); font-size: .8rem; margin-top: .15rem; }

.empty { padding: 2.4rem 1.2rem; text-align: center; color: var(--muted); }
.empty p { margin: .3rem 0 0; font-size: .88rem; }
.empty strong { display: block; color: var(--ink); font-size: .96rem; }

.badge {
  display: inline-block; padding: .15rem .5rem; border-radius: 20px;
  font-size: .73rem; font-weight: 650; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.badge-ok      { background: var(--ok-bg);   color: var(--ok);   border-color: transparent; }
.badge-err     { background: var(--err-bg);  color: var(--err);  border-color: transparent; }
.badge-warn    { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge-info    { background: var(--brand-bg);color: var(--brand-ink); border-color: transparent; }

.field { margin-bottom: 1rem; }
.field label, .form-label {
  display: block; font-weight: 600; font-size: .86rem; margin-bottom: .3rem;
}
.field .hint { display: block; font-weight: 400; color: var(--muted); font-size: .81rem; margin-top: .2rem; }

input[type=text], input[type=password], input[type=email], input[type=number],
input[type=url], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: .55rem .65rem; font: inherit;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand);
}
textarea { resize: vertical; min-height: 90px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
select { cursor: pointer; }

.check { display: flex; align-items: flex-start; gap: .55rem; margin-bottom: .7rem; }
.check input { margin-top: .22rem; flex: none; }
.check label { font-weight: 500; font-size: .88rem; margin: 0; }

.form-row { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  background: var(--brand); color: #fff; border: 1px solid transparent;
  border-radius: 8px; padding: .5rem 1rem; font: inherit; font-size: .88rem;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--brand-ink); color: #fff; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--err); }
.btn-danger:hover { background: color-mix(in srgb, var(--err) 85%, #000); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-row { display: flex; gap: .55rem; flex-wrap: wrap; align-items: center; }

.link-button {
  background: none; border: 0; color: inherit; font: inherit;
  text-decoration: underline; cursor: pointer; padding: 0;
}
.inline { display: inline; }

.filters {
  display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end;
  padding: .85rem 1.1rem; border-bottom: 1px solid var(--line-soft);
}
.filters .field { margin: 0; min-width: 140px; flex: 1 1 140px; }
.filters .field.grow { flex: 3 1 220px; }
.filters label { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }

.pagination {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .85rem 1.1rem; border-top: 1px solid var(--line-soft);
}
.pagination .count { color: var(--muted); font-size: .83rem; flex: 1; }
.page-link {
  padding: .3rem .65rem; border: 1px solid var(--line); border-radius: 7px;
  text-decoration: none; color: var(--ink-soft); font-size: .84rem; background: var(--surface);
}
.page-link:hover { background: var(--surface-2); }
.page-link[aria-disabled="true"] { opacity: .45; pointer-events: none; }

code, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .84em; background: var(--surface-2); padding: .1rem .35rem;
  border-radius: 5px; word-break: break-all;
}
pre.block {
  background: #111a26; color: #d8e4f3; padding: .85rem 1rem; border-radius: 9px;
  overflow-x: auto; font-size: .81rem; line-height: 1.55; margin: .5rem 0;
}
.thumb {
  width: 64px; height: 44px; object-fit: cover; border-radius: 6px;
  background: var(--surface-2); flex: none;
}
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 360px; display: block; }
.muted { color: var(--muted); }
.small { font-size: .83rem; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 130px; padding: .4rem 0; }
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.chart-bar {
  background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px;
  transition: opacity .15s;
}
.chart-col:hover .chart-bar { opacity: .75; }
.chart-labels { display: flex; gap: 4px; margin-top: .3rem; }
.chart-labels span {
  flex: 1; text-align: center; font-size: .66rem; color: var(--muted);
  overflow: hidden; white-space: nowrap;
}

.article-body {
  line-height: 1.7; font-size: .95rem; max-width: 70ch;
}
.article-body p { margin: 0 0 1rem; }
.article-body img { max-width: 100%; height: auto; border-radius: 8px; }
.article-body figure { margin: 1rem 0; }
.article-body figcaption { font-size: .82rem; color: var(--muted); margin-top: .35rem; }
.article-body blockquote {
  margin: 1rem 0; padding-left: 1rem; border-left: 3px solid var(--line); color: var(--ink-soft);
}

dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0; font-size: .86rem; }
dl.meta dt { color: var(--muted); font-weight: 600; }
dl.meta dd { margin: 0; word-break: break-word; }

@media (max-width: 880px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 50;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.2);
  }
  .sidebar.is-open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .main { padding: 1rem; }
  .truncate { max-width: 200px; }
}

@media print {
  .sidebar, .topbar, .foot, .filters, .pagination, .btn-row { display: none !important; }
  .main { padding: 0; }
  .card { border: none; box-shadow: none; }
}

.runall { margin: 0 0 1rem; padding: .85rem 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.runall__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.runall__track { height: 6px; margin: .6rem 0 .35rem; border-radius: 3px; background: rgba(127,127,127,.2); overflow: hidden; }
.runall__track span { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--brand); transition: width .2s; }
.runall__log { max-height: 240px; margin: .5rem 0 0; padding-left: 1.2rem; overflow-y: auto; font-size: .85rem; }
.runall__log li { margin: .15rem 0; }
.runall__ok { color: var(--ok); }
.runall__warn { color: var(--warn); }
.runall__err { color: var(--err); }
