:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #fff;
  --side: #ededf0;
  --text: #1d1d1f;
  --muted: #626269;
  --border: #dedee3;
  --control-border: #85858d;
  --blue: #0071e3;
  --primary-ink: #fff;
  --hover: #e8f0fc;
  --selected: #e1e1e6;
  --danger: #b32624;
  --focus: #0071e3;
  --radius: 12px;
}
body[data-theme=dark] {
  color-scheme: dark;
  --bg: #141416; --surface: #202023; --side: #19191c;
  --text: #f5f5f7; --muted: #b0b0b8; --border: #36363d;
  --control-border: #777780; --blue: #3895ff; --primary-ink: #101114;
  --hover: #26364e; --selected: #303036; --danger: #ff817e; --focus: #69adff;
}
@media (prefers-color-scheme: dark) {
  body:not([data-theme=light]) {
    color-scheme: dark;
    --bg: #141416; --surface: #202023; --side: #19191c;
    --text: #f5f5f7; --muted: #b0b0b8; --border: #36363d;
    --control-border: #777780; --blue: #3895ff; --primary-ink: #101114;
    --hover: #26364e; --selected: #303036; --danger: #ff817e; --focus: #69adff;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 1rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--blue); text-underline-offset: .2em; }
button, input, select, textarea { font: inherit; }
button, .button { border: 1px solid var(--control-border); background: var(--surface); color: var(--text); padding: 10px 15px; border-radius: 9px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; line-height: 1.4; }
button:hover, .button:hover { background: var(--selected); }
button:active, .button:active { transform: translateY(1px); }
button:disabled { background: var(--side); color: var(--muted); border-color: var(--control-border); cursor: wait; transform: none; }
.primary { background: var(--blue); color: var(--primary-ink); border-color: transparent; }
.primary:not(:disabled):hover { background: var(--blue); text-decoration: underline; }
.danger, .error { color: var(--danger); }
input, select, textarea { background: var(--surface); color: var(--text); border: 1px solid var(--control-border); border-radius: 9px; padding: 10px 12px; min-height: 44px; min-width: 0; max-width: 100%; caret-color: var(--blue); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
textarea { resize: vertical; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
::selection { background: var(--blue); color: var(--primary-ink); }
.shell { display: flex; min-height: 100dvh; }
.sidebar { width: 244px; position: fixed; inset: 0 auto 0 0; padding: 28px 16px 20px; background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: auto; }
.brand-row { margin: 0 8px 32px; }
.brand { display: flex; align-items: center; gap: 11px; color: var(--text); text-decoration: none; font-weight: 650; font-size: 1.125rem; }
.brand-icon { color: var(--blue); flex: none; }
.brand small { display: block; color: var(--muted); font-size: .75rem; font-weight: 400; }
.nav { display: flex; text-decoration: none; padding: 11px 12px; border-radius: 8px; margin-bottom: 5px; min-height: 44px; color: var(--text); font-size: .9375rem; }
.nav:hover { background: var(--surface); }
.nav.active { background: var(--selected); font-weight: 600; }
.side-heading { font-size: .8125rem; color: var(--muted); padding: 26px 12px 10px; }
.side-bottom { margin-top: auto; padding: 36px 12px 0; }
.nav-toggle { display: none; }
main { margin-left: 244px; min-width: 0; width: calc(100% - 244px); }
main.auth-main { margin: 0; width: 100%; }
main:focus { outline: none; }
.topbar { min-height: 72px; padding: 12px 40px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 18px; color: var(--muted); font-size: .8125rem; }
.topbar button { font-size: .8125rem; background: transparent; border-color: transparent; }
.workspace { max-width: 1280px; margin: auto; padding: 36px 40px 56px; }
.heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 26px; gap: 24px; }
.heading .button { flex: none; }
h1 { font-size: 1.75rem; letter-spacing: -.025em; font-weight: 650; margin: 0 0 9px; line-height: 1.25; overflow-wrap: anywhere; }
h2 { font-size: 1.1875rem; letter-spacing: -.015em; margin: 0 0 12px; line-height: 1.4; }
h3 { font-size: 1.0625rem; margin: 28px 0 12px; }
p { margin: 0 0 16px; max-width: 72ch; }
.heading p { margin: 0; }
.muted, small { color: var(--muted); }
small { font-weight: 400; }
.banner { display: flex; gap: 20px; justify-content: space-between; align-items: center; padding: 20px 24px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); margin-bottom: 24px; }
.banner p { font-size: .9375rem; margin: 6px 0 0; }
.emergency-link { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 20px 0; margin-bottom: 26px; border-block: 1px solid var(--border); color: var(--text); text-decoration: none; }
.emergency-link strong { display: block; font-size: 1rem; font-weight: 600; }
.emergency-link>span>span:not(.emergency-action) { display: block; color: var(--muted); font-size: .9375rem; margin-top: 4px; }
.emergency-action { flex: none; color: var(--blue); font-weight: 500; }
.emergency-link:hover .emergency-action { text-decoration: underline; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.toolbar>input { flex: 1; min-width: 160px; }
.toolbar select { max-width: 240px; }
.toolbar label { margin: 0; flex: 1; min-width: 130px; }
.document-filters { align-items: flex-end; }
.document-filters .search-field { flex: 2; min-width: 190px; }
.result-line { margin: 24px 0; color: var(--muted); font-size: .875rem; display: flex; justify-content: space-between; gap: 16px; }
.document-group { margin-bottom: 28px; }
.document-group h2 { display: flex; gap: 10px; align-items: baseline; font-size: 1rem; margin-bottom: 10px; }
.group-count { font-size: .8125rem; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.document-list { list-style: none; margin: 0; padding: 0 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.document-list li+li { border-top: 1px solid var(--border); }
.document-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(150px, .7fr) auto; gap: 24px; align-items: center; min-height: 88px; padding: 18px 0; color: var(--text); text-decoration: none; border-radius: 5px; }
.document-name { font-weight: 600; overflow-wrap: anywhere; }
.document-name>span { display: block; font-size: .875rem; color: var(--muted); font-weight: 400; margin-top: 4px; }
.document-location { color: var(--muted); font-size: .8125rem; }
.document-open { color: var(--blue); font-size: .875rem; white-space: nowrap; }
.document-row:hover .document-name { text-decoration: underline; text-underline-offset: .2em; }
.panel { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 24px; }
.empty { padding: 40px 24px; }
.empty p { max-width: 62ch; }
.empty .button { margin-top: 8px; }
.auth-card { max-width: 460px; margin: 24px auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; }
.auth-card h1 { font-size: 1.625rem; }
label { display: flex; flex-direction: column; gap: 8px; font-size: .875rem; font-weight: 500; margin: 18px 0; }
label input, label select, label textarea { width: 100%; font-size: 1rem; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.check { flex-direction: row; align-items: center; font-size: .9375rem; gap: 12px; }
.check input { width: 20px; height: 20px; min-height: 20px; accent-color: var(--blue); }
.full { width: 100%; }
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 20px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border: 0; }
.row p { font-size: .875rem; color: var(--muted); margin: 5px 0 0; }
.row form { max-width: 370px; }
.row label { margin: 0; }
.preserve { white-space: pre-wrap; overflow-wrap: anywhere; }
.emergency-guide { margin-top: 32px; }
.reading { max-width: 72ch; }
.detail-heading { margin-top: 24px; }
.qr { display: block; width: 240px; height: 240px; max-width: 100%; margin: 24px auto; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 28px 0; }
code { overflow-wrap: anywhere; background: var(--bg); padding: 5px 8px; border-radius: 6px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 26px 0; }
details { margin-bottom: 24px; }
summary { cursor: pointer; }
.paperless-result { border-top: 1px solid var(--border); padding: 24px 0; margin-top: 20px; }
.paperless-result>small { display: block; }
dd { margin: 8px 0 20px; }
.skip-link { position: fixed; top: 12px; left: 12px; transform: translateY(-160%); background: var(--surface); border: 2px solid var(--focus); padding: 10px 16px; border-radius: 8px; z-index: 100; }
.skip-link:focus { transform: none; }
@media (prefers-reduced-motion: no-preference) {
  button, .button, .nav { transition: background-color 160ms ease-out, border-color 160ms ease-out; }
}
@media (max-width: 1050px) {
  .sidebar { width: 216px; }
  main { margin-left: 216px; width: calc(100% - 216px); }
  .workspace { padding: 30px 24px; }
  .topbar { padding: 12px 24px; }
  .heading, .banner { align-items: flex-start; flex-direction: column; }
  .toolbar select { max-width: 100%; }
  .document-location { display: none; }
  .document-row { grid-template-columns: minmax(0, 1fr) auto; }
}
@media (max-width: 700px) {
  .shell { display: block; }
  .sidebar { position: static; width: 100%; padding: 18px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0; }
  .sidebar nav { margin-top: 18px; }
  .nav { margin: 0 0 4px; }
  .sidebar.nav-ready .nav-toggle { display: inline-flex; }
  .sidebar.nav-ready:not(.nav-open) nav, .sidebar.nav-ready:not(.nav-open) .side-bottom { display: none; }
  .side-heading { padding-top: 16px; }
  .side-bottom { display: flex; justify-content: space-between; align-items: center; padding: 20px 12px 0; }
  .side-bottom p { margin: 0; font-size: .875rem; }
  main { width: 100%; margin: 0; }
  .workspace { padding: 24px 18px 40px; }
  .topbar { padding: 10px 18px; min-height: 60px; }
  .form-grid { grid-template-columns: 1fr; }
  .row { align-items: flex-start; flex-direction: column; }
  .codes { grid-template-columns: 1fr; }
  .auth-card { padding: 24px; margin: 0 auto; }
  .toolbar { align-items: stretch; }
  .toolbar input, .toolbar select { width: 100%; }
  .document-filters { display: grid; grid-template-columns: 1fr 1fr; align-items: end; }
  .document-filters .search-field { grid-column: 1 / -1; min-width: 0; }
  .document-filters label { min-width: 0; }
  .document-filters button { grid-column: 1 / -1; }
  .document-row { gap: 16px; }
  .document-list { padding: 0 16px; }
  .actions { align-items: stretch; }
  .panel { padding: 20px; }
  .banner { padding: 20px; }
  .emergency-link { flex-direction: column; align-items: flex-start; gap: 12px; }
}

/* Installed web apps retain room for the notch, landscape edges, and Home indicator. */
.sidebar { padding-top: max(28px, env(safe-area-inset-top)); }
.workspace { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
.topbar { flex-wrap: wrap; }
.topbar button { white-space: normal; text-align: left; }
.app-footer { display: flex; align-items: center; gap: 8px 20px; flex-wrap: wrap; border-top: 1px solid var(--border); margin-top: 40px; padding-top: 20px; color: var(--muted); font-size: .8125rem; }
.app-footer a { display: inline-flex; align-items: center; min-height: 44px; }
.version-number { font-variant-numeric: tabular-nums; }
.side-release { display: flex; align-items: center; min-height: 44px; margin-top: 12px; font-size: .8125rem; font-variant-numeric: tabular-nums; }
.install-guide { max-width: 76ch; }
.install-guide ol { margin: 16px 0 20px; padding-left: 24px; }
.install-guide li { padding-left: 4px; margin: 12px 0; }
.install-guide p:last-child { margin-bottom: 0; }
.release-history { max-width: 76ch; margin-top: 36px; }
.release { padding: 28px 0; border-top: 1px solid var(--border); }
.release-meta { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px 20px; }
.release-meta h2 { margin: 0; }
.release-meta>span { font-size: .8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.release h3 { margin: 18px 0 12px; }
.release ul { margin: 0; padding-left: 20px; }
.release li { margin: 10px 0; }
@media (max-width: 700px) {
  .side-bottom { flex-wrap: wrap; gap: 12px; }
  .side-release { flex-basis: 100%; margin-top: 0; }
  .sidebar { padding-top: calc(18px + env(safe-area-inset-top)); padding-left: max(18px, env(safe-area-inset-left)); padding-right: max(18px, env(safe-area-inset-right)); }
  .workspace { padding-left: max(18px, env(safe-area-inset-left)); padding-right: max(18px, env(safe-area-inset-right)); padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  .topbar { padding-left: max(18px, env(safe-area-inset-left)); padding-right: max(18px, env(safe-area-inset-right)); }
  .auth-main .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .form-grid>* { min-width: 0; }
  .actions { max-width: 100%; }
}
@media (min-width: 701px) and (max-width: 1050px) {
  .sidebar { padding-left: max(16px, env(safe-area-inset-left)); }
  .workspace, .topbar { padding-right: max(24px, env(safe-area-inset-right)); }
}
