:root {
  --navy: #082f5b;
  --navy-2: #0b3a6f;
  --blue: #1769e0;
  --blue-soft: #eaf2ff;
  --red: #c9362b;
  --red-soft: #fff0ee;
  --gold: #bd8412;
  --gold-soft: #fff7dd;
  --orange: #ed6b17;
  --orange-soft: #fff1e7;
  --green: #167a54;
  --ink: #172033;
  --muted: #687387;
  --line: #dce2ea;
  --bg: #f3f5f8;
  --surface: #fff;
  --shadow: 0 10px 30px rgba(20, 36, 61, .08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", sans-serif;
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, var(--navy) 0 9px, transparent 9px),
    var(--bg);
}
.login-panel {
  width: min(430px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-top: 5px solid var(--blue);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-panel h1 { margin: 34px 0 18px; font-size: 28px; letter-spacing: 0; }
.legal-note { margin: 20px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-lockup > div { display: grid; line-height: 1.15; }
.brand-lockup strong { color: var(--navy); font-size: 25px; }
.brand-lockup span { color: var(--muted); font-size: 13px; font-weight: 700; }
.brand-lockup.compact strong { font-size: 21px; }
.brand-mark { display: grid; grid-template-columns: repeat(2, 9px); gap: 3px; flex: 0 0 auto; }
.brand-mark i { width: 9px; height: 9px; display: block; }
.brand-mark i:nth-child(1) { background: var(--blue); }
.brand-mark i:nth-child(2) { background: var(--red); }
.brand-mark i:nth-child(3) { background: var(--gold); }
.brand-mark i:nth-child(4) { background: var(--orange); }

.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: #3d4759; font-size: 13px; font-weight: 800; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cfd7e3;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input, select { min-height: 46px; padding: 0 12px; }
textarea { min-height: 92px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 105, 224, .12); }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 850;
}
.button svg, .icon-button svg, .nav-item svg { width: 18px; height: 18px; stroke-width: 2.2; }
.button.primary { background: var(--blue); color: #fff; box-shadow: 0 7px 16px rgba(23, 105, 224, .20); }
.button.primary:hover { background: #0f58c3; }
.button.secondary { border-color: #bdc9d9; background: #fff; color: var(--navy); }
.button.warning { background: var(--orange); color: #fff; }
.button.danger { background: var(--red); color: #fff; }
.button.small { min-height: 34px; padding: 5px 10px; font-size: 12px; }
.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}
.icon-button:hover { background: #edf1f6; color: var(--navy); }
.form-error { min-height: 20px; color: var(--red); font-weight: 750; font-size: 13px; }

.app-shell { min-height: 100svh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 248px;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  border-right: 1px solid #173e69;
  background: var(--navy);
  color: #fff;
}
.sidebar .brand-lockup strong, .sidebar .brand-lockup span { color: #fff; }
.side-nav { display: grid; gap: 6px; margin-top: 36px; }
.nav-item {
  position: relative;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: transparent;
  color: #cfdaea;
  font-weight: 800;
  text-align: left;
}
.nav-item:hover, .nav-item.active { background: #154b82; color: #fff; }
.nav-item.active::before { content: ""; position: absolute; left: -16px; width: 4px; height: 26px; background: var(--orange); }
.nav-item b { margin-left: auto; min-width: 20px; border-radius: 10px; background: var(--red); color: #fff; padding: 1px 6px; font-size: 11px; text-align: center; }
.user-block {
  margin-top: auto;
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  align-items: center;
  gap: 9px;
  border-top: 1px solid rgba(255,255,255,.18);
  padding-top: 18px;
}
.user-block > span {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  font-weight: 900;
}
.user-block div { display: grid; min-width: 0; }
.user-block strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.user-block small { color: #b9c9dd; font-size: 11px; }
.user-block .icon-button { color: #cfdaea; }

.workspace { min-height: 100svh; margin-left: 248px; }
.mobile-header { display: none; }
main { width: min(1320px, 100%); margin: 0 auto; padding: 36px 34px 70px; }
.view { display: none; }
.view.active-view { display: block; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-heading h1 { margin: 2px 0 3px; color: var(--navy); font-size: 32px; line-height: 1.2; letter-spacing: 0; }
.page-heading p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--orange); font-size: 11px; font-weight: 900; letter-spacing: 1.2px; }
.heading-actions { display: flex; gap: 8px; }

.tool-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--blue);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
  box-shadow: var(--shadow);
}
.address-form { grid-template-columns: 1fr 1fr 1fr 2.3fr 1fr 1fr auto; align-items: end; }
.reverse-form { grid-template-columns: 1fr 1fr 1fr auto; align-items: end; }
.case-form { grid-template-columns: 2fr 1fr 1fr auto; align-items: end; margin-bottom: 18px; border-top-color: var(--gold); }
.account-form { grid-template-columns: 1fr 1.4fr 1fr 1fr auto; align-items: end; margin-bottom: 18px; border-top-color: var(--red); }
.analyze-button { min-width: 132px; height: 46px; }
.state-panel {
  min-height: 240px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  margin-top: 22px;
  border: 1px dashed #bec9d7;
  color: var(--muted);
  background: rgba(255,255,255,.55);
}
.state-panel svg { width: 38px; height: 38px; color: #8292a8; }

.decision-band {
  display: grid;
  grid-template-columns: 180px 1fr 250px;
  align-items: center;
  gap: 26px;
  margin-top: 24px;
  border-top: 4px solid var(--gold);
  border-bottom: 1px solid var(--line);
  padding: 24px 0;
}
.score-gauge {
  --score: 0;
  width: 156px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--blue) calc(var(--score) * 1%), #dfe6ef 0);
  position: relative;
}
.score-gauge::before { content: ""; position: absolute; inset: 14px; border-radius: 50%; background: var(--surface); }
.score-gauge div { position: relative; display: grid; text-align: center; line-height: 1; }
.score-gauge strong { color: var(--navy); font-size: 44px; }
.score-gauge span { margin-top: 8px; color: var(--muted); font-size: 12px; font-weight: 800; }
.decision-copy h2 { margin: 0 0 8px; color: var(--navy); font-size: 25px; }
.decision-copy p { margin: 0; color: #485468; }
.decision-chip { display: inline-flex; margin-bottom: 10px; border-radius: 999px; padding: 5px 10px; background: var(--gold-soft); color: #805806; font-size: 12px; font-weight: 900; }
.confidence-block { border-left: 1px solid var(--line); padding-left: 22px; }
.confidence-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 850; }
.progress { height: 10px; overflow: hidden; margin: 9px 0; border-radius: 6px; background: #e1e7ef; }
.progress i { display: block; height: 100%; background: var(--orange); }
.confidence-block small { color: var(--muted); }

.section { padding: 28px 0; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section-heading { display: flex; justify-content: space-between; gap: 16px; align-items: baseline; margin-bottom: 16px; }
.section-heading h2 { margin: 0; color: var(--navy); font-size: 21px; }
.section-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric {
  min-height: 116px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 15px;
}
.metric::before { content: ""; display: block; width: 34px; height: 3px; margin-bottom: 14px; background: var(--blue); }
.metric:nth-child(2)::before { background: var(--red); }
.metric:nth-child(3)::before { background: var(--gold); }
.metric:nth-child(4)::before { background: var(--orange); }
.metric span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; }
.metric strong { display: block; margin-top: 6px; color: var(--navy); font-size: 24px; overflow-wrap: anywhere; }
.metric small { color: var(--muted); font-size: 11px; }

.dimension-grid { display: grid; gap: 13px; }
.dimension-row { display: grid; grid-template-columns: 126px 1fr 46px; align-items: center; gap: 12px; }
.dimension-row > span { color: #3d485b; font-size: 13px; font-weight: 800; }
.dimension-row > strong { color: var(--navy); text-align: right; }
.dimension-track { height: 13px; overflow: hidden; border-radius: 7px; background: #e5eaf1; }
.dimension-track i { height: 100%; display: block; border-radius: 7px; background: var(--blue); }
.dimension-row:nth-child(2) i { background: var(--red); }
.dimension-row:nth-child(3) i { background: var(--gold); }
.dimension-row:nth-child(4) i { background: var(--orange); }
.dimension-row:nth-child(5) i { background: var(--green); }

.map-shell { position: relative; height: 400px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #dfe6ec; }
.map-shell iframe { width: 100%; height: 100%; border: 0; filter: saturate(.72) contrast(.96); }
.map-dot { position: absolute; width: 14px; height: 14px; border: 2px solid #fff; border-radius: 50%; background: var(--blue); box-shadow: 0 2px 7px rgba(0,0,0,.25); transform: translate(-50%,-50%); }
.map-dot.direct { width: 17px; height: 17px; background: var(--red); }
.map-pin { position: absolute; left: 50%; top: 50%; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50% 50% 50% 5px; background: var(--orange); color: #fff; transform: translate(-50%,-70%) rotate(-45deg); box-shadow: 0 4px 12px rgba(0,0,0,.25); }
.map-pin svg { width: 16px; transform: rotate(45deg); }
.map-legend { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 14px; border: 1px solid rgba(0,0,0,.08); border-radius: 6px; background: rgba(255,255,255,.94); padding: 8px 10px; font-size: 11px; font-weight: 850; }
.map-legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 5px; border-radius: 50%; background: var(--blue); }
.map-legend span:first-child::before { background: var(--red); }

.ring-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.ring-item { border-left: 4px solid var(--blue); background: #fff; padding: 12px 14px; }
.ring-item strong { display: block; color: var(--navy); font-size: 20px; }
.ring-item span, .ring-item small { display: block; color: var(--muted); font-size: 11px; }

.scenario-grid, .competitor-grid, .reverse-grid, .case-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.scenario, .competitor-card, .reverse-card, .case-card, .notification {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 17px;
  box-shadow: 0 5px 18px rgba(20, 36, 61, .05);
}
.scenario { border-top: 4px solid var(--blue); }
.scenario:nth-child(2) { border-top-color: var(--gold); }
.scenario:nth-child(3) { border-top-color: var(--orange); }
.scenario span, .competitor-card small, .reverse-card small { color: var(--muted); font-size: 12px; }
.scenario strong { display: block; margin: 8px 0; color: var(--navy); font-size: 26px; }
.scenario p { margin: 2px 0; color: #4e596c; font-size: 13px; }

.competitor-card { position: relative; }
.rank { position: absolute; right: 14px; top: 12px; color: #c8d0dc; font-size: 28px; font-weight: 950; }
.competitor-card h3 { max-width: calc(100% - 45px); margin: 0 0 9px; font-size: 17px; line-height: 1.35; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag { border-radius: 999px; padding: 3px 8px; background: var(--blue-soft); color: var(--navy); font-size: 11px; font-weight: 850; }
.tag.gold { background: var(--gold-soft); color: #795408; }
.tag.red { background: var(--red-soft); color: #9a271e; }
.competitor-card p { margin: 7px 0; color: #4e596c; font-size: 13px; }
.quote { border-left: 3px solid var(--line); padding-left: 9px; color: #59667a; font-size: 12px; }
.text-link { display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; color: var(--blue); font-size: 12px; font-weight: 850; text-decoration: none; }

.evidence-table, .compare-table { width: 100%; border-collapse: collapse; background: #fff; }
.evidence-table th, .evidence-table td, .compare-table th, .compare-table td { border-bottom: 1px solid var(--line); padding: 11px 10px; text-align: left; font-size: 13px; vertical-align: top; }
.evidence-table th, .compare-table th { color: var(--navy); font-weight: 850; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--green); }
.status-dot.partial { background: var(--gold); }
.status-dot.failed { background: var(--red); }
.empty-note { border-left: 4px solid var(--gold); background: var(--gold-soft); padding: 12px 14px; color: #67552b; font-size: 13px; }

.save-strip { position: sticky; bottom: 12px; z-index: 10; display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 24px; border: 1px solid #bfcbd9; border-radius: 8px; background: rgba(255,255,255,.96); padding: 12px; box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.save-strip select { min-height: 42px; }

.reverse-card { border-top: 4px solid var(--blue); }
.reverse-card:nth-child(2) { border-top-color: var(--red); }
.reverse-card:nth-child(3) { border-top-color: var(--gold); }
.reverse-card h3 { margin: 0 0 10px; color: var(--navy); }
.reverse-score { display: flex; align-items: baseline; gap: 5px; margin: 10px 0; }
.reverse-score strong { font-size: 30px; color: var(--navy); }
.reverse-card p { color: #505b6e; font-size: 13px; }
.reverse-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.case-card { display: grid; gap: 10px; border-top: 4px solid var(--gold); }
.case-card header { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.case-card h3 { margin: 0; color: var(--navy); font-size: 17px; }
.case-card p { margin: 0; color: var(--muted); font-size: 12px; }
.status-chip { white-space: nowrap; border-radius: 999px; padding: 3px 8px; background: var(--orange-soft); color: #a3450c; font-size: 10px; font-weight: 900; }
.case-detail { margin-top: 24px; border-top: 4px solid var(--navy); background: #fff; padding: 20px; }
.case-detail-header { display: flex; justify-content: space-between; gap: 14px; align-items: start; }
.case-detail h2 { margin: 0; color: var(--navy); }
.candidate-list { display: grid; gap: 10px; margin: 18px 0; }
.candidate-row { display: grid; grid-template-columns: auto 1fr repeat(3, minmax(80px, auto)) auto; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 12px 0; }
.candidate-row strong { display: block; font-size: 13px; }
.candidate-row span, .candidate-row small { color: var(--muted); font-size: 11px; }
.survey-form, .review-form { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; align-items: end; margin-top: 12px; }
.review-form { grid-template-columns: 160px 1fr auto; }
.notification-list { display: grid; gap: 10px; }
.notification { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; }
.notification.unread { border-left: 4px solid var(--orange); }
.notification p { margin: 0; }
.notification small { color: var(--muted); }

.busy-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; align-content: center; gap: 14px; background: rgba(8, 25, 45, .56); color: #fff; backdrop-filter: blur(3px); }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 120; max-width: 380px; border-left: 4px solid var(--orange); border-radius: 6px; background: #fff; padding: 13px 16px; box-shadow: 0 12px 38px rgba(0,0,0,.2); font-weight: 750; }

@media (max-width: 1100px) {
  .address-form { grid-template-columns: 2fr 1fr 1fr; }
  .address-form .wide { grid-column: span 2; }
  .analyze-button { height: 46px; }
  .decision-band { grid-template-columns: 160px 1fr; }
  .confidence-block { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); padding: 16px 0 0; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 12px 0 30px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .workspace { margin-left: 0; }
  .mobile-header { position: sticky; top: 0; z-index: 25; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); border-top: 4px solid var(--navy); background: rgba(255,255,255,.96); padding: 11px 16px; backdrop-filter: blur(12px); }
  main { padding: 24px 16px 60px; }
  .scenario-grid, .competitor-grid, .reverse-grid, .case-grid { grid-template-columns: 1fr 1fr; }
  .reverse-form, .case-form, .account-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .page-heading { align-items: start; }
  .page-heading h1 { font-size: 26px; }
  .page-heading p { font-size: 13px; }
  .heading-actions .button { font-size: 0; width: 42px; padding: 0; }
  .heading-actions .button svg { width: 18px; }
  .address-form, .reverse-form, .case-form, .account-form { grid-template-columns: 1fr; }
  .address-form .wide { grid-column: auto; }
  .decision-band { grid-template-columns: 1fr; text-align: center; }
  .score-gauge { margin: auto; }
  .confidence-block { text-align: left; }
  .metric-grid, .scenario-grid, .competitor-grid, .reverse-grid, .case-grid, .ring-grid { grid-template-columns: 1fr; }
  .dimension-row { grid-template-columns: 104px 1fr 38px; gap: 8px; }
  .map-shell { height: 330px; }
  .save-strip { grid-template-columns: 1fr; bottom: 8px; }
  .candidate-row { grid-template-columns: auto 1fr auto; }
  .candidate-row > :nth-child(3), .candidate-row > :nth-child(4), .candidate-row > :nth-child(5) { display: none; }
  .survey-form, .review-form { grid-template-columns: 1fr; }
  .notification { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .mobile-header, .tool-panel, .page-heading, .save-strip, .busy-overlay, .toast { display: none !important; }
  .workspace { margin: 0; }
  main { padding: 0; }
  body { background: #fff; }
  .section { break-inside: avoid; }
  #reportResult { display: block !important; }
  .view:not(#addressView) { display: none !important; }
}
