/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --border:   #30363d;
  --text:     #c9d1d9;
  --muted:    #8b949e;
  --green:    #3fb950;
  --yellow:   #d29922;
  --red:      #f85149;
  --blue:     #58a6ff;
  --radius:   6px;
  --gap:      12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  min-height: 100vh;
}

/* ── Header ────────────────────────────────────────────── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
header h1 { font-size: 18px; font-weight: 600; }
#updated { color: var(--muted); font-size: 12px; }

/* ── Sections ──────────────────────────────────────────── */
section { margin-bottom: 24px; }
h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Stat cards ────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--gap);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card.alert { border-left: 3px solid var(--red); }

.label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.value.small { font-size: 13px; font-weight: 400; line-height: 1.5; }

.value.ok    { color: var(--green); }
.value.warn  { color: var(--yellow); }
.value.err   { color: var(--red); }

/* ── Tables ────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 500; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.03); }

/* ── Log tail ──────────────────────────────────────────── */
.logs-toolbar select {
  appearance: none;
  background: rgba(12, 18, 26, 0.85);
  border: 1px solid rgba(88, 166, 255, 0.4);
  color: #d7e5f8;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.logs-panel {
  min-height: calc(100vh - 170px);
}

.logs-shell {
  height: calc(100vh - 190px);
  margin-bottom: 0;
  border: 1px solid rgba(88, 166, 255, 0.22);
  border-radius: 10px;
  background:
    radial-gradient(circle at 0% 0%, rgba(56, 189, 248, 0.11) 0%, rgba(13, 17, 23, 0) 45%),
    radial-gradient(circle at 100% 100%, rgba(59, 130, 246, 0.09) 0%, rgba(13, 17, 23, 0) 42%),
    #0b1017;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.logs-title {
  margin-bottom: 0;
  justify-content: space-between;
  color: #c4d5ea;
  letter-spacing: 0.08em;
}

.tail-state {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
}

.tail-state.live {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.5);
  box-shadow: inset 0 0 16px rgba(34, 197, 94, 0.1);
}

.tail-state.paused {
  color: #facc15;
  border-color: rgba(250, 204, 21, 0.55);
  box-shadow: inset 0 0 16px rgba(250, 204, 21, 0.08);
}

.logs-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tail-btn {
  border: 1px solid rgba(88, 166, 255, 0.5);
  background: linear-gradient(180deg, rgba(88, 166, 255, 0.22), rgba(13, 17, 23, 0.35));
  color: #dbeafe;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.tail-btn:hover {
  border-color: rgba(125, 211, 252, 0.75);
}

.tail-level-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid rgba(88, 166, 255, 0.35);
  border-radius: 8px;
  background: rgba(6, 12, 20, 0.7);
}

.tail-level-btn {
  border: 1px solid transparent;
  background: transparent;
  color: #8aa0bc;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  cursor: pointer;
}

.tail-level-btn:hover {
  color: #dbeafe;
  background: rgba(56, 189, 248, 0.12);
}

.tail-level-btn.active {
  color: #dbeafe;
  border-color: rgba(125, 211, 252, 0.55);
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.35), rgba(13, 17, 23, 0.25));
  box-shadow: inset 0 0 14px rgba(96, 165, 250, 0.2);
}

.tail-pending {
  min-width: 56px;
  color: #facc15;
  font-size: 12px;
}

.tail-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

.tail-toggle input {
  accent-color: var(--blue);
}

#tail-box {
  background: linear-gradient(180deg, rgba(11, 16, 23, 0.9), rgba(12, 18, 26, 0.96));
  border: 1px solid rgba(88, 166, 255, 0.25);
  border-radius: var(--radius);
  padding: 10px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
}

#tail-box::-webkit-scrollbar {
  width: 10px;
}

#tail-box::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.28);
  border-radius: 999px;
}

.log-line { display: flex; gap: 10px; }
.log-line .ts   { color: var(--muted); flex-shrink: 0; }
.log-line .ns   { color: var(--blue);  flex-shrink: 0; min-width: 90px; }
.log-line .lvl  { flex-shrink: 0; width: 36px; font-weight: 600; }
.log-line .msg  { color: var(--text); word-break: break-all; }

.tail-empty {
  color: #94a3b8;
  font-size: 12px;
  padding: 10px 4px;
}

.lvl.error, .lvl.fatal, .lvl.panic { color: var(--red); }
.lvl.warn, .lvl.warning            { color: var(--yellow); }
.lvl.info                          { color: var(--green); }

.ansi-bold { font-weight: 700; }
.ansi-black { color: #4b5563; }
.ansi-red { color: #f87171; }
.ansi-green { color: #4ade80; }
.ansi-yellow { color: #facc15; }
.ansi-blue { color: #60a5fa; }
.ansi-magenta { color: #e879f9; }
.ansi-cyan { color: #22d3ee; }
.ansi-white { color: #e5e7eb; }
.ansi-bright-black { color: #9ca3af; }
.ansi-bright-red { color: #ef4444; }
.ansi-bright-green { color: #22c55e; }
.ansi-bright-yellow { color: #fde047; }
.ansi-bright-blue { color: #3b82f6; }
.ansi-bright-magenta { color: #d946ef; }
.ansi-bright-cyan { color: #06b6d4; }
.ansi-bright-white { color: #ffffff; }

/* ── Badge ─────────────────────────────────────────────── */
.badge {
  background: var(--red);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 7px;
  font-weight: 600;
}
.badge:empty { display: none; }

/* -- Tabs -- */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-btn {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--text);
  border-color: var(--blue);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.trend-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.trend-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid rgba(88, 166, 255, 0.35);
  border-radius: 8px;
  background: rgba(6, 12, 20, 0.7);
}

.trend-btn {
  border: 1px solid transparent;
  background: transparent;
  color: #8aa0bc;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  cursor: pointer;
}

.trend-btn:hover {
  color: #dbeafe;
  background: rgba(56, 189, 248, 0.12);
}

.trend-btn.active {
  color: #dbeafe;
  border-color: rgba(125, 211, 252, 0.55);
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.35), rgba(13, 17, 23, 0.25));
}

.trend-field {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.trend-field select {
  appearance: none;
  background: rgba(12, 18, 26, 0.85);
  border: 1px solid rgba(88, 166, 255, 0.4);
  color: #d7e5f8;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  min-width: 180px;
}

.trend-status {
  color: var(--muted);
  font-size: 14px;
  margin-left: auto;
}

.trend-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--gap);
}

.trend-card .value {
  font-size: 34px;
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
}

.trend-chart-card {
  padding: 12px;
}

.trend-chart-card h2 {
  color: var(--text);
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: 16px;
  margin-bottom: 8px;
}

.trend-chart {
  width: 100%;
  height: 300px;
  border: 1px solid rgba(88, 166, 255, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(11, 16, 23, 0.95), rgba(12, 18, 26, 0.95)),
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.03) 0,
      rgba(255, 255, 255, 0.03) 1px,
      transparent 1px,
      transparent 44px
    );
}

.trend-axis {
  stroke: rgba(148, 163, 184, 0.3);
  stroke-width: 1;
}

.trend-path {
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trend-empty {
  fill: #94a3b8;
  font-size: 16px;
}

.trend-label {
  fill: #b7c0cb;
  font-size: 14px;
}

.trend-y-tick {
  text-anchor: end;
}

.trend-x-tick {
  text-anchor: middle;
}

.trend-gridline {
  stroke: rgba(148, 163, 184, 0.18);
  stroke-width: 1;
}

.trend-spike-note {
  font-size: 11px;
  color: var(--yellow);
  margin-top: 4px;
  min-height: 1em;
}

.trend-chart-note {
  font-size: 12px;
  font-weight: 400;
  color: var(--yellow);
  letter-spacing: 0;
  text-transform: none;
}

.trend-field-inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding-bottom: 2px;
  text-transform: none;
  font-size: 13px;
  letter-spacing: 0;
}

.trend-field-inline input {
  accent-color: var(--green);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

@media (max-width: 900px) {
  .logs-panel {
    min-height: calc(100vh - 184px);
  }

  .logs-shell {
    height: calc(100vh - 206px);
    padding: 10px;
  }

  .trend-status {
    width: 100%;
    margin-left: 0;
  }

  .trend-grid {
    grid-template-columns: 1fr;
  }

  .trend-chart {
    height: 240px;
  }
}

/* ── Visitors map tab ──────────────────────────────────── */
.visitors-map-section { margin-bottom: 24px; }

.visitors-map-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.visitors-map {
  display: block;
  width: 100%;
  height: auto;
}

/* SVG map elements */
.vis-sphere   { fill: #0a1628; }
.vis-graticule { fill: none; stroke: #1e2d42; stroke-width: .4px; }
.vis-country  { fill: #1a2535; stroke: none; }
.vis-borders  { fill: none; stroke: #2a3a50; stroke-width: .5px; }

/* Visitor dots */
.vis-dot { cursor: pointer; stroke-width: 1.5px; }
.vis-dot-human { fill: rgba(88,166,255,.25); }
.vis-dot-bot   { fill: var(--red); stroke: none !important; }

/* Great-circle arcs from visitor to server */
.vis-arc {
  fill: none;
  stroke-width: 1px;
  opacity: 0.35;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* Server marker */
.vis-server-pulse {
  fill: none;
  stroke: #fff;
  stroke-width: 1.5px;
  opacity: 0.5;
  animation: vis-pulse 2s ease-out infinite;
}
.vis-server-dot {
  fill: #fff;
}
.vis-server-label {
  fill: #cdd9e5;
  font-size: 10px;
  font-family: inherit;
  font-weight: 600;
}
@keyframes vis-pulse {
  0%   { r: 6px;  opacity: 0.6; }
  80%  { r: 14px; opacity: 0; }
  100% { r: 14px; opacity: 0; }
}

/* Service legend below map */
.visitors-service-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 6px 4px;
  font-size: 12px;
  color: var(--muted);
}
.vis-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.visitors-map-tip {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
}

.visitors-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  font-weight: 400;
}

.vis-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}
.vis-legend-dot.vis-dot-human { background: var(--blue); }
.vis-legend-dot.vis-dot-bot   { background: var(--red); }

.security-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.security-hero {
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  background: linear-gradient(135deg, rgba(88,166,255,.12), rgba(22,27,34,.95));
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
}

.security-hero-status {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 6px;
}

.security-hero-detail {
  color: var(--muted);
  font-size: 13px;
}

.security-hero-critical {
  border-left-color: var(--red);
  background: linear-gradient(135deg, rgba(248,81,73,.18), rgba(22,27,34,.96));
}

.security-hero-high {
  border-left-color: #ff7b72;
  background: linear-gradient(135deg, rgba(255,123,114,.16), rgba(22,27,34,.96));
}

.security-hero-medium {
  border-left-color: var(--yellow);
  background: linear-gradient(135deg, rgba(210,153,34,.15), rgba(22,27,34,.96));
}

.security-hero-ok {
  border-left-color: var(--green);
  background: linear-gradient(135deg, rgba(63,185,80,.14), rgba(22,27,34,.96));
}

.security-hero-neutral {
  border-left-color: var(--blue);
}

.severity-card .value {
  font-size: 36px;
}

.severity-critical .value {
  color: var(--red);
}

.severity-high .value {
  color: #ff7b72;
}

.severity-medium .value {
  color: var(--yellow);
}

.severity-low .value {
  color: var(--green);
}

.action-btn {
  background: var(--blue);
  color: #0d1117;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.action-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.security-status {
  color: var(--muted);
  font-size: 12px;
}

.warn-col { color: var(--yellow); }
.err-col { color: var(--red); }
.ok-col { color: var(--green); }

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}
