:root {
  --red: #dc2626;
  --red-soft: #fef2f2;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e9ebef;
  --bg: #f6f7f9;
  --card: #ffffff;
  --up: #15803d;
  --up-soft: #ecfdf3;
  --down: #b91c1c;
  --down-soft: #fef2f2;
  --pad: clamp(16px, 3vw, 48px);
  --max: 1800px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 600; margin: 0; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px var(--pad);
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 36px; height: 36px; flex: none; }
.brand strong { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line);
  background: #fff; color: var(--ink);
  font-weight: 500; font-size: 15px; text-decoration: none; cursor: pointer;
}
.btn:hover { background: #f9fafb; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn svg { width: 18px; height: 18px; }
.btn.icon-only { width: 42px; padding: 0; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #b91c1c; }

/* ---------- controls ---------- */
.controls {
  max-width: var(--max); margin: 0 auto; padding: 22px var(--pad) 0;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.site-tabs { display: flex; gap: 4px; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.site-tabs::-webkit-scrollbar { display: none; }
.site-tabs button { border: 0; background: none; padding: 9px 16px; border-radius: 10px; font-size: 15px; font-weight: 500; color: var(--muted); cursor: pointer; white-space: nowrap; }
.site-tabs button:hover { color: var(--ink); }
.site-tabs button[aria-selected="true"] { background: var(--red); color: #fff; }
.select, .date-input { height: 42px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 15px; }
.select { padding-right: 34px; appearance: none; cursor: pointer; min-width: 170px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.custom-range { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: inline-flex; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; font-size: 15px; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg button:disabled { opacity: 0.35; cursor: not-allowed; }

/* ---------- report ---------- */
.report { max-width: var(--max); margin: 0 auto; padding: 26px var(--pad) 60px; display: flex; flex-direction: column; gap: 20px; transition: opacity 0.2s; }
.report.is-loading { opacity: 0.45; pointer-events: none; }
.report-head h1 { font-size: clamp(26px, 3vw, 34px); line-height: 1.2; }
.report-head p { margin: 4px 0 0; color: var(--muted); }

.notice { padding: 12px 16px; border-radius: 12px; font-size: 15px; }
.notice + .notice { margin-top: 8px; }
.notice.demo { background: #fffbeb; color: #92400e; }
.notice.info { background: #eef2ff; color: #3730a3; }
.notice.info b { font-weight: 600; }
.tag { display: inline-block; margin-left: 6px; padding: 1px 9px; border-radius: 999px; background: #eef2ff; color: #3730a3; font-size: 13px; vertical-align: 1px; }
.notice.error { background: var(--down-soft); color: var(--down); }

.card { background: var(--card); border-radius: 18px; padding: 26px 28px; box-shadow: 0 1px 3px rgba(31, 41, 55, 0.05); min-width: 0; }
.card h2 { font-size: 20px; }
.card > h2 { margin-bottom: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.chart { width: 100%; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.row.single { grid-template-columns: 1fr; }

/* ---------- big numbers ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
.kpi { background: var(--card); border-radius: 18px; padding: 24px 26px; box-shadow: 0 1px 3px rgba(31, 41, 55, 0.05); min-width: 0; }
.kpi-label { color: var(--muted); font-size: 16px; }
.kpi-value { font-size: clamp(34px, 3.4vw, 48px); font-weight: 700; line-height: 1.1; margin-top: 8px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi.main .kpi-value { color: var(--red); }
.kpi-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 15px; flex-wrap: wrap; }
.delta { display: inline-flex; align-items: center; gap: 3px; padding: 2px 10px; border-radius: 999px; font-size: 14px; font-weight: 600; }
.delta.up { background: var(--up-soft); color: var(--up); }
.delta.down { background: var(--down-soft); color: var(--down); }
.delta.flat { background: var(--bg); color: var(--muted); }

/* ---------- funnel ---------- */
.funnel { display: flex; flex-direction: column; gap: 6px; }
.f-row { display: grid; grid-template-columns: 260px 1fr 120px; align-items: center; gap: 18px; }
.f-label { font-size: 16px; }
.f-track { height: 40px; border-radius: 10px; background: var(--bg); overflow: hidden; }
.f-bar { height: 100%; border-radius: 10px; min-width: 6px; }
.f-num { text-align: right; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.f-drop { margin-left: 278px; color: var(--muted); font-size: 15px; padding: 2px 0; }
.f-drop b { color: var(--ink); font-weight: 600; }

/* ---------- pills ---------- */
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pills button { border: 1px solid var(--line); background: #fff; padding: 8px 16px; border-radius: 999px; font-size: 15px; color: var(--muted); cursor: pointer; }
.pills button:hover { color: var(--ink); }
.pills button[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- simple bars ---------- */
.bars { display: flex; flex-direction: column; gap: 16px; }
.b-top { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 7px; font-size: 16px; }
.b-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-val { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.b-val span { color: var(--muted); font-weight: 400; }
.b-track { height: 10px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.b-fill { height: 100%; border-radius: 99px; min-width: 3px; }

/* ---------- more numbers ---------- */
details summary { cursor: pointer; font-size: 18px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "Show"; color: var(--red); font-size: 15px; font-weight: 500; }
details[open] summary::after { content: "Hide"; }
.more { display: flex; flex-direction: column; gap: 30px; margin-top: 24px; }
.more h3 { font-size: 17px; margin-bottom: 14px; }
.more-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 30px 40px; }
.note { color: var(--muted); margin: -6px 0 14px; font-size: 15px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap + .table-wrap { margin-top: 22px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 500; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.num, td.num { text-align: right; }
tfoot td { font-weight: 600; border-bottom: 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

.foot { color: var(--muted); font-size: 14px; line-height: 1.7; }
.foot p { margin: 0 0 4px; }

.empty { color: var(--muted); margin: 0; }

/* ---------- loading / error ---------- */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 40; overflow: hidden; }
.progress::after { content: ""; position: absolute; inset: 0; width: 40%; background: var(--red); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
.fatal { max-width: 560px; margin: 80px auto; text-align: center; padding: 0 16px; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; padding: 34px 28px; box-shadow: 0 1px 3px rgba(31, 41, 55, 0.06); }
.login-card .brand-mark { width: 44px; height: 44px; }
.login-card h1 { margin: 16px 0 4px; font-size: 24px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-card label { display: block; font-weight: 500; margin-bottom: 6px; }
.login-card input { width: 100%; height: 48px; border-radius: 12px; border: 1px solid #d1d5db; padding: 0 14px; font-size: 16px; }
.login-card input:focus { outline: 3px solid #fecaca; border-color: var(--red); }
.login-card .btn { width: 100%; height: 48px; margin-top: 16px; }
.login-error { color: var(--down); background: var(--down-soft); padding: 10px 12px; border-radius: 10px; margin: 0 0 14px !important; }

/* ---------- PDF export ---------- */
body.exporting .no-export { display: none !important; }
body.exporting .report { width: 1200px; max-width: none; padding: 24px; }
body.exporting .card, body.exporting .kpi { box-shadow: none; border: 1px solid var(--line); }
body.exporting .kpis { grid-template-columns: repeat(4, 1fr); }
body.exporting .row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body.exporting .row.single { grid-template-columns: 1fr; }
body.exporting .more-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body.exporting .table-wrap { overflow: visible; }

/* ---------- smaller screens ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .f-row { grid-template-columns: 1fr auto; gap: 6px 12px; }
  .f-label { grid-column: 1; }
  .f-num { grid-column: 2; grid-row: 1; font-size: 19px; }
  .f-track { grid-column: 1 / -1; height: 28px; }
  .f-drop { margin-left: 0; }
  .more-grid { grid-template-columns: 1fr; }
  .card { padding: 20px 18px; }
  .controls { align-items: stretch; }
  .filters { width: 100%; }
  .select { flex: 1; }
}
@media (max-width: 520px) {
  body { font-size: 15px; }
  .topbar { padding: 10px 14px; }
  .brand strong { font-size: 16px; }
  .btn { height: 40px; }
  .btn.icon-only { width: 40px; }
  .btn .pdf-label { font-size: 0; }
  .btn .pdf-label::after { content: "PDF"; font-size: 14px; }
  .kpis { gap: 12px; }
  .kpi { padding: 16px; }
  .kpi-label { font-size: 14.5px; }
  .kpi-value { font-size: 30px; }
  .kpi-foot { font-size: 14px; }
  .card h2 { font-size: 18px; }
}
body.exporting details summary::after { content: none; }
