/* ============================================================ Family UI ===
   Warm, calm design system. Light is the base palette; dark redefines only
   the tokens. Both are reachable via data-theme (explicit) and
   prefers-color-scheme (auto).
   ========================================================================= */

:root {
  --bg: #f6f1ec;
  --bg-tint: #efe7df;
  --surface: #ffffff;
  --surface-2: #fbf7f3;
  --surface-raised: #ffffff;
  --border: #e9dfd7;
  --border-strong: #dbcbbf;
  --text: #241e1a;
  --text-muted: #7c6c62;
  --text-subtle: #9c8c82;

  --accent: #c9502c;
  --accent-hover: #b14425;
  --accent-contrast: #ffffff;
  --accent-soft: #fdf2ea;
  --accent-border: #f2d7c5;
  --accent-glow: rgba(201, 80, 44, .16);

  --success: #2f7a5b;
  --success-soft: #eaf6f0;
  --success-border: #c9e6d8;
  --warning: #a3730f;
  --warning-soft: #fdf5e3;
  --warning-border: #f0dfb4;
  --danger: #bb3a2b;
  --danger-soft: #fdeeec;
  --danger-border: #f4cfc9;

  --shadow-sm: 0 1px 2px rgba(36, 30, 26, .05), 0 1px 3px rgba(36, 30, 26, .04);
  --shadow-md: 0 4px 12px rgba(36, 30, 26, .07), 0 1px 3px rgba(36, 30, 26, .05);
  --shadow-lg: 0 18px 44px rgba(36, 30, 26, .12), 0 3px 10px rgba(36, 30, 26, .06);

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;

  --nav-width: 252px;
  --header-height: 60px;
  --ease: cubic-bezier(.22, .8, .3, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17120f;
    --bg-tint: #120e0c;
    --surface: #1f1815;
    --surface-2: #261e1a;
    --surface-raised: #2a221d;
    --border: #33291f;
    --border-strong: #443729;
    --text: #f5eee8;
    --text-muted: #ab9c92;
    --text-subtle: #8a7b71;

    --accent: #f0805a;
    --accent-hover: #f79070;
    --accent-contrast: #26140d;
    --accent-soft: #2c1d16;
    --accent-border: #4a3024;
    --accent-glow: rgba(240, 128, 90, .2);

    --success: #58bd90;
    --success-soft: #17281f;
    --success-border: #26402f;
    --warning: #d8a33f;
    --warning-soft: #2a2114;
    --warning-border: #453521;
    --danger: #ef7a68;
    --danger-soft: #2d1916;
    --danger-border: #4a2822;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .42);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .55);

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #17120f;
  --bg-tint: #120e0c;
  --surface: #1f1815;
  --surface-2: #261e1a;
  --surface-raised: #2a221d;
  --border: #33291f;
  --border-strong: #443729;
  --text: #f5eee8;
  --text-muted: #ab9c92;
  --text-subtle: #8a7b71;

  --accent: #f0805a;
  --accent-hover: #f79070;
  --accent-contrast: #26140d;
  --accent-soft: #2c1d16;
  --accent-border: #4a3024;
  --accent-glow: rgba(240, 128, 90, .2);

  --success: #58bd90;
  --success-soft: #17281f;
  --success-border: #26402f;
  --warning: #d8a33f;
  --warning-soft: #2a2114;
  --warning-border: #453521;
  --danger: #ef7a68;
  --danger-soft: #2d1916;
  --danger-border: #4a2822;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .42);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, .55);

  color-scheme: dark;
}

/* ------------------------------------------------------------- basics --- */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -.005em;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 660;
  letter-spacing: -.022em;
  line-height: 1.22;
}

h1 { font-size: 1.72rem; }
h2 { font-size: 1.16rem; }
h3 { font-size: 1rem; }

p { margin: 0; }
a { color: var(--accent); }

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); font-size: .86rem; }
.nowrap { white-space: nowrap; }

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

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

/* -------------------------------------------------------------- brand --- */

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-weight: 680;
  font-size: 1.12rem;
  letter-spacing: -.025em;
  color: var(--text);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(165deg, #ec7c4e, #c14428);
  color: #fff7f0;
  display: grid;
  place-items: center;
  flex: none;
  box-shadow: 0 2px 8px rgba(193, 68, 40, .3);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.16;
  min-width: 0;
}

.brand-sub {
  font-size: .74rem;
  font-weight: 500;
  letter-spacing: -.005em;
  color: var(--text-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-mark svg { width: 60%; height: 60%; }

.brand-mark svg path { stroke: currentColor; stroke-width: 8.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.brand-mark svg circle { fill: currentColor; }

/* ------------------------------------------------------------ buttons --- */

button {
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 17px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  font-weight: 580;
  font-size: .93rem;
  white-space: nowrap;
  transition: background .16s var(--ease), border-color .16s var(--ease), transform .12s var(--ease), box-shadow .16s var(--ease), color .16s var(--ease);
}

.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 1px 2px var(--accent-glow);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn.secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn.secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-subtle); }

.btn.ghost { background: transparent; color: var(--text-muted); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { filter: brightness(1.07); }

.btn.danger-outline { border-color: var(--danger-border); color: var(--danger); background: var(--surface); }
.btn.danger-outline:hover:not(:disabled) { background: var(--danger-soft); }

.btn.wide { width: 100%; }
.btn.small { padding: 6px 12px; font-size: .84rem; border-radius: 8px; }

.link-btn {
  color: var(--text-muted);
  font-size: .9rem;
  font-weight: 520;
  text-decoration: none;
  padding: 4px;
  border-radius: 6px;
  transition: color .16s var(--ease);
}
.link-btn:hover { color: var(--accent); }

/* ------------------------------------------------------------- inputs --- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: .82rem;
  font-weight: 620;
  color: var(--text-muted);
  letter-spacing: .005em;
}

input[type="text"], input[type="email"], input[type="password"], select, textarea {
  font: inherit;
  letter-spacing: inherit;
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}

input::placeholder { color: var(--text-subtle); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% + 1px), calc(100% - 13px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 38px;
}

/* --------------------------------------------------------- login view --- */

.login-screen {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
}

.login-aside {
  position: relative;
  overflow: hidden;
  background: linear-gradient(158deg, #2a201b 0%, #1b1512 58%, #241a15 100%);
  color: #f7efe8;
  padding: 54px 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.login-aside::before {
  content: "";
  position: absolute;
  width: 720px;
  height: 720px;
  left: -300px;
  bottom: -330px;
  background: radial-gradient(circle, rgba(216, 96, 56, .5), rgba(216, 96, 56, 0) 68%);
  pointer-events: none;
}

.login-aside::after {
  content: "";
  position: absolute;
  width: 520px;
  height: 520px;
  right: -230px;
  top: -230px;
  background: radial-gradient(circle, rgba(198, 124, 96, .28), rgba(198, 124, 96, 0) 70%);
  pointer-events: none;
}

.login-aside > * { position: relative; z-index: 1; }
.login-aside .brand { color: #fff; }

.aside-copy h2 {
  font-size: 2.35rem;
  line-height: 1.14;
  letter-spacing: -.03em;
  margin-bottom: 16px;
  max-width: 16ch;
}

.aside-copy p {
  color: #c5b4a9;
  font-size: 1.03rem;
  line-height: 1.6;
  max-width: 38ch;
}

.aside-list {
  list-style: none;
  margin: 30px 0 0;
  padding: 0;
  display: grid;
  gap: 13px;
}

.aside-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #d8c8bd;
  font-size: .95rem;
}

.aside-list .icon {
  width: 17px;
  height: 17px;
  color: #ef8b62;
  stroke-width: 2;
}

.aside-foot { color: #8d7d73; font-size: .82rem; }

.login-main {
  display: grid;
  place-items: center;
  padding: 40px 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 396px;
}

.login-card .brand { display: none; margin-bottom: 28px; }

.auth-head { margin-bottom: 26px; }
.auth-head h1 { margin-bottom: 8px; }
.auth-head p { color: var(--text-muted); }

.auth-form { display: grid; gap: 15px; }
.auth-form .btn.primary { margin-top: 4px; padding: 12px 17px; }

.auth-foot {
  display: flex;
  justify-content: center;
  margin-top: 2px;
}

.auth-note {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-subtle);
  font-size: .84rem;
  line-height: 1.55;
  text-align: center;
}

.auth-message {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: .89rem;
  line-height: 1.5;
  white-space: pre-line;
}

.auth-message.error { background: var(--danger-soft); border: 1px solid var(--danger-border); color: var(--danger); }
.auth-message.ok { background: var(--success-soft); border: 1px solid var(--success-border); color: var(--success); }

.password-hint { color: var(--text-subtle); font-size: .8rem; margin-top: -6px; }

/* ---------------------------------------------------------- app shell --- */

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--nav-width) 1fr;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100dvh;
}

.side-nav {
  display: grid;
  gap: 3px;
  align-content: start;
  flex: 1;
}

.nav-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-subtle);
  padding: 0 12px;
  margin: 14px 0 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 540;
  font-size: .94rem;
  text-align: left;
  transition: background .15s var(--ease), color .15s var(--ease);
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 620;
}

.nav-item[disabled] {
  opacity: .55;
  cursor: default;
  pointer-events: none;
}

.nav-soon {
  margin-left: auto;
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-subtle);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 999px;
}

.side-user {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: grid;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 6px;
  min-width: 0;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: linear-gradient(165deg, #ec7c4e, #c14428);
  color: #fff7f0;
  display: grid;
  place-items: center;
  font-weight: 680;
  font-size: .92rem;
  flex: none;
  letter-spacing: 0;
}

.user-chip-text { min-width: 0; }
.user-chip-name { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-mail { color: var(--text-subtle); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; display: flex; flex-direction: column; }

/* viewport-fit=cover plus a translucent status bar means the page is drawn
   underneath the notch, so every fixed/sticky edge has to pay back the inset
   itself. Without this the hamburger sits under the iPhone status bar. */
.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--text-muted);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.content {
  padding: 34px 38px 64px;
  max-width: 1120px;
  width: 100%;
  flex: 1;
}

.view { display: none; }
.view.active-view { display: block; animation: viewIn .28s var(--ease); }

@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.view-head { margin-bottom: 26px; }
.view-head h1 { margin-bottom: 6px; }
.view-head p { color: var(--text-muted); }

/* ---------------------------------------------------------- surfaces --- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.panel + .panel { margin-top: 18px; }

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-head p { color: var(--text-muted); font-size: .89rem; margin-top: 3px; }

/* ------------------------------------------------------------- home --- */

.welcome {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-xl);
  background: linear-gradient(150deg, #2a201b, #1a1411 62%, #251b16);
  color: #f7efe8;
  padding: 40px 42px;
  margin-bottom: 22px;
}

.welcome::before {
  content: "";
  position: absolute;
  width: 620px;
  height: 620px;
  right: -240px;
  top: -280px;
  background: radial-gradient(circle, rgba(224, 106, 62, .42), rgba(224, 106, 62, 0) 68%);
  pointer-events: none;
}

.welcome > * { position: relative; z-index: 1; }

.welcome h1 {
  font-size: 2rem;
  margin-bottom: 10px;
  letter-spacing: -.028em;
}

.welcome p {
  color: #c8b7ac;
  max-width: 52ch;
  font-size: 1.01rem;
}

.welcome-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: .81rem;
  font-weight: 560;
  background: rgba(255, 255, 255, .09);
  border: 1px solid rgba(255, 255, 255, .13);
  color: #e2d3c9;
}

.pill .icon { width: 14px; height: 14px; stroke-width: 2; }

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 14px;
}

.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 21px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 11px;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s var(--ease);
}

.module-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.module-icon {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
}

.module-icon .icon { width: 21px; height: 21px; }

.module-card h3 { font-size: .99rem; }
.module-card p { color: var(--text-muted); font-size: .88rem; line-height: 1.5; }

.module-tag {
  margin-top: auto;
  align-self: flex-start;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-subtle);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
}

/* --------------------------------------------------------- settings --- */

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 17px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: 0; padding-bottom: 0; }
.setting-row:first-child { padding-top: 0; }

.setting-text h3 { font-size: .96rem; margin-bottom: 3px; }
.setting-text p { color: var(--text-muted); font-size: .87rem; max-width: 56ch; }

.setting-control { flex: none; min-width: 168px; }
.setting-control select { min-width: 168px; }

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 2px;
}

.segmented button {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: .86rem;
  font-weight: 560;
  color: var(--text-muted);
  transition: background .15s var(--ease), color .15s var(--ease);
}

.segmented button:hover { color: var(--text); }

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 620;
  box-shadow: var(--shadow-sm);
}

.danger-zone { border-color: var(--danger-border); }
.danger-zone .panel-head h2 { color: var(--danger); }

/* ------------------------------------------------------------ admin --- */

/* Exactly eight KPIs, so lock the grid to factors of eight and avoid a lonely
   card wrapping onto its own row. */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 13px;
  margin-bottom: 18px;
}

@media (min-width: 700px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 17px 18px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-subtle);
  margin-bottom: 7px;
}

.kpi-value {
  font-size: 1.85rem;
  font-weight: 680;
  letter-spacing: -.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.kpi-hint { font-size: .8rem; color: var(--text-muted); margin-top: 3px; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 132px;
  padding-top: 8px;
  border-bottom: 1px solid var(--border);
}

.chart-bar {
  flex: 1;
  min-width: 0;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
  min-height: 3px;
  position: relative;
  transition: background .15s var(--ease);
}

.chart-bar[data-has-data="true"] { background: var(--accent); border-color: var(--accent); }
.chart-bar:hover { filter: brightness(1.08); }

.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 9px;
  font-size: .76rem;
  color: var(--text-subtle);
}

.table-wrap {
  overflow-x: auto;
  margin: 0 -24px -24px;
  padding: 0 24px 4px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .89rem;
  min-width: 720px;
}

table.data th {
  text-align: left;
  font-size: .73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-subtle);
  padding: 0 14px 10px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data td {
  padding: 13px 14px 13px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background .13s var(--ease); }
table.data tbody tr:hover { background: var(--surface-2); }

.cell-user { display: flex; align-items: center; gap: 11px; min-width: 0; }
.cell-user .avatar { width: 33px; height: 33px; border-radius: 10px; font-size: .84rem; }
.cell-name { font-weight: 590; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-mail { color: var(--text-subtle); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 620;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge.ok { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.badge.pending { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.badge.off { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.badge.bad { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.badge.admin { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Email, name, a selector and the submit button. */
.invite-form {
  display: grid;
  grid-template-columns: 1.15fr 1fr .95fr auto;
  gap: 12px;
  align-items: end;
}

.invite-form.two-col { grid-template-columns: 1fr auto; }

@media (max-width: 1080px) {
  .invite-form { grid-template-columns: 1fr 1fr; }
  .invite-form > button { grid-column: 1 / -1; }
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: .89rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.event-list { display: grid; gap: 2px; }

.event-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .87rem;
}

.event-row:last-child { border-bottom: 0; }
.event-mail { font-weight: 560; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-time { margin-left: auto; color: var(--text-subtle); font-size: .8rem; white-space: nowrap; }
.event-diag { color: var(--text-subtle); font-size: .8rem; }

.empty {
  text-align: center;
  padding: 42px 20px;
  color: var(--text-muted);
}

.empty .icon { width: 34px; height: 34px; color: var(--text-subtle); margin-bottom: 12px; stroke-width: 1.4; }
.empty h3 { margin-bottom: 5px; }
.empty p { font-size: .89rem; }

.loading-row {
  height: 15px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2), var(--bg-tint), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ------------------------------------------------------------ vault --- */

.vault-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 17px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: .91rem;
  margin-bottom: 18px;
}

.vault-banner .icon { flex: none; }
.vault-banner span { min-width: 0; }
.vault-banner .btn { margin-left: auto; flex: none; }

.vault-banner.locked { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.vault-banner.waiting { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }

.recovery-code {
  margin: 18px 0 14px;
  padding: 18px 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.12rem;
  font-weight: 650;
  letter-spacing: .06em;
  text-align: center;
  word-break: break-all;
  user-select: all;
}

/* ------------------------------------------------------------ modal --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 18, 15, .55);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
  animation: fadeIn .16s var(--ease);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 26px;
  width: 100%;
  max-width: 452px;
  animation: modalIn .22s var(--ease);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.modal h2 { margin-bottom: 9px; }
.modal p { color: var(--text-muted); font-size: .92rem; }
.modal .field { margin-top: 18px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ------------------------------------------------------------ toast --- */

.toast-stack {
  position: fixed;
  bottom: 22px;
  right: 22px;
  display: grid;
  gap: 9px;
  z-index: 200;
  max-width: min(400px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 16px;
  border-radius: var(--radius);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: .9rem;
  line-height: 1.45;
  animation: toastIn .26s var(--ease);
}

.toast.ok { border-color: var(--success-border); }
.toast.ok .icon { color: var(--success); }
.toast.error { border-color: var(--danger-border); }
.toast.error .icon { color: var(--danger); }
.toast .icon { flex: none; margin-top: 1px; stroke-width: 2; }
.toast span { white-space: pre-line; min-width: 0; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: none; }
}

/* ----------------------------------------------------------- footer --- */

.app-foot {
  color: var(--text-subtle);
  font-size: .78rem;
  text-align: center;
  padding: 26px 16px 0;
}

/* ------------------------------------------------------- mobile menu --- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(24, 18, 15, .5);
  backdrop-filter: blur(2px);
  z-index: 50;
  animation: fadeIn .16s var(--ease);
}

/* ------------------------------------------------------ responsive --- */

@media (max-width: 1000px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-aside { display: none; }
  .login-card .brand { display: flex; justify-content: center; }
  .login-main {
    padding: calc(32px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-left, 0px))
             calc(56px + env(safe-area-inset-bottom, 0px));
    align-content: center;
  }
  .auth-head { text-align: center; }
}

@media (max-width: 860px) {
  body { font-size: 15px; }

  .app-shell { grid-template-columns: 1fr; }

  .topbar { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(84vw, 300px);
    height: 100dvh;
    z-index: 60;
    transform: translateX(-102%);
    transition: transform .26s var(--ease);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    /* Clear the notch at the top and the home indicator at the bottom. */
    padding-top: calc(22px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px));
  }

  .sidebar.open { transform: none; }

  .content {
    padding: 22px 18px 52px;
    padding-left: max(18px, env(safe-area-inset-left, 0px));
    padding-right: max(18px, env(safe-area-inset-right, 0px));
    padding-bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  }

  .welcome { padding: 30px 24px; border-radius: var(--radius-lg); }
  .welcome h1 { font-size: 1.6rem; }
  .welcome p { font-size: .96rem; }

  .panel { padding: 19px; border-radius: var(--radius); }
  .table-wrap { margin: 0 -19px -19px; padding: 0 19px 4px; }

  .view-head h1 { font-size: 1.46rem; }

  .setting-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .setting-control { min-width: 0; }
  .setting-control select { width: 100%; min-width: 0; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }

  .invite-form { grid-template-columns: 1fr; }

  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(136px, 1fr)); gap: 10px; }
  .kpi { padding: 14px 15px; }
  .kpi-value { font-size: 1.55rem; }

  .toast-stack {
    left: 16px;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
