/* dododo LP monitoring dashboard — quiet business UI.
   White / soft grey / ink base; lime is an accent only. */

:root {
  --bg: #f5f6f5;
  --surface: #ffffff;
  --ink: #1d211f;
  --muted: #6b726e;
  --faint: #9aa09c;
  --line: #e5e8e4;
  --line-strong: #d6dad3;
  --lime: #79b528;
  --lime-soft: #eef7dc;
  --danger: #b04434;
  --danger-soft: #fbeae6;
  --warn-soft: #fdf4e3;
  --warn-line: #ecd9af;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 20, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }
/* The hidden attribute must always win over layout display rules (.login/.state use display). */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, p { margin: 0; }
button { font-family: inherit; }

/* ===== Login ===== */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-title { font-size: 18px; font-weight: 700; letter-spacing: 0.01em; }
.login-sub { color: var(--muted); font-size: 13px; margin-top: -4px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input {
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
.field input:focus { outline: 2px solid var(--lime-soft); border-color: var(--lime); }
.login-error { color: var(--danger); font-size: 13px; }

/* ===== Buttons ===== */
.btn-primary {
  appearance: none;
  border: 1px solid var(--lime);
  background: var(--lime);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(0.96); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-ghost {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--ink); border-color: var(--faint); }

/* ===== App shell ===== */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 22px 48px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.title { font-size: 18px; font-weight: 700; letter-spacing: 0.01em; }
.subtitle { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* segmented control */
.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  overflow: hidden;
  background: #fff;
}
.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 7px 14px;
  cursor: pointer;
  border-left: 1px solid var(--line);
}
.segmented button:first-child { border-left: 0; }
.segmented button.is-active { background: var(--lime-soft); color: #355e0c; font-weight: 600; }

/* stale banner */
.stale {
  background: var(--warn-soft);
  border: 1px solid var(--warn-line);
  color: #7a5a17;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

/* ===== States ===== */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  min-height: 320px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
}
.state-empty h2 { font-size: 16px; color: var(--ink); font-weight: 700; }
.state-error { color: var(--danger); }
.spinner {
  width: 26px; height: 26px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--lime);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== KPI cards ===== */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 14px;
  min-width: 0;
}
.kpi-label { font-size: 12.5px; color: var(--muted); }
.kpi-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 6px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.kpi-value-sm { font-size: 19px; font-weight: 600; }
.kpi-sub { font-size: 11.5px; color: var(--faint); margin-top: 4px; }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 14.5px; font-weight: 700; }
.card-note { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 14px; height: 0; vertical-align: middle; }
.lg-bar { width: 11px; height: 11px; border-radius: 2px; background: var(--lime); }
.lg-line { width: 16px; height: 0; border-top: 2px solid #2f6b86; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 .card { margin-bottom: 0; }

/* ===== Chart (compact, fixed height; SVG stretches, labels are HTML overlays) ===== */
.chart { position: relative; width: 100%; height: 205px; }
.chart svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.chart .bar { fill: var(--lime); }
.chart .cta-line { fill: none; stroke: #2f6b86; stroke-width: 2; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart-ylabel { position: absolute; left: 0; transform: translateY(-50%); font-size: 10px; color: var(--faint); font-variant-numeric: tabular-nums; }
.chart-vlabel { position: absolute; transform: translate(-50%, -135%); font-size: 11px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-xlabel { position: absolute; bottom: 1px; transform: translateX(-50%); font-size: 10px; color: var(--faint); white-space: nowrap; }
.chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; text-align: center; }
@media (max-width: 720px) { .chart { height: 178px; } .chart-vlabel { font-size: 10px; } }

/* ===== Tables ===== */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
tbody td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ellip { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-empty { color: var(--muted); text-align: center; padding: 22px 14px; font-size: 13px; line-height: 1.8; }
.table-empty code { background: var(--bg); border: 1px solid var(--line); padding: 1px 6px; border-radius: 4px; font-size: 12px; color: var(--ink); }
.utm-src { font-weight: 600; }
.utm-meta { color: var(--faint); font-size: 11.5px; margin-top: 2px; }
.entry-src { font-weight: 600; }
.entry-how { margin-top: 4px; }
.badge { display: inline-block; font-size: 11px; line-height: 1.5; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap; }
.badge-utm { background: var(--lime-soft); border-color: #cce39a; color: #3f6312; }
.badge-ref { background: #eaf2f6; border-color: #cfe0e8; color: #2f6b86; }
.badge-direct { background: var(--bg); border-color: var(--line-strong); color: var(--muted); }

/* ===== Legend ===== */
.legend { color: var(--muted); font-size: 12px; line-height: 1.7; margin-top: 4px; }
.legend b { color: var(--ink); font-weight: 600; }

/* ===== Responsive ===== */
@media (max-width: 720px) {
  .app { padding: 16px 14px 48px; }
  .topbar { align-items: flex-start; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .grid-2 { grid-template-columns: 1fr; }
  .kpi-value { font-size: 26px; }
}
@media (max-width: 420px) {
  .segmented button { padding: 7px 10px; font-size: 12.5px; }
  .kpis { gap: 10px; }
}
