:root {
  --bg: #0f1218; --surface: #181c25; --surface-2: #222836; --text: #e9edf5; --muted: #9aa4b8;
  --accent: #2d8cff; --accent-text: #ffffff; --border: #2b3242; --danger: #e5484d; --overlay: rgba(5, 8, 14, .66);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f4f6fb; --surface: #ffffff; --surface-2: #eaeef6; --text: #161b26; --muted: #5b667c;
    --accent: #1a6fe0; --border: #d5dbe8; --danger: #c9302f; --overlay: rgba(20, 28, 45, .45); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #eaeef6; --text: #161b26; --muted: #5b667c;
  --accent: #1a6fe0; --border: #d5dbe8; --danger: #c9302f; --overlay: rgba(20, 28, 45, .45); color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
h1 { font-size: 1.5rem; margin: .25rem 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0; }
p { margin: .5rem 0; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* forms and buttons */
.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.field small { color: var(--muted); }
input[type="text"], input[type="email"], select {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; width: 100%; }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 16px; cursor: pointer; }
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn.account { text-align: left; }
.btn.account.current { opacity: 1; border-color: var(--accent); }
.link { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.links { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 16px; font-size: .9rem; }
.error { color: var(--danger); margin: 0; font-size: .9rem; }
.notice { background: var(--surface-2); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 4px; font-size: .9rem; }
.icon-btn { font-size: 1.4rem; line-height: 1; color: var(--muted); background: none; border: 0; cursor: pointer; padding: 2px 8px; }

/* sign-in, sign-up and recovery */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.brand-icon { width: 64px; height: 64px; display: block; margin-bottom: 8px; }
.setup { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; font-size: .9rem; }
.qr { background: #fff; padding: 6px; border-radius: 8px; }
.secret { font-size: .85rem; letter-spacing: .02em; max-width: 100%; background: var(--surface-2); padding: 6px 10px; border-radius: 6px; user-select: all; }

/* signed-in frame */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 600; }
.brand img { width: 32px; height: 32px; }
.page { padding: 24px 20px; max-width: 1200px; margin: 0 auto; }
.profile { position: relative; }
.profile-btn { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--accent); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 700; cursor: pointer; }
.menu { position: absolute; right: 0; top: 46px; min-width: 250px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); z-index: 10; display: flex; flex-direction: column; }
.menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-head small { color: var(--muted); }
.menu-item { font: inherit; text-align: left; color: var(--text); background: none; border: 0; border-radius: 6px; padding: 8px 10px; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); }

/* windows */
.overlay { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 50; padding: 16px; }
.dialog { width: min(460px, 100%); max-height: 90vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.dialog.wide { width: min(900px, 100%); }
.dialog header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px 20px; border-bottom: 1px solid var(--border); }
.dialog-body { padding: 16px 20px; overflow: auto; min-height: 0; }
.dialog footer { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--border); }
.table-scroll { max-height: 60vh; overflow: auto; }
.users { width: 100%; border-collapse: collapse; font-size: .92rem; }
.users th, .users td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.users th { position: sticky; top: 0; background: var(--surface); color: var(--muted); font-weight: 600; }
.lock-cell { display: flex; align-items: center; gap: 10px; }
.badge { margin-left: 8px; font-size: .72rem; background: var(--accent); color: var(--accent-text); padding: 1px 6px; border-radius: 99px; }
.sentinel { height: 1px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--border); padding: 10px 16px;
  border-radius: 8px; z-index: 60; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); }
