:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9dee8;
  --primary: #126d8f;
  --primary-dark: #0b536d;
  --success: #0f766e;
  --danger: #b42318;
  --warning: #a15c07;
  --card-radius: 14px;
  --shadow-soft: 0 10px 30px rgba(15,23,42,.06);
  --border-soft: 1px solid rgba(148,163,184,.35);
  --month-alt: #f3f6fb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
}

a {
  color: var(--primary);
  text-decoration: none;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 230px;
  background: #172033;
  color: #fff;
  padding: 22px 18px;
}

.brand {
  display: block;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 28px;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.sidebar nav a {
  color: #dbe4f0;
  border-radius: 6px;
  padding: 11px 12px;
}

.sidebar nav a:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.main {
  margin-left: 230px;
  padding: 30px;
}

.report-main {
  padding: 0;
}

.auth-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 22px;
}

h1 {
  margin: 0;
  font-size: 28px;
}

h2 {
  margin: 0 0 16px;
  font-size: 20px;
}

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

.panel,
.auth-box,
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel,
.auth-box {
  padding: 22px;
}

.auth-box {
  width: min(430px, 100%);
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 20px;
}

.card {
  padding: 18px;
}

.stat-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
  margin-top: 6px;
}

.form-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 7px;
}

.field.full {
  grid-column: 1 / -1;
}

label {
  color: #344054;
  font-weight: 700;
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  font: inherit;
  background: #fff;
}

.check-list {
  display: grid;
  gap: 9px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.check-item input {
  width: auto;
  min-height: auto;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 16px;
}

.actions.full {
  grid-column: 1 / -1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.btn:hover {
  background: var(--primary-dark);
  color: #fff;
}

.btn.secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.btn.danger {
  background: var(--danger);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  vertical-align: top;
}

th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
}

.table-wrap {
  overflow-x: auto;
}

.alert {
  padding: 12px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  border: 1px solid;
}

.alert.success {
  color: var(--success);
  background: #f0fdfa;
  border-color: #99f6e4;
}

.alert.error {
  color: var(--danger);
  background: #fff1f0;
  border-color: #fda29b;
}

.admin-user-shell {
  width: min(1296px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 60px;
}

.admin-user-shell.edit {
  width: min(1296px, calc(100% - 56px));
}

.admin-user-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.admin-user-head h1 {
  color: #09111f;
  font-size: 24px;
  line-height: 1.15;
}

.admin-user-head p {
  margin: 3px 0 0;
}

.admin-user-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-user-grid {
  display: grid;
  grid-template-columns: minmax(620px, 1.35fr) minmax(360px, .95fr);
  gap: 18px;
  align-items: start;
}

.admin-user-grid.edit-grid {
  grid-template-columns: minmax(420px, .92fr) minmax(560px, 1.3fr);
}

.admin-card {
  background: #fff;
  border: var(--border-soft);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.admin-card-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  color: #0f172a;
  font-weight: 700;
}

.admin-card-body {
  display: grid;
  gap: 13px;
  padding: 16px;
}

.admin-two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.admin-card label {
  color: #475467;
  font-weight: 400;
}

.admin-card input,
.admin-card select {
  min-height: 31px;
  border-color: #d8dee7;
  border-radius: 12px;
  padding: 6px 10px;
}

.admin-card input:disabled {
  color: #111827;
  background: #e6e9ee;
}

.admin-user-table th,
.admin-user-table td {
  padding: 9px 8px;
  vertical-align: middle;
}

.admin-user-table th {
  background: #f8fafc;
  color: #000;
  font-size: 16px;
  text-transform: none;
}

.admin-user-table .strong {
  color: #000;
  font-weight: 700;
}

.text-end {
  text-align: right;
}

.btn.btn-slim {
  min-height: 30px;
  border-radius: 12px;
  padding: 5px 10px;
  font-size: 14px;
  font-weight: 400;
}

.btn.btn-dark {
  background: #1b2027;
  color: #fff;
}

.btn.btn-dark:hover {
  background: #070b11;
}

.role-badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  border-radius: 999px;
  padding: 3px 8px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.role-badge.admin {
  background: #1b2027;
}

.role-badge.user {
  background: #1677ff;
}

.status-badge.active {
  background: #12845b;
}

.status-badge.disabled {
  background: #667085;
}

.admin-note {
  margin: 0;
  font-size: 14px;
}

.admin-section-label {
  margin: 6px 0 0;
  color: #475467;
  font-size: 13px;
  font-weight: 700;
}

.domain-check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 11px 36px;
}

.domain-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.domain-check input {
  width: 16px;
  min-height: 16px;
  accent-color: #1677ff;
}

.domain-check span {
  overflow-wrap: anywhere;
}

.chart-shell {
  height: 360px;
}

.report-shell {
  width: min(1296px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0;
}

.report-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.domain-picker {
  display: flex;
  align-items: center;
  gap: 10px;
}

.domain-picker select {
  min-width: 280px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.report-title {
  margin-bottom: 16px;
}

.report-filters {
  margin-bottom: 16px;
}

.modern-card {
  border: var(--border-soft);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-soft);
}

.filter-grid {
  display: grid;
  grid-template-columns: 155px 155px 180px 1fr 125px 125px;
  gap: 14px;
  align-items: end;
}

.filter-card-body {
  display: grid;
  grid-template-columns: minmax(430px, 1fr) minmax(420px, .82fr);
  gap: 18px;
  align-items: end;
}

.range-form {
  display: grid;
  grid-template-columns: 155px 155px 180px;
  gap: 10px;
  align-items: end;
}

.range-form .quick-ranges {
  grid-column: 1 / -1;
}

.client-filter-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 125px 150px;
  gap: 10px;
  align-items: end;
}

.field.compact input {
  min-height: 32px;
}

.quick-ranges {
  display: flex;
  align-items: center;
  gap: 6px;
  grid-column: 1 / 4;
}

.quick-ranges .btn {
  min-height: 32px;
  padding: 5px 9px;
}

.btn.dark {
  background: #111827;
}

.btn.secondary.active {
  border-color: #111827;
  color: #111827;
}

.no-margin {
  margin-top: 0;
}

.filter-count {
  margin: 10px 0 0;
  text-align: right;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.chart-panel {
  padding: 0;
  overflow: hidden;
}

.chart-panel h2,
.matrix-head {
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  margin: 0;
}

.chart-panel .chart-shell {
  height: 274px;
  padding: 16px;
}

.matrix-panel {
  padding: 0;
}

.matrix-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}

.legend b {
  display: inline-flex;
  min-width: 22px;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 5px;
  color: var(--ink);
  background: #f8fafc;
}

.matrix-wrap {
  max-height: 70vh;
  overflow: auto;
  padding: 0;
  border-radius: var(--card-radius);
  background: #fff;
  border: var(--border-soft);
  margin: 16px;
}

.matrix-table {
  min-width: 1180px;
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 0;
}

.matrix-table th,
.matrix-table td {
  border-right: 1px solid rgba(148,163,184,.35);
  border-bottom: 1px solid rgba(148,163,184,.25);
  padding: 6px 8px;
  text-align: center;
  white-space: nowrap;
  vertical-align: middle;
  background: #fff;
}

.matrix-table tbody tr:nth-child(odd) td {
  background: #fbfcff;
}

.matrix-table tbody tr:nth-child(odd) td.month-alt,
.matrix-table td.month-alt,
.matrix-table th.month-alt {
  background: var(--month-alt) !important;
}

.matrix-table thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  color: #000;
  height: 36px;
}

.matrix-table thead tr:nth-child(2) th {
  top: 36px;
  z-index: 19;
  height: 32px;
  border-bottom: 2px solid rgba(148,163,184,.5);
}

.seq-cell {
  min-width: 50px;
  text-align: center;
}

.url-cell {
  min-width: 520px;
  max-width: 900px;
  text-align: left;
  white-space: normal;
  word-break: break-word;
}

.type-cell {
  min-width: 96px;
  text-align: center;
}

.trend-cell {
  min-width: 68px;
  text-align: center;
}

.metric {
  min-width: 56px;
  text-align: center;
}

.sticky-seq {
  position: sticky;
  left: 0;
  z-index: 8;
}

.sticky-url {
  position: sticky;
  left: 50px;
  z-index: 8;
}

.sticky-type {
  position: sticky;
  left: 570px;
  z-index: 8;
}

.sticky-trend {
  position: sticky;
  left: 666px;
  z-index: 8;
}

thead .sticky-seq,
thead .sticky-url,
thead .sticky-type,
thead .sticky-trend {
  z-index: 30;
}

.month-alt {
  background: var(--month-alt) !important;
}

.month-start-visible {
  border-left: 2px solid rgba(148,163,184,.65) !important;
}

.matrix-table .month-head {
  background: #f8fafc;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #1a73e8;
  color: #fff;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
}

.trend-icon,
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 34px;
  height: 30px;
  padding: 0;
  background: #fff;
  color: var(--primary);
  font-size: 11px;
  cursor: pointer;
}

.trend-modal[hidden] {
  display: none;
}

.trend-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
}

.trend-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,.5);
}

.trend-dialog {
  position: relative;
  width: min(980px, calc(100% - 36px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  margin: 18px auto;
  background: #fff;
  border-radius: var(--card-radius);
  padding: 18px;
  box-shadow: 0 24px 80px rgba(15,23,42,.28);
}

.trend-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.trend-head h2 {
  margin-bottom: 4px;
}

.trend-head p {
  margin: 0;
  word-break: break-word;
}

.trend-table-wrap {
  border: var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 12px;
}

.trend-table-wrap th,
.trend-table-wrap td {
  padding: 8px 10px;
}

@media print {
  .no-print {
    display: none !important;
  }

  body {
    background: #fff !important;
  }

  .matrix-wrap {
    max-height: none !important;
    overflow: visible !important;
    border: none !important;
  }
}

@media (max-width: 860px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .main {
    margin-left: 0;
    padding: 20px;
  }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .grid.stats,
  .form-grid,
  .chart-grid,
  .filter-grid,
  .filter-card-body,
  .range-form,
  .client-filter-grid {
    grid-template-columns: 1fr;
  }

  .report-topbar,
  .admin-user-head,
  .matrix-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-user-grid,
  .admin-user-grid.edit-grid,
  .admin-two-col,
  .domain-check-grid {
    grid-template-columns: 1fr;
  }

  .admin-user-shell,
  .admin-user-shell.edit {
    width: min(100% - 24px, 1296px);
  }

  .admin-user-actions {
    justify-content: flex-start;
  }

  .quick-ranges {
    grid-column: auto;
    flex-wrap: wrap;
  }
}
