/* Layout, cards, forms, results, tab bar. */

/* ---------- shell ---------- */

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: calc(env(safe-area-inset-top) + 10px) var(--pad) 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-inline-end: auto;
  min-width: 0;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 9px;
  background: linear-gradient(150deg, var(--accent), #d98d12);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
}

.brand-text { min-width: 0; }
.brand-name { font-size: 16px; font-weight: 700; line-height: 1.1; }
.brand-sub {
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.chip-btn:active { background: var(--surface-2); }

main {
  flex: 1;
  padding: 14px var(--pad) 0;
  padding-bottom: calc(env(safe-area-inset-bottom) + 190px);
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.screen[hidden] { display: none; }

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .spacer { margin-inline-start: auto; }

/* ---------- form ---------- */

.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }

.field > label,
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 6px;
  line-height: 1.4;
}

input[type='text'],
input[type='number'],
input[type='search'],
select {
  width: 100%;
  height: var(--tap);
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
}

input::placeholder { color: var(--text-faint); }

input[type='number'] { -moz-appearance: textfield; }
input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
                    linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: right 16px center, right 11px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-inline-end: 32px;
}
[dir='rtl'] select {
  background-position: left 11px center, left 16px center;
  background-image: linear-gradient(45deg, var(--text-faint) 50%, transparent 50%),
                    linear-gradient(135deg, transparent 50%, var(--text-faint) 50%);
}

.row {
  display: grid;
  gap: 10px;
}
.row-2 { grid-template-columns: 1fr 1fr; }
.row-price { grid-template-columns: 1fr 116px; }
.row-3 { grid-template-columns: repeat(3, 1fr); }

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 12px;
  border: 1px solid var(--line);
}
.segmented button {
  flex: 1;
  height: 36px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.segmented button[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-ink);
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
}
.switch-row .switch-text { flex: 1; min-width: 0; }
.switch-row .switch-text b { display: block; font-size: 14px; font-weight: 600; }

.switch {
  flex: none;
  width: 50px;
  height: 30px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  position: relative;
  transition: background 0.15s ease;
}
.switch::after {
  content: '';
  position: absolute;
  inset-inline-start: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: inset-inline-start 0.15s ease, background 0.15s ease;
}
.switch[aria-checked='true'] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked='true']::after { inset-inline-start: 24px; background: var(--accent-ink); }

/* ---------- badges & notes ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid transparent;
}
.badge-good { background: var(--good-soft); color: var(--good); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); border-color: var(--line); }

.notice {
  display: flex;
  gap: 9px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 8px;
  border: 1px solid transparent;
}
.notice:last-child { margin-bottom: 0; }
.notice-warn { background: var(--warn-soft); color: var(--text); border-color: color-mix(in srgb, var(--warn) 26%, transparent); }
.notice-info { background: var(--surface-2); color: var(--text-muted); border-color: var(--line); }
.notice-icon { flex: none; font-size: 14px; line-height: 1.4; }

/* ---------- results ---------- */

.result-hero {
  background: linear-gradient(165deg, var(--surface) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 12px;
}
.result-hero .label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
}
.result-total {
  font-size: clamp(30px, 9vw, 42px);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 4px 0 2px;
  line-height: 1.05;
}
.result-total .unit { font-size: 0.45em; font-weight: 700; color: var(--text-muted); margin-inline-start: 6px; }
.result-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.lines { display: flex; flex-direction: column; }

.line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14.5px;
}
.line:last-child { border-bottom: none; }
.line .line-name { flex: 1; min-width: 0; color: var(--text-muted); }
.line .line-rate {
  font-size: 11.5px;
  color: var(--text-faint);
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  flex: none;
}
.line .line-value { font-weight: 650; flex: none; }
.line-sub .line-name { padding-inline-start: 12px; font-size: 13.5px; }
.line-total {
  border-top: 1px solid var(--line);
  border-bottom: none;
  margin-top: 4px;
  padding-top: 12px;
  font-size: 16px;
}
.line-total .line-name { color: var(--text); font-weight: 650; }
.line-total .line-value { font-weight: 800; }
.line-strike .line-value { text-decoration: line-through; color: var(--text-faint); font-weight: 500; }

.cliff {
  border: 1px solid color-mix(in srgb, var(--good) 32%, transparent);
  background: var(--good-soft);
}
.cliff .cliff-amount { font-size: 22px; font-weight: 800; color: var(--good); }

/* ---------- sticky total ---------- */

.sticky-total {
  position: fixed;
  inset-inline: 0;
  bottom: calc(env(safe-area-inset-bottom) + 62px);
  z-index: 25;
  padding: 0 var(--pad) 8px;
  pointer-events: none;
}
.sticky-total-inner {
  pointer-events: auto;
  max-width: 640px;
  margin: 0 auto;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}
.sticky-total .st-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.72; }
.sticky-total .st-value { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.sticky-total .st-save {
  margin-inline-start: auto;
  flex: none;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  background: var(--accent-ink);
  color: var(--accent);
  font-weight: 700;
  font-size: 13.5px;
}
.sticky-total[hidden] { display: none; }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-top: 1px solid var(--line-soft);
}
.tabbar button {
  flex: 1;
  height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 650;
  color: var(--text-faint);
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button[aria-selected='true'] { color: var(--accent); }

/* ---------- saved list ---------- */

.saved-item {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 10px;
}
.saved-head { display: flex; align-items: flex-start; gap: 10px; }
.saved-name { font-size: 15.5px; font-weight: 700; line-height: 1.25; }
.saved-sub { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.saved-total { margin-inline-start: auto; text-align: end; flex: none; }
.saved-total b { display: block; font-size: 16px; font-weight: 800; letter-spacing: -0.02em; }
.saved-total span { font-size: 11.5px; color: var(--text-faint); }
.saved-actions { display: flex; gap: 8px; margin-top: 11px; }
.saved-actions button {
  height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.saved-actions .danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-faint);
}
.empty .empty-emoji { font-size: 34px; display: block; margin-bottom: 10px; }
.empty b { display: block; color: var(--text-muted); font-size: 15px; margin-bottom: 4px; }

/* ---------- rates table ---------- */

.rate-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.rate-table th {
  text-align: start;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 0 6px 8px;
}
.rate-table td { padding: 8px 6px; border-top: 1px solid var(--line-soft); }
.rate-table td:first-child { color: var(--text-muted); }
.rate-table .num { font-weight: 650; }

.source-item { padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.source-item:last-child { border-bottom: none; }
.source-item b { display: block; font-weight: 650; }
.source-item span { color: var(--text-faint); }

.checklist { margin: 0; padding: 0; list-style: none; }
.checklist li {
  position: relative;
  padding-inline-start: 22px;
  padding-block: 6px;
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.45;
}
.checklist li::before {
  content: '';
  position: absolute;
  inset-inline-start: 4px;
  top: 13px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 640px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 18px var(--pad) calc(env(safe-area-inset-bottom) + 18px);
  border: 1px solid var(--line);
  border-bottom: none;
  max-height: 88dvh;
  overflow-y: auto;
}
.sheet h3 { font-size: 18px; margin-bottom: 4px; }
.sheet .sheet-sub { font-size: 13px; color: var(--text-faint); margin-bottom: 14px; }

.btn {
  width: 100%;
  height: var(--tap);
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--line); }
.btn-row { display: flex; gap: 10px; margin-top: 10px; }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 130px);
  z-index: 70;
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 650;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.toast.show { opacity: 1; }

.footnote {
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
  text-align: center;
  padding: 4px 8px 20px;
}
