/* --- Variables --- */
:root {
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-border: #dde3ec;
  --color-text: #1a2332;
  --color-text-muted: #5a6a7e;
  --color-primary: #2563eb;
  --color-primary-light: #eff6ff;
  --color-deduction: #dc2626;
  --color-deduction-bg: #fef2f2;
  --color-addition: #2563eb;
  --color-addition-bg: #eff6ff;
  --color-short-term-bg: #fdf2f8;
  --color-short-term: #db2777;
  --color-base: #059669;
  --color-base-bg: #ecfdf5;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --header-height: 0px;
  --bottom-nav-height: 3.5rem;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* --- Reset & Base (mobile-first) --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
  width: 100%;
  max-width: 100vw;
}

/* --- App shell --- */
.app {
  height: 100%;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

/* --- Scrollable main --- */
.main-content {
  position: fixed;
  top: 0;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
  left: 0;
  right: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: calc(0.5rem + env(safe-area-inset-top, 0px)) 0.5rem 0.5rem;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
}

.panel,
#calc-form,
.visit-input-list {
  min-width: 0;
  max-width: 100%;
}

.panel[hidden] {
  display: none;
}

/* --- Bottom navigation (fixed) --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: var(--safe-bottom);
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.125rem;
  min-height: var(--bottom-nav-height);
  padding: 0.375rem 0.5rem;
  border: none;
  background: none;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  border-top: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  line-height: 1;
}

.bottom-nav__icon svg {
  width: 100%;
  height: 100%;
}

.bottom-nav__label {
  line-height: 1.2;
}

.bottom-nav__item:hover {
  color: var(--color-primary);
  background: var(--color-primary-light);
}

.bottom-nav__item.active {
  color: var(--color-primary);
  border-top-color: var(--color-primary);
  background: var(--color-primary-light);
}

.bottom-nav--categories .bottom-nav__item {
  padding: 0.25rem 0.125rem;
  font-size: 0.7rem;
  gap: 0.0625rem;
}

.bottom-nav--categories .bottom-nav__item[data-tab="calc"],
.bottom-nav--categories .bottom-nav__item[data-tab="settings"] {
  flex: 0.8;
}

.bottom-nav--categories .bottom-nav__icon {
  width: 1rem;
  height: 1rem;
}

/* --- Calc panels --- */
.calc-panel__intro {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 0.625rem;
  padding: 0.5rem 0.625rem;
  background: var(--color-primary-light);
  border-radius: var(--radius);
  border: 1px solid #bfdbfe;
}

.calc-panel__hint {
  margin-bottom: 0.75rem;
}

.category-results {
  margin-top: 0.75rem;
}

.category-results__inner .summary {
  margin-bottom: 0.75rem;
}

.category-burden {
  margin-top: 0.75rem;
}

.category-burden-tabs {
  margin-top: 0.5rem;
}

.category-copay-wrap {
  margin-top: 0.75rem;
}

.category-note {
  margin-top: 0.75rem;
}

/* --- Form --- */
.fieldset {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 0.625rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
  max-width: 100%;
  min-width: 0;
}

.fieldset legend {
  font-weight: 700;
  font-size: 0.875rem;
  padding: 0 0.375rem;
  color: var(--color-text);
}

.input-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.input-group--wide {
  margin-top: 0.75rem;
}

.input-label {
  font-size: 0.875rem;
  flex-shrink: 0;
  min-width: 0;
}

.input-group input[type="number"] {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 1rem;
  min-width: 0;
}

.input-group input[type="number"]:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.input-unit {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
}

/* --- Visit inputs --- */
.visit-inputs-fieldset {
  margin-top: 0;
}

.visit-input-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.625rem;
}

.visit-input-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 0.75rem;
  padding: 0.5rem 0.375rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  min-height: 2.5rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.visit-input-row__label {
  flex: 0 0 auto;
  min-width: 3.5rem;
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visit-input-row__control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  justify-content: flex-start;
  width: auto;
}

.visit-input-row__control--stepper {
  flex: 1;
  justify-content: center;
  gap: 0.625rem;
}

.stepper-group {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.stepper-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--color-primary);
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.stepper-btn:hover {
  background: var(--color-primary-light);
  border-color: #bfdbfe;
}

.stepper-btn:active {
  transform: scale(0.96);
}

.visit-input-row__control--dual {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.25rem 0.25rem;
  width: 100%;
  max-width: 100%;
}

.visit-input-row input[type="number"],
.visit-input-row .visit-count {
  min-height: 2.75rem;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 1.125rem;
  text-align: right;
  background: var(--color-surface);
  -webkit-appearance: none;
  appearance: none;
  -moz-appearance: textfield;
}

.visit-input-row input[type="number"]::-webkit-inner-spin-button,
.visit-input-row input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.visit-input-row__control--stepper input[type="number"],
.visit-input-row__control--stepper .visit-count {
  width: 2.25rem;
  min-height: 2.25rem;
  padding: 0.125rem;
  flex-shrink: 0;
  text-align: center;
  font-size: 1rem;
}

.visit-input-row--custom input[type="number"] {
  width: 100%;
}

.visit-input-row input[type="number"]:focus,
.visit-input-row .visit-count:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
  border-color: var(--color-primary);
}

.custom-visits {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--color-border);
}

.custom-visits-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.5rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  user-select: none;
}

.custom-visits-title::-webkit-details-marker {
  display: none;
}

.custom-visits-title::before {
  content: "▶";
  font-size: 0.65rem;
  color: var(--color-text-muted);
  transition: transform 0.15s ease;
}

.custom-visits[open] .custom-visits-title::before {
  transform: rotate(90deg);
}

.custom-visits[open] .custom-visits-title {
  margin-bottom: 0.625rem;
}

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

.visit-input-row--custom .visit-input-row__label {
  flex: none;
  min-width: 4.5rem;
  font-size: 0.85rem;
}

.visit-input-row--custom .visit-input-row__control {
  width: 100%;
  justify-content: center;
}

/* --- Results modal --- */
.results-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--color-bg);
}

.results-modal[hidden] {
  display: none;
}

.results-modal__panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
}

.results-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
  background: var(--color-primary);
  color: #fff;
}

.results-modal__title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}

.results-modal__close-icon {
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.results-modal__close-icon:hover {
  background: rgba(255, 255, 255, 0.25);
}

.results-modal__body {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
}

.results-modal__footer {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.insurance-tabs-section {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.insurance-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.375rem;
}

.insurance-tabs__btn {
  min-height: 2.5rem;
  padding: 0.375rem 0.25rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.insurance-tabs__btn:hover {
  border-color: #bfdbfe;
  color: var(--color-primary);
}

.insurance-tabs__btn.active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.insurance-amount {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  background: var(--color-primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
}

.insurance-amount__label {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

.insurance-amount__value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.shien-burden-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.375rem;
}

.shien-burden-tabs__btn {
  min-height: 2.25rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.shien-burden-tabs__btn.active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.fieldset-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin: 0.375rem 0 0.625rem;
  line-height: 1.45;
}

.shien-results-intro {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 0.625rem;
}

.shien-copay-wrap {
  margin-top: 0.75rem;
}

.shien-copay-title {
  font-size: 0.875rem;
  font-weight: 700;
  padding: 0.625rem 0.75rem 0.375rem;
  color: var(--color-text);
}

.shien-note {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  padding: 0.625rem 0.75rem;
  background: #f8fafc;
  border-radius: 6px;
  border: 1px solid var(--color-border);
}

.results-modal__close-btn {
  width: 100%;
  min-height: 2.75rem;
  border: none;
  border-radius: var(--radius);
  background: var(--color-primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.results-modal__close-btn:hover {
  background: #1d4ed8;
}

.results-output .summary {
  margin-bottom: 0.75rem;
}

@media (min-width: 600px) {
  .results-modal {
    left: 50%;
    transform: translateX(-50%);
    max-width: 900px;
  }
}

/* --- Summary --- */
.summary {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  background: var(--color-primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 0.625rem 1rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
}

.summary-row strong {
  font-size: 1rem;
  color: var(--color-primary);
}

.summary-row--total strong {
  font-size: 1.05rem;
  font-weight: 800;
}

/* --- Results --- */
.empty-message {
  text-align: center;
  color: var(--color-text-muted);
  padding: 1.5rem 0.75rem;
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px dashed var(--color-border);
  font-size: 0.875rem;
}

.table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
  margin-bottom: 0.75rem;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.results-table th,
.results-table td {
  padding: 0.5rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.results-table th {
  background: #f8fafc;
  font-weight: 600;
  white-space: nowrap;
  font-size: 0.75rem;
}

.results-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}

.item-name__label {
  display: block;
  font-weight: 600;
  line-height: 1.35;
}

.item-name__formula {
  display: block;
  margin-top: 0.125rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.35;
  white-space: nowrap;
}

.item-name__limit-note {
  display: block;
  margin-top: 0.125rem;
  font-size: 0.6875rem;
  color: var(--color-accent, #b45309);
  line-height: 1.35;
}

/* Mobile: hide code column on medical table only */
.results-table--medical th:nth-child(1),
.results-table--medical td:nth-child(1) {
  display: none;
}

@media (max-width: 599px) {
  .results-table {
    table-layout: auto;
    font-size: 0.75rem;
  }

  .results-table th,
  .results-table td {
    padding: 0.375rem 0.375rem;
  }

  .results-table--medical th:nth-child(2),
  .results-table--medical td:nth-child(2),
  .results-table--shien th:nth-child(1),
  .results-table--shien td:nth-child(1) {
    width: auto;
    white-space: normal;
  }

  .results-table--medical th:nth-child(3),
  .results-table--medical td:nth-child(3),
  .results-table--medical th:nth-child(4),
  .results-table--medical td:nth-child(4),
  .results-table--shien th:nth-child(2),
  .results-table--shien td:nth-child(2),
  .results-table--shien th:nth-child(3),
  .results-table--shien td:nth-child(3) {
    width: 1%;
    white-space: nowrap;
  }

  .table-wrap {
    overflow-x: auto;
  }
}

.row-base td {
  background: var(--color-base-bg);
}

.results-table--medical .row-base td:nth-child(3),
.results-table--shien .row-base td:nth-child(2) {
  color: var(--color-base);
  font-weight: 600;
}

.row-deduction td {
  background: var(--color-deduction-bg);
}

.results-table--medical .row-deduction td:nth-child(3),
.results-table--shien .row-deduction td:nth-child(2) {
  color: var(--color-deduction);
  font-weight: 600;
}

.row-addition td {
  background: var(--color-addition-bg);
}

.results-table--medical .row-addition td:nth-child(3),
.results-table--shien .row-addition td:nth-child(2) {
  color: var(--color-addition);
  font-weight: 600;
}

.row-short-term td {
  background: var(--color-short-term-bg);
}

.results-table--medical .row-short-term td:nth-child(3),
.results-table--shien .row-short-term td:nth-child(2) {
  color: var(--color-short-term);
  font-weight: 600;
}

.total-row td {
  font-weight: 700;
  font-size: 0.875rem;
  background: #f8fafc;
  border-top: 2px solid var(--color-border);
}

.total-row .total-label {
  font-weight: 700;
}

.total-row .num {
  color: var(--color-primary);
  font-size: 1.125rem;
  font-weight: 700;
}

.total-row--wide {
  display: none;
}

/* --- Simple calculator --- */
.simple-calc {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem;
  box-shadow: var(--shadow);
  max-width: 100%;
  min-height: 0;
}

.simple-calc__tape {
  flex: 1 1 auto;
  min-height: 10.5rem;
  max-height: min(48vh, 300px);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem;
  background: #f1f5f9;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.simple-calc__row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.35rem 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.625rem;
  font-size: 1.125rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.simple-calc__row--active {
  border-color: #bfdbfe;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.simple-calc__row--finalized {
  background: #fafafa;
}

.simple-calc__row--empty {
  justify-content: flex-end;
  align-items: center;
  min-height: 1.75rem;
}

.simple-calc__placeholder {
  color: #d1d5db;
  font-size: 1.125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.simple-calc__expression {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.25rem 0.375rem;
  flex: 1 1 auto;
  min-width: 0;
}

.simple-calc__segment {
  white-space: nowrap;
}

.simple-calc__segment--value {
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: var(--color-text);
  font: inherit;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.simple-calc__segment--value:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.simple-calc__segment--selected {
  background: #ffffff;
  color: var(--color-text);
  border-color: var(--color-primary);
  outline: 2px solid rgba(37, 99, 235, 0.2);
  outline-offset: 1px;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.12);
}

.simple-calc__segment--empty {
  min-width: 1.5rem;
  color: #cbd5e1;
  background: #fafafa;
}

.simple-calc__segment--op {
  color: var(--color-primary);
  font-weight: 700;
  min-width: 1rem;
  text-align: center;
}

.simple-calc__segment--eq {
  color: var(--color-text-muted);
}

.simple-calc__segment--result {
  font-weight: 700;
  color: #b45309;
}

.simple-calc__segment--result-btn {
  border: 1px solid transparent;
  background: transparent;
  padding: 0.125rem 0.25rem;
  margin: -0.125rem -0.25rem;
  font: inherit;
  cursor: pointer;
  border-radius: 0.25rem;
}

.simple-calc__segment--result-btn:hover {
  background: #fff7ed;
  border-color: #fdba74;
}

.simple-calc__keys {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.simple-calc__key {
  min-height: 3rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--color-text);
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, transform 0.05s;
}

.simple-calc__key:hover {
  background: #eef2f7;
}

.simple-calc__key:active {
  transform: scale(0.97);
}

.simple-calc__key--fn {
  background: #e2e8f0;
  color: var(--color-text);
  font-size: 1rem;
}

.simple-calc__key--op {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: #bfdbfe;
}

.simple-calc__key--eq {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.simple-calc__key--eq:hover {
  background: #1d4ed8;
}

.simple-calc__key--wide {
  grid-column: span 2;
}

@media (min-width: 600px) {
  .simple-calc {
    max-width: 400px;
    margin: 0 auto;
  }

  .simple-calc__tape {
    max-height: 320px;
  }

  .simple-calc__row {
    font-size: 1.25rem;
  }

  .simple-calc__key {
    min-height: 3.25rem;
  }
}

/* --- Settings --- */
.settings-unit-price {
  margin-bottom: 0.75rem;
}

.settings-intro {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}

.settings-category {
  margin-bottom: 1rem;
}

.category-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-text);
  padding: 0.375rem 0;
  border-bottom: 2px solid var(--color-primary);
  margin-bottom: 0.5rem;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.settings-item {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.625rem 0.5rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  max-width: 100%;
  min-width: 0;
}

.settings-item:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow);
}

.settings-item input {
  margin-top: 0.2rem;
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.settings-info {
  flex: 1;
  min-width: 0;
}

.settings-header {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  margin-bottom: 0.25rem;
}

.settings-code {
  font-family: monospace;
  font-size: 0.75rem;
  background: #f1f5f9;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  color: var(--color-text-muted);
  align-self: flex-start;
}

.settings-name {
  font-weight: 600;
  font-size: 0.875rem;
}

.settings-units {
  font-size: 0.75rem;
  color: var(--color-primary);
  font-weight: 600;
}

.settings-desc {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.45;
}

.settings-item--deduction {
  border-left: 3px solid var(--color-deduction);
}

.settings-item--addition {
  border-left: 3px solid var(--color-addition);
}

.settings-item--base {
  border-left: 3px solid var(--color-base);
}

.settings-item--linked {
  opacity: 0.95;
}

/* --- Compact phones (extra narrow) --- */
@media (max-width: 359px) {
  .stepper-btn {
    width: 2rem;
    height: 2rem;
    font-size: 1rem;
  }

  .visit-input-row__control--stepper input[type="number"],
  .visit-input-row__control--stepper .visit-count {
    width: 2rem;
    min-height: 2rem;
    font-size: 0.95rem;
  }

  .visit-input-row__label {
    font-size: 0.8rem;
  }

  .input-unit {
    font-size: 0.75rem;
  }
}

/* --- Tablet & desktop enhancements --- */
@media (min-width: 600px) {
  .main-content,
  .bottom-nav {
    left: 50%;
    transform: translateX(-50%);
    max-width: 900px;
  }

  .main-content {
    padding: 1.25rem 1rem;
  }

  .fieldset {
    padding: 0.875rem 1rem;
  }

  .visit-input-row {
    padding: 0.625rem 0.75rem;
    gap: 0.5rem;
    min-height: 2.75rem;
  }

  .visit-input-row__label {
    flex: 0 0 auto;
    min-width: 4.5rem;
    font-size: 1rem;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    word-break: break-word;
  }

  .stepper-btn {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.25rem;
  }

  .visit-input-row__control--stepper input[type="number"],
  .visit-input-row__control--stepper .visit-count {
    width: 2.75rem;
    min-height: 2.75rem;
    font-size: 1.125rem;
  }

  .settings-item {
    padding: 0.625rem 0.75rem;
  }

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

  .summary {
    flex-direction: row;
    gap: 1.5rem;
  }

  .summary-row {
    justify-content: flex-start;
    gap: 0.5rem;
  }

  .input-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  .visit-input-row__control--dual {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .visit-input-row input[type="number"] {
    width: 4.5rem;
  }

  .visit-input-row--custom .custom-minutes,
  .visit-input-row--custom .custom-count {
    width: 3.75rem;
  }

  .results-table {
    font-size: 0.875rem;
  }

  .results-table th {
    font-size: 0.875rem;
  }

  .results-table--medical th:nth-child(1),
  .results-table--medical td:nth-child(1) {
    display: table-cell;
  }

  .total-row--compact {
    display: none;
  }

  .total-row--wide {
    display: table-row;
  }

  .results-table th,
  .results-table td {
    padding: 0.625rem 0.75rem;
  }

  .settings-header {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
  }

  .settings-units {
    margin-left: auto;
    font-size: 0.8rem;
  }

  .settings-name {
    font-size: 0.9rem;
  }

  .settings-desc {
    font-size: 0.8rem;
  }
}
