:root {
  --bg: #ffffff; --side: #f6f6f7; --panel: #ffffff; --field: #ffffff; --hover: #ececef; --bubble: #f1f1f3;
  --text: #1d1f23; --muted: #6a707c; --line: #e3e4e8; --code-bg: #f5f6f8;
  --accent: #4f46e5; --accent-hover: #4338ca; --accent-soft: #eeedfd; --on-accent: #ffffff;
  --danger: #d43a2f; --ok: #188a42;
  --shadow: 0 1px 2px rgba(15, 17, 22, .05), 0 8px 24px rgba(15, 17, 22, .07);
  --radius: 14px; --sidebar: 268px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1c1d20; --side: #151618; --panel: #242529; --field: #26272c; --hover: #2c2d33; --bubble: #2d2e34;
  --text: #ececf0; --muted: #9a9fab; --line: #33353c; --code-bg: #141517;
  --accent: #8f8bf9; --accent-hover: #a5a2fb; --accent-soft: #2a2a44; --on-accent: #14141c;
  --danger: #ff7b70; --ok: #5fd08a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1 { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin: 0 0 6px; }
h2 { font-size: 16px; font-weight: 650; margin: 0 0 14px; }
p { margin: 0 0 12px; }
svg.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }

/* ---- application shell: sidebar + content ---- */
body.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); overflow: hidden; }
#nav { display: flex; flex-direction: column; min-height: 0; height: 100vh; padding: 14px 10px 10px;
  background: var(--side); border-right: 1px solid var(--line); }
#nav .brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; font-weight: 700; font-size: 16px;
  letter-spacing: -.01em; color: var(--text); text-decoration: none; }
.mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--accent), #9333ea); color: #fff; font-size: 12px; font-weight: 700; letter-spacing: 0; }
.app-version { color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap; letter-spacing: 0; }
.nav-links { display: flex; flex-direction: column; gap: 2px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--text);
  text-decoration: none; font-weight: 500; }
.nav-link:hover { background: var(--hover); }
.nav-link.current { background: var(--hover); font-weight: 600; }
.nav-link svg { color: var(--muted); }
.nav-link.current svg { color: var(--accent); }
#nav-slot { flex: 1; min-height: 0; overflow-y: auto; margin-top: 10px; }
.nav-foot { display: flex; align-items: center; gap: 4px; padding: 10px 4px 2px; margin-top: 8px; border-top: 1px solid var(--line); }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; text-transform: uppercase; }
.nav-foot .who { flex: 1; min-width: 0; padding-left: 6px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px;
  background: none; color: var(--muted); cursor: pointer; text-decoration: none; flex: none; }
.icon-button:hover { background: var(--hover); color: var(--text); }
.icon-button.risky:hover { color: var(--danger); }

main { min-width: 0; height: 100vh; overflow-y: auto; }
.page { max-width: 940px; margin: 0 auto; padding: 40px 32px 72px; }
.page > .lead { color: var(--muted); margin-bottom: 26px; }
.topbar { display: none; }
.scrim { display: none; }

@media (max-width: 860px) {
  body.app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  #nav { position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(84vw, 300px); transform: translateX(-102%);
    transition: transform .2s ease; box-shadow: var(--shadow); }
  body.nav-open #nav { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .4); }
  .topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line);
    font-weight: 650; }
  main { height: auto; min-height: 0; }
  .page { padding: 24px 16px 56px; }
}

/* ---- components ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; }
label { display: block; font-weight: 600; font-size: 13.5px; margin: 14px 0 6px; }
label.inline { display: inline-flex; align-items: center; gap: 7px; font-weight: 450; font-size: 14.5px; margin: 4px 16px 4px 0; cursor: pointer; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--field);
  color: var(--text); font: inherit; outline: none; transition: border-color .12s, box-shadow .12s; }
input[type=text]:focus, input[type=password]:focus, input[type=number]:focus, textarea:focus, select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
input[type=file] { font: inherit; color: var(--muted); max-width: 100%; }
input[type=file]::file-selector-button { margin-right: 10px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--field); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; }
textarea { min-height: 96px; resize: vertical; }
button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 16px;
  border: 1px solid var(--accent); border-radius: 10px; background: var(--accent); color: var(--on-accent);
  font: inherit; font-weight: 600; cursor: pointer; transition: background .12s, border-color .12s; }
button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.secondary { background: var(--field); color: var(--text); border-color: var(--line); }
button.secondary:hover { background: var(--hover); border-color: var(--line); }
button.danger { background: transparent; color: var(--danger); border-color: var(--line); }
button.danger:hover { background: var(--hover); border-color: var(--danger); }
button.small { padding: 5px 10px; font-weight: 500; font-size: 13px; border-radius: 8px; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, a:focus-visible, .icon-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.actions { margin-top: 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
td .actions { margin-top: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 14px; }
.msg { margin: 12px 0 0; font-size: 14px; }
.msg:empty { display: none; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.secret { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13.5px; background: var(--code-bg);
  border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; word-break: break-all; user-select: all; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 550;
  background: var(--accent-soft); color: var(--accent); margin: 0 4px 4px 0; }
.scroll { overflow-x: auto; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; gap: 6px; padding: 20px; text-decoration: none; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); transition: border-color .12s, box-shadow .12s, transform .12s; }
.card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.card .card-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; margin-bottom: 8px;
  background: var(--accent-soft); color: var(--accent); }
.card .card-icon svg { width: 21px; height: 21px; }
.card strong { font-size: 16px; }
.card span { color: var(--muted); font-size: 14px; }

/* ---- login ---- */
body.auth { display: grid; place-items: center; padding: 24px; background: var(--side); }
.auth-card { width: 100%; max-width: 380px; padding: 32px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--shadow); }
.auth-card .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 4px; }
.auth-card .mark { width: 34px; height: 34px; border-radius: 11px; font-size: 14px; }
.auth-card .lead { color: var(--muted); margin: 0 0 8px; }
.auth-card button { width: 100%; padding: 11px; }

.server-activity { display: inline-flex; color: var(--accent); flex: none; animation: server-pulse 1.2s ease-in-out infinite; }
.server-activity .icon { width: 26px; height: 26px; }
@keyframes server-pulse { 0%, 100% { opacity: .35; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.1); } }
@media (prefers-reduced-motion: reduce) { .server-activity { animation: none; } }
