:root {
  --navy: #0b2f4a;
  --navy-2: #123e5f;
  --navy-3: #1b506f;
  --blue: #6fb8df;
  --blue-2: #bfe3f7;
  --blue-soft: #eaf6fc;
  --ink: #183244;
  --muted: #6b7d89;
  --line: #dbe6ec;
  --line-2: #c9d7df;
  --panel: #ffffff;
  --bg: #f4f8fb;
  --success: #356c55;
  --success-bg: #eaf5ef;
  --warning: #745313;
  --warning-bg: #fff4d9;
  --danger: #9d3f3f;
  --danger-bg: #fff0f0;
  --shadow: 0 16px 40px rgba(11, 47, 74, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.is-hidden { display: none !important; }

/* Login */
.login-page {
  background: linear-gradient(125deg, #071f31 0%, #0b2f4a 55%, #164c6d 100%);
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 32px;
}
.login-shell {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  overflow: hidden;
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(0,0,0,.28);
  background: white;
}
.login-brand {
  background: var(--navy);
  padding: 70px 64px;
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-logo { width: min(420px, 100%); height: auto; display: block; margin-bottom: 22px; }
.login-kicker { margin: 0 0 36px; text-transform: uppercase; letter-spacing: .16em; font-size: 12px; color: #a8c6d7; }
.login-brand h1 { font-size: clamp(34px, 4.2vw, 56px); line-height: 1.02; margin: 0 0 18px; letter-spacing: -.03em; }
.login-subcopy { margin: 0; max-width: 520px; color: #c8dbe6; line-height: 1.6; font-size: 16px; }
.login-card { padding: 70px 56px; display: flex; flex-direction: column; justify-content: center; }
.login-card h2 { margin: 8px 0 8px; font-size: 32px; color: var(--navy); }
.login-card .muted { margin-top: 0; margin-bottom: 28px; }
.login-card form { display: grid; gap: 18px; }
.login-card label, .filter-panel label, .record-form label, .field-full { display: grid; gap: 8px; font-size: 13px; font-weight: 700; color: var(--ink); }
.login-card input, .record-form input, .record-form select, .record-form textarea, .filter-panel select, .field-full select {
  width: 100%; border: 1px solid var(--line-2); background: white; color: var(--ink); border-radius: 10px; padding: 12px 13px; outline: none; transition: border-color .2s, box-shadow .2s;
}
.login-card input:focus, .record-form input:focus, .record-form select:focus, .record-form textarea:focus, .filter-panel select:focus, .field-full select:focus {
  border-color: var(--blue); box-shadow: 0 0 0 3px rgba(111,184,223,.18);
}
.login-footnote { font-size: 12px; color: var(--muted); margin-top: 22px; line-height: 1.5; }
.form-error { min-height: 20px; color: var(--danger); font-size: 13px; margin: 0; }

/* App shell */
.app-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; background: var(--navy); color: white; padding: 28px 18px 18px; display: flex; flex-direction: column; z-index: 5;
}
.brand-wrap { padding: 2px 8px 28px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-logo { width: 190px; max-width: 100%; height: auto; display: block; }
.brand-market { margin-top: 12px; color: #9fb9c8; font-size: 10px; text-transform: uppercase; letter-spacing: .14em; }
.side-nav { display: grid; gap: 6px; margin-top: 28px; }
.nav-item {
  border: 0; background: transparent; color: #d5e4ec; text-align: left; border-radius: 10px; padding: 12px 13px; display: flex; align-items: center; gap: 11px; font-weight: 650; font-size: 13px;
}
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.is-active { background: #173f5a; color: white; }
.nav-dot { width: 7px; height: 7px; border-radius: 50%; background: #6e8b9d; flex: 0 0 auto; }
.nav-item.is-active .nav-dot { background: var(--blue); }
.sidebar-user { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding: 18px 6px 2px; display: flex; gap: 11px; align-items: center; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--blue); color: var(--navy); display: grid; place-items: center; font-size: 12px; font-weight: 800; }
.user-copy { min-width: 0; display: grid; gap: 3px; }
.user-copy strong { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-copy span { font-size: 10px; color: #9fb9c8; }

.main-content { min-width: 0; padding: 32px 34px 28px; max-width: 1680px; width: 100%; margin: 0 auto; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.topbar h1 { margin: 7px 0 6px; color: var(--navy); font-size: clamp(28px, 3vw, 42px); line-height: 1.08; letter-spacing: -.025em; }
.subtitle { color: var(--muted); margin: 0; font-size: 13px; line-height: 1.5; max-width: 780px; }
.top-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; align-items: center; }
.button { border: 1px solid transparent; border-radius: 9px; padding: 10px 14px; font-weight: 750; font-size: 12px; transition: transform .12s, background .2s, border-color .2s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.button-primary { background: var(--navy); color: white; border-color: var(--navy); }
.button-primary:hover { background: var(--navy-2); }
.button-secondary { background: white; color: var(--navy); border-color: var(--line); }
.button-secondary:hover { border-color: var(--blue); }
.button-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.button-danger { background: var(--danger-bg); color: var(--danger); border-color: #f1caca; }
.button-small { padding: 7px 9px; font-size: 11px; }
.button-block { width: 100%; padding: 13px 16px; }
.role-pill { border-radius: 999px; background: var(--blue-soft); color: var(--navy-2); padding: 8px 11px; font-size: 11px; font-weight: 800; }

.filter-panel { background: white; border: 1px solid var(--line); border-radius: var(--radius); display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; padding: 14px; margin-bottom: 18px; }
.filter-panel label > span, .filter-meta > span { text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-size: 9px; font-weight: 850; }
.filter-panel select { padding: 10px 11px; }
.filter-meta { display: grid; gap: 9px; align-content: center; padding: 0 10px; }
.filter-meta strong { font-size: 12px; color: var(--navy); }

.dashboard-view { display: grid; gap: 18px; }
.section-grid { display: grid; gap: 14px; }
.section-grid.kpis { grid-template-columns: repeat(4, minmax(0,1fr)); }
.section-grid.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
.section-grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.section-grid.five { grid-template-columns: repeat(5, minmax(0,1fr)); }
.card { background: white; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card.shadow { box-shadow: var(--shadow); }
.kpi-label, .section-label { text-transform: uppercase; letter-spacing: .105em; color: var(--muted); font-size: 9px; font-weight: 850; }
.kpi-value { color: var(--navy); font-size: 30px; line-height: 1; letter-spacing: -.025em; font-weight: 820; margin: 14px 0 8px; }
.kpi-foot { color: var(--muted); font-size: 11px; line-height: 1.35; }
.card-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.card-header h2, .card-header h3 { margin: 4px 0 0; color: var(--navy); }
.card-header h2 { font-size: 18px; }
.card-header h3 { font-size: 15px; }
.card-subtitle { margin: 4px 0 0; color: var(--muted); font-size: 11px; }

.funnel { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.funnel-step { position: relative; background: #f8fbfd; border: 1px solid var(--line); border-radius: 12px; padding: 13px; }
.funnel-step:not(:last-child)::after { content: "→"; position: absolute; right: -12px; top: 50%; transform: translate(50%,-50%); color: #9eb2bd; font-weight: 800; }
.funnel-step span { color: var(--muted); font-size: 10px; }
.funnel-step strong { display: block; color: var(--navy); font-size: 24px; margin-top: 7px; }
.market-bar-row { display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; align-items: center; margin-top: 13px; }
.market-bar-row span, .market-bar-row strong { font-size: 11px; }
.market-bar { grid-column: 1 / -1; height: 9px; background: #e9f0f4; border-radius: 999px; overflow: hidden; }
.market-bar > i { display: block; height: 100%; background: var(--blue); border-radius: inherit; }
.metric-list { display: grid; }
.metric-row { display: flex; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid #edf2f5; }
.metric-row:first-child { padding-top: 2px; }
.metric-row:last-child { border-bottom: 0; padding-bottom: 0; }
.metric-row span { color: var(--ink); font-size: 11px; line-height: 1.4; }
.metric-row strong { color: var(--navy); font-size: 12px; white-space: nowrap; }

.trend-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.trend-card { background: white; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; overflow: hidden; }
.trend-card svg { width: 100%; height: 92px; display: block; margin-top: 12px; }
.trend-meta { display: flex; justify-content: space-between; gap: 12px; align-items: flex-end; }
.trend-value { color: var(--navy); font-size: 22px; font-weight: 820; }
.trend-caption { color: var(--muted); font-size: 10px; }
.spark-grid { stroke: #e9f0f4; stroke-width: 1; }
.spark-line { fill: none; stroke: var(--navy-2); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.spark-area { fill: rgba(111,184,223,.15); }
.spark-dot { fill: var(--blue); stroke: white; stroke-width: 2; }

.mom-card { display: grid; gap: 8px; }
.mom-values { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.mom-current { font-size: 24px; font-weight: 820; color: var(--navy); }
.mom-previous { color: var(--muted); font-size: 11px; }
.delta { font-size: 10px; font-weight: 800; border-radius: 999px; padding: 5px 8px; justify-self: start; }
.delta.up { background: var(--success-bg); color: var(--success); }
.delta.down { background: var(--danger-bg); color: var(--danger); }
.delta.flat { background: #eef3f6; color: var(--muted); }

.table-card { padding: 0; overflow: hidden; }
.table-card .card-header { padding: 18px 18px 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 840px; }
th { background: #f7fafc; color: var(--muted); text-align: left; font-size: 9px; text-transform: uppercase; letter-spacing: .09em; font-weight: 850; padding: 11px 14px; white-space: nowrap; }
td { border-top: 1px solid #edf2f5; padding: 13px 14px; font-size: 11px; color: var(--ink); vertical-align: top; }
td strong { color: var(--navy); }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty-row td { color: var(--muted); text-align: center; padding: 36px 18px; }
.status-tag { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 7px; font-size: 9px; font-weight: 800; background: var(--blue-soft); color: var(--navy-2); }

.notes-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.note-box { border: 1px solid var(--line-2); background: #fbfdfe; border-radius: 11px; padding: 13px; min-height: 132px; }
.note-box h4 { margin: 0 0 8px; color: var(--navy); font-size: 12px; }
.note-box p { margin: 0; white-space: pre-wrap; color: var(--muted); font-size: 11px; line-height: 1.5; }
.note-box textarea { width: 100%; min-height: 82px; resize: vertical; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 11px; line-height: 1.5; padding: 0; }
.note-save-status { color: var(--muted); font-size: 10px; }

.breakdown-list { display: grid; gap: 12px; }
.breakdown-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px 12px; align-items: center; }
.breakdown-row span, .breakdown-row strong { font-size: 11px; }
.breakdown-track { grid-column: 1 / -1; height: 8px; background: #edf2f5; border-radius: 999px; overflow: hidden; }
.breakdown-track i { display: block; height: 100%; background: var(--blue); border-radius: inherit; }

.callout { background: var(--blue-soft); border: 1px solid var(--blue-2); color: var(--navy-2); border-radius: 12px; padding: 13px 14px; font-size: 11px; line-height: 1.5; }
.empty-state { border: 1px dashed var(--line-2); border-radius: 14px; padding: 38px 24px; text-align: center; color: var(--muted); background: rgba(255,255,255,.55); }
.empty-state strong { display: block; color: var(--navy); margin-bottom: 6px; }
.site-footer { color: #8a9aa3; font-size: 10px; text-align: center; margin: 10px 0 2px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(7,31,49,.58); display: grid; place-items: center; padding: 24px; }
.modal { background: white; width: min(820px, 100%); max-height: min(860px, calc(100vh - 40px)); border-radius: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.28); overflow: hidden; display: grid; grid-template-rows: auto 1fr; }
.modal-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; padding: 22px 24px 16px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 5px 0 0; color: var(--navy); font-size: 22px; }
.icon-button { border: 0; background: #f1f5f7; width: 36px; height: 36px; border-radius: 50%; color: var(--muted); font-size: 22px; line-height: 1; }
.modal-body { overflow-y: auto; padding: 20px 24px 24px; }
.field-full { margin-bottom: 18px; }
.record-form { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.record-form label.full { grid-column: 1 / -1; }
.record-form label > span { font-size: 11px; }
.record-form textarea { min-height: 110px; resize: vertical; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 9px; padding-top: 8px; }
.form-help { grid-column: 1 / -1; margin: -4px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; background: var(--navy); color: white; border-radius: 10px; padding: 11px 14px; font-size: 12px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .2s, transform .2s; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.error { background: #7d3030; }
.loading-screen { position: fixed; inset: 0; background: var(--navy); display: grid; place-items: center; z-index: 200; }
.loading-card { text-align: center; color: #c9dbe4; }
.loading-card img { width: min(330px, 70vw); }
.loading-card p { font-size: 12px; }
.spinner { width: 26px; height: 26px; border: 3px solid rgba(255,255,255,.18); border-top-color: var(--blue); border-radius: 50%; margin: 26px auto 14px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .section-grid.kpis, .section-grid.five { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .trend-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
  .top-actions { justify-content: flex-start; }
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding-bottom: 12px; }
  .brand-wrap { border-bottom: 0; padding-bottom: 12px; }
  .brand-logo { width: 210px; }
  .side-nav { grid-auto-flow: column; grid-auto-columns: max-content; overflow-x: auto; margin-top: 8px; padding-bottom: 4px; }
  .sidebar-user { display: none; }
  .main-content { padding: 22px 18px; }
  .filter-panel { grid-template-columns: 1fr; }
  .filter-meta { padding: 4px 0 0; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { padding: 44px 34px; }
  .login-card { padding: 40px 34px; }
}
@media (max-width: 680px) {
  .section-grid.kpis, .section-grid.three, .section-grid.two, .section-grid.five, .notes-grid { grid-template-columns: 1fr; }
  .funnel { grid-template-columns: 1fr; }
  .funnel-step:not(:last-child)::after { content: "↓"; right: 50%; top: auto; bottom: -18px; transform: translate(50%, 50%); }
  .record-form { grid-template-columns: 1fr; }
  .record-form label.full, .form-actions, .form-help { grid-column: 1; }
  .modal-backdrop { padding: 8px; }
  .modal { max-height: calc(100vh - 16px); border-radius: 15px; }
  .top-actions { width: 100%; }
  .top-actions .button { flex: 1 1 auto; }
}
