:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e3e6ee;
  --text: #1b1f2a;
  --muted: #5d6475;
  --faint: #8a90a0;
  --accent: #2f5bea;
  --accent-hover: #2449c7;
  --accent-soft: #e8eefe;
  --ok: #17803d;
  --ok-soft: #e4f5ea;
  --warn: #a15c00;
  --warn-soft: #fdf1df;
  --danger: #c4302b;
  --danger-soft: #fdeceb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1f2430;
    --border: #2b3140;
    --text: #e8eaf0;
    --muted: #a3a9b8;
    --faint: #7a8193;
    --accent: #7c9cff;
    --accent-hover: #9bb3ff;
    --accent-soft: #1e2847;
    --ok: #5bd28a;
    --ok-soft: #15301f;
    --warn: #f0b45c;
    --warn-soft: #36290f;
    --danger: #ff7b74;
    --danger-soft: #3a1a19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 550; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .input:focus-visible, .icon-btn:focus-visible, .nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b1020; } }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > label { font-weight: 550; font-size: 13px; }
.field .hint { color: var(--faint); font-size: 12px; }
.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
}
.input:focus { border-color: var(--accent); }
textarea.input { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.addr { display: flex; align-items: stretch; }
.addr .input:first-child { border-radius: 8px 0 0 8px; }
.addr .suffix {
  display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--border); border-left: 0;
  border-radius: 0 8px 8px 0; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.addr select.suffix { cursor: pointer; }
.pw { display: flex; gap: 6px; }
.pw .input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px 32px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin: 18px 0 4px; font-weight: 600; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-card .btn { width: 100%; margin-top: 8px; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; font-size: 13px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 16px;
}
@media (prefers-color-scheme: dark) { .brand .logo { color: #0b1020; } }
.brand small { font-weight: 450; color: var(--muted); font-size: 15px; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 64px; display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .search {
  flex: 1; max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 10px;
  height: 44px; padding: 0 16px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.topbar .search input { flex: 1; border: 0; background: transparent; outline: none; min-width: 0; }
.topbar .right { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 650; font-size: 13px; color: #fff; text-transform: uppercase;
}
.menu-btn { display: none; }

.layout { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 64px); }
.nav { padding: 12px 12px 12px 0; }
.nav a {
  display: flex; align-items: center; gap: 14px; height: 40px; padding: 0 20px; margin-bottom: 2px;
  border-radius: 0 999px 999px 0; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.nav a.active .count { color: var(--accent); }
.nav hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0 12px 20px; }
.main { padding: 28px 32px 64px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 24px; font-weight: 600; margin: 0; margin-right: auto; }
.page-head p { width: 100%; margin: 2px 0 0; color: var(--muted); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px 22px; }
.card h2 { font-size: 16px; font-weight: 600; margin: 0 0 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat .label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.stat .value { font-size: 30px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--faint); font-size: 12px; margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.quick { display: grid; gap: 8px; }
.quick button {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-align: left;
}
.quick button:hover { background: var(--surface-2); }
.quick .qi { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.quick b { display: block; font-weight: 600; }
.quick span { color: var(--muted); font-size: 12px; }

/* ---------- table ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.chip-filter {
  height: 32px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 500;
}
.chip-filter.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 650; }
.toolbar .spacer { flex: 1; }
.toolbar .total { color: var(--muted); font-size: 13px; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.person .who { min-width: 0; }
.person .who b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .who span { display: block; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--warn-soft); color: var(--warn); }
.storage { min-width: 150px; }
.storage .bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 4px; }
.storage .bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.storage .bar i.high { background: var(--danger); }
.storage small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.members { display: flex; flex-wrap: wrap; gap: 6px; }
.member { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; background: var(--surface-2); font-size: 12px; }
.member button { border: 0; background: transparent; cursor: pointer; padding: 0; color: var(--muted); display: grid; place-items: center; }
.member button:hover { color: var(--danger); }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty .icon { width: 40px; height: 40px; color: var(--faint); margin-bottom: 8px; }
.empty b { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- drawer & dialog ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 22, .45); z-index: 40; animation: fade .15s ease-out; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); z-index: 41;
  background: var(--surface); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  animation: slide .2s cubic-bezier(.2, .8, .2, 1);
}
.drawer header { display: flex; align-items: center; gap: 8px; padding: 16px 16px 16px 24px; border-bottom: 1px solid var(--border); }
.drawer header h2 { font-size: 18px; font-weight: 600; margin: 0; flex: 1; }
.drawer .body { padding: 24px; overflow-y: auto; flex: 1; }
.drawer footer { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 24px; border-top: 1px solid var(--border); }
.dialog {
  position: fixed; z-index: 42; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px)); background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 24px;
  animation: pop .15s ease-out;
}
.dialog h2 { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.dialog p { margin: 0 0 16px; color: var(--muted); }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%) scale(.98); } }
@media (prefers-reduced-motion: reduce) { .overlay, .drawer, .dialog { animation: none; } }

.profile { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.profile .avatar { width: 56px; height: 56px; font-size: 20px; }
.profile b { display: block; font-size: 18px; font-weight: 600; }
.section { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 14px; }
.section > div { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.section > div:last-child { border-bottom: 0; }
.section .k { color: var(--muted); width: 120px; flex: none; font-size: 13px; }
.section .v { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.credentials {
  background: var(--surface-2); border-radius: 10px; padding: 14px 16px; margin: 16px 0;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.success-mark { width: 48px; height: 48px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; margin-bottom: 12px; }
.callout { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }

/* ---------- setup page ---------- */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }
.setup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  background: #1f2430; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px; animation: pop-up .2s ease-out;
}
.toast.error { background: var(--danger); }
@media (prefers-color-scheme: dark) { .toast { background: #e8eaf0; color: #10131a; } .toast.error { background: var(--danger); color: #10131a; } }
@keyframes pop-up { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
  .hide-md { display: none; }
}
@media (max-width: 760px) {
  .menu-btn { display: inline-grid; }
  .topbar { gap: 8px; }
  .topbar .brand small, .topbar .webmail-label { display: none; }
  .topbar .search { height: 40px; }
  .layout { grid-template-columns: 1fr; }
  .nav {
    position: fixed; top: 64px; left: 0; bottom: 0; width: 260px; z-index: 30; background: var(--surface);
    box-shadow: var(--shadow-lg); transform: translateX(-100%); transition: transform .2s;
  }
  .nav.open { transform: none; }
  .main { padding: 20px 16px 48px; }
  .hide-sm { display: none; }
  .table td, .table th { padding: 10px 12px; }
  .row { flex-direction: column; gap: 0; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 10px; }
}
