:root {
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-alt: #eef3f7;
  --ink: #17212b;
  --muted: #5f6e7d;
  --line: #d8e0e8;
  --teal: #007c78;
  --teal-dark: #005f5c;
  --blue: #2b62b8;
  --amber: #b86f00;
  --red: #c2413d;
  --green: #277a45;
  --shadow: 0 16px 42px rgba(30, 45, 62, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", Arial, sans-serif;
}

body {
  font-size: 15px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.lock-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(0, 124, 120, 0.08), transparent 38%),
    linear-gradient(315deg, rgba(184, 111, 0, 0.08), transparent 42%),
    var(--bg);
}

.lock-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.lock-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.lock-panel h1,
.topbar h1,
.modal-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.lock-panel p {
  color: var(--muted);
  margin: 8px 0 24px;
}

.login-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.password-row input,
.select-label select,
.select-label input,
.admin-content input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

.password-row button,
.primary-button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
}

.password-row button:hover,
.primary-button:hover {
  background: var(--teal-dark);
}

.form-message {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--red);
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 22px;
}

.top-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.select-label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.select-label select,
.select-label input {
  min-width: 92px;
}

#singleDateLabel input,
#startDateLabel input,
#endDateLabel input {
  min-width: 150px;
}

.secondary-button,
.icon-button,
.tabs button,
.subtabs button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  min-height: 40px;
  padding: 0 12px;
  font-weight: 700;
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.secondary-button:hover,
.icon-button:hover,
.tabs button:hover,
.subtabs button:hover {
  border-color: #aebdca;
  background: #f9fbfc;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 24px 10px;
}

.tabs button {
  white-space: nowrap;
}

.tabs button.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.subtabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 24px 12px;
}

.subtabs:empty {
  display: none;
}

.subtabs button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.subtabs button.active {
  border-color: var(--teal);
  background: #e7f5f3;
  color: var(--teal-dark);
}

.mini-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 14px 14px 0;
}

.mini-tabs button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 800;
}

.mini-tabs button.active {
  border-color: var(--teal);
  background: #e7f5f3;
  color: var(--teal-dark);
}

.status-strip {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin: 0 24px 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.content {
  padding: 0 24px 32px;
}

.section {
  display: grid;
  gap: 16px;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

.section-title h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.section-title p {
  margin: 4px 0 0;
  color: var(--muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
}

.kpi-grid.single {
  grid-template-columns: 1fr;
}

.kpi-grid.pair {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.kpi {
  min-height: 116px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.kpi.wide {
  min-height: 104px;
}

.kpi.compact {
  min-height: 94px;
  padding: 14px;
}

.kpi.compact .value {
  font-size: clamp(18px, 1.5vw, 22px);
}

.media-spend-layout {
  display: grid;
  gap: 12px;
}

.media-spend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.media-spend-grid.primary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.media-spend-section {
  display: grid;
  gap: 8px;
}

.media-spend-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.media-spend-grid.crm {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.kpi .label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi .value {
  margin-top: 12px;
  font-size: clamp(20px, 2vw, 28px);
  font-weight: 800;
  word-break: keep-all;
}

.kpi .sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.kpi.good .value {
  color: var(--green);
}

.kpi.warn .value {
  color: var(--amber);
}

.kpi.bad .value {
  color: var(--red);
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 16px;
}

.panel-grid.equal {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
}

.funnel-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.funnel-select {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.funnel-select select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
}

.funnel-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.funnel-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.product-controls {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.product-select {
  display: grid;
  gap: 6px;
  min-width: min(360px, 100%);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.product-select select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
}

.funnel-flow {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.funnel-step {
  display: grid;
  gap: 8px;
}

.funnel-step-head,
.funnel-step-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.funnel-step-head strong {
  font-size: 14px;
}

.funnel-step-head span,
.funnel-step-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.funnel-bar-track {
  height: 18px;
  border-radius: 999px;
  background: #e6edf2;
  overflow: hidden;
}

.funnel-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), #2b62b8);
}

.funnel-tree-wrap {
  min-height: 260px;
}

.funnel-tree-svg {
  display: block;
  height: auto;
  min-height: 260px;
}

.funnel-tree-node rect {
  fill: #f0f2f4;
  stroke: #e3e7eb;
}

.funnel-tree-node text {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.funnel-tree-node text.meta {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.journey-path {
  display: inline-block;
  max-width: 760px;
  white-space: normal;
  word-break: keep-all;
  line-height: 1.55;
}

.journey-path.ltv-path {
  max-width: 920px;
}

.retention-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}

.retention-table {
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 8px;
}

.retention-table th,
.retention-table td {
  border: 0;
  background: transparent;
  padding: 0;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.retention-table thead th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  padding: 0 8px 6px;
}

.retention-table tbody th {
  min-width: 180px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-align: left;
}

.retention-cell {
  min-width: 116px;
  border: 1px solid rgba(109, 89, 229, 0.12);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.retention-cell.strong {
  color: #fff;
  text-shadow: 0 1px 1px rgba(18, 23, 34, 0.25);
}

.retention-cell strong,
.retention-cell span {
  display: block;
  line-height: 1.25;
}

.retention-cell strong {
  font-size: 14px;
  font-weight: 950;
}

.retention-cell span {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 850;
}

.retention-max {
  min-width: 92px;
  border-radius: 8px;
  background: #f4f6f8 !important;
  color: var(--ink);
  font-weight: 950;
  padding: 13px 14px !important;
}

.chart-box {
  min-height: 280px;
  padding: 14px;
}

.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
}

.chart-svg {
  display: block;
  width: 100%;
  height: 280px;
}

.vertical-chart {
  height: 330px;
}

.year-compare-chart {
  height: 360px;
}

.chart-legend text {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.readable-bar-chart {
  height: auto;
}

.bar-item {
  outline: none;
  cursor: default;
}

.bar-hitarea {
  fill: transparent;
}

.bar-tooltip {
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.bar-tooltip rect {
  fill: rgba(23, 33, 43, 0.94);
  stroke: rgba(255, 255, 255, 0.72);
}

.bar-tooltip text {
  fill: #fff;
  font-size: 12px;
  font-weight: 800;
}

.bar-item:hover .bar-tooltip,
.bar-item:focus .bar-tooltip {
  opacity: 1;
}

.line-hover-item {
  outline: none;
}

.line-hitarea {
  fill: transparent;
  cursor: default;
}

.line-hover-guide,
.line-hover-dot,
.line-tooltip {
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.line-hover-guide {
  stroke: rgba(23, 33, 43, 0.28);
  stroke-dasharray: 4 4;
}

.line-tooltip rect {
  fill: rgba(23, 33, 43, 0.94);
  stroke: rgba(255, 255, 255, 0.72);
}

.line-tooltip text {
  fill: #fff;
  font-size: 12px;
  font-weight: 800;
}

.line-hover-item:hover .line-hover-guide,
.line-hover-item:hover .line-hover-dot,
.line-hover-item:hover .line-tooltip,
.line-hover-item:focus .line-hover-guide,
.line-hover-item:focus .line-hover-dot,
.line-hover-item:focus .line-tooltip {
  opacity: 1;
}

.donut-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.95fr) minmax(240px, 1.05fr);
  align-items: center;
  gap: 16px;
  padding: 16px 16px 18px;
}

.donut-chart {
  height: 380px;
  max-width: 420px;
  justify-self: center;
}

.donut-slice {
  outline: none;
  cursor: default;
}

.donut-segment,
.donut-segment-hit {
  transition: opacity 140ms ease, stroke-width 140ms ease;
}

.donut-segment-hit {
  fill: transparent;
  pointer-events: all;
}

.donut-tooltip {
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.donut-tooltip rect {
  fill: rgba(23, 33, 43, 0.94);
  stroke: rgba(255, 255, 255, 0.72);
}

.donut-tooltip text {
  fill: #fff;
  font-size: 12px;
  font-weight: 800;
}

.donut-slice:hover .donut-segment-hit,
.donut-slice:focus .donut-segment-hit {
  stroke: #fff;
  stroke-width: 3;
}

.donut-slice:hover .donut-tooltip,
.donut-slice:focus .donut-tooltip {
  opacity: 1;
}

.donut-legend {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.donut-legend-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.legend-name {
  overflow: hidden;
  color: var(--ink);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-value {
  color: var(--muted);
  font-weight: 800;
}

.legend-rate {
  color: var(--teal-dark);
  font-weight: 900;
}

.chart-empty {
  display: grid;
  place-items: center;
  min-height: 220px;
  color: var(--muted);
  background: var(--surface-alt);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.extract-body {
  display: grid;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.extract-body p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.extract-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.extract-controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.extract-controls select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.extract-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.extract-actions span {
  color: var(--muted);
  font-size: 12px;
}

.extract-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.age-table table {
  min-width: 420px;
}

.table-preview {
  position: relative;
  max-height: 486px;
  overflow-y: hidden;
}

.table-preview::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 76px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), var(--surface) 82%);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

td.number,
th.number {
  text-align: right;
}

.name-cell {
  max-width: 360px;
  white-space: normal;
  word-break: keep-all;
}

.grouped-table .group-row td {
  background: #eef3f7;
  color: var(--ink);
  font-weight: 800;
  border-top: 1px solid #cbd6e0;
}

.grouped-table .total-row td {
  background: #14313a;
  color: #fff;
  font-weight: 900;
  border-bottom-color: #14313a;
}

.grouped-table .group-row + tr td {
  border-top: 0;
}

.table-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.table-toggle-button {
  min-height: 36px;
  padding: 0 18px;
  border: 1px solid var(--teal);
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

.table-toggle-button:hover {
  border-color: var(--teal-dark);
  background: var(--teal-dark);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge.green {
  background: #e8f5ee;
  color: var(--green);
}

.badge.amber {
  background: #fff4dd;
  color: var(--amber);
}

.badge.red {
  background: #fdebea;
  color: var(--red);
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: min(var(--value), 100%);
  background: var(--teal);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 33, 43, 0.42);
}

.modal-panel {
  width: min(680px, 100%);
  max-height: min(760px, 90vh);
  overflow: auto;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.admin-content {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.admin-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.admin-box h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.admin-box p {
  margin: 6px 0;
  color: var(--muted);
}

.admin-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.admin-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 10px 0 0;
  list-style: none;
}

.admin-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.danger-button {
  border: 1px solid #f0b8b5;
  border-radius: 6px;
  background: #fff;
  color: var(--red);
  min-height: 32px;
  padding: 0 10px;
  font-weight: 800;
}

.toast {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1100px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .media-spend-grid.primary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-grid,
  .panel-grid.equal {
    grid-template-columns: 1fr;
  }

  .funnel-controls {
    grid-template-columns: 1fr;
  }

  .donut-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions > * {
    flex: 1 1 120px;
  }

  .tabs,
  .subtabs,
  .content,
  .status-strip {
    margin-left: 0;
    margin-right: 0;
    padding-left: 16px;
    padding-right: 16px;
  }

  .status-strip {
    margin-bottom: 12px;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .media-spend-grid.primary,
  .media-spend-grid.crm {
    grid-template-columns: 1fr;
  }

  .password-row,
  .admin-form {
    grid-template-columns: 1fr;
  }

  .extract-controls {
    grid-template-columns: 1fr;
  }

  .product-controls {
    justify-content: stretch;
  }

  .product-select {
    width: 100%;
  }

  .donut-layout {
    padding: 8px;
  }

  .donut-legend-row {
    grid-template-columns: 12px minmax(0, 1fr) auto;
  }

  .legend-rate {
    display: none;
  }
}
