:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f1f1ed;
  --text: #1c1c1e;
  --muted: #6c6c70;
  --border: #e4e3de;
  --accent: #2459d6;
  --accent-text: #ffffff;
  --accent-soft: #e8eefc;
  --danger: #c9362d;
  --danger-soft: #fbe9e7;
  --ok: #1f8a4c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .08);
  --radius: 10px;
  --row-h: 52px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131315;
    --surface: #1b1b1e;
    --surface-2: #232327;
    --text: #ececef;
    --muted: #9b9ba3;
    --border: #2d2d32;
    --accent: #6b93ff;
    --accent-text: #0d1426;
    --accent-soft: #1d2843;
    --danger: #ff6b5f;
    --danger-soft: #3a1f1d;
    --ok: #4cc47f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
svg { flex: none; }

button, input, select { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 14px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 8px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.input {
  height: 38px; width: 100%; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- dialog ---------- */
dialog {
  border: 0; padding: 0; border-radius: 14px; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 10, 14, .45); }
.dlg { padding: 22px; display: grid; gap: 14px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg p { margin: 0; color: var(--muted); }
.dlg .row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dlg .err { color: var(--danger); font-size: 14px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; }
.toast {
  background: #26262a; color: #f3f3f5; padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 14px; max-width: min(520px, calc(100vw - 32px));
  animation: toast-in .18s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- menus ---------- */
.menu {
  position: fixed; z-index: 50; min-width: 200px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; text-align: left;
}
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }
.menu button svg { color: var(--muted); }
.menu button.danger svg { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 4px; }

/* ---------- page shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--accent-text);
}
.brand .title { font-weight: 650; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .subtitle { color: var(--muted); font-size: 13px; }
.brand > div:last-child { min-width: 0; }
.actions { display: flex; gap: 8px; align-items: center; }

main { padding: 18px clamp(16px, 4vw, 40px) 120px; max-width: 1280px; margin: 0 auto; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .btn .label-wide { display: none; }
  .brand .subtitle { display: none; }
}
