:root {
  --bg: #f3f7f8;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --ink: #173039;
  --muted: #677b82;
  --line: #dbe5e7;
  --primary: #0f766e;
  --primary-dark: #0a5d57;
  --primary-soft: #e7f5f2;
  --accent: #d99b38;
  --accent-soft: #fff5df;
  --danger: #b84242;
  --danger-soft: #fff0ef;
  --shadow: 0 18px 50px rgba(29, 61, 69, .08);
  --radius: 18px;
  --radius-sm: 11px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; }
a { color: inherit; }

.app-header {
  min-height: 76px;
  padding: 12px clamp(18px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: white;
  background: linear-gradient(145deg, #11877d, #0a5b56);
  font-weight: 800;
  letter-spacing: -.04em;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; }
.brand small { color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.header-actions form { margin: 0; }
.user-name { color: var(--muted); font-size: 14px; }
.app-main { width: min(1200px, calc(100% - 36px)); margin: 0 auto; padding: 46px 0 64px; }
.app-footer { padding: 20px; text-align: center; color: var(--muted); font-size: 12px; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(28px, 4vw, 42px); line-height: 1.22; letter-spacing: -.03em; }
h2 { font-size: 21px; line-height: 1.35; }
h3 { font-size: 17px; }
.muted { color: var(--muted); }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.page-heading { margin-bottom: 28px; }
.page-heading p { max-width: 760px; }
.heading-with-action { display: flex; justify-content: space-between; align-items: end; gap: 24px; }
.back-link { display: inline-block; margin-bottom: 18px; color: var(--muted); text-decoration: none; font-size: 14px; }
.back-link:hover { color: var(--primary); }

.button {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: .18s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.button-primary { color: white; background: var(--primary); box-shadow: 0 8px 20px rgba(15, 118, 110, .18); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: var(--primary); background: var(--primary-soft); border-color: #c6e5df; }
.button-ghost { color: var(--muted); background: transparent; border-color: var(--line); }
.button-small { padding: 7px 12px; font-size: 13px; }
.button-wide { width: 100%; }

.messages { position: fixed; top: 88px; right: 24px; z-index: 40; width: min(380px, calc(100% - 48px)); }
.message { padding: 13px 16px; border: 1px solid #bde1da; border-radius: 12px; background: #ecfaf7; box-shadow: var(--shadow); }
.panel { padding: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-heading { margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-heading h2 { margin: 0; }

.metric-grid { display: grid; gap: 14px; }
.metric-grid-3 { grid-template-columns: repeat(3, 1fr); margin-bottom: 24px; }
.metric-grid-4 { grid-template-columns: repeat(4, 1fr); }
.metric-card { min-height: 138px; padding: 21px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(29, 61, 69, .045); }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card strong { display: inline-block; margin: 10px 5px 0 0; color: var(--primary); font-size: 32px; line-height: 1; }
.metric-card.compact { min-height: 116px; }
.metric-card.compact strong { display: block; font-size: clamp(21px, 3vw, 27px); }
.metric-card.accent { background: var(--primary-soft); border-color: #b9ded8; }
.metric-card.danger { background: var(--danger-soft); border-color: #f0c9c7; }
.metric-card.danger strong { color: var(--danger); }

.case-list { display: grid; }
.case-row { padding: 17px 5px; display: grid; grid-template-columns: 44px 1fr auto auto; align-items: center; gap: 14px; border-top: 1px solid var(--line); }
.case-row:first-child { border-top: 0; }
.avatar { width: 42px; height: 42px; display: inline-grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 800; }
.case-main h3 { margin: 0; }
.case-main p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.case-meta { min-width: 150px; text-align: right; }
.case-meta small { display: block; margin-top: 5px; color: var(--muted); }
.status { display: inline-block; padding: 4px 9px; border-radius: 999px; background: #eef2f3; font-size: 12px; font-weight: 700; }
.status-ready { color: var(--primary); background: var(--primary-soft); }
.status-completed { color: #80570f; background: var(--accent-soft); }
.empty-state { padding: 46px 20px; text-align: center; }
.empty-state p { color: var(--muted); }
.empty-icon { width: 58px; height: 58px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 28px; }

.auth-main { min-height: calc(100vh - 160px); display: grid; place-items: center; }
.auth-card { width: min(440px, 100%); padding: 36px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.stack-form { margin-top: 24px; display: grid; gap: 17px; }
.form-alert { margin: 15px 0; padding: 12px 14px; color: var(--danger); background: var(--danger-soft); border: 1px solid #f0c9c7; border-radius: 10px; }

label { display: block; color: var(--ink); font-size: 14px; font-weight: 700; }
label > span { display: block; margin-bottom: 6px; }
label small { display: block; margin-top: 5px; color: var(--muted); font-weight: 400; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cddadd;
  border-radius: 9px;
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .11); }
.required, .field-error { color: var(--danger); }
.form-grid { display: grid; gap: 18px; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.form-panel { max-width: 850px; }
.form-actions { margin-top: 28px; padding-top: 20px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); }
.block-label { margin-top: 22px; }

.wizard-main { width: min(1500px, calc(100% - 30px)); padding-top: 26px; }
.wizard-shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); align-items: start; gap: 24px; }
.wizard-sidebar { position: sticky; top: 102px; max-height: calc(100vh - 120px); overflow: auto; padding: 6px 7px 24px; }
.client-chip { margin-bottom: 22px; display: flex; align-items: center; gap: 11px; }
.client-chip strong, .client-chip small { display: block; }
.client-chip small { color: var(--muted); font-size: 12px; }
.phase-label { margin: 18px 8px 7px; color: #91a2a7; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.step-link { margin: 3px 0; padding: 8px; display: flex; align-items: center; gap: 9px; border-radius: 10px; color: var(--muted); text-decoration: none; font-size: 13px; }
.step-link > span { width: 26px; height: 26px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: #fff; font-size: 11px; }
.step-link:hover { color: var(--ink); background: #eaf0f1; }
.step-link.active { color: var(--primary-dark); background: var(--primary-soft); font-weight: 800; }
.step-link.active > span { color: #fff; background: var(--primary); border-color: var(--primary); }
.wizard-card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.wizard-card > :not(.wizard-actions) { margin-left: clamp(22px, 4vw, 52px); margin-right: clamp(22px, 4vw, 52px); }
.wizard-heading { margin-top: 36px; margin-bottom: 20px; display: flex; align-items: center; gap: 18px; }
.wizard-heading h1 { margin: 3px 0 0; font-size: clamp(25px, 3.5vw, 37px); }
.step-count { min-width: 58px; height: 58px; display: grid; place-items: center; border-radius: 16px; color: var(--primary); background: var(--primary-soft); font-size: 22px; font-weight: 800; }
.section-intro { margin-bottom: 28px; max-width: 850px; color: var(--muted); }
.mobile-progress { display: none; }
.subsection-heading { margin: 32px 0 13px; padding-top: 24px; display: flex; justify-content: space-between; align-items: end; gap: 20px; border-top: 1px solid var(--line); }
.subsection-heading h2, .subsection-heading p { margin-bottom: 0; }
.subsection-heading p { color: var(--muted); font-size: 13px; }
.subsection-title { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
.subsection-gap { margin-top: 24px; }
.repeat-list { display: grid; gap: 10px; }
.repeat-row { padding: 13px; display: grid; align-items: end; gap: 10px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 12px; }
.repeat-row label > span { color: var(--muted); font-size: 11px; }
.repeat-grid-5 { grid-template-columns: 1.5fr 1.2fr .7fr 1fr 36px; }
.repeat-grid-6 { grid-template-columns: 1.3fr 1fr .9fr .85fr .8fr 36px; }
.remove-row { width: 34px; height: 42px; border: 0; border-radius: 8px; color: #a16060; background: transparent; font-size: 22px; cursor: pointer; }
.remove-row:hover { background: var(--danger-soft); }
.priority-list { max-width: 760px; margin: 0 0 26px; padding: 0; display: grid; gap: 9px; counter-reset: priority; }
.priority-item { min-height: 58px; padding: 10px 12px; display: grid; grid-template-columns: 24px 34px 1fr auto; align-items: center; gap: 12px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 11px; list-style: none; }
.drag-handle { color: #a6b4b7; cursor: grab; }
.priority-number { width: 28px; height: 28px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border-radius: 50%; font-size: 12px; font-weight: 800; }
.priority-buttons { display: flex; gap: 4px; }
.priority-buttons button { width: 31px; height: 31px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: white; cursor: pointer; }
.highlight-field { padding: 19px; display: grid; grid-template-columns: minmax(280px, 450px) 1fr; align-items: end; gap: 20px; background: var(--primary-soft); border: 1px solid #c4e4df; border-radius: 13px; }
.highlight-field small { color: var(--muted); }
.input-suffix, .big-money-input { display: flex; align-items: stretch; border: 1px solid #cddadd; border-radius: 9px; overflow: hidden; background: #fff; }
.input-suffix input, .big-money-input input { border: 0; border-radius: 0; box-shadow: none; }
.input-suffix em, .big-money-input em { padding: 0 12px; display: grid; place-items: center; color: var(--muted); background: #f3f7f8; font-style: normal; white-space: nowrap; }
.budget-box { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.budget-box > label { padding: 20px; background: var(--primary-soft); border: 1px solid #c4e4df; border-radius: 14px; }
.big-money-input > span { padding-left: 12px; display: grid; place-items: center; color: var(--primary); font-size: 20px; font-weight: 800; }
.big-money-input input { min-width: 60px; color: var(--primary-dark); font-size: 24px; font-weight: 800; }
.notice { margin-top: 24px; padding: 15px 17px; display: grid; gap: 2px; color: #70551f; background: var(--accent-soft); border: 1px solid #eddbaf; border-radius: 11px; }
.notice span { font-size: 13px; }
.choice-cards { display: grid; gap: 12px; }
.choice-cards-3 { grid-template-columns: repeat(3, 1fr); }
.choice-card { position: relative; }
.choice-card input { width: 1px; height: 1px; position: absolute; opacity: 0; }
.choice-card > span { height: 100%; margin: 0; padding: 18px; display: block; border: 1px solid var(--line); border-radius: 13px; cursor: pointer; }
.choice-card strong, .choice-card small { display: block; }
.choice-card small { margin-top: 4px; color: var(--muted); font-weight: 400; }
.choice-card input:checked + span { background: var(--primary-soft); border-color: var(--primary); box-shadow: 0 0 0 2px rgba(15, 118, 110, .08); }
.wizard-actions { margin-top: 38px; padding: 20px clamp(22px, 4vw, 52px); display: flex; align-items: center; justify-content: space-between; gap: 14px; background: var(--surface-soft); border-top: 1px solid var(--line); }
.wizard-actions > div { display: flex; gap: 9px; }

.alert-list { margin-bottom: 24px; display: grid; gap: 8px; }
.summary-alert { padding: 12px 14px; display: flex; align-items: center; gap: 10px; color: #7b5221; background: var(--accent-soft); border: 1px solid #ecd8aa; border-radius: 10px; }
.summary-alert > span { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--accent); font-weight: 800; }
.summary-section { margin-top: 30px !important; padding-top: 28px; border-top: 1px solid var(--line); }
.summary-section:first-of-type { margin-top: 0 !important; padding-top: 0; border-top: 0; }
.summary-section-heading { margin-bottom: 17px; display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.summary-section-heading h2 { margin: 3px 0 0; }
.assumption-chip { padding: 5px 10px; border-radius: 999px; color: var(--primary); background: var(--primary-soft); font-size: 12px; font-weight: 700; }
.gap-visual { padding: 18px; display: grid; grid-template-columns: 1fr auto 1fr 1.2fr; align-items: center; gap: 14px; background: #f8fbfb; border: 1px solid var(--line); border-radius: 14px; }
.gap-visual span, .gap-visual strong { display: block; }
.gap-visual span { color: var(--muted); font-size: 12px; }
.gap-visual strong { margin-top: 4px; font-size: 21px; }
.gap-arrow { color: #9aabad; font-size: 22px; }
.gap-result { padding: 13px; color: var(--primary-dark); background: var(--primary-soft); border-radius: 10px; }
.retirement-timeline { margin-bottom: 16px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.retirement-timeline article { position: relative; padding: 18px; background: #f6f9f9; border-top: 3px solid #bcd7d3; }
.retirement-timeline article:nth-child(2) { border-color: var(--primary); background: var(--primary-soft); }
.retirement-timeline span, .retirement-timeline strong, .retirement-timeline small { display: block; }
.retirement-timeline span, .retirement-timeline small { color: var(--muted); }
.retirement-timeline strong { margin: 4px 0; font-size: 21px; }
.scenario-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; align-items: stretch; }
.scenario-card { position: relative; padding: 21px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.scenario-card.recommended { border: 2px solid var(--primary); box-shadow: 0 12px 28px rgba(15, 118, 110, .1); }
.recommended-label { margin: -21px -21px 17px; padding: 5px 10px; color: white; background: var(--primary); border-radius: 11px 11px 0 0; text-align: center; font-size: 11px; font-weight: 800; }
.scenario-card h3 { margin-bottom: 7px; }
.scenario-price strong { color: var(--primary); font-size: 28px; }
.scenario-price span { color: var(--muted); font-size: 12px; }
.scenario-card p { margin: 8px 0 12px; color: var(--muted); font-size: 13px; }
.scenario-card ul { margin: 0; padding-left: 18px; font-size: 13px; }
.calculation-note { margin-top: 28px !important; padding: 16px; color: var(--muted); background: #f5f7f7; border-radius: 10px; font-size: 12px; }
.calculation-note strong { color: var(--ink); }
.calculation-note p { margin: 3px 0 0; }
.summary-hero { margin-bottom: 22px; padding: 28px; display: flex; align-items: end; justify-content: space-between; gap: 24px; color: #fff; background: linear-gradient(135deg, #0e7169, #164b55); border-radius: 22px; }
.summary-hero .back-link, .summary-hero .eyebrow, .summary-hero p { color: #cce5e2; }
.summary-hero h1 { margin: 4px 0; }
.summary-hero p { margin: 0; }
.summary-hero-actions { display: flex; gap: 9px; }
.summary-hero .button-secondary { color: #fff; background: rgba(255,255,255,.13); border-color: rgba(255,255,255,.24); }
.summary-hero .button-primary { color: #164b55; background: #fff; }
.summary-panel { padding: clamp(22px, 4vw, 44px); }

@media (max-width: 1150px) {
  .repeat-grid-5, .repeat-grid-6 { grid-template-columns: repeat(2, minmax(0, 1fr)) 36px; }
  .repeat-row .remove-row { grid-column: 3; grid-row: 1; }
  .metric-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 850px) {
  .app-header { position: static; }
  .app-main { padding-top: 28px; }
  .wizard-main { width: min(100% - 22px, 900px); }
  .wizard-shell { display: block; }
  .wizard-sidebar { display: none; }
  .mobile-progress { margin-bottom: 14px; padding: 13px 16px; display: block; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
  .mobile-progress > div:first-child { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
  .mobile-progress span { color: var(--primary); }
  .progress-track { height: 5px; margin-top: 9px; border-radius: 5px; background: #e6eded; overflow: hidden; }
  .progress-track span { height: 100%; display: block; background: var(--primary); }
  .choice-cards-3, .scenario-grid { grid-template-columns: 1fr; }
  .gap-visual { grid-template-columns: 1fr 1fr; }
  .gap-arrow { display: none; }
  .gap-result { grid-column: span 2; }
  .summary-hero { align-items: start; flex-direction: column; }
}

@media (max-width: 650px) {
  body { font-size: 15px; }
  .app-header { padding: 10px 14px; }
  .brand small, .user-name { display: none; }
  .app-main { width: min(100% - 22px, 600px); }
  .heading-with-action { align-items: stretch; flex-direction: column; }
  .metric-grid-3, .metric-grid-4 { grid-template-columns: 1fr; }
  .metric-card { min-height: auto; }
  .case-row { grid-template-columns: 40px 1fr auto; }
  .case-meta { grid-column: 2; min-width: 0; text-align: left; }
  .case-actions { grid-row: 1 / span 2; grid-column: 3; }
  .form-grid-2, .budget-box { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .form-actions, .wizard-actions { align-items: stretch; flex-direction: column-reverse; }
  .form-actions .button, .wizard-actions > .button, .wizard-actions > div, .wizard-actions > div .button { width: 100%; }
  .wizard-actions > div { flex-direction: column-reverse; }
  .wizard-heading { align-items: flex-start; }
  .step-count { min-width: 46px; height: 46px; border-radius: 12px; font-size: 18px; }
  .repeat-grid-5, .repeat-grid-6 { grid-template-columns: 1fr 36px; }
  .repeat-row label { grid-column: 1 / -1; }
  .repeat-row .remove-row { grid-column: 2; grid-row: 1; }
  .highlight-field { grid-template-columns: 1fr; }
  .priority-item { grid-template-columns: 25px 30px 1fr; }
  .priority-buttons { grid-column: 3; }
  .retirement-timeline { grid-template-columns: 1fr; }
  .summary-hero-actions { width: 100%; flex-direction: column; }
  .summary-hero-actions .button { width: 100%; }
}

@media print {
  body { background: #fff; }
  .app-header, .app-footer, .summary-hero-actions, .back-link { display: none !important; }
  .app-main { width: 100%; padding: 0; }
  .panel, .summary-hero { box-shadow: none; }
}
