:root {
  color-scheme: light;
  --navy: #17324d;
  --blue: #246b91;
  --blue-dark: #164d6d;
  --sky: #e8f4f8;
  --ink: #16212b;
  --muted: #5d6b76;
  --line: #d6e0e5;
  --paper: #ffffff;
  --background: #f3f6f7;
  --danger: #a32020;
  --danger-bg: #fff0ef;
  --warning: #795000;
  --warning-bg: #fff7db;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--background);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(87, 167, 190, .17), transparent 30rem),
    var(--background);
  overscroll-behavior-y: none;
}

button, input, select { font: inherit; }
button { touch-action: manipulation; }

.app-shell {
  width: min(100% - 28px, 760px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
}

.app-header { padding: 6px 4px 22px; }
.top-nav { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px; }
.home-link { color: var(--blue-dark); font-weight: 700; text-decoration: none; }
.home-link:hover { text-decoration: underline; }

.eyebrow {
  margin: 18px 0 3px;
  color: var(--blue-dark);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; color: var(--navy); font-size: clamp(2.1rem, 9vw, 3.5rem); line-height: 1; letter-spacing: -.035em; }
.precise-title { font-size: .5em; letter-spacing: -.015em; }
h2 { margin-bottom: 0; color: var(--navy); font-size: 1.28rem; }
.intro { max-width: 40rem; margin-bottom: 0; color: var(--muted); font-size: 1.03rem; line-height: 1.5; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.input-card, .results-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 12px 34px rgba(27, 52, 68, .08);
}

.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-heading .eyebrow { margin-top: 0; }
.heading-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }

.text-button {
  min-height: 44px;
  padding: 0 5px;
  border: 0;
  color: var(--blue-dark);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.details-button, .small-button {
  padding: 0 12px;
  border: 1px solid var(--blue);
  border-radius: 9px;
  color: var(--blue-dark);
  background: var(--sky);
  font-weight: 800;
  cursor: pointer;
}

.small-button { min-height: 38px; background: #fff; }
.details-button {
  width: 100%;
  min-height: 28px;
  margin-top: 8px;
  border-color: var(--blue-dark);
  border-radius: 7px;
  color: #fff;
  background: var(--blue);
  font-size: .82rem;
}
.details-button:hover { background: var(--blue-dark); }
.card-load-button { flex: none; min-height: 32px; padding: 0; white-space: nowrap; }

.fields { display: grid; gap: 17px; }
.field { display: grid; gap: 7px; color: #35434e; font-size: .91rem; font-weight: 750; }
.field small { color: var(--muted); font-size: .78rem; font-weight: 550; }
.description-field { margin-top: 17px; }

.input-wrap {
  display: flex;
  min-height: 54px;
  align-items: center;
  overflow: hidden;
  border: 1.5px solid #aebdc5;
  border-radius: 11px;
  background: var(--paper);
  color: var(--muted);
  transition: border-color .15s, box-shadow .15s;
}

.input-wrap:focus-within { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(36, 107, 145, .14); }
.input-wrap.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(163, 32, 32, .1); }
.input-wrap > span { padding: 0 0 0 15px; font-size: 1.05rem; font-weight: 750; }
.input-wrap.suffix > span { padding: 0 15px 0 0; }

input {
  width: 100%;
  min-width: 0;
  min-height: 51px;
  padding: 13px 14px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  font-weight: 650;
}

select {
  width: 100%;
  min-width: 0;
  min-height: 51px;
  padding: 12px 38px 12px 14px;
  border: 0;
  outline: 0;
  appearance: none;
  color: var(--ink);
  background: transparent;
  font-size: 16px;
  font-weight: 650;
}

.select-wrap { position: relative; }
.select-wrap::after { position: absolute; right: 14px; content: "▾"; color: var(--muted); pointer-events: none; }

.prefix input { padding-left: 8px; }
.suffix input { padding-right: 8px; }
input::placeholder { color: #89969e; font-weight: 450; opacity: 1; }

.form-help { margin: 16px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.details-summary { margin: 10px 0 0; padding: 9px 11px; border-radius: 9px; color: var(--blue-dark); background: var(--sky); font-size: .8rem; font-weight: 700; line-height: 1.4; }
.error-message { margin-top: 14px; padding: 12px 14px; border-radius: 10px; color: var(--danger); background: var(--danger-bg); font-weight: 700; line-height: 1.4; }

.go-button, .schedule-button, .save-button, .print-button, .secondary-button {
  min-height: 52px;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
}

.go-button {
  width: 100%;
  margin: 16px 0;
  border: 1px solid var(--blue-dark);
  color: #fff;
  background: var(--blue);
  box-shadow: 0 7px 16px rgba(36, 107, 145, .22);
  font-size: 1.1rem;
}

.go-button:hover, .save-button:hover, .print-button:hover { background: var(--blue-dark); }
.go-button:active, .schedule-button:active, .save-button:active, .print-button:active { transform: translateY(1px); }

.results-card { scroll-margin-top: 16px; }
.result-description { margin: 6px 0 0; color: var(--muted); font-weight: 700; }
.calculated-badge { flex: none; padding: 6px 9px; border-radius: 999px; color: var(--blue-dark); background: var(--sky); font-size: .74rem; font-weight: 800; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; overflow: hidden; margin: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--line); }
.summary-grid > div { min-width: 0; padding: 13px 14px; background: var(--paper); }
.summary-grid .featured { background: var(--sky); }
.summary-grid dt { margin-bottom: 4px; color: var(--muted); font-size: .74rem; font-weight: 800; letter-spacing: .025em; text-transform: uppercase; }
.summary-grid dd { margin: 0; overflow-wrap: anywhere; color: var(--navy); font-size: clamp(1.03rem, 4vw, 1.25rem); font-weight: 850; font-variant-numeric: tabular-nums; }
.summary-grid dd > span, .summary-grid dd > small { display: block; }
.summary-grid dd > small { min-height: 1.2em; margin-top: 3px; color: var(--muted); font-size: .66rem; font-weight: 700; line-height: 1.2; }

.result-note { margin: 14px 0 0; padding: 11px 13px; border-radius: 10px; color: var(--blue-dark); background: var(--sky); line-height: 1.45; }
.result-note.warning { color: var(--warning); background: var(--warning-bg); }

.result-actions { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(105px, .7fr); gap: 10px; margin-top: 18px; }
.schedule-button { width: 100%; border: 1px solid var(--blue); color: var(--blue-dark); background: #fff; }
.schedule-button:hover { background: var(--sky); }
.save-button { border: 1px solid var(--blue); color: #fff; background: var(--blue); }
.save-message { margin: 14px 0 0; color: #276332; font-size: .88rem; font-weight: 750; text-align: right; }
.disclaimer { margin: 16px 10px 0; color: var(--muted); font-size: .76rem; line-height: 1.45; text-align: center; }

dialog {
  width: min(980px, calc(100% - 20px));
  max-width: none;
  height: min(860px, calc(100dvh - 20px));
  max-height: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 18px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .32);
}

dialog::backdrop { background: rgba(10, 24, 34, .68); backdrop-filter: blur(2px); }
.dialog-shell { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
.dialog-header .eyebrow { margin: 0 0 3px; }
.dialog-header p:last-child { margin: 6px 0 0; color: var(--muted); font-size: .84rem; }
.icon-button { width: 46px; height: 46px; flex: none; border: 1px solid var(--line); border-radius: 50%; color: var(--navy); background: var(--paper); font-size: 1.8rem; line-height: 1; cursor: pointer; }
.dialog-body { overflow: auto; overscroll-behavior: contain; padding: 18px; }

.form-dialog { width: min(760px, calc(100% - 20px)); }
.details-body { display: grid; gap: 18px; background: var(--background); }
.detail-section { padding: 17px; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.detail-section h3, .saved-card h3 { margin: 0; color: var(--navy); font-size: 1rem; }
.section-help { margin: 5px 0 14px; color: var(--muted); font-size: .8rem; line-height: 1.4; }
.detail-grid { display: grid; gap: 14px; }
.detail-section > .detail-grid + .field,
.detail-section > .field + .field { margin-top: 14px; }
.detail-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.detail-title-row .section-help { margin-bottom: 0; }

.info-disclosure { position: relative; flex: none; }
.info-disclosure summary { display: grid; width: 28px; height: 28px; place-items: center; border: 1px solid var(--blue); border-radius: 50%; color: var(--blue-dark); background: var(--sky); font-family: Georgia, serif; font-weight: 800; cursor: pointer; list-style: none; }
.info-disclosure summary::-webkit-details-marker { display: none; }
.info-disclosure p { position: absolute; z-index: 3; top: 34px; right: 0; width: min(330px, calc(100vw - 66px)); margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .16); font-size: .82rem; font-weight: 500; line-height: 1.45; }

.extra-list { display: grid; gap: 12px; }
.extra-card { padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: #f8fafb; }
.extra-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; color: var(--navy); }
.extra-description-field { margin-bottom: 12px; }
.remove-extra { min-height: 38px; padding: 0 5px; border: 0; color: var(--danger); background: transparent; font-weight: 750; cursor: pointer; }
.check-label { display: flex; min-height: 44px; align-items: center; gap: 9px; margin-top: 8px; color: var(--navy); font-size: .88rem; font-weight: 750; }
.check-label input { width: 20px; min-height: 20px; accent-color: var(--blue); }
.recurring-fields { padding-top: 5px; }
.inline-input { display: flex; align-items: center; gap: 9px; }
.inline-input .input-wrap { width: 90px; }
.inline-input > span:last-child { color: var(--muted); font-weight: 550; white-space: nowrap; }
.empty-note { margin: 6px 0 0; color: var(--muted); font-size: .86rem; font-style: italic; }

.saved-list { display: grid; gap: 10px; }
.saved-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.saved-card p { margin: 4px 0 0; color: var(--muted); font-size: .82rem; }
.saved-card > div:last-child { display: flex; align-items: center; gap: 8px; }
.saved-actions { flex-wrap: wrap; }
.saved-actions button:disabled { cursor: not-allowed; opacity: .5; }

.table-wrap { overflow: auto; overscroll-behavior: contain; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; color: #fff; background: var(--navy); font-size: .76rem; letter-spacing: .02em; }
tbody tr:nth-child(even) { background: #f6f9fa; }
tbody tr.balloon-row { color: var(--warning); background: var(--warning-bg); font-weight: 800; }
th:first-child, td:first-child { text-align: center; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 13px 18px max(13px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); }
.print-button, .secondary-button { min-width: 105px; padding: 0 18px; }
.print-button { border: 1px solid var(--blue); color: #fff; background: var(--blue); }
.secondary-button { border: 1px solid #aebdc5; color: var(--navy); background: #fff; }

:focus-visible { outline: 3px solid #f0a43b; outline-offset: 2px; }
[hidden] { display: none !important; }

@media (min-width: 640px) {
  .app-shell { padding-top: 30px; }
  .input-card, .results-card { padding: 26px; }
  .fields { grid-template-columns: 1fr 1fr; column-gap: 20px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .compact-grid { align-items: end; }
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 430px) {
  .app-shell { width: min(100% - 20px, 760px); }
  .input-card, .results-card { padding: 16px; border-radius: 15px; }
  .heading-actions { gap: 4px; }
  .summary-grid { grid-template-columns: 1fr; }
  .result-actions { grid-template-columns: 1fr 110px; }
  dialog { width: 100%; height: 100dvh; border-radius: 0; }
  .dialog-header { padding-top: max(14px, env(safe-area-inset-top)); }
  .dialog-body { padding: 12px; }
  .detail-section { padding: 14px; }
  .saved-card { align-items: flex-start; }
  .saved-card > div:last-child { flex-direction: column; align-items: stretch; }
  th, td { padding: 10px; font-size: .85rem; }
  .dialog-actions > button { flex: 1 1 105px; }
}

@media (prefers-reduced-motion: no-preference) {
  .results-card { animation: reveal .22s ease-out; }
  @keyframes reveal { from { opacity: 0; transform: translateY(8px); } }
}

@media print {
  body * { visibility: hidden; }
  dialog, dialog * { visibility: visible; }
  dialog { position: absolute; inset: 0; width: 100%; height: auto; overflow: visible; border-radius: 0; box-shadow: none; }
  .dialog-shell { display: block; }
  .dialog-header { padding: 0 0 14px; }
  .icon-button, .dialog-actions { display: none; }
  .table-wrap { overflow: visible; }
  th { position: static; color: #000; background: #e7ecef !important; }
  th, td { padding: 6px 8px; border-color: #aaa; font-size: 9pt; }
  tbody tr:nth-child(even), tbody tr.balloon-row { background: transparent !important; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
}
