:root {
  color-scheme: light;
  --ink: #1c2730;
  --muted: #64727f;
  --line: #d8e1e8;
  --bg: #f5f7f4;
  --panel: #ffffff;
  --navy: #1e526f;
  --teal: #187465;
  --mint: #dceee8;
  --amber: #c98127;
  --rose: #c2474f;
  --rose-soft: #f8e5e7;
  --green-soft: #e6f3d9;
  --shadow: 0 18px 45px rgba(21, 44, 58, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  font-size: 16px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.auth-screen.hidden {
  display: none;
}

.auth-card {
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: #fff;
  box-shadow: var(--shadow);
}

.auth-brand {
  color: var(--ink);
  margin-bottom: 22px;
}

.auth-brand span {
  color: var(--muted);
}

.auth-card h1 {
  margin-bottom: 8px;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.6;
}

.login-help {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--teal) !important;
}

.login-form {
  margin: 18px 0 12px;
}

.auth-message {
  min-height: 22px;
  margin: 10px 0;
  color: var(--rose);
  font-weight: 800;
}

.recent-visit-list {
  display: grid;
  gap: 12px;
}

.recent-visit-item {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.recent-visit-item.needs-review {
  border-color: #ecb8bd;
  background: var(--rose-soft);
}

.recent-visit-item strong {
  display: block;
  font-size: 18px;
  color: var(--navy);
}

.recent-visit-item span,
.recent-visit-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.recent-visit-item em {
  justify-self: start;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--teal);
  font-style: normal;
  font-weight: 900;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #15394e;
  color: #fff;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f2c94c;
  color: #15394e;
  font-weight: 900;
  font-size: 22px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.role-card {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.role-card label {
  color: rgba(255, 255, 255, 0.78);
}

.role-card select {
  min-height: 44px;
  margin-top: 7px;
  border: 0;
}

.role-card small {
  display: block;
  margin-top: 9px;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.5;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  padding: 14px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  text-align: left;
  font-size: 15px;
  font-weight: 800;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-note {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-note span,
.sidebar-note small {
  display: block;
  color: rgba(255, 255, 255, 0.72);
}

.sidebar-note strong {
  display: block;
  margin: 6px 0;
  font-size: 30px;
}

.main {
  padding: 28px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 14px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  padding: 0 18px;
  font-weight: 800;
}

.primary-button {
  background: var(--teal);
  color: #fff;
}

.secondary-button,
.icon-button {
  background: #e8eef1;
  color: var(--navy);
}

.full {
  width: 100%;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.mobile-worker-home {
  display: none;
  margin-bottom: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span,
.metric small {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 34px;
}

.metric.warning strong {
  color: var(--rose);
}

.metric.good strong {
  color: var(--teal);
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.admin-ops {
  margin-top: 18px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(340px, 0.7fr);
  gap: 18px;
}

.admin-filter-bar {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(260px, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.admin-feedback-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.admin-feedback-form .wide-field,
.admin-feedback-form button {
  grid-column: 1 / -1;
}

.admin-elder-edit {
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.compact-header {
  margin-bottom: 12px;
}

.compact-header h3 {
  margin: 0;
  font-size: 17px;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 12px;
}

.wide-field {
  grid-column: 1 / -1;
}

.consent-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 12px 0 14px;
  font-weight: 800;
  color: var(--navy);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
  background: #fff;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

.admin-table th {
  background: #eef3f5;
  color: var(--navy);
  font-weight: 900;
  white-space: nowrap;
}

.admin-table tr:last-child td {
  border-bottom: 0;
}

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

.compact-button {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.next-action-panel {
  margin-top: 18px;
}

.panel {
  padding: 20px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.badge {
  border-radius: 999px;
  background: var(--mint);
  color: var(--teal);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.badge.danger {
  background: var(--rose-soft);
  color: var(--rose);
}

.stack-list,
.request-list {
  display: grid;
  gap: 10px;
}

.risk-item,
.request-item,
.elder-card,
.report-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfb;
}

.risk-item {
  border-left: 5px solid var(--rose);
}

.risk-item strong,
.request-item strong,
.elder-card strong {
  display: block;
  margin-bottom: 5px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.timeline {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 20px;
}

.timeline li {
  padding-left: 6px;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
  gap: 18px;
}

form {
  display: grid;
  gap: 16px;
}

.mobile-stepper {
  display: flex;
  gap: 9px;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}

.step-dot {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}

.step-dot.active {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.step-dot.done {
  border-color: var(--teal);
  background: var(--mint);
  color: var(--teal);
}

.form-step {
  display: none;
  gap: 16px;
  scroll-margin-top: 14px;
}

.form-step.active {
  display: grid;
}

.step-title {
  border-radius: 8px;
  padding: 14px;
  background: #eef6f3;
}

.step-title strong,
.step-title span {
  display: block;
}

.step-title strong {
  font-size: 18px;
  color: var(--teal);
}

.step-title span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

label,
fieldset {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 48px;
  padding: 12px 13px;
}

textarea {
  resize: vertical;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

legend {
  padding: 0 6px;
  color: var(--muted);
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.check-pill,
.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.check-pill input,
.toggle-row input {
  width: 20px;
  height: 20px;
  flex: none;
}

.check-pill:has(input:checked),
.toggle-row:has(input:checked) {
  border-color: var(--teal);
  background: var(--mint);
}

.check-pill.urgent {
  border-color: #f1b6bb;
  background: #fff8f8;
}

.check-pill.urgent:has(input:checked) {
  border-color: var(--rose);
  background: var(--rose-soft);
}

.plain-list {
  padding-left: 18px;
  color: var(--ink);
  line-height: 1.75;
}

.soft-box {
  margin-top: 16px;
  border-radius: 8px;
  padding: 15px;
  background: var(--green-soft);
}

.soft-box p {
  margin: 7px 0 0;
  color: var(--muted);
}

.field-help {
  margin: 2px 0 0;
  color: var(--rose);
  font-size: 13px;
  font-weight: 800;
}

.field-help.neutral {
  color: var(--muted);
}

.emergency-box {
  border-color: #f1b6bb;
  background: #fffafa;
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.followup-section {
  background: #fbf7ee;
  border-color: #ead8b9;
}

.followup-list {
  display: grid;
  gap: 14px;
}

.followup-group {
  display: grid;
  gap: 10px;
}

.followup-group strong {
  color: var(--amber);
}

.hidden {
  display: none !important;
}

.form-preview,
.next-action-item,
.feedback-item {
  border: 1px solid var(--line);
  border-left: 5px solid var(--amber);
  border-radius: 8px;
  padding: 14px;
  background: #fffdf7;
}

.form-preview strong,
.next-action-item strong,
.feedback-item strong {
  display: block;
  margin-bottom: 6px;
}

.form-preview p,
.next-action-item p,
.feedback-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.draft-status {
  border-radius: 8px;
  padding: 12px 14px;
  background: #eef3f5;
  color: var(--navy);
  font-size: 14px;
  font-weight: 800;
}

.mobile-form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mobile-elder-list {
  display: grid;
  gap: 10px;
}

.install-hint {
  border: 1px solid var(--line);
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  background: #f7fbfa;
}

.install-hint strong {
  display: block;
  margin-bottom: 5px;
  color: var(--teal);
}

.install-hint p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.mobile-elder-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.mobile-elder-card span,
.mobile-elder-card strong,
.mobile-elder-card small {
  display: block;
}

.mobile-elder-card strong {
  font-size: 18px;
}

.mobile-elder-card small {
  margin-top: 3px;
  color: var(--muted);
}

.mobile-elder-card em {
  display: inline-flex;
  margin: 10px 0 8px;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--green-soft);
  color: var(--teal);
  font-style: normal;
  font-size: 12px;
  font-weight: 900;
}

.mobile-elder-card em.needs-review {
  background: var(--rose-soft);
  color: var(--rose);
}

.visit-rounds {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 4px 0 10px;
}

.visit-rounds span {
  display: grid;
  min-height: 48px;
  align-content: center;
  justify-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 4px;
  background: #f7faf9;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.visit-rounds span.done {
  border-color: #b8d8ca;
  background: var(--mint);
  color: var(--teal);
}

.visit-rounds span.current {
  border-color: #e7bd84;
  background: #fff4df;
  color: var(--amber);
}

.visit-rounds small {
  overflow: hidden;
  width: 100%;
  margin-top: 2px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.mobile-elder-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.privacy-box {
  border: 1px solid var(--line);
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  padding: 14px;
  background: #f7fbfa;
}

.privacy-box strong {
  display: block;
  margin-bottom: 6px;
  color: var(--teal);
}

.privacy-box p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.elder-grid,
.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  border-radius: 999px;
  padding: 5px 8px;
  background: #eef3f5;
  color: var(--navy);
  font-size: 12px;
  font-weight: 800;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 900;
}

.status.open {
  background: var(--rose-soft);
  color: var(--rose);
}

.status.progress {
  background: #fff0d9;
  color: var(--amber);
}

.status.done {
  background: var(--green-soft);
  color: var(--teal);
}

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

  .sidebar {
    position: static;
    padding: 16px;
    gap: 14px;
  }

  .nav {
    grid-template-columns: repeat(6, minmax(120px, 1fr));
    overflow-x: auto;
  }

  .sidebar-note {
    display: none;
  }

  .mobile-worker-home {
    display: block;
  }

  .metric-grid,
  .content-grid,
  .admin-grid,
  .split-layout,
  .elder-grid,
  .report-grid,
  .question-grid {
    grid-template-columns: 1fr;
  }

  .admin-filter-bar {
    grid-template-columns: 1fr;
  }

  .admin-feedback-form {
    grid-template-columns: 1fr;
  }

  .edit-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 19px;
  }

  .main {
    padding: 10px;
    padding-bottom: 104px;
  }

  .auth-screen {
    align-items: stretch;
    padding: 10px;
  }

  .auth-card {
    align-self: center;
    padding: 22px;
  }

  .auth-card h1 {
    font-size: 32px;
  }

  label {
    gap: 9px;
    font-size: 19px;
  }

  input,
  select,
  textarea {
    min-height: 56px;
    padding: 14px 15px;
    font-size: 20px;
  }

  textarea {
    min-height: 112px;
  }

  button,
  .primary-button,
  .secondary-button {
    min-height: 56px;
    font-size: 19px;
  }

  .sidebar {
    padding: 12px;
    gap: 12px;
  }

  .brand strong {
    font-size: 19px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .brand span {
    font-size: 14px;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(104px, 1fr));
    gap: 8px;
  }

  .nav-item {
    min-height: 54px;
    padding: 12px 8px;
    font-size: 17px;
  }

  .topbar,
  .top-actions,
  .two-cols {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .check-grid {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    gap: 8px;
  }

  .metric {
    padding: 16px;
  }

  .metric strong {
    font-size: 34px;
  }

  .panel {
    padding: 16px;
  }

  .panel-header h2 {
    font-size: 23px;
  }

  .mobile-elder-card {
    min-height: 150px;
    padding: 18px;
  }

  .mobile-elder-card strong {
    font-size: 22px;
  }

  .mobile-elder-card small,
  .mobile-elder-card p {
    font-size: 17px;
  }

  .mobile-elder-card em {
    font-size: 16px;
    padding: 8px 10px;
  }

  .visit-rounds {
    gap: 8px;
    margin: 6px 0 12px;
  }

  .visit-rounds span {
    min-height: 60px;
    font-size: 17px;
  }

  .visit-rounds small {
    font-size: 13px;
  }

  .check-pill,
  .radio-card {
    min-height: 58px;
    padding: 14px;
    font-size: 19px;
  }

  .step-title strong {
    font-size: 22px;
  }

  .step-title span,
  .helper-text,
  .meta {
    font-size: 16px;
  }

  .recent-visit-item {
    padding: 18px;
  }

  .recent-visit-item strong {
    font-size: 22px;
  }

  .recent-visit-item span,
  .recent-visit-item p {
    font-size: 17px;
  }

  .mobile-form-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    padding: 12px;
    background: rgba(245, 247, 244, 0.96);
    border-top: 1px solid var(--line);
  }

  .mobile-form-actions .hidden {
    display: none !important;
  }

  .role-card {
    padding: 12px;
  }
}

@media print {
  .sidebar,
  .top-actions,
  #dashboard,
  #visit,
  #elders,
  #requests {
    display: none !important;
  }

  .app-shell,
  .main,
  .view.active,
  #monthly {
    display: block;
  }

  .main {
    padding: 0;
  }

  .panel,
  .metric {
    box-shadow: none;
  }
}
