:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e3e5e9;
  --text: #1c1f26;
  --muted: #6b7280;
  --accent: #2451c9;
  --accent-light: #e8edfc;
  --up: #1a8f4c;
  --down: #c0392b;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1080px; margin: 0 auto; padding: 24px 20px 60px; }

/* Nav */
.topnav { background: var(--card); border-bottom: 1px solid var(--border); position: relative; }
.topnav-inner { max-width: 1080px; margin: 0 auto; padding: 14px 20px; display: flex; align-items: center; gap: 24px; justify-content: space-between; }
.topnav .brand { font-weight: 700; color: var(--text); display: flex; align-items: center; line-height: 0; }
.topnav .brand-logo { height: 40px; width: auto; aspect-ratio: 655 / 115; display: block; vertical-align: middle; }
.topnav nav { flex: 1; }
.topnav nav a { color: var(--muted); font-size: .95rem; padding: 4px 0; border-bottom: 2px solid transparent; }
.topnav nav a.active, .topnav nav a:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.topnav .logout { color: var(--muted); font-size: .9rem; }

/* Nav - mobile collapse (hamburger-menu.js toggles nav-desktop/nav-mobile and the icon's select/deselect state) */
.hamburger-menu-icon {
  display: block;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  background: transparent center / 20px no-repeat;
  background-image: url('../img/menu-burger-icon-black.svg');
  cursor: pointer;
  flex-shrink: 0;
}
.hamburger-menu-icon.hamburger-menu-deselect { background-image: url('../img/cross-icon-black.svg'); }

.topnav nav.nav-desktop { display: none; }
.topnav nav.nav-mobile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px 16px;
}

@media (min-width: 720px) {
  .hamburger-menu-icon { display: none; }
  .topnav nav.nav-mobile,
  .topnav nav.nav-desktop {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    gap: 18px;
    position: static;
    background: none;
    border: 0;
    padding: 0;
  }
}

/* Toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.site-switch select { padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--card); font-size: .95rem; min-width: 200px; }
.range-picker { display: flex; flex-wrap: wrap; gap: 4px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 3px; }
.range-picker a { padding: 6px 12px; border-radius: 6px; color: var(--muted); font-size: .9rem; }
.range-picker a.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.range-picker a:hover { text-decoration: none; }

/* Custom date range: a quiet text trigger above the range buttons */
.range-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.custom-range { position: relative; }
.custom-range-btn { display: inline-flex; align-items: center; gap: 5px; background: none; border: 0; padding: 2px 4px; color: var(--muted); font-family: inherit; font-size: .85rem; cursor: pointer; }
.custom-range-btn:hover, .custom-range-btn[aria-expanded="true"] { color: var(--text); }
.custom-range-btn.active { color: var(--accent); font-weight: 600; }
.custom-range-btn[aria-expanded="true"] .stat-picker-caret { transform: rotate(180deg); }
.custom-range-menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 20; display: flex; flex-direction: column; gap: 10px; width: 220px; padding: 12px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(28, 31, 38, .1); }
.custom-range-menu[hidden] { display: none; } /* display:flex above would otherwise override [hidden] */
.custom-range-menu label { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.custom-range-menu input { padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: .9rem; color: var(--text); background: var(--card); }
.custom-range-menu button[type="submit"] { font-family: inherit; }

.refresh-icon { display: inline-block; }
#refresh-btn.is-refreshing .refresh-icon { animation: refresh-spin .6s linear infinite; }
#refresh-btn:disabled { opacity: .7; cursor: default; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }

/* Stat tiles */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-tile { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.stat-tile .label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.stat-tile .value { font-size: 1.7rem; font-weight: 700; }
.stat-tile .change { font-size: .82rem; font-weight: 600; }
.stat-tile .change.up { color: var(--up); }
.stat-tile .change.down { color: var(--down); }

/* Visitors tile: label doubles as a compact total/new/returning switcher */
.stat-picker { position: relative; align-self: flex-start; }
.stat-picker-btn { display: inline-flex; align-items: center; gap: 5px; background: none; border: 0; padding: 0; color: var(--muted); font-family: inherit; line-height: inherit; cursor: pointer; }
.stat-picker-btn:hover, .stat-picker-btn[aria-expanded="true"] { color: var(--text); }
.stat-picker-btn:hover .label, .stat-picker-btn[aria-expanded="true"] .label { color: var(--text); }
.stat-picker-caret { transition: transform .15s ease; }
.stat-picker-btn[aria-expanded="true"] .stat-picker-caret { transform: rotate(180deg); }
.stat-picker-menu { position: absolute; top: calc(100% + 6px); left: -6px; z-index: 20; min-width: 180px; padding: 4px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(28, 31, 38, .1); }
.stat-picker-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 5px; padding: 7px 10px; color: var(--text); font-family: inherit; font-size: .88rem; cursor: pointer; }
.stat-picker-menu button:hover { background: var(--bg); }
.stat-picker-menu button[aria-checked="true"] { background: var(--accent-light); color: var(--accent); font-weight: 600; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; }
.card h2 { margin: 0 0 14px; font-size: 1.05rem; }

.chart-card { position: relative; }
#chart { width: 100%; height: 260px; overflow: visible; }
.chart-tooltip { position: absolute; background: var(--text); color: #fff; font-size: .78rem; padding: 6px 9px; border-radius: 5px; pointer-events: none; white-space: nowrap; transform: translate(-50%, -110%); }

/* Tabs + breakdown table */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; font-size: .85rem; color: var(--muted); cursor: pointer; }
.tabs button.active { background: var(--accent-light); color: var(--accent); border-color: transparent; font-weight: 600; }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); font-size: .9rem; }
.table th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar-track { position: relative; background: var(--accent-light); border-radius: 3px; height: 6px; width: 100%; min-width: 80px; }
.bar-fill { position: absolute; inset: 0; background: var(--accent); border-radius: 3px; }

/* Breakdown table: long labels (URL paths have no spaces to break at) wrap
   instead of pushing the count and bar columns off narrow screens. */
#breakdown-table td:first-child { overflow-wrap: anywhere; }
#breakdown-table td.num { white-space: nowrap; }
@media (max-width: 480px) {
  #breakdown-table .bar-track { min-width: 40px; }
}

.muted { color: var(--muted); }

/* ---- Chart panels (bars, donuts, map) ---- */
.viz-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 20px; margin-bottom: 20px; transition: opacity .2s; }
.viz-grid .card { margin-bottom: 0; }
.viz-grid.is-loading { opacity: .6; }
.viz-card h2 { font-size: .95rem; }
.viz-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 14px; }
.viz-head h2 { margin: 0; }
.viz-empty { margin: 8px 0; font-size: .9rem; }
.seg { display: flex; gap: 2px; background: var(--bg); border-radius: 6px; padding: 2px; }
.seg button { background: none; color: var(--muted); border: 0; border-radius: 5px; padding: 4px 10px; font-family: inherit; font-size: .8rem; }
.seg button.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(28, 31, 38, .08); }

.viz-tip { position: fixed; z-index: 50; pointer-events: none; max-width: 260px; background: var(--text); color: #fff; font-size: .78rem; line-height: 1.4; padding: 6px 9px; border-radius: 5px; overflow-wrap: anywhere; }

.hbars { display: grid; gap: 4px; }
.hbar { display: grid; grid-template-columns: minmax(0, 38%) 1fr auto; align-items: center; gap: 10px; padding: 4px 2px; border-radius: 4px; outline: none; }
.hbar:hover, .hbar:focus-visible { background: var(--bg); }
.hbar-label { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-plot { height: 10px; border-left: 1px solid var(--border); }
.hbar-fill { display: block; height: 100%; min-width: 2px; background: var(--accent); border-radius: 0 4px 4px 0; }
.hbar-value { font-size: .85rem; font-variant-numeric: tabular-nums; color: var(--text); min-width: 3ch; text-align: right; }

.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut-svg { width: 160px; height: 160px; flex: none; }
.donut-svg path { cursor: default; outline: none; transition: opacity .15s; }
.donut-total { font-size: 22px; font-weight: 700; fill: var(--text); }
.donut-caption { font-size: 12px; fill: var(--muted); }
.donut-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 180px; display: grid; gap: 2px; }
.donut-legend li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto 3.4em; align-items: center; gap: 8px; font-size: .85rem; padding: 3px 4px; border-radius: 4px; outline: none; transition: opacity .15s; }
.donut-legend li:hover, .donut-legend li:focus-visible { background: var(--bg); }
.donut-legend li.dim { opacity: .45; }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend .lg-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend .lg-value, .donut-legend .lg-pct { font-variant-numeric: tabular-nums; text-align: right; }
.donut-legend .lg-pct { color: var(--muted); }

.geo-svg { display: block; width: 100%; height: auto; }
.geo-country { transition: opacity .15s; }
.geo-country:hover { opacity: .8; }
.geo-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: .8rem; color: var(--muted); }
.geo-legend .lg-item { display: inline-flex; align-items: center; gap: 6px; }
.geo-legend i { width: 14px; height: 10px; border-radius: 2px; }
.geo-legend i.dot { width: 10px; height: 10px; border-radius: 50%; background: #eb6834; }
.attribution { margin: -8px 0 20px; text-align: right; font-size: .75rem; }
.attribution a { color: inherit; }

/* Forms */
.form-grid { display: grid; gap: 12px; max-width: 480px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: .88rem; font-weight: 600; color: var(--text); }
.form-grid input, .form-grid select { padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: .95rem; font-weight: 400; background: var(--card); }
button, .btn-secondary { display: inline-block; padding: 9px 16px; background: var(--accent); color: #fff; border: 0; border-radius: 6px; font-size: .92rem; cursor: pointer; }
.btn-secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); margin-left: 8px; }
.link-danger { background: none; border: 0; color: var(--down); cursor: pointer; font-size: .88rem; padding: 0; }

/* Users page: site assignment checkboxes */
.site-checks { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin: 0; display: grid; gap: 8px; }
.site-checks legend { padding: 0 4px; font-size: .88rem; font-weight: 600; }
.site-checks[disabled] { opacity: .5; }
.form-grid .site-checks .check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.form-grid .site-checks .check input { padding: 0; margin: 0; }

.flash { padding: 10px 14px; border-radius: 6px; font-size: .9rem; margin-bottom: 16px; }
.flash.ok { background: #e9f8ee; color: #1a6b34; border: 1px solid #bfe6cc; }
.flash.error { background: #fdecea; color: #9d2f2c; border: 1px solid #f5c2c0; }
.error { color: var(--down); font-size: .88rem; }

.snippet { font-size: .78rem; background: var(--bg); padding: 4px 6px; border-radius: 4px; display: inline-block; white-space: normal; overflow-wrap: anywhere; }
.row-actions { display: flex; align-items: center; gap: 10px; }
.row-actions form { display: inline; }

/* Splash page (logged-out root) */
.splash-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.splash { text-align: center; }
.splash-logo { height: 48px; width: auto; }
.splash-text { margin: 14px 0 0; color: var(--muted); font-size: .95rem; }

/* Auth page */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 30px; width: 320px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { margin: 0 0 6px; text-align: center; }
.auth-logo { height: 35px; width: auto; }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: .88rem; font-weight: 600; }
.auth-card input { padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: .95rem; font-weight: 400; }
