:root {
  --bg: #f3f5f1;
  --surface: #ffffff;
  --surface-2: #f8faf6;
  --text: #1f2937;
  --muted: #667085;
  --line: #dde3da;
  --accent: #8da17a;
  --accent-strong: #73895f;
  --accent-soft: #e9efdf;
  --accent-contrast: #ffffff;
  --danger: #b42318;
  --success: #067647;
  --radius: 18px;
  --shadow: 0 12px 34px rgba(31, 41, 55, .07);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(141, 161, 122, .12), transparent 35%),
    linear-gradient(180deg, #f7f8f5 0%, var(--bg) 34%, var(--bg) 100%);
  overflow-x: hidden;
}
a { color: inherit; }
button, input, select { font: inherit; }
img { max-width: 100%; }

.app-shell { min-height: 100vh; padding-bottom: 88px; overflow-x: clip; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; max-width: min(72vw, 440px); }
.brand-emblem {
  display: block;
  width: 50px;
  height: 50px;
  object-fit: contain;
  flex: 0 0 50px;
}
.brand-copy { display: block; min-width: 0; overflow: hidden; }
.brand-title { display: block; letter-spacing: -.03em; font-size: 1.02rem; white-space: nowrap; }
.brand small { display: block; color: var(--muted); font-size: .72rem; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip { max-width: min(38vw, 280px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid var(--line); border-radius: 999px; padding: 8px 11px; font-size: .85rem; background: var(--surface-2); }

.main-content { width: min(1120px, calc(100% - 28px)); margin: 0 auto; padding: 28px 0 42px; min-width: 0; }
.hero, .page-head { padding: 8px 2px 20px; }
.hero h1, .page-head h1, .card h1 { margin: 4px 0 6px; font-size: clamp(1.8rem, 7vw, 3rem); letter-spacing: -.045em; line-height: 1.02; }
h2 { margin: 0; font-size: 1.15rem; letter-spacing: -.02em; }
p { line-height: 1.55; }
.muted { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 800; color: var(--muted); }
.section-heading { display: flex; align-items: center; gap: 8px; margin: 14px 2px 12px; }
.badge { min-width: 25px; height: 25px; display: inline-grid; place-items: center; padding: 0 8px; border-radius: 999px; background: var(--accent-soft); color: #42543a; font-size: .75rem; font-weight: 800; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.narrow { width: min(100%, 560px); margin: 5vh auto 0; }
.center { text-align: center; }
.big-code { font-size: 4rem; font-weight: 900; color: var(--muted); }

.hero-dashboard { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; align-items: center; }
.hero-intro { min-width: 0; }
.brand-lockup {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(88px, 27%) minmax(0, 1fr);
  align-items: center;
  justify-content: stretch;
  gap: clamp(12px, 2vw, 22px);
  padding: clamp(16px, 2.2vw, 24px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.brand-lockup-emblem {
  display: block;
  width: min(100%, 158px);
  height: auto;
  max-height: 168px;
  object-fit: contain;
  justify-self: center;
}
.brand-lockup-copy { min-width: 0; width: 100%; max-width: 100%; overflow: hidden; }
.wordmark {
  font-weight: 520;
  letter-spacing: -.055em;
  line-height: .95;
  color: var(--text);
}
.wordmark-os { color: var(--accent-strong); text-transform: uppercase; font-weight: 650; }
.brand-lockup .wordmark {
  /* Deliberately sized from the viewport conservatively: the complete wordmark
     stays inside the card even when the dashboard itself uses two columns. */
  font-size: clamp(1.18rem, 2.15vw, 2.25rem);
  white-space: nowrap;
  max-width: 100%;
}
.wordmark-caption { margin-top: 8px; color: var(--muted); font-size: .82rem; letter-spacing: .08em; text-transform: uppercase; }

.auth-card { overflow: hidden; }
.auth-brand { display: grid; justify-items: center; gap: 8px; margin: -4px 0 18px; max-width: 100%; }
.auth-emblem { display: block; width: clamp(108px, 24vw, 170px); height: auto; object-fit: contain; }
.auth-wordmark { max-width: 100%; font-size: clamp(1.45rem, 7vw, 2.35rem); white-space: nowrap; }

.module-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.module-card { min-height: 92px; display: grid; grid-template-columns: 48px minmax(0,1fr) auto; align-items: center; gap: 14px; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); text-decoration: none; transition: transform .15s ease, border-color .15s ease; min-width: 0; }
.module-card:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent) 58%, var(--line)); }
.module-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; background: var(--accent-soft); color: #334155; font-weight: 900; }
.module-card strong, .module-card small { display: block; overflow-wrap: anywhere; }
.module-card small { color: var(--muted); margin-top: 4px; line-height: 1.3; }
.arrow { font-size: 1.8rem; color: var(--muted); }

.account-card { margin-top: 26px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.stack { display: grid; gap: 15px; margin-top: 18px; }
label { display: grid; gap: 7px; font-size: .88rem; font-weight: 700; }
input, select { width: 100%; border: 1px solid #cdd5cf; border-radius: 12px; padding: 12px 13px; background: var(--surface); color: var(--text); outline: none; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(141, 161, 122, .18); }
.check-row { display: grid; grid-template-columns: 22px 1fr; align-items: start; gap: 8px; font-weight: 500; line-height: 1.35; }
.check-row input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--accent-strong); }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; border: 1px solid transparent; border-radius: 12px; padding: 9px 14px; text-decoration: none; font-weight: 750; cursor: pointer; }
.button.primary { background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%); color: var(--accent-contrast); }
.button.secondary { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.button.danger { background: var(--danger); color: #fff; }
.button.ghost { background: transparent; color: var(--danger); border-color: #f1c6c1; }

.flash { margin-bottom: 14px; border-radius: 12px; padding: 12px 14px; border: 1px solid var(--line); background: var(--surface); }
.flash-error { border-color: #f1c6c1; color: #8a1c13; background: #fff4f2; }
.flash-success { border-color: #a9dfc5; color: #05603a; background: #ecfdf3; }
.flash-info { border-color: #d8e3d1; color: #435045; background: #f7faf3; }

.two-column { display: grid; grid-template-columns: 1fr; gap: 16px; }
.device-list, .user-list { display: grid; gap: 0; margin-top: 8px; }
.device-row, .user-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.device-row:last-child, .user-row:last-child { border-bottom: 0; }
.device-row small, .user-row small { display: block; color: var(--muted); margin-top: 4px; max-width: 68ch; overflow-wrap: anywhere; }
.hint { color: var(--muted); font-size: .82rem; }
.top-gap { margin-top: 14px; }
code { background: #edf2e9; border-radius: 6px; padding: 2px 5px; }

.bottom-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 8px max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(18px); border-top: 1px solid var(--line); }
.bottom-nav a { min-height: 54px; display: grid; place-items: center; align-content: center; gap: 2px; text-decoration: none; color: var(--muted); }
.bottom-nav span { font-size: 1.15rem; line-height: 1; }
.bottom-nav small { font-size: .67rem; }
.footer { text-align: center; color: var(--muted); font-size: .72rem; padding: 20px; }

@media (max-width: 520px) {
  .topbar { gap: 10px; }
  .brand { max-width: 68vw; }
  .brand-emblem { width: 44px; height: 44px; flex-basis: 44px; }
  .brand-lockup { grid-template-columns: minmax(0, 1fr); text-align: center; gap: 10px; }
  .brand-lockup-emblem { width: min(44vw, 150px); }
  .brand-lockup-copy { overflow: visible; }
  .brand-lockup .wordmark { font-size: clamp(1.25rem, 7.2vw, 1.9rem); white-space: normal; overflow-wrap: normal; }
  .auth-wordmark { font-size: clamp(1.3rem, 8vw, 1.9rem); white-space: normal; text-align: center; }
  .account-card { align-items: flex-start; flex-direction: column; }
}

@media (min-width: 720px) {
  .main-content { padding-top: 42px; }
  /* The logo gets the wider dashboard column on desktop.  This prevents the
     long wordmark from being squeezed against the card edge. */
  .hero-dashboard { grid-template-columns: minmax(230px, .72fr) minmax(0, 1.28fr); gap: clamp(24px, 3vw, 40px); }
  .module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column { grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); }
  .admin-layout { grid-template-columns: minmax(300px, .7fr) minmax(0, 1.3fr); }
  .bottom-nav { width: fit-content; min-width: 420px; left: 50%; right: auto; bottom: 18px; transform: translateX(-50%); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 12px 36px rgba(17,24,39,.14); padding: 6px 10px; }
  .app-shell { padding-bottom: 106px; }
}

@media (min-width: 980px) {
  .module-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 1280px) {
  .brand-lockup .wordmark { font-size: 2.25rem; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1110;
    --surface: #121918;
    --surface-2: #17211f;
    --text: #f1f5f3;
    --muted: #a6b0aa;
    --line: #273430;
    --accent: #8ba17a;
    --accent-strong: #9fb88b;
    --accent-soft: #1e2924;
    --accent-contrast: #f8faf8;
    --shadow: 0 8px 30px rgba(0,0,0,.18);
  }
  body { background: radial-gradient(circle at top, rgba(139,161,122,.16), transparent 35%), linear-gradient(180deg,#0e1413 0%,var(--bg) 34%,var(--bg) 100%); }
  .badge { background: #243029; color: #dbe6d5; }
  input, select { border-color: #33413b; }
  code { background: #1d2622; }
  .flash-error { background: #351715; color: #fecaca; border-color: #7f1d1d; }
  .flash-success { background: #0f2a20; color: #a7f3d0; border-color: #14532d; }
  .flash-info { background: #16211d; color: #d2ddd5; border-color: #314137; }
  .module-icon { color: #dfe7dd; }
}
