:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --border: #dfe4e7;
  --text: #182126;
  --muted: #65747c;
  --accent: #0f6b54;
  --accent-dark: #0a4d3d;
  --danger: #b42318;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: inherit; }
button, input, select { font: inherit; }
button { border: 0; border-radius: 6px; background: var(--accent); color: white; min-height: 38px; padding: 0 16px; cursor: pointer; }
button:hover { background: var(--accent-dark); }
input, select { min-height: 38px; border: 1px solid var(--border); border-radius: 6px; background: white; padding: 0 10px; color: var(--text); }
label { display: grid; gap: 6px; color: var(--muted); font-weight: 600; }
h1, h2, p { margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }

.topbar { min-height: 58px; padding: 0 28px; border-bottom: 1px solid var(--border); background: var(--surface); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.topbar nav { display: flex; height: 58px; }
.topbar nav a { display: grid; place-items: center; padding: 0 18px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.topbar nav a[aria-current="page"] { color: var(--text); border-color: var(--accent); }
.topbar form { justify-self: end; }
.brand { font-size: 18px; font-weight: 750; color: var(--accent-dark); text-decoration: none; }
.quiet { background: transparent; color: var(--muted); padding: 0 8px; }
.quiet:hover { background: #edf1f2; color: var(--text); }

.page { width: min(1180px, calc(100% - 40px)); margin: 30px auto 60px; }
.page.wide { width: min(1720px, calc(100% - 40px)); }
.page-heading, .section-heading { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.page-heading { margin-bottom: 24px; }
.page-heading p { color: var(--muted); margin-top: 5px; }
.section-heading { margin: 30px 0 12px; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border); background: var(--surface); }
.metrics div { min-height: 94px; padding: 18px; border-right: 1px solid var(--border); display: grid; align-content: space-between; }
.metrics div:last-child { border-right: 0; }
.metrics span { color: var(--muted); }
.metrics strong { font-size: 20px; font-weight: 700; }
.danger { color: var(--danger); }
.level { display: inline-block; border-radius: 4px; padding: 3px 7px; font-size: 12px; font-weight: 700; }
.level.INFO { background: #e5f5ef; color: #126348; }
.level.ERROR { background: #feeceb; color: var(--danger); }
.level.WARN { background: #fff4d6; color: #7a4b00; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: #f8fafb; color: var(--muted); font-size: 12px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.online-recent { background: #cbe3b9; }
.client-name { display: flex; align-items: center; gap: 10px; }
.presence { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; padding: 4px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; line-height: 1; }
.presence.online { background: #f6feeb; color: #489024; }
.presence.offline { background: #f3f3f3; color: #1e1e1e; }
.presence-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: #85ca5c; animation: presence-pulse 1.8s ease-in-out infinite; }
@keyframes presence-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .15; transform: scale(.7); }
}
.empty { text-align: center; color: var(--muted); padding: 36px; }
.logs-table td { vertical-align: top; }
.logs-table td:nth-child(5) { white-space: normal; min-width: 220px; overflow-wrap: anywhere; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.filters { display: flex; gap: 12px; align-items: end; margin-bottom: 14px; }
.filters label { min-width: 150px; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 16px; padding: 20px; color: var(--muted); }
.pagination a { color: var(--accent); }
.danger-button { background: var(--danger); }
.danger-button:hover { background: #8e1b12; }

.auth-page { min-height: 100vh; display: grid; place-items: center; }
.auth-shell { width: min(380px, calc(100% - 32px)); }
.auth-shell > .brand { margin-bottom: 18px; display: block; }
.auth-form { display: grid; gap: 16px; padding: 28px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; }
.auth-form h1 { font-size: 20px; }
.alert { padding: 10px 12px; background: #feeceb; color: var(--danger); border-radius: 6px; }
.date-controls { display: flex; align-items: end; gap: 8px; }
.date-controls input { width: 150px; }
.icon-button, .today-link { min-height: 38px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); text-decoration: none; display: grid; place-items: center; }
.icon-button { width: 38px; font-size: 18px; }
.icon-button:hover, .today-link:hover { border-color: #b9c4c9; background: #edf1f2; }
.icon-button.disabled { color: #aab4b9; background: #f4f6f7; }
.today-link { padding: 0 13px; color: var(--accent); font-weight: 700; }
.presence-chart { width: 100%; height: clamp(460px, 62vh, 720px); border: 1px solid var(--border); background: var(--surface); }
.chart-empty { min-height: 360px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); display: grid; place-items: center; }
.activity-controls { display: flex; align-items: end; gap: 12px; }
.activity-controls label { min-width: 180px; }
.range-control { display: flex; }
.range-control button { border: 1px solid var(--border); border-right: 0; border-radius: 0; background: var(--surface); color: var(--muted); padding: 0 13px; }
.range-control button:first-child { border-radius: 6px 0 0 6px; }
.range-control button:last-child { border-right: 1px solid var(--border); border-radius: 0 6px 6px 0; }
.range-control button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: white; }
.activity-legend { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.activity-legend span { display: inline-flex; align-items: center; gap: 7px; }
.activity-swatch { width: 18px; height: 13px; border: 1px solid #d8dee1; display: inline-block; }
.activity-swatch.missing { background: #f5f7f8; }
.activity-swatch.offline { background: #e2e7e9; }
.activity-swatch.light { background: #dff0d4; }
.activity-swatch.medium { background: #9fd27c; }
.activity-swatch.heavy { background: #4f9f35; }
.activity-chart { width: 100%; min-height: 420px; border: 1px solid var(--border); background: var(--surface); }

@media (prefers-reduced-motion: reduce) {
  .presence-dot { animation: none; }
}

@media (max-width: 760px) {
  .topbar { padding: 0 14px; grid-template-columns: 1fr auto; }
  .topbar .brand, .topbar form { margin-top: 8px; }
  .topbar nav { grid-column: 1 / -1; grid-row: 2; justify-content: center; height: 46px; }
  .topbar nav a { padding: 0 9px; font-size: 13px; }
  .page { width: min(100% - 24px, 1180px); margin-top: 20px; }
  .page.wide { width: min(100% - 24px, 1720px); }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics div:nth-child(2) { border-right: 0; }
  .metrics div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .filters { align-items: stretch; flex-direction: column; }
  .page-heading { align-items: flex-start; }
  .presence-heading { align-items: stretch; flex-direction: column; }
  .activity-heading { align-items: stretch; flex-direction: column; }
  .activity-controls { align-items: stretch; flex-direction: column; }
  .activity-controls label { min-width: 0; }
  .range-control button { flex: 1; }
  .date-controls { align-items: center; }
  .presence-chart { height: 520px; }
}
