:root {
  --bg: #f5f4f1;
  --surface: #fbfaf8;
  --surface-2: #efede9;
  --text: #191a1d;
  --muted: #626872;
  --border: #ddd9d2;
  --accent: #5964f2;
  --accent-soft: #e9e9fb;
  --danger: #c73b3b;
  --warning: #a66d12;
  --success: #258562;
  --success-soft: #e3f2eb;
  --danger-soft: #fae8e8;
  --warning-soft: #f8efd9;
  --shadow: 0 8px 24px rgba(40,35,28,.055);
  --radius: 18px;
  --sidebar-width: 260px;
  --sidebar-compact-width: 76px;
  --sidebar-padding: 18px;
  --nav-gap: 8px;
  --nav-height: 46px;
  --logo-size: 42px;
}

html[data-theme="dark"] {
  --bg:#0f1114;
  --surface:#181b20;
  --surface-2:#22262d;
  --text:#f2f4f7;
  --muted:#adb5c0;
  --border:#2e343d;
  --accent:#8e96ff;
  --accent-soft:#272b50;
  --danger:#ff7474;
  --warning:#f2bd55;
  --success:#46c894;
  --success-soft:#18382d;
  --danger-soft:#442225;
  --warning-soft:#40351e;
  --shadow:0 10px 30px rgba(0,0,0,.22);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg:#0f1114;
    --surface:#181b20;
    --surface-2:#22262d;
    --text:#f2f4f7;
    --muted:#adb5c0;
    --border:#2e343d;
    --accent:#8e96ff;
    --accent-soft:#272b50;
    --danger:#ff7474;
    --warning:#f2bd55;
    --success:#46c894;
    --success-soft:#18382d;
    --danger-soft:#442225;
    --warning-soft:#40351e;
    --shadow:0 10px 30px rgba(0,0,0,.22);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, select, input { font: inherit; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  transition: grid-template-columns .2s ease;
}

html[data-sidebar="compact"] .app-shell {
  grid-template-columns: var(--sidebar-compact-width) 1fr;
}

html[data-sidebar="hidden"] .app-shell {
  grid-template-columns: 0 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: var(--sidebar-padding);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .2s ease, opacity .2s ease;
}

html[data-sidebar="hidden"] .sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

.sidebar-top { display: grid; gap: 14px; }

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: var(--logo-size);
  height: var(--logo-size);
  min-width: var(--logo-size);
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.brand-mark.large { width: 54px; height: 54px; }
.brand-text { display: grid; line-height: 1.05; }
.brand-text span { color: var(--muted); font-size: .86rem; margin-top: 4px; }

.nav-list { display: grid; gap: var(--nav-gap); }

.nav-item {
  min-height: var(--nav-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

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

.nav-icon {
  width: 28px;
  min-width: 28px;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
}

.sidebar-bottom { margin-top: auto; }
.status-dot-row { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .9rem; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #36b37e; display: inline-block; }

html[data-sidebar="compact"] .brand-text,
html[data-sidebar="compact"] .nav-label { display: none; }

html[data-sidebar="compact"] .brand { justify-content: center; }
html[data-sidebar="compact"] .nav-item { justify-content: center; padding-inline: 0; }
html[data-sidebar="compact"] .sidebar { padding-inline: 12px; }

.main { min-width: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 24px 30px 14px;
}

.topbar h1 { margin: 2px 0 0; font-size: clamp(1.6rem,2.5vw,2.25rem); }
.eyebrow { margin: 0; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-button, .control {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  min-height: 42px;
}

.icon-button { min-width: 42px; cursor: pointer; }
.icon-button:hover { background: var(--surface-2); }
.control { padding: 0 12px; }

.floating-menu-button {
  display: none;
  position: fixed;
  z-index: 40;
  left: 12px;
  top: 12px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
}

html[data-sidebar="hidden"] .floating-menu-button { display: block; }

.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--text);
  color: var(--surface);
  font-weight: 700;
  font-size: .82rem;
  cursor: pointer;
  list-style: none;
}

.avatar::-webkit-details-marker { display:none; }
.user-menu { position: relative; }
.user-menu-panel {
  position: absolute;
  right: 0;
  top: 50px;
  z-index: 30;
  min-width: 220px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
}

.content { padding: 12px 30px 36px; }

.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 28px;
  border-radius: var(--radius);
  background: linear-gradient(135deg,var(--accent-soft),var(--surface));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.hero h2 { margin: 4px 0 8px; font-size: clamp(1.5rem,3vw,2.4rem); }
.muted { color: var(--muted); }

.health-pill, .badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  white-space: nowrap;
  font-size: .88rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 16px;
  margin-top: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.card h2, .card h3 { margin-top: 0; }
.service-card { display: grid; gap: 14px; }

.service-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent-soft);
  font-size: 1.5rem;
}

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.auth-card {
  width: min(100%,460px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 30px;
  box-shadow: var(--shadow);
}

.auth-brand { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.auth-brand h1, .auth-card h1 { margin: .2rem 0 0; }

.form-stack { display: grid; gap: 16px; margin-top: 22px; }
.form-stack.narrow { max-width: 560px; }
.form-stack label { display: grid; gap: 7px; font-weight: 600; }

.input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.code-input { font-size: 1.15rem; letter-spacing: .08em; text-align: center; }

.button {
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 0 16px;
  cursor: pointer;
  font-weight: 700;
}

.button.primary { background: var(--accent); color: white; border-color: var(--accent); }
.button.secondary { background: var(--surface-2); color: var(--text); }
.button.danger { background: var(--danger); color: white; border-color: var(--danger); }
.button.full { width: 100%; }
.link-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.text-link { color: var(--accent); text-decoration: none; font-weight: 650; }
.text-link:hover { text-decoration: underline; }

.qr-wrap { background: white; border-radius: 18px; padding: 18px; width: fit-content; margin: 20px auto; }
.qr-wrap img { display: block; width: 220px; height: 220px; }

.secret-box { margin: 16px 0; color: var(--muted); }
.secret-box code { display: block; margin-top: 10px; padding: 12px; border-radius: 10px; background: var(--bg); overflow-wrap: anywhere; color: var(--text); }

.flash-stack { display: grid; gap: 8px; margin-bottom: 16px; }
.flash { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.flash.error { border-color: var(--danger); }
.flash.success { border-color: #36b37e; }
.flash.warning { border-color: var(--warning); }

.notice { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); margin: 14px 0; }
.notice.warning { border-color: var(--warning); background: color-mix(in srgb, var(--warning) 10%, transparent); }

.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.settings-tabs a {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  background: var(--surface);
}

.settings-tabs a.is-active { background: var(--accent-soft); color: var(--text); border-color: var(--accent); }

.settings-card { max-width: 780px; }
.settings-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.danger-card { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); }

.recovery-card { max-width: 760px; margin-inline: auto; }

.recovery-grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 10px;
  margin: 20px 0;
}

.recovery-grid code {
  display: block;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
  font-size: 1.02rem;
}

.activity-mini { display: grid; gap: 10px; margin: 12px 0; }
.activity-mini > div { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.activity-mini span { color: var(--muted); font-size: .85rem; }

.activity-table-wrap { overflow-x: auto; }
.activity-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.activity-table th, .activity-table td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.activity-table th { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }

.visually-hidden {
  position:absolute!important;
  width:1px!important;
  height:1px!important;
  padding:0!important;
  margin:-1px!important;
  overflow:hidden!important;
  clip:rect(0,0,0,0)!important;
  white-space:nowrap!important;
  border:0!important;
}

@media (max-height: 780px) {
  :root {
    --sidebar-padding: 12px;
    --nav-gap: 4px;
    --nav-height: 40px;
    --logo-size: 36px;
  }

  .sidebar { gap: 12px; }
  .brand-text span { display: none; }
}

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell,
  html[data-sidebar="compact"] .app-shell,
  html[data-sidebar="hidden"] .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    z-index: 50;
    inset: 0 auto 0 0;
    width: min(82vw,300px);
    transform: translateX(-100%);
    opacity: 1;
    pointer-events: auto;
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }

  html[data-mobile-sidebar="open"] .sidebar { transform: translateX(0); }

  .floating-menu-button,
  html[data-sidebar="hidden"] .floating-menu-button { display: block; }

  .main { width: 100%; }
  .topbar, .content { padding-left: 18px; padding-right: 18px; }
  .topbar { align-items: flex-start; padding-left: 68px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .grid { grid-template-columns: 1fr; }
  .hero { align-items: flex-start; flex-direction: column; }
  .recovery-grid { grid-template-columns: 1fr; }

  html[data-sidebar="compact"] .brand-text,
  html[data-sidebar="compact"] .nav-label { display: initial; }

  html[data-sidebar="compact"] .brand { justify-content: flex-start; }
  html[data-sidebar="compact"] .nav-item { justify-content: flex-start; padding-inline: 12px; }
}


/* Version & changelog — v0.3.4 */
.sidebar-bottom {
  display: grid;
  gap: 10px;
}

.portal-version-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 6px 8px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: .78rem;
  white-space: nowrap;
}

.portal-version-link:hover,
.portal-version-link.is-active {
  background: var(--surface-2);
  color: var(--text);
}

.portal-version-mark {
  width: 20px;
  min-width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .7rem;
  font-weight: 800;
}

html[data-sidebar="compact"] .portal-version-link {
  justify-content: center;
  padding-inline: 0;
}

.changelog-layout {
  display: grid;
  gap: 18px;
}

.changelog-intro {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.changelog-intro h2 {
  margin: 4px 0 8px;
  font-size: 1.35rem;
}

.version-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: .85rem;
  font-weight: 700;
  white-space: nowrap;
}

.changelog-card {
  max-width: 900px;
}

.changelog-content > h1:first-child {
  display: none;
}

.changelog-content h2 {
  margin: 26px 0 12px;
  padding-top: 4px;
  font-size: 1.2rem;
}

.changelog-content h2:first-of-type {
  margin-top: 0;
}

.changelog-content h3 {
  margin: 18px 0 8px;
  color: var(--text);
  font-size: .9rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.changelog-content p,
.changelog-content li {
  color: var(--muted);
  line-height: 1.65;
}

.changelog-content ul {
  margin: 8px 0 12px;
  padding-left: 22px;
}

.changelog-content li + li {
  margin-top: 4px;
}

.changelog-content hr {
  margin: 24px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.changelog-content code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: .88em;
}

@media (max-width: 620px) {
  .changelog-intro {
    align-items: stretch;
    flex-direction: column;
  }

  .version-badge {
    align-self: flex-start;
  }
}


/* Layout polish — v0.3.5 */

/* Global navigation stays available while page content scrolls. */
.global-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
}

/* Give the sticky bar a subtle separation without making it feel heavy. */
.global-topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  background: var(--border);
  opacity: .55;
  pointer-events: none;
}

/* Changelog uses the same outer content width as the rest of the portal. */
.changelog-layout {
  width: 100%;
  max-width: none;
}

/* Keep long-form text comfortably readable without narrowing the whole page. */
.changelog-reading-column {
  width: 100%;
  max-width: 940px;
}

.changelog-card {
  width: 100%;
  max-width: none;
}

@media (max-width: 980px) {
  .changelog-reading-column {
    max-width: none;
  }
}


/* Design system polish — v0.3.6 */

/* A little more depth between page, sidebar and content surfaces. */
.sidebar {
  box-shadow: 1px 0 0 rgba(255,255,255,.015);
}

.card {
  box-shadow: 0 4px 16px rgba(35,31,25,.035);
}

/* Service cards are actionable/product-like; information cards are calmer. */
.service-card {
  position: relative;
  overflow: hidden;
  border-color: color-mix(in srgb, var(--accent) 24%, var(--border));
  background:
    linear-gradient(145deg,
      color-mix(in srgb, var(--accent-soft) 38%, var(--surface)),
      var(--surface) 48%);
  box-shadow: 0 8px 24px rgba(35,31,25,.055);
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.service-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
  opacity: .8;
}

.service-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent) 42%, var(--border));
  box-shadow: 0 12px 28px rgba(35,31,25,.075);
}

.service-card .service-icon {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 15%, transparent);
}

.info-card {
  background: color-mix(in srgb, var(--surface) 96%, var(--bg));
  box-shadow: none;
}

.info-card h3 {
  margin-bottom: 14px;
}

/* Keep the hero as the portal-level visual anchor, but slightly calmer. */
.hero {
  box-shadow: 0 8px 24px rgba(35,31,25,.045);
  background:
    linear-gradient(135deg,
      color-mix(in srgb, var(--accent-soft) 82%, var(--surface)),
      var(--surface) 62%);
}

/* Semantic status language: color supports the text, never replaces it. */
.status-dot {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 12%, transparent);
}

.health-pill {
  background: color-mix(in srgb, var(--success-soft) 55%, var(--surface));
  color: color-mix(in srgb, var(--success) 72%, var(--text));
  border-color: color-mix(in srgb, var(--success) 26%, var(--border));
}

.notice.warning {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 52%, var(--border));
}

.notice.danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 52%, var(--border));
}

/* Explicit dark/system-dark tuning for depth without changing identity. */
html[data-theme="dark"] .card,
html[data-theme="dark"] .info-card {
  background: var(--surface);
}

html[data-theme="dark"] .service-card {
  background:
    linear-gradient(145deg,
      color-mix(in srgb, var(--accent-soft) 45%, var(--surface)),
      var(--surface) 52%);
  box-shadow: 0 8px 26px rgba(0,0,0,.16);
}

html[data-theme="dark"] .hero {
  box-shadow: 0 8px 26px rgba(0,0,0,.14);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .card,
  html[data-theme="system"] .info-card {
    background: var(--surface);
  }

  html[data-theme="system"] .service-card {
    background:
      linear-gradient(145deg,
        color-mix(in srgb, var(--accent-soft) 45%, var(--surface)),
        var(--surface) 52%);
    box-shadow: 0 8px 26px rgba(0,0,0,.16);
  }

  html[data-theme="system"] .hero {
    box-shadow: 0 8px 26px rgba(0,0,0,.14);
  }
}

/* Respect users who prefer less motion. */
@media (prefers-reduced-motion: reduce) {
  .service-card {
    transition: none;
  }
  .service-card:hover {
    transform: none;
  }
}
