:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #6b7280; --border: #e3e6eb;
  --primary: #2459d6; --primary-text: #fff; --in: #137a3a; --out: #b42318; --warn: #b54708;
  --warn-bg: #fff6e5; --ok-bg: #e9f7ef; --err-bg: #fdecec; --sidebar: #141a26; --sidebar-text: #d8dde8;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1rem 0 .25rem; }
code { font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.danger { color: var(--out) !important; }

/* shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 1rem; display: flex; flex-direction: column; gap: .5rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar a { color: var(--sidebar-text); }
.brand { font-weight: 700; font-size: 1.1rem; display: block; margin-bottom: .75rem; color: inherit; }
.org-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; opacity: .7; }
.org-switcher { width: 100%; padding: .5rem; border-radius: 6px; border: 1px solid #333c4f; background: #1e2636; color: #fff; font-size: .95rem; }
.role-pill { font-size: .8rem; opacity: .8; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; margin-top: .5rem; }
.sidebar nav a { padding: .45rem .6rem; border-radius: 6px; }
.sidebar nav a:hover { background: #1e2636; text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.nav-head { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; opacity: .6; margin: .9rem .6rem .25rem; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #2a3245; padding-top: .75rem; }
.sidebar-foot .muted { color: #9aa3b5; }
.sidebar-foot .link { color: #9aa3b5; padding: 0; margin-top: .4rem; }
.main { padding: 1.5rem 2rem; max-width: 1200px; width: 100%; }
.auth { max-width: 440px; margin: 4rem auto; padding: 0 1rem; }

/* blocks */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head p { margin: 0; }
.crumbs { font-size: .85rem; color: var(--muted); margin: 0 0 .5rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 1rem; }
.empty { color: var(--muted); padding: .5rem 0; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.perm-list { columns: 2; padding-left: 1rem; list-style: none; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.25rem; }
.stat-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-value .unit { font-size: 1rem; font-weight: 400; color: var(--muted); }
.stat-warn { border-color: #f5c27a; background: var(--warn-bg); }

.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tool-card { display: block; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem; color: var(--text); }
.tool-card:hover { border-color: var(--primary); text-decoration: none; }
.tool-card.soon { opacity: .55; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { border-top: 2px solid var(--border); font-weight: 600; }
.in { color: var(--in); }
.out { color: var(--out); }
tr.archived td, tr.reversed td { opacity: .55; }
tr.reversed td:not(:last-child) { text-decoration: line-through; text-decoration-color: rgba(0,0,0,.3); }
td.note { max-width: 320px; color: var(--muted); word-break: break-word; }
.matrix td, .matrix th { border-right: 1px solid var(--border); }
.report .grp { border-left: 1px solid var(--border); }
.stat-value.in { color: var(--in); }
.stat-value.out { color: var(--out); }

.badge { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: #eef0f4; color: var(--muted); font-weight: 500; vertical-align: middle; }
.badge-warn { background: var(--warn-bg); color: var(--warn); }

/* forms */
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; font-weight: 500; }
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.inline-form { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form .grow { flex: 1; min-width: 200px; }
form.inline { display: inline; }
.search { display: flex; gap: .5rem; align-items: center; }
.search label { flex-direction: row; align-items: center; gap: .3rem; font-weight: 400; }
.radio-row { display: flex; flex-direction: column; gap: .35rem; }
.radio-row label, label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; font-size: .92rem; }
label.check.disabled { opacity: .45; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { display: inline; }
.copy-row { display: flex; gap: .5rem; margin-top: .5rem; }
.copy-row input { flex: 1; font-family: ui-monospace, monospace; font-size: .85rem; }

.btn { display: inline-block; font: inherit; font-size: .9rem; padding: .5rem .9rem; border-radius: 6px; border: 1px solid var(--border); background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c6cbd3; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: #1c4ab8; }
button.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash-ok { background: var(--ok-bg); border-color: #b5e2c4; }
.flash-err { background: var(--err-bg); border-color: #f4c2c0; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main { padding: 1rem; }
  .row { grid-template-columns: 1fr; }
}
