:root {
  color-scheme: light;
  --navy-950: #041321;
  --navy-900: #061a2f;
  --navy-800: #0b2945;
  --navy-700: #123c61;
  --teal-600: #0aa6a6;
  --teal-500: #13c1ba;
  --teal-100: #dff8f6;
  --orange-600: #db6c20;
  --orange-100: #fff0e5;
  --red-600: #c33d42;
  --red-100: #fdeced;
  --green-600: #23866b;
  --green-100: #e4f6ef;
  --ink: #132238;
  --muted: #607086;
  --line: #dbe3eb;
  --surface: #ffffff;
  --surface-soft: #f4f7fa;
  --shadow: 0 18px 50px rgba(6, 26, 47, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--surface-soft); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: linear-gradient(180deg, #edf5f7 0, var(--surface-soft) 38%, #eef2f6 100%); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
a { color: inherit; }

.brand-logo { width: 168px; max-width: 58vw; height: auto; display: block; }
.splash { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 24px; background: var(--navy-900); color: white; }
.splash .brand-logo { filter: brightness(0) invert(1); width: 220px; }
.spinner { width: 36px; height: 36px; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--teal-500); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(280px, 1fr) minmax(360px, 520px); }
.auth-brand { background: radial-gradient(circle at top right, #0b5571, var(--navy-900) 58%); color: white; padding: clamp(40px, 8vw, 110px); display: flex; flex-direction: column; justify-content: center; gap: 22px; }
.auth-brand .brand-logo { width: min(340px, 75%); filter: brightness(0) invert(1); }
.auth-brand p { margin: 0; font-size: clamp(20px, 2.4vw, 34px); font-weight: 700; max-width: 520px; }
.auth-card { align-self: center; margin: 32px; padding: clamp(28px, 5vw, 58px); border-radius: var(--radius-xl); background: rgba(255,255,255,.96); box-shadow: var(--shadow); }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(32px, 5vw, 54px); line-height: 1.02; letter-spacing: -.04em; }
h2 { font-size: 23px; letter-spacing: -.02em; }
.eyebrow { display: block; color: var(--teal-600); text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 900; margin-bottom: 9px; }
.muted, small { color: var(--muted); }

.form-stack { display: grid; gap: 18px; }
.form-stack label { display: grid; gap: 8px; font-weight: 750; }
.form-stack small { font-weight: 500; line-height: 1.45; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 13px; padding: 14px 15px; color: var(--ink); background: white; outline: none; transition: border .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--teal-500); box-shadow: 0 0 0 4px rgba(19,193,186,.14); }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 800; margin-bottom: 10px; }

.button { min-height: 50px; border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 850; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.button-primary { color: white; background: linear-gradient(135deg, var(--teal-600), var(--teal-500)); box-shadow: 0 12px 28px rgba(10,166,166,.25); }
.button-secondary { color: var(--navy-900); background: white; border: 1px solid var(--line); }
.button-warning { color: #7b350d; background: #ffd9bd; }
.button-ghost { min-height: 38px; color: var(--navy-700); background: var(--surface-soft); }
.button-small { min-height: 38px; padding: 8px 12px; font-size: 13px; }
.button-hero { min-height: 62px; border-radius: 18px; font-size: 18px; }
.text-button, .back-button { border: 0; background: none; padding: 8px 0; color: var(--teal-600); font-weight: 800; }
.icon-button { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--surface-soft); color: var(--red-600); font-size: 24px; }

.debug-card { margin: 18px 0; padding: 15px; border-radius: var(--radius-md); background: #fff8d9; color: #6a5200; display: grid; gap: 10px; }

.app-shell { min-height: 100vh; padding-bottom: calc(90px + var(--safe-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; height: 72px; padding: 12px clamp(18px, 4vw, 44px); display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.92); backdrop-filter: blur(18px); border-bottom: 1px solid rgba(219,227,235,.8); }
.topbar .brand-logo { width: 150px; }
.secure-pill { padding: 8px 11px; border-radius: 999px; background: var(--teal-100); color: #076b69; font-size: 12px; font-weight: 850; }
.app-main { width: min(920px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 52px; }

.hero-card { padding: clamp(28px, 6vw, 58px); border-radius: var(--radius-xl); color: white; background: radial-gradient(circle at 90% 10%, rgba(19,193,186,.55), transparent 35%), linear-gradient(135deg, var(--navy-900), var(--navy-700)); box-shadow: var(--shadow); }
.hero-card h1 { margin-bottom: 10px; }
.hero-card p { max-width: 520px; font-size: 18px; line-height: 1.55; color: #dce9f3; }
.hero-card .button { width: min(100%, 380px); margin-top: 10px; }

.notice { margin: 20px 0; padding: 17px 18px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: white; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.notice p { margin: 4px 0 0; color: var(--muted); line-height: 1.45; }
.notice-warning { border-color: #f4c399; background: var(--orange-100); }
.notice-calm { background: #ecf5fa; border-color: #cce1ec; }

.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin: 20px 0 28px; }
.quick-card { min-height: 140px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: white; text-align: left; box-shadow: 0 8px 24px rgba(6,26,47,.05); }
.quick-card span { display: block; font-size: 34px; color: var(--teal-600); font-weight: 900; }
.quick-card strong, .quick-card small { display: block; }
.quick-card small { margin-top: 5px; }

.section-block { margin: 28px 0; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 13px; }
.section-heading h2 { margin: 0; }
.count-badge { min-width: 34px; height: 34px; padding: 0 10px; border-radius: 999px; display: grid; place-items: center; background: var(--navy-900); color: white; font-weight: 850; }
.card-list { display: grid; gap: 10px; }
.check-card, .person-card { width: 100%; padding: 15px; border: 1px solid var(--line); border-radius: 16px; background: white; display: flex; align-items: center; gap: 13px; text-align: left; }
.check-card:hover { border-color: #9ccfce; transform: translateY(-1px); }
.check-icon, .avatar { flex: 0 0 46px; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--teal-100); color: var(--navy-900); font-size: 20px; font-weight: 900; }
.avatar { border-radius: 50%; }
.check-main, .person-card > div { min-width: 0; flex: 1; }
.check-main strong, .check-main small, .person-card strong, .person-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check-main small, .person-card small { margin-top: 4px; }
.status { display: inline-flex; align-items: center; min-height: 28px; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 850; white-space: nowrap; }
.status-open { color: #8a3f0f; background: var(--orange-100); }
.status-answered { color: #116a53; background: var(--green-100); }
.status-closed { color: #516173; background: #e9eef3; }
.empty-state { min-height: 150px; border: 1px dashed #bdc9d5; border-radius: var(--radius-lg); display: grid; place-content: center; justify-items: center; color: var(--muted); background: rgba(255,255,255,.58); }
.empty-state span { font-size: 32px; color: var(--teal-600); }

.page-heading { margin-bottom: 24px; }
.page-heading h1 { margin-bottom: 8px; }
.page-heading p { color: var(--muted); }
.filter-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; }
.chip { border: 1px solid var(--line); border-radius: 999px; background: white; padding: 9px 13px; font-weight: 750; white-space: nowrap; }
.chip.active { background: var(--navy-900); color: white; border-color: var(--navy-900); }

.split-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.panel, .detail-card { padding: 22px; border-radius: var(--radius-lg); border: 1px solid var(--line); background: white; box-shadow: 0 10px 30px rgba(6,26,47,.05); }
.code-card { margin-top: 16px; padding: 18px; border-radius: 16px; background: var(--navy-900); color: white; text-align: center; }
.code-card strong { display: block; margin: 8px 0; font-size: 30px; letter-spacing: .16em; }
.code-card .text-button { color: var(--teal-500); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.option-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.option-card { position: relative; padding: 16px; min-height: 112px; border: 1px solid var(--line); border-radius: 16px; background: white; display: grid !important; align-content: center; gap: 8px !important; }
.option-card input { position: absolute; opacity: 0; }
.option-card:has(input:checked) { border-color: var(--teal-500); background: var(--teal-100); box-shadow: 0 0 0 3px rgba(19,193,186,.12); }
.option-card span { font-size: 24px; }
.create-form { max-width: 720px; }

.detail-card h2 { margin-top: 24px; margin-bottom: 8px; }
.detail-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.detail-meta strong { margin-left: auto; font-size: 20px; }
.detail-text { white-space: pre-wrap; line-height: 1.65; }
.urgency { padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 850; background: #edf1f5; }
.urgency-high, .urgency-very_high { color: #8b2e32; background: var(--red-100); }
.attachment-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.attachment-grid a { text-decoration: none; border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: var(--surface-soft); }
.attachment-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.attachment-grid small { display: block; padding: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recommendation { margin: 18px 0; padding: 24px; border-radius: var(--radius-lg); }
.recommendation-danger { background: var(--red-100); color: #772b30; }
.recommendation-warning { background: var(--orange-100); color: #71340e; }
.recommendation-positive { background: var(--green-100); color: #145e4b; }
.recommendation-navy { background: #e4eef8; color: var(--navy-800); }
.recommendation-options { display: grid; gap: 9px; }
.recommendation-choice { padding: 14px; border-radius: 13px; border: 1px solid var(--line); display: flex !important; grid-template-columns: auto 1fr; align-items: center; }
.recommendation-choice input { width: auto; }
.recommendation-choice:has(input:checked) { border-color: var(--teal-500); box-shadow: 0 0 0 3px rgba(19,193,186,.12); }
.legal-hint { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 20px 4px; }

.account-panel { margin-bottom: 18px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row small { display: block; margin-top: 4px; }

.bottom-nav { position: fixed; left: 50%; bottom: max(12px, var(--safe-bottom)); transform: translateX(-50%); z-index: 30; width: min(620px, calc(100% - 22px)); min-height: 68px; padding: 7px; border: 1px solid rgba(219,227,235,.86); border-radius: 22px; background: rgba(255,255,255,.95); backdrop-filter: blur(18px); box-shadow: 0 18px 45px rgba(6,26,47,.18); display: grid; grid-template-columns: repeat(4, 1fr); }
.bottom-nav button { border: 0; background: transparent; border-radius: 16px; color: var(--muted); font-size: 11px; font-weight: 800; display: grid; place-content: center; gap: 2px; }
.bottom-nav button span { font-size: 20px; }
.bottom-nav button.active { background: var(--navy-900); color: white; }

.toast-root { position: fixed; top: 82px; right: 18px; z-index: 100; display: grid; gap: 8px; width: min(360px, calc(100% - 36px)); }
.toast { padding: 14px 16px; border-radius: 14px; color: white; background: var(--navy-900); box-shadow: var(--shadow); font-weight: 700; }
.toast-error { background: var(--red-600); }
.toast-success { background: var(--green-600); }

@media (max-width: 760px) {
  .auth-page { display: block; padding: 18px; background: var(--navy-900); }
  .auth-brand { min-height: auto; padding: 28px 10px 18px; background: transparent; }
  .auth-brand .brand-logo { width: 210px; }
  .auth-brand p { font-size: 18px; }
  .auth-card { margin: 0; padding: 25px 20px; }
  .auth-card h1 { font-size: 34px; }
  .app-main { width: min(100% - 24px, 920px); padding-top: 22px; }
  .topbar { height: 64px; padding: 10px 14px; }
  .topbar .brand-logo { width: 132px; }
  .secure-pill { font-size: 10px; }
  .quick-grid, .split-grid, .form-grid { grid-template-columns: 1fr; }
  .option-grid { grid-template-columns: 1fr 1fr; }
  .notice { align-items: flex-start; flex-direction: column; }
  .check-card { align-items: flex-start; }
  .check-card .status { margin-left: auto; }
  .attachment-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-heading { align-items: center; }
  .detail-meta strong { width: 100%; margin-left: 0; }
}

@media (max-width: 390px) {
  .option-grid { grid-template-columns: 1fr; }
  .check-card { display: grid; grid-template-columns: 46px 1fr; }
  .check-card .status { grid-column: 2; justify-self: start; }
}

/* Phase 3.8: senior-first accessibility */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-size: 17px;
  line-height: 1.55;
}

button, a, input, select, textarea, summary {
  touch-action: manipulation;
}

input, select, textarea {
  min-height: 54px;
  font-size: 16px;
  line-height: 1.4;
}

textarea { min-height: 132px; }
small { font-size: .9rem; line-height: 1.5; }
.status, .urgency { font-size: 12px; }

.button,
.button-small,
.button-ghost,
.chip,
.text-button,
.back-button,
.icon-button,
.bottom-nav button {
  min-height: 48px;
}

.icon-button {
  min-width: 48px;
  width: 48px;
  height: 48px;
}

.text-button, .back-button {
  padding: 10px 8px;
}

.bottom-nav button { font-size: 12px; }

:where(button, a, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 4px solid var(--navy-800);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px #fff;
}

.hero-card :where(button, a):focus-visible,
.bottom-nav button.active:focus-visible {
  outline-color: #fff;
  box-shadow: 0 0 0 7px var(--navy-900);
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1000;
  transform: translateY(-180%);
  padding: 12px 16px;
  border-radius: 12px;
  background: #fff;
  color: var(--navy-900);
  border: 2px solid var(--navy-900);
  font-weight: 850;
  text-decoration: none;
  box-shadow: var(--shadow);
}

.skip-link:focus { transform: translateY(0); }
#app:focus { outline: none; }

@media (max-width: 760px) {
  body { font-size: 18px; }
  .bottom-nav button { font-size: 13px; }
  .bottom-nav button span { font-size: 22px; }
  .secure-pill { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .spinner {
    animation: none;
    border-top-color: #fff;
  }
  .check-card:hover { transform: none; }
}

@media (prefers-contrast: more) {
  :root {
    --muted: #435267;
    --line: #8e9cad;
  }
  .panel,
  .detail-card,
  .notice,
  .check-card,
  .person-card,
  .quick-card,
  input,
  select,
  textarea,
  .button-secondary,
  .chip {
    border-width: 2px;
  }
}

@media (forced-colors: active) {
  .button,
  .bottom-nav,
  .panel,
  .detail-card,
  .notice,
  .check-card,
  .person-card,
  .quick-card {
    box-shadow: none;
  }
  .button-primary,
  .bottom-nav button.active,
  .status,
  .urgency {
    forced-color-adjust: auto;
  }
}
