:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1c2530;
  --muted: #6b7a8c;
  --line: #e3e8ee;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --off: #dc2626;
  --off-soft: #fee2e2;
  --bot: #9333ea;
  --bot-soft: #f3e8ff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--accent-soft); color: #1e40af; border-radius: 4px; padding: 1px 6px; font-size: .92em; }
pre { background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: var(--radius); overflow-x: auto; font-size: 13px; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h3 { font-size: 15px; color: var(--ink); }

/* Topbar */
.topbar { background: #0f172a; color: #e2e8f0; }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 28px; height: 52px;
}
.brand { color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand span { color: #60a5fa; }
.brand.big { font-size: 26px; margin-bottom: 14px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #cbd5e1; padding: 6px 12px; border-radius: 6px; font-weight: 500; }
.nav a:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,.08); }
.nav a.active { color: #fff; background: rgba(96,165,250,.22); }

/* Filters bar */
.filters { background: var(--card); border-bottom: 1px solid var(--line); }
.filters-form {
  max-width: 1200px; margin: 0 auto; padding: 10px 20px;
  display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap;
}
.filter-group { display: flex; gap: 8px; align-items: center; }
.filter-group label { font-size: 12.5px; color: var(--muted); display: block; margin-bottom: 3px; }
.custom-dates { display: none; }
.filters-form.custom .custom-dates { display: flex; }

select, input[type="search"], input[type="date"], input[type="text"], input[type="password"] {
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px;
  font: inherit; color: var(--ink); background: #fff;
}
input[type="search"] { min-width: 240px; }

/* Buttons */
.btn {
  display: inline-block; border: none; border-radius: 7px; cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; font-weight: 550;
  padding: 8px 14px; transition: filter .12s;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.topbar .btn-ghost { color: #cbd5e1; border-color: rgba(255,255,255,.25); }
.btn-danger { background: var(--off); }
.btn-ok { background: var(--ok); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-wide { width: 100%; }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 22px 20px 60px; }
.grid { display: grid; gap: 18px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 18px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 18px;
}
.chart-card.wide { grid-column: 1 / -1; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi-label { font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 27px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12.5px; color: var(--muted); }

/* Banner */
.banner { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.banner-actions { display: flex; gap: 10px; align-items: center; }
.progress { flex-basis: 100%; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width .3s; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); font-weight: 600; white-space: nowrap; }
th a { color: var(--muted); }
th a:hover { color: var(--accent); text-decoration: none; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.ua { max-width: 200px; font-size: 12.5px; color: var(--muted); }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.muted { color: var(--muted); }
.row-disabled td { opacity: .55; }

/* Badges */
.badge { display: inline-block; border-radius: 999px; font-size: 11.5px; font-weight: 600; padding: 1px 9px; }
.badge-on { background: var(--ok-soft); color: #166534; }
.badge-off { background: var(--off-soft); color: #991b1b; }
.badge-bot { background: var(--bot-soft); color: #6b21a8; }

/* Pagination */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.page { padding: 5px 11px; border: 1px solid var(--line); border-radius: 7px; color: var(--accent); background: #fff; }
.page.current { background: var(--accent); color: #fff; border-color: var(--accent); }
.page.gap { border: none; color: var(--muted); }

/* Link detail */
.link-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.link-head-main { min-width: 0; flex: 1; }
.link-head-actions { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.big-code { font-size: 22px; padding: 2px 12px; }
.shorturl-line { display: flex; gap: 10px; align-items: center; margin: 6px 0; }
.link-title { font-size: 16px; font-weight: 600; margin: 4px 0; }

/* Charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; }
.chart-tooltip {
  position: absolute; pointer-events: none; background: #0f172a; color: #e2e8f0;
  border-radius: 6px; padding: 6px 10px; font-size: 12.5px; white-space: nowrap;
  transform: translate(-50%, -110%); z-index: 5; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* HBar (HTML bars) */
.hbar-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(30px, 1fr) max-content; gap: 10px; align-items: center; margin: 7px 0; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.hbar-track { background: var(--line); border-radius: 4px; height: 14px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 4px; background: var(--accent); min-width: 2px; }
.hbar-value { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }

/* VBar (HTML bars) */
.vbar { display: flex; align-items: flex-end; gap: 3px; height: 170px; padding-top: 8px; }
.vbar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 0; }
.vbar-bar { background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; width: 100%; }
.vbar-labels { display: flex; gap: 3px; margin-top: 4px; }
.vbar-label { flex: 1; text-align: center; font-size: 10.5px; color: var(--muted); overflow: hidden; white-space: nowrap; }

/* Donut */
.donut-wrap { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.donut-wrap svg { flex: 0 1 150px; height: auto; }
.donut-legend { display: flex; flex-direction: column; gap: 6px; font-size: 13px; flex: 1; min-width: 0; }
.donut-legend .hbar-row { grid-template-columns: minmax(0, 1fr) max-content; }
.donut-legend .hbar-track { display: none; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 34px 36px; width: 100%; max-width: 400px;
}
.login-card.wide { max-width: 620px; }
.login-card h1 { margin-bottom: 8px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--muted); }
.form-group input { width: 100%; }
.alert { background: var(--off-soft); color: #991b1b; border-radius: 7px; padding: 9px 12px; margin-bottom: 16px; font-size: 13.5px; }

@media (max-width: 900px) {
  .grid, .grid-main { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .grid, .grid-main { grid-template-columns: 1fr; }
  .truncate { max-width: 160px; }
  .topbar-inner { gap: 14px; }
  .nav a { padding: 6px 8px; }
}
