:root {
  color-scheme: light;
  font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --canvas: #f4f2ee;
  --card: #fff;
  --ink: #17232a;
  --muted: #54636c;
  --line: #deded8;
  --action: #b63d13;
  --on-action: #fff9ef;
  --tint: #fff0e8;
  --good: #28664b;
  --good-bg: #e8f3ec;
  --danger: #a32938;
  --danger-bg: #fcecef;
  --focus: #236f9f;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #131c20;
  --card: #1d292f;
  --ink: #edf0ed;
  --muted: #afbabd;
  --line: #34434a;
  --action: #ffac80;
  --on-action: #241b15;
  --tint: #382b24;
  --good: #a1dbb9;
  --good-bg: #22382e;
  --danger: #ffb3bb;
  --danger-bg: #3e272e;
  --focus: #8bc7ee;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.6; }
button, input, select { border-radius: 12px; }
button { min-height: 48px; padding: 10px 16px; border: 1px solid transparent; font-size: 0.9rem; font-weight: 600; }
button, .actions, .section-heading { display: flex; align-items: center; gap: 8px; }
button { justify-content: center; }
button:hover:not(:disabled) { filter: brightness(0.96); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
a { color: var(--action); text-underline-offset: 3px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 2rem; line-height: 1.15; letter-spacing: -0.035em; margin-bottom: 10px; }
h2 { font-size: 1.25rem; letter-spacing: -0.02em; margin-bottom: 12px; }
h3 { font-size: 1rem; margin-bottom: 8px; }
p { margin-bottom: 16px; }
label { display: block; font-size: 0.85rem; font-weight: 600; margin: 20px 0 7px; }
input, select { display: block; width: 100%; min-height: 48px; padding: 11px 12px; background: var(--card); color: var(--ink); border: 1px solid var(--line); }
select { appearance: none; padding-right: 40px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) center, calc(100% - 15px) center; background-size: 5px 5px; background-repeat: no-repeat; }
input::placeholder { color: var(--muted); opacity: 1; }
.primary { background: var(--action); color: var(--on-action); }
.secondary { background: var(--card); color: var(--ink); border-color: var(--line); }
.quiet { background: transparent; color: var(--muted); }
.danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.full { width: 100%; margin-top: 12px; }
.invitation-action { display: flex; justify-content: center; align-items: center; min-height: 48px; padding: 10px 16px; border-radius: 12px; text-decoration: none; font-weight: 600; }
.invitation-fallback { margin-top: 24px; }
.invitation-page .auth-icon { width: 64px; height: 64px; }
.muted, .help { color: var(--muted); }
.help { font-size: 0.8rem; line-height: 1.6; margin-top: 10px; }
.eyebrow { color: var(--muted); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; margin-bottom: 10px; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.8rem; overflow-wrap: anywhere; }
.glyph { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.glyph-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.skip-link { position: absolute; left: 16px; top: -80px; background: var(--card); padding: 12px; z-index: 20; }
.skip-link:focus { top: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.shell { max-width: 1440px; margin: auto; }
main { padding: 32px; min-width: 0; }
body:not(.authenticated) main { max-width: 520px; margin: 8vh auto 0; }
.authenticated .shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }
.sidebar { padding: 32px 20px; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 100dvh; position: sticky; top: 0; height: 100dvh; }
.brand-header { display: flex; align-items: center; gap: 10px; margin-bottom: 40px; }
.brand-icon { width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; }
.brand-name { font-size: 1.2rem; letter-spacing: -0.035em; font-weight: 700; }
.brand-header p { color: var(--muted); font-size: 0.7rem; margin: 0; }
nav { display: grid; gap: 8px; }
nav button { width: 100%; justify-content: flex-start; background: transparent; color: var(--muted); gap: 12px; }
nav button[aria-current="page"] { color: var(--action); background: var(--tint); }
.sidebar-foot { margin-top: auto; padding-top: 40px; }
.sidebar-foot p { font-size: 0.75rem; color: var(--muted); margin-left: 16px; }
.sidebar-foot button { width: 100%; justify-content: flex-start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 24px; }
.auth-card { margin-top: 32px; padding: 32px; }
.auth-mark { width: 64px; height: 64px; border-radius: 20px; margin-bottom: 24px; }
.auth-card h1 { font-size: 1.8rem; }
.auth-foot { text-align: center; margin: 24px 0 0; }
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin: 12px 0 32px; }
.page-header p:last-child { margin-bottom: 0; }
.actions { flex-shrink: 0; flex-wrap: wrap; }
.device-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.filters { display: flex; gap: 4px; flex-wrap: wrap; }
.filters button { background: transparent; color: var(--muted); padding: 10px 12px; font-size: 0.8rem; }
.filters button[aria-pressed="true"] { background: var(--tint); color: var(--action); border-color: var(--line); }
.search-field { position: relative; flex: 1; max-width: 300px; min-width: 200px; }
.search-field .glyph { position: absolute; top: 13px; left: 12px; color: var(--muted); pointer-events: none; }
.search-field input { padding-left: 42px; }
.device-card { padding: 0; overflow: hidden; }
.device-columns, .device-row { display: grid; grid-template-columns: minmax(0, 1.4fr) 100px minmax(130px, 1fr) 12px; gap: 20px; align-items: center; }
.device-columns { color: var(--muted); padding: 16px 24px; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; border-bottom: 1px solid var(--line); }
.device-list, .grant-list, .plain-list { list-style: none; padding: 0; margin: 0; }
.device-list li + li { border-top: 1px solid var(--line); }
.device-row { width: 100%; min-height: 88px; border: 0; border-radius: 0; padding: 16px 24px; background: transparent; color: var(--ink); text-align: left; font-weight: 400; }
.device-row:hover:not(:disabled) { background: var(--tint); filter: none; }
.device-row:focus-visible { outline-offset: -4px; }
.identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar { width: 40px; height: 40px; border-radius: 13px; background: var(--tint); color: var(--action); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.avatar.large { width: 56px; height: 56px; font-size: 1.3rem; margin: 16px 0; }
.device-name { display: block; font-size: 0.95rem; font-weight: 600; overflow-wrap: anywhere; }
.device-meta { display: block; color: var(--muted); font-size: 0.75rem; margin-top: 3px; }
.pill { display: inline-flex; align-items: center; justify-content: center; justify-self: start; padding: 5px 10px; border-radius: 20px; font-size: 0.7rem; font-weight: 700; color: var(--muted); background: var(--canvas); }
.pill.enrolled, .pill.allowed { color: var(--good); background: var(--good-bg); }
.pill.pending { color: var(--action); background: var(--tint); }
.pill.revoked { color: var(--danger); background: var(--danger-bg); }
.device-access { color: var(--muted); font-size: 0.8rem; }
.chevron { width: 8px; height: 8px; border-top: 1.5px solid currentColor; border-right: 1.5px solid currentColor; transform: rotate(45deg); color: var(--muted); }
.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); font-size: 0.9rem; }
.visibility-intro { margin-bottom: 20px; }
.section-heading { gap: 16px; align-items: flex-start; }
.section-heading p { margin-bottom: 0; }
.icon-tile { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 14px; color: var(--action); background: var(--tint); flex-shrink: 0; margin-bottom: 16px; }
.section-heading .icon-tile { margin-bottom: 0; }
.visibility-intro select { max-width: 500px; }
.grant-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 0; }
.grant-row + .grant-row { border-top: 1px solid var(--line); }
.grant-row .identity { flex: 1; }
.grant-row .actions { justify-content: flex-end; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.facts { margin: 16px 0 0; }
.facts dt { font-size: 0.75rem; color: var(--muted); margin-top: 16px; }
.facts dd { margin: 4px 0 0; font-size: 0.9rem; overflow-wrap: anywhere; }
.notice { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 20px; background: var(--tint); font-size: 0.9rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.notice.error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.loading { color: var(--muted); padding: 24px 0; }
footer { color: var(--muted); font-size: 0.7rem; line-height: 1.8; margin-top: 48px; }
dialog { color: var(--ink); background: var(--card); border: 1px solid var(--line); padding: 24px; max-width: calc(100vw - 32px); }
dialog::backdrop { background: #10212a66; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.dialog-header p { margin: 0; }
.icon-button { padding: 0; width: 48px; flex-shrink: 0; }
.detail-dialog { margin: 0 0 0 auto; width: 440px; height: 100dvh; max-height: 100dvh; border-radius: 20px 0 0 20px; }
.detail-dialog h2 { font-size: 1.6rem; overflow-wrap: anywhere; }
.detail-section { border-top: 1px solid var(--line); padding-top: 24px; margin-top: 24px; }
.detail-section h3:not(:first-child) { margin-top: 24px; }
.plain-list li { font-size: 0.9rem; padding: 6px 0; overflow-wrap: anywhere; }
.danger-zone h3 { color: var(--danger); }
.enrollment-dialog { width: 480px; border-radius: 20px; max-height: calc(100dvh - 32px); }
#enrollment-result { margin-top: 20px; overflow-wrap: anywhere; }
[hidden] { display: none !important; }

@media (min-width: 1440px) {
  .sidebar { border-left: 1px solid var(--line); }
}
@media (max-width: 1100px) {
  .authenticated .shell { grid-template-columns: 200px minmax(0, 1fr); }
  main { padding: 24px; }
  .page-header { align-items: flex-start; flex-direction: column; gap: 16px; }
  .device-columns, .device-row { gap: 12px; grid-template-columns: minmax(0, 1.3fr) 90px minmax(100px, 1fr) 8px; padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 760px) {
  .authenticated .shell { display: block; }
  main { padding: 24px 16px; }
  .sidebar { position: static; height: auto; min-height: 0; border-right: 0; border-bottom: 1px solid var(--line); padding: 16px; display: grid; grid-template-columns: 1fr auto; gap: 16px; }
  .brand-header { margin: 0; }
  .sidebar-foot { padding: 0; margin: 0; grid-column: 2; grid-row: 1; }
  .sidebar-foot p { display: none; }
  nav { grid-row: 2; grid-column: 1 / -1; display: flex; gap: 4px; }
  nav button { justify-content: center; gap: 7px; padding: 10px; font-size: 0.8rem; }
  nav .glyph { width: 18px; height: 18px; }
  .device-toolbar { align-items: stretch; }
  .search-field { max-width: none; }
  .device-columns { display: none; }
  .device-card { border: 0; background: transparent; overflow: visible; }
  .device-list { display: grid; gap: 12px; }
  .device-list li { border: 1px solid var(--line); border-radius: 20px; background: var(--card); overflow: hidden; }
  .device-list li + li { border-top: 1px solid var(--line); }
  .device-row { grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 16px; border-radius: 20px; }
  .device-row .identity { grid-column: 1 / -1; }
  .device-row .pill { grid-column: 1; grid-row: 2; margin-left: 52px; }
  .device-row .device-access { grid-column: 1; grid-row: 3; margin-left: 52px; }
  .device-row .chevron { grid-column: 2; grid-row: 2; }
  .settings-grid { grid-template-columns: 1fr; }
  .card { padding: 20px; }
  .device-card { padding: 0; }
  .grant-row { flex-wrap: wrap; }
  .grant-row .actions { width: 100%; justify-content: flex-start; padding-left: 52px; }
  .detail-dialog { width: 100%; max-width: none; border: 0; border-radius: 0; }
  body:not(.authenticated) main { margin-top: 4vh; }
}
@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color 0.15s, color 0.15s; }
}
