:root {
  color-scheme: light;
  --primary: #24443d;
  --primary-hover: #1e3a34;
  --primary-active: #19332d;
  --action-soft-bg: #d9e7e3;
  --action-soft-border: #6f958c;
  --action-soft-text: #24443d;
  --action-soft-hover-bg: #6f958c;
  --action-soft-hover-text: #ffffff;
  --action-quiet-bg: #edf5f2;
  --action-quiet-border: #d9e7e3;
  --action-quiet-text: #6f958c;
  --action-quiet-hover-bg: #d9e7e3;
  --action-quiet-hover-text: #24443d;
  --secondary: #f4f6f5;
  --accent: #5b9ea6;
  --accent-hover: #4d9098;
  --accent-soft: #e8efee;
  --info: #3b82f6;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-active: #b91c1c;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-tertiary: #475569;
  --text-on-primary: #f4f6f5;
  --text-on-accent: #f4f6f5;
  --bg: #f4f6f5;
  --panel: #ffffff;
  --surface-section: #f0f4f3;
  --surface-muted: #e8efee;
  --surface-dark: #1e2a28;
  --line: #d9e1df;
  --line-soft: #e6ebea;
  --divider: #eceff1;
  --focus: #5b9ea6;
  --disabled: #edf2f7;
  --disabled-text: #94a3b8;
  --detail-hero-start: #ffffff;
  --radius: 12px;
  --radius-sm: 10px;
  --shadow: 0 6px 18px rgba(16, 24, 40, 0.09);
  --shadow-strong: 0 12px 28px rgba(16, 24, 40, 0.13);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-primary);
}

body[data-theme="business-blue"] {
  --primary: #1e293b;
  --primary-hover: #172033;
  --primary-active: #111827;
  --action-soft-bg: #e2e8f0;
  --action-soft-border: #64748b;
  --action-soft-text: #1e293b;
  --action-soft-hover-bg: #64748b;
  --action-soft-hover-text: #ffffff;
  --action-quiet-bg: #f1f5f9;
  --action-quiet-border: #e2e8f0;
  --action-quiet-text: #64748b;
  --action-quiet-hover-bg: #e2e8f0;
  --action-quiet-hover-text: #1e293b;
  --secondary: #f8fafc;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8f0ff;
  --info: #2563eb;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-active: #991b1b;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-tertiary: #475569;
  --text-on-primary: #f8fafc;
  --text-on-accent: #f8fafc;
  --bg: #f8fafc;
  --panel: #ffffff;
  --surface-section: #eef4fb;
  --surface-muted: #e2e8f0;
  --surface-dark: #1e293b;
  --line: #cbd5e1;
  --line-soft: #e2e8f0;
  --divider: #e2e8f0;
  --focus: #2563eb;
  --disabled: #e2e8f0;
  --disabled-text: #94a3b8;
}

body[data-theme="warm-amber"] {
  --primary: #292D32;
  --primary-hover: #1F2328;
  --primary-active: #161A1F;
  --action-soft-bg: #F2DEBC;
  --action-soft-border: #C58B3A;
  --action-soft-text: #292D32;
  --action-soft-hover-bg: #C58B3A;
  --action-soft-hover-text: #FFFFFF;
  --action-quiet-bg: #FAF0DC;
  --action-quiet-border: #F2DEBC;
  --action-quiet-text: #C58B3A;
  --action-quiet-hover-bg: #F2DEBC;
  --action-quiet-hover-text: #292D32;
  --secondary: #FAF9F6;
  --accent: #C58B3A;
  --accent-hover: #B77822;
  --accent-soft: #F7E8D2;
  --info: #3B82F6;
  --success: #22A06B;
  --warning: #E59A3A;
  --danger: #E0524D;
  --danger-hover: #C93E3A;
  --danger-active: #A9302D;
  --text-primary: #292D32;
  --text-secondary: #4B5563;
  --text-tertiary: #6B6F76;
  --text-on-primary: #FAF9F6;
  --text-on-accent: #FFFFFF;
  --bg: #FFFFFF;
  --panel: #FFFFFF;
  --surface-section: #FAF9F6;
  --surface-muted: #F1EEE8;
  --surface-dark: #292D32;
  --line: #E2E2E2;
  --line-soft: #EFEDEA;
  --divider: #E8E5DF;
  --focus: #C58B3A;
  --disabled: #E5E7EB;
  --disabled-text: #9CA3AF;
}

body[data-theme="gentle-pink"] {
  --primary: #8b5e83;
  --primary-hover: #7a5072;
  --primary-active: #684361;
  --action-soft-bg: #f3dce8;
  --action-soft-border: #c48aae;
  --action-soft-text: #8b5e83;
  --action-soft-hover-bg: #c48aae;
  --action-soft-hover-text: #ffffff;
  --action-quiet-bg: #fbeef4;
  --action-quiet-border: #f3dce8;
  --action-quiet-text: #c48aae;
  --action-quiet-hover-bg: #f3dce8;
  --action-quiet-hover-text: #8b5e83;
  --secondary: #fff7f8;
  --accent: #d88fa3;
  --accent-hover: #c77d91;
  --accent-soft: #fde8ee;
  --info: #8b5cf6;
  --success: #22a06b;
  --warning: #e59a3a;
  --danger: #e05263;
  --danger-hover: #c83f50;
  --danger-active: #ae3343;
  --text-primary: #2f2430;
  --text-secondary: #5f4456;
  --text-tertiary: #6b4e5f;
  --text-on-primary: #fff7f8;
  --text-on-accent: #fff7f8;
  --bg: #fff7f8;
  --panel: #ffffff;
  --surface-section: #fff0f3;
  --surface-muted: #f7dce4;
  --surface-dark: #3a2937;
  --line: #f0d6de;
  --line-soft: #f6e4e9;
  --divider: #f6e4e9;
  --focus: #d88fa3;
  --disabled: #f6e4e9;
  --disabled-text: #b58a9a;
}

body[data-theme="memory-paper"] {
  --primary: #667887;
  --primary-hover: #566978;
  --primary-active: #465866;
  --action-soft-bg: #E1E7EA;
  --action-soft-border: #A9B4BC;
  --action-soft-text: #3D4143;
  --action-soft-hover-bg: #A9B4BC;
  --action-soft-hover-text: #FFFFFF;
  --action-quiet-bg: #F0F3F4;
  --action-quiet-border: #E1E7EA;
  --action-quiet-text: #667887;
  --action-quiet-hover-bg: #E1E7EA;
  --action-quiet-hover-text: #3D4143;
  --secondary: #F3EEE4;
  --accent: #A77A52;
  --accent-hover: #936946;
  --accent-soft: #E8E2D8;
  --info: #4F7EA8;
  --success: #4F8A68;
  --warning: #B9853E;
  --danger: #B85C56;
  --danger-hover: #A24E49;
  --danger-active: #8B423D;
  --text-primary: #3D4143;
  --text-secondary: #5E625F;
  --text-tertiary: #74716C;
  --text-on-primary: #F8F5EE;
  --text-on-accent: #FFF9F0;
  --bg: #F3EEE4;
  --panel: #FFFDF8;
  --surface-section: #E8E2D8;
  --surface-muted: #EFE8DD;
  --surface-dark: #3D4143;
  --line: #CFC7BB;
  --line-soft: #E2DCD2;
  --divider: #E2DCD2;
  --focus: #A77A52;
  --disabled: #E6DED3;
  --disabled-text: #9A948C;
}

body[data-theme="midnight-black"] {
  --primary: #E5E7EB;
  --primary-hover: #F3F4F6;
  --primary-active: #FFFFFF;
  --action-soft-bg: #1F2937;
  --action-soft-border: #64748B;
  --action-soft-text: #F8FAFC;
  --action-soft-hover-bg: #334155;
  --action-soft-hover-text: #FFFFFF;
  --action-quiet-bg: #121826;
  --action-quiet-border: #475569;
  --action-quiet-text: #CBD5E1;
  --action-quiet-hover-bg: #1F2937;
  --action-quiet-hover-text: #F8FAFC;
  --secondary: #1A1A1A;
  --accent: #60A5FA;
  --accent-hover: #93C5FD;
  --accent-soft: #0F1B2D;
  --info: #60A5FA;
  --success: #22C55E;
  --warning: #F59E0B;
  --danger: #F87171;
  --danger-hover: #EF4444;
  --danger-active: #DC2626;
  --text-primary: #F8FAFC;
  --text-secondary: #CBD5E1;
  --text-tertiary: #94A3B8;
  --text-on-primary: #050505;
  --text-on-accent: #050505;
  --bg: #050505;
  --panel: #121212;
  --surface-section: #1A1A1A;
  --surface-muted: #1F2937;
  --surface-dark: #020617;
  --line: #4B5563;
  --line-soft: #374151;
  --divider: #374151;
  --focus: #60A5FA;
  --disabled: #1F2937;
  --disabled-text: #64748B;
  --detail-hero-start: #050505;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.42);
  --shadow-strong: 0 16px 38px rgba(0, 0, 0, 0.58);
}

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

button {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  min-height: 40px;
  padding: 8px 14px;
  background: var(--primary);
  color: var(--text-on-primary);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.35;
}

button:hover {
  background: var(--primary-hover);
}

button:active {
  background: var(--primary-active);
}

button.secondary {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text-secondary);
}

button.secondary:hover {
  background: var(--secondary);
  border-color: var(--accent);
  color: var(--primary);
}

button.action-soft {
  background: var(--action-soft-bg);
  border-color: var(--action-soft-border);
  color: var(--action-soft-text);
  font-weight: 700;
}

button.action-soft:hover {
  background: var(--action-soft-hover-bg);
  border-color: var(--action-soft-hover-bg);
  color: var(--action-soft-hover-text);
}

button.action-soft:active {
  filter: brightness(0.96);
}

button.action-quiet {
  background: var(--action-quiet-bg);
  border-color: var(--action-quiet-border);
  color: var(--action-quiet-text);
  font-weight: 700;
}

button.action-quiet:hover {
  background: var(--action-quiet-hover-bg);
  border-color: var(--action-quiet-hover-bg);
  color: var(--action-quiet-hover-text);
}

button.action-quiet:active {
  filter: brightness(0.98);
}

button.biometric-button {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 800;
}

button.biometric-button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
}

button.biometric-button:active {
  filter: brightness(0.96);
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: var(--danger-hover);
}

button.danger:active {
  background: var(--danger-active);
}

button.warning {
  background: var(--warning);
  color: var(--text-primary);
}

button.warning:hover {
  background: #d97706;
  color: var(--text-on-primary);
}

button.warning:active {
  background: #b45309;
  color: var(--text-on-primary);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--primary);
  padding-inline: 6px;
}

button:disabled {
  cursor: not-allowed;
  background: var(--disabled);
  color: var(--disabled-text);
}

button.is-processing:disabled {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--action-soft-bg);
  border-color: var(--action-soft-border);
  color: var(--action-soft-text);
  cursor: wait;
  opacity: 1;
}

button.is-processing:disabled::before {
  content: "";
  width: 0.9em;
  height: 0.9em;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: processing-button-spin 0.75s linear infinite;
}

@keyframes processing-button-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  button.is-processing:disabled::before { animation: none; }
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text-primary);
  min-height: 46px;
  padding: 10px 12px;
  font-size: 14px;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--accent);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(91, 158, 166, 0.16);
  outline: none;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.app {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 16px 92px;
}

.route-detail {
  background: linear-gradient(180deg, var(--detail-hero-start) 0, var(--detail-hero-start) 66px, var(--bg) 150px);
}

.page-transition-forward {
  animation: page-enter-from-right 400ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.page-transition-back {
  animation: page-enter-from-left 400ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.page-transition-fade {
  animation: page-fade-in 220ms ease-out;
}

@keyframes page-enter-from-right {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes page-enter-from-left {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes page-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .page-transition-forward,
  .page-transition-back,
  .page-transition-fade {
    animation: none;
  }
}

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

.topbar-centered {
  position: relative;
  justify-content: center;
  min-height: 38px;
}

.topbar-centered > :first-child {
  position: absolute;
  left: 0;
}

.topbar-centered .section-title {
  position: absolute;
  left: 50%;
  max-width: calc(100% - 160px);
  overflow: hidden;
  margin: 0;
  text-align: center;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  white-space: nowrap;
}

.topbar-centered .detail-page-title {
  max-width: calc(100% - 190px);
  color: var(--text-primary);
  font-size: clamp(34px, 7vw, 46px);
  font-weight: 800;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.route-detail .topbar-centered {
  min-height: 110px;
  margin-bottom: 10px;
}

.topbar-centered .detail-title-block {
  position: absolute;
  left: 50%;
  display: grid;
  justify-items: center;
  gap: 3px;
  max-width: calc(100% - 150px);
  text-align: center;
  transform: translateX(-50%);
}

.topbar-centered .detail-title-block .section-title {
  position: static;
  max-width: 100%;
  transform: none;
}

.detail-date-meta {
  margin: 0;
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
}

.detail-title-block .detail-date-meta:first-of-type {
  margin-top: 16px;
}

.detail-edit-button {
  position: absolute;
  right: 0;
}

.home-header {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.app-header {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.brand-logo-wrap {
  display: grid;
}

.welcome-brand {
  justify-items: center;
}

.home-brand {
  justify-items: start;
}

.brand-logo {
  display: block;
  width: min(78vw, 360px);
  height: auto;
  object-fit: contain;
}

.home-brand .brand-logo {
  width: min(46vw, 210px);
  max-height: 86px;
}

.icon-actions {
  display: inline-flex;
  gap: 6px;
  justify-self: end;
}

.icon-button {
  display: inline-flex;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-color: var(--line);
  background: var(--panel);
  color: var(--primary);
}

.icon-button:hover {
  background: var(--secondary);
  border-color: var(--accent);
}

.button-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.home-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.install-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  border-color: rgba(91, 158, 166, 0.42);
  background: linear-gradient(135deg, var(--panel), var(--accent-soft));
}

.install-card .section-title {
  margin-bottom: 4px;
}

.install-card p {
  margin: 0;
}

.install-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.title {
  margin: 0;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0;
}

.home-header .title,
.welcome .title {
  font-size: 38px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--text-secondary);
}

.section {
  margin: 16px 0;
}

.section-title {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 700;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  font-size: 15px;
}

.person-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  width: 100%;
  margin: 10px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
  color: var(--text-primary);
  text-align: left;
  box-shadow: var(--shadow);
}

.person-card:hover {
  background: var(--surface-section);
  border-color: var(--accent);
}

.person-card:focus-visible,
button:focus-visible,
.button-link:focus-visible {
  box-shadow: 0 0 0 3px rgba(91, 158, 166, 0.22);
  outline: none;
}

.person-card .name {
  font-size: 20px;
  font-weight: 700;
}

.person-card .phone {
  grid-column: 1;
  color: var(--text-tertiary);
}

.person-card .card-updated {
  justify-self: end;
  align-self: end;
  color: var(--text-tertiary);
  font-size: 12px;
  white-space: nowrap;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 18px;
  display: flex;
  gap: 8px;
  transform: translateX(-50%);
}

.bottom-nav button {
  min-width: 220px;
}

.update-prompt {
  position: fixed;
  right: 16px;
  bottom: 82px;
  left: 16px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(calc(100% - 32px), 520px);
  margin: 0 auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-dark);
  color: var(--text-on-primary);
  box-shadow: var(--shadow-strong);
  font-size: 14px;
}

.update-prompt button {
  background: var(--accent);
  color: var(--text-on-accent);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-card {
  width: min(100%, 420px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text-primary);
  box-shadow: var(--shadow-strong);
}

.modal-actions {
  justify-content: center;
}

.modal-actions button {
  min-width: 112px;
}

.message-dialog-card {
  max-width: 380px;
}

.message-dialog-text {
  margin: 0 0 20px;
  color: var(--text-primary);
  line-height: 1.65;
  white-space: pre-line;
}

.field {
  margin: 13px 0;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

.security-form {
  gap: 8px;
}

.security-field {
  margin: 4px 0;
}

.security-field label {
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 700;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row > * {
  min-width: 0;
}

.name-check-row {
  align-items: stretch;
}

.name-check-row input {
  flex: 1 1 auto;
}

.name-check-row button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.birthday-search-row {
  align-items: stretch;
}

.birthday-search-row select {
  flex: 1 1 0;
}

.compact-editor-row {
  align-items: stretch;
}

.compact-editor-row input {
  flex: 1 1 auto;
}

.compact-row-button {
  flex: 0 0 auto;
}

.interest-manage-field {
  margin: 0;
}

.interest-manage-row {
  align-items: stretch;
}

.interest-manage-row input {
  flex: 1 1 auto;
}

.interest-manage-row button {
  flex: 0 0 auto;
}

.list-editor-row {
  display: grid;
  grid-template-columns: 5.2em auto minmax(0, 1fr);
  align-items: stretch;
}

.list-editor-row.has-delete {
  grid-template-columns: 5.2em auto minmax(0, 1fr) auto;
}

.phone-list-row {
  grid-template-columns: 4.4em auto minmax(0, 1fr);
}

.phone-list-row.has-delete {
  grid-template-columns: 4.4em auto minmax(0, 1fr) auto;
}

.list-label-select {
  min-width: 0;
  padding-inline: 8px 6px;
}

.phone-label-select {
  padding-inline: 6px 4px;
}

.default-inline-button {
  min-width: 4.8em;
  padding-inline: 8px;
}

.address-list-row {
  display: grid;
  gap: 8px;
}

.address-list-top-row,
.address-region-row,
.address-list-bottom-row {
  align-items: stretch;
}

.address-list-top-row .list-label-select {
  flex: 0 0 5.2em;
}

.address-list-top-row .default-inline-button {
  flex: 0 0 auto;
}

.address-list-bottom-row input {
  flex: 1 1 auto;
}

.address-city-select,
.address-district-select {
  flex: 1 1 0;
  min-width: 0;
}

.address-list-bottom-row .danger {
  flex: 0 0 auto;
}

.family-member-row {
  display: grid;
  grid-template-columns: 4.6em minmax(0, 1fr);
  align-items: stretch;
}

.family-member-row.has-custom-relationship {
  grid-template-columns: 4.6em minmax(5.2em, 0.45fr) minmax(0, 1fr);
}

.family-member-row.has-delete {
  grid-template-columns: 4.6em minmax(0, 1fr) auto;
}

.family-member-row.has-custom-relationship.has-delete {
  grid-template-columns: 4.6em minmax(5.2em, 0.45fr) minmax(0, 1fr) auto;
}

.relationship-select {
  min-width: 0;
  padding-inline: 8px 6px;
}

.life-event-row {
  display: grid;
  grid-template-columns: 8.9em minmax(0, 1fr);
  align-items: stretch;
}

.life-event-row.has-delete {
  grid-template-columns: 8.9em minmax(0, 1fr) auto;
}

.life-event-textarea {
  min-height: 46px;
  overflow: hidden;
  resize: vertical;
}

.date-input {
  min-width: 0;
}

.custom-date-range-row {
  display: grid;
  gap: 8px;
}

.date-range-date-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: stretch;
}

.date-range-date-row input {
  min-width: 0;
}

.input-status-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.field-error {
  min-width: max-content;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

.custom-field-main {
  margin-top: 0;
}

.custom-field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.custom-field-header label {
  min-width: 0;
  margin-bottom: 0;
}

.custom-field-header button {
  flex: 0 0 auto;
}

.custom-option-row {
  align-items: stretch;
}

.custom-option-row input {
  flex: 1 1 0;
}

.custom-option-row button {
  flex: 0 0 auto;
}

.more-fields-toggle {
  display: grid;
  justify-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

.disclosure-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-section);
  color: var(--primary);
}

.detail-actions-row {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.detail-actions-row > * {
  flex: 0 0 auto;
}

.stack {
  display: grid;
  gap: 10px;
}

.settings-meta-list {
  display: grid;
  gap: 2px;
}

.settings-meta-list p {
  margin: 0;
}

.basic-inline-field {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  column-gap: 12px;
  align-items: center;
}

.basic-inline-field .section-title {
  margin: 0;
  white-space: nowrap;
}

.basic-inline-control {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.basic-inline-control input {
  min-width: 0;
}

.basic-inline-control .field-error {
  justify-self: end;
  text-align: right;
}

.basic-inline-gender .chip-list {
  justify-content: flex-start;
}

.route-settings > .panel {
  margin: 22px 0;
}

.route-settings > .panel:first-of-type {
  margin-top: 0;
}

.route-settings > .panel:last-of-type {
  margin-bottom: 0;
}

.guide-list {
  margin: 0;
  padding-left: 22px;
  color: var(--text-secondary);
}

.guide-list li {
  margin: 6px 0;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text-secondary);
  font-size: 13px;
  padding: 7px 10px;
}

.chip:hover {
  background: var(--secondary);
  border-color: var(--accent);
  color: var(--primary);
}

.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
}

.chip.inert {
  cursor: default;
  background: var(--panel);
  border-color: var(--line);
  color: var(--text-secondary);
}

.chip.inert:hover {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text-secondary);
}

.tag-option {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tag-name-edit-option {
  align-items: stretch;
}

.tag-name-input {
  width: min(42vw, 180px);
  min-height: 34px;
  padding: 6px 8px;
}

.mini {
  padding: 6px 8px;
  font-size: 12px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: var(--primary);
  color: var(--text-on-primary);
  text-decoration: none;
  font-size: 14px;
}

.button-link:hover {
  background: var(--primary-hover);
}

.link-button {
  min-height: auto;
  padding: 0 2px;
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-button:hover {
  background: transparent;
  color: var(--accent);
}

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

.candidate-card {
  display: grid;
  justify-items: start;
  gap: 4px;
  width: 100%;
  min-height: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text-primary);
  text-align: left;
}

.candidate-card:hover {
  background: var(--surface-section);
  border-color: var(--accent);
}

.candidate-name {
  font-size: 17px;
  font-weight: 700;
}

.inline-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--secondary);
}

.custom-field-card .field label {
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
}

.manage-form {
  margin-top: 12px;
}

.detail-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}

.detail-line:last-child {
  border-bottom: 0;
}

.detail-panel {
  padding-block: 4px;
}

.detail-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line-soft);
}

.detail-section:first-child {
  padding-top: 10px;
}

.detail-section:last-child {
  border-bottom: 0;
  padding-bottom: 10px;
}

.detail-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.detail-section .section-title {
  margin-bottom: 8px;
  color: var(--text-primary);
  font-size: 18px;
}

.detail-section-header .section-title {
  margin-bottom: 0;
}

.section-header-button {
  min-height: 34px;
  padding: 6px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.detail-value {
  margin: 0;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.7;
}

.detail-value-link {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.detail-value-link:hover {
  color: var(--accent);
}

.custom-detail-line > span:first-child {
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
}

.custom-detail-line .muted {
  display: inline-block;
  margin-top: 2px;
  font-size: 14px;
  font-weight: 400;
}

.blank-detail-card {
  min-height: 96px;
}

.detail-actions {
  justify-content: center;
}

.search-actions {
  justify-content: center;
}

.search-panel .field label {
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 700;
}

.archived-banner {
  border-color: rgba(245, 158, 11, 0.45);
  background: #fff7ed;
}

.archived-person-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.archived-person-card h2 {
  margin: 0;
  font-size: 18px;
}

.recovery-code {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-section);
  color: var(--primary);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  word-break: break-word;
}

.muted {
  color: var(--text-tertiary);
}

.danger-text {
  color: var(--danger);
}

.sync-password-notice {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text-secondary);
}

.sync-password-notice strong {
  color: var(--accent);
  font-weight: 800;
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-tertiary);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-actions input {
  flex: 1 1 180px;
}

.conflict-card {
  background: var(--surface-section);
}

.health-issue {
  background: #fff7ed;
  border-color: #fed7aa;
}

.storage-warning {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #7c2d12;
}

.storage-warning strong {
  color: #7c2d12;
}

.storage-warning .muted {
  color: #9a3412;
}

.detail-value,
.detail-line,
.detail-value-link,
.recovery-code,
.storage-warning,
textarea,
input {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

.data-summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.data-summary span {
  padding: 6px 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-section);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 700;
}

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

.theme-option {
  display: grid;
  gap: 8px;
  justify-items: center;
  min-height: 76px;
  padding: 10px;
  border-color: var(--line);
  background: var(--panel);
  color: var(--text-secondary);
}

.theme-option:hover {
  background: var(--secondary);
  border-color: var(--accent);
  color: var(--primary);
}

.theme-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 158, 166, 0.14);
}

.theme-swatches {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}

.theme-swatches span {
  width: 24px;
  height: 18px;
}

.sync-summary {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-section);
  color: var(--text-secondary);
  font-size: 13px;
}

.sync-summary strong {
  color: var(--text-primary);
}

.status-summary {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-section);
}

.status-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  font-size: 14px;
}

.status-row span {
  color: var(--text-tertiary);
}

.status-row strong {
  color: var(--text-primary);
  font-weight: 700;
  word-break: break-word;
}

.snapshot-card {
  background: var(--surface-section);
}

.troubleshoot-item.ok {
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.troubleshoot-item.warn {
  background: #fff7ed;
  border-color: #fed7aa;
}

.troubleshoot-item.error {
  background: #fef2f2;
  border-color: #fecaca;
}

.legal-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
}

.legal-links a {
  color: var(--primary);
  font-weight: 700;
}

.legal-page .panel h2 {
  margin-top: 8px;
}

code {
  padding: 2px 4px;
  border-radius: 4px;
  background: var(--surface-section);
  color: var(--primary);
  font-size: 0.92em;
}

.conflict-choice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel);
  font-size: 13px;
}

.welcome {
  display: grid;
  min-height: calc(100vh - 120px);
  align-content: center;
  gap: 18px;
}

@media (max-width: 520px) {
  .app {
    padding-inline: 12px;
  }

  .install-card {
    grid-template-columns: 1fr;
  }

  .install-actions {
    justify-content: stretch;
  }

  .install-actions button {
    flex: 1 1 auto;
  }

  .topbar {
    align-items: flex-start;
  }

  .row {
    align-items: stretch;
    flex-direction: column;
  }

  .name-check-row,
  .birthday-search-row,
  .compact-editor-row,
    .interest-manage-row,
    .address-list-top-row,
    .address-region-row,
    .address-list-bottom-row,
  .custom-option-row {
    flex-direction: row;
  }

  .family-member-row.has-custom-relationship {
    grid-template-columns: 4.6em minmax(5.2em, 0.45fr) minmax(0, 1fr);
  }

  .family-member-row.has-delete {
    grid-template-columns: 4.6em minmax(0, 1fr) auto;
  }

  .family-member-row.has-custom-relationship.has-delete {
    grid-template-columns: 4.6em minmax(5.2em, 0.45fr) minmax(0, 1fr) auto;
  }

  .life-event-row,
  .life-event-row.has-delete {
    grid-template-columns: 8.9em minmax(0, 1fr) auto;
  }

  .life-event-row:not(.has-delete) {
    grid-template-columns: 8.9em minmax(0, 1fr);
  }

  .list-editor-row {
    grid-template-columns: 5.2em auto minmax(0, 1fr);
  }

  .list-editor-row.has-delete {
    grid-template-columns: 5.2em auto minmax(0, 1fr) auto;
  }

  .phone-list-row {
    grid-template-columns: 4.4em auto minmax(0, 1fr);
  }

  .phone-list-row.has-delete {
    grid-template-columns: 4.4em auto minmax(0, 1fr) auto;
  }

  .input-status-row {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .bottom-nav {
    left: 16px;
    right: 16px;
    transform: none;
  }

  .bottom-nav button {
    flex: 1;
    min-width: 0;
  }

  .theme-options {
    grid-template-columns: 1fr;
  }
}
