:root {
  --ink: #0f1720;
  --ink-soft: #4b5a6b;
  --muted: #8592a3;
  --line: #e2e6ea;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --accent: #3b6ef6;
  --accent-ink: #1d3fa0;
  --ok: #1a9c6e;
  --ok-bg: #e6f7f0;
  --warn: #b5820c;
  --warn-bg: #fbf1dc;
  --danger: #c0392b;
  --radius: 8px;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

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

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }

/* ---- layout ---- */
.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
}
.wrap-narrow { max-width: 680px; }

main.wrap { padding-top: 28px; padding-bottom: 60px; }

/* ---- top nav ---- */
.topnav {
  background: var(--ink);
  color: #fff;
}
.topnav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 54px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.brand:hover { text-decoration: none; opacity: 0.9; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  background: var(--accent);
  border-radius: 6px;
  font-size: 14px;
}
.topnav-links a {
  color: #cfd8e3;
  margin-left: 20px;
  font-size: 13px;
}
.topnav-links a:hover { color: #fff; }

/* ---- stat cards ---- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.stat-label { color: var(--muted); font-size: 12px; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.4px; }

/* ---- panels ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.panel-head.plain {
  background: transparent;
  border: none;
  padding: 0;
  margin-bottom: 20px;
}
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-head-actions { display: flex; gap: 10px; align-items: center; }

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); text-decoration: none; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { border-color: var(--ink-soft); text-decoration: none; }
.btn-block { width: 100%; margin-top: 6px; }

/* ---- table ---- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
}
.table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table tr:last-child td { border-bottom: none; }
.truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-actions a { margin-right: 12px; font-size: 12px; }
.danger-link { color: var(--danger); }
.clicks-link { font-weight: 600; }

/* ---- badges ---- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.badge-perm { background: #e8edff; color: var(--accent-ink); }
.badge-temp { background: #fdeee0; color: #a05a12; }
.badge-status-active { background: var(--ok-bg); color: var(--ok); }
.badge-status-paused { background: var(--warn-bg); color: var(--warn); }

/* ---- forms ---- */
.form-row { margin-bottom: 16px; }
.form-row-inline { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.checkbox-row { display: flex; flex-direction: column; gap: 8px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); }
.checkbox-label input { width: auto; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
input[type="text"], input[type="url"], input[type="password"], select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 110, 246, 0.15);
}
.hint { font-size: 12px; color: var(--muted); margin: 5px 0 0; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; }

.search-form input {
  width: 240px;
}

/* ---- empty state ---- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .btn { margin-top: 10px; }

/* ---- alerts ---- */
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
}
.alert-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c0; }

/* ---- login ---- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0f1720 0%, #1c2a3a 100%);
}
.login-card {
  background: #fff;
  width: 340px;
  padding: 32px 30px;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.login-mark {
  width: 40px; height: 40px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin-bottom: 14px;
}
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-card p { margin: 0 0 18px; }

/* ---- QR panel ---- */
.qr-row {
  display: flex;
  align-items: center;
  gap: 20px;
}
.qr-image {
  width: 140px;
  height: 140px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px;
}

/* ---- breakdown grid (device/OS/browser/country) ---- */
.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.breakdown-grid .panel { margin-bottom: 0; padding: 16px 18px; }
.breakdown-grid .table td { padding: 7px 4px; font-size: 13px; }
.breakdown-grid .table td:last-child { text-align: right; font-weight: 600; }

/* ---- bot indicators ---- */
.badge-bot { background: #f1f0f4; color: #6b6478; }
tr.row-bot { opacity: 0.6; }

@media (max-width: 900px) {
  .breakdown-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .form-row-inline { grid-template-columns: 1fr; }
  .search-form input { width: 160px; }
}
