:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f8f9fc; --border: #e2e6ef; --border-strong: #cfd5e2;
  --text: #1b2333; --muted: #5d6880; --accent: #2f5bea; --accent-hover: #2149cc; --accent-soft: #e8eefe;
  --danger: #c62f3d; --danger-soft: #fdecee; --ok: #1f8a4c; --ok-soft: #e6f6ec; --warn: #a86400; --warn-soft: #fff4e0;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --radius: 10px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --surface: #171d2b; --surface-2: #1c2333; --border: #273046; --border-strong: #34405c;
    --text: #e4e9f4; --muted: #95a0b8; --accent: #6d8dff; --accent-hover: #87a1ff; --accent-soft: #1f2a4a;
    --danger: #ff6b78; --danger-soft: #3a1c23; --ok: #4fd18b; --ok-soft: #15301f; --warn: #ffb547; --warn-soft: #36290f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 4px 0 8px; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 13px; margin: 18px 0 8px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
label { display: block; font-weight: 550; margin: 12px 0 4px; font-size: 13px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; margin: 0 8px 0 0; accent-color: var(--accent); }
.check { display: flex; align-items: center; font-weight: 450; margin: 8px 0; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 7px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; margin-top: 20px; padding: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.alert { padding: 10px 12px; border-radius: 8px; margin: 12px 0; font-size: 13.5px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--accent-soft); color: var(--accent); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.chip { display: inline-block; white-space: nowrap; padding: 1px 8px; margin: 2px 4px 2px 0; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 550; }
.chip.gray { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.chip.red { background: var(--danger-soft); color: var(--danger); }
.chip.green { background: var(--ok-soft); color: var(--ok); }
.chip.amber { background: var(--warn-soft); color: var(--warn); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand small { font-weight: 500; color: var(--muted); font-size: 12.5px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 650; font-size: 13px; flex: none; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.avatar.group { border-radius: 8px; }

/* ---------- portal ---------- */
.auth-wrap { min-height: calc(100vh - 40px); display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 28px 32px; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 18px; }
.portal-foot { text-align: center; color: var(--muted); font-size: 12px; padding: 10px; }
.portal-top { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.portal-top nav { display: flex; gap: 6px; }
.portal-top form { margin: 0; }
.account { max-width: 980px; margin: 0 auto; padding: 24px 16px; display: grid; gap: 18px; }
.hero { display: flex; gap: 16px; align-items: center; }
.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 6px; } }
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.app-tile { display: flex; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); }
.app-tile:hover { border-color: var(--accent); text-decoration: none; }
.app-tile small { display: block; color: var(--muted); }
.app-icon { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }

/* ---------- admin shell ---------- */
.admin { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 52px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .spacer { flex: 1; }
.topbar .who { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.globalsearch { max-width: 380px; }
.sidenav { background: var(--surface); border-right: 1px solid var(--border); padding: 12px 8px; overflow-y: auto; }
.sidenav a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 7px; color: var(--text); font-weight: 520; margin-bottom: 2px; }
.sidenav a:hover { background: var(--surface-2); text-decoration: none; }
.sidenav a.active { background: var(--accent-soft); color: var(--accent); }
.sidenav svg { width: 18px; height: 18px; flex: none; }
.main { overflow: auto; padding: 20px 24px; min-width: 0; overflow-wrap: break-word; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head p { margin: 0; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.navtoggle { display: none; }
@media (max-width: 860px) {
  .admin { grid-template-columns: minmax(0, 1fr); }
  .topbar .who a.btn { display: none; }
  .topbar { gap: 8px; padding: 0 8px; }
  .sidenav { position: fixed; top: 52px; left: 0; bottom: 0; width: 240px; z-index: 30; transform: translateX(-100%); transition: transform .15s; box-shadow: var(--shadow); }
  .sidenav.open { transform: none; }
  .navtoggle { display: inline-flex; }
  .main { padding: 16px; }
  .topbar .who span { display: none; }
  .globalsearch { display: none; }
}

/* directory explorer */
.explorer { display: grid; grid-template-columns: 280px 1fr; gap: 14px; min-height: calc(100vh - 150px); }
@media (max-width: 980px) { .explorer { grid-template-columns: minmax(0, 1fr); } .tree { max-height: 260px; } }
.tree { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; overflow: auto; }
.tree ul { list-style: none; margin: 0; padding-left: 14px; }
.tree > ul { padding-left: 0; }
.tree .node { display: flex; align-items: center; gap: 4px; padding: 4px 6px; border-radius: 6px; cursor: pointer; white-space: nowrap; user-select: none; }
.tree .node:hover { background: var(--surface-2); }
.tree .node.sel { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree .twisty { width: 16px; text-align: center; color: var(--muted); font-size: 10px; flex: none; }
.ico { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: middle; }
.listpane { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-width: 0; }
.listpane .bar { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); align-items: center; flex-wrap: wrap; }
.crumbs { font-size: 12.5px; color: var(--muted); padding: 8px 12px 0; overflow-wrap: anywhere; }
.crumbs a { cursor: pointer; }
.tablewrap { overflow: auto; flex: 1; border-radius: 0 0 var(--radius) var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.sel { background: var(--accent-soft); }
td .namecell { display: flex; align-items: center; gap: 8px; font-weight: 550; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.hide-sm { }
@media (max-width: 700px) { .hide-sm { display: none; } }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 980px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.copyrow { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.copyrow:last-child { border-bottom: 0; }
.copyrow .k { width: 150px; color: var(--muted); flex: none; font-size: 13px; }
.copyrow .v { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
@media (max-width: 600px) { .copyrow { flex-wrap: wrap; } .copyrow .k { width: 100%; } }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(10,15,30,.35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--surface); z-index: 41; box-shadow: -8px 0 30px rgba(0,0,0,.15); display: flex; flex-direction: column; }
.drawer header { padding: 16px 20px 0; border-bottom: 1px solid var(--border); }
.drawer .dhead { display: flex; gap: 12px; align-items: center; }
.drawer .dhead h2 { margin: 0; font-size: 18px; }
.drawer .dbody { padding: 16px 20px 24px; overflow: auto; flex: 1; }
.drawer .actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px; font: inherit; color: var(--muted); cursor: pointer; font-weight: 550; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.formgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.formgrid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .formgrid { grid-template-columns: 1fr; } }
.attr-table td { vertical-align: top; font-size: 13px; }
.attr-table td:first-child { font-weight: 600; white-space: nowrap; width: 1%; }
.attr-table tbody tr { cursor: default; }
.attr-table .vals div { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }

/* modal */
.modal-wrap { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; background: rgba(10,15,30,.45); padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(760px, 100%); }
.modal header { padding: 18px 22px 0; }
.modal header h2 { font-size: 18px; margin: 0; }
.modal .mbody { padding: 6px 22px 10px; overflow: auto; }
.modal footer { padding: 14px 22px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }
.picker-results { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; margin-top: 8px; }
.picker-results div { display: flex; gap: 8px; align-items: center; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.picker-results div:last-child { border-bottom: 0; }
.picker-results div:hover { background: var(--surface-2); }
.picker-results div.on { background: var(--accent-soft); }
.secret-box { font-family: var(--mono); background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 8px; padding: 10px 12px; overflow-wrap: anywhere; margin: 8px 0; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 9px; z-index: 60; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); color: #fff; }
.menu { position: relative; display: inline-block; }
.menu-list { position: absolute; left: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; box-shadow: var(--shadow); min-width: 200px; z-index: 20; padding: 4px; }
.menu-list button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; font: inherit; color: var(--text); cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }
.menu-list button.danger { color: var(--danger); }
.menu-list hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- help ---------- */
.center-note { text-align: center; margin: 14px 0 0; font-size: 13px; }
.help-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 28px; max-width: 1180px; margin: 0 auto; padding: 24px 16px; }
.help-toc { position: sticky; top: 16px; align-self: start; display: flex; flex-direction: column; gap: 2px; max-height: calc(100vh - 32px); overflow: auto; }
.help-toc strong { margin-bottom: 6px; }
.help-toc a { color: var(--muted); padding: 4px 10px; border-radius: 6px; border-left: 2px solid transparent; }
.help-toc a:hover { color: var(--accent); background: var(--surface-2); text-decoration: none; }
.help { min-width: 0; }
.help .lead { font-size: 15.5px; color: var(--muted); max-width: 760px; }
.help section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 22px; margin: 18px 0; scroll-margin-top: 16px; }
.help h2 { font-size: 18px; margin-bottom: 10px; }
.help h3 { margin-top: 20px; }
.help li { margin: 4px 0; }
.help code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; overflow-wrap: anywhere; }
.help kbd { font-family: var(--mono); font-size: 12px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }
.help-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 13.5px; }
.help-table th, .help-table td { border-bottom: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.help-table th { position: static; }
.help-dl dt { font-weight: 650; margin-top: 10px; }
.help-dl dd { margin: 2px 0 0 0; color: var(--text); }
.help-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: 14px 0; }
.help-facts div { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; min-width: 0; }
.help-facts span { display: block; color: var(--muted); font-size: 12px; }
@media (max-width: 860px) {
  .help-layout { grid-template-columns: minmax(0, 1fr); }
  .help-toc { position: static; max-height: none; flex-direction: row; flex-wrap: wrap; }
  .help-toc strong { width: 100%; }
  .help section { padding: 14px 14px; }
  .help-table { display: block; overflow-x: auto; }
}
.topbar .iconbtn { padding: 6px 10px; }
.about-head { display: flex; gap: 14px; align-items: center; margin: 6px 0 12px; }
.about-head img { width: 48px; height: 48px; }
@media (max-width: 560px) {
  .portal-top { flex-wrap: wrap; gap: 4px; padding: 8px 12px; }
  .portal-top nav { flex-wrap: wrap; gap: 2px; }
  .portal-top .brand small { display: none; }
  .portal-top .btn { padding: 6px 8px; }
}
