:root {
  --bg: #0f1218;
  --panel: #171c26;
  --panel-2: #1e2432;
  --border: #262d3d;
  --fg: #e8ebf1;
  --muted: #8b93a5;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --green: #22c55e;
}

* { box-sizing: border-box; }

/* Το hidden πρέπει να νικάει οποιοδήποτε display (flex/grid) των στοιχείων */
[hidden] { display: none !important; }

body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- Sidebar ---------- */

#sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { font-size: 17px; font-weight: 700; padding: 4px 8px; }

#site-filter {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
#site-filter:focus { border-color: var(--accent); }

#site-list { display: flex; flex-direction: column; gap: 2px; }

.site-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--fg);
  padding: 8px 10px;
  font-size: 13.5px;
  cursor: pointer;
}
.site-btn .domain { display: block; font-size: 11px; color: var(--muted); }
.site-btn:hover { background: var(--panel-2); }
.site-btn.active { background: var(--accent-soft); color: #93c5fd; }
.site-btn.active .domain { color: #93c5fd99; }

/* ---------- Main ---------- */

#main { flex: 1; padding: 20px 28px; min-width: 0; }

#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
#topbar h1 { margin: 0; font-size: 20px; display: inline; }
.muted { color: var(--muted); font-size: 13px; margin-left: 8px; }

.badge {
  margin-left: 14px;
  font-size: 12px;
  color: var(--green);
  background: rgba(34, 197, 94, 0.12);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.dot {
  display: inline-block;
  width: 7px; height: 7px;
  background: var(--green);
  border-radius: 50%;
  margin-right: 5px;
  animation: pulse 1.6s infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

#period-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
#period-buttons button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 13px;
  cursor: pointer;
}
#period-buttons button:hover { color: var(--fg); }
#period-buttons button.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #93c5fd;
}

/* ---------- Cards ---------- */

#cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.card .num { font-size: 24px; font-weight: 700; }
.card .cap { font-size: 12px; color: var(--muted); margin-top: 3px; }
.card .delta { font-size: 11.5px; margin-top: 4px; }
.delta.up { color: var(--green); }
.delta.down { color: #f87171; }
.delta.flat { color: var(--muted); }

/* ---------- Panels / Lists ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 20px;
}
.panel h2 { margin: 0 0 12px; font-size: 14px; color: var(--muted); font-weight: 600; }

.chart-wrap { height: 260px; }

#lists {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.metric-list ul { list-style: none; margin: 0; padding: 0; }
.metric-list li {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 9px;
  font-size: 13px;
  border-radius: 6px;
  overflow: hidden;
}
.metric-list .bar {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent-soft);
  border-radius: 6px;
}
.metric-list .label {
  position: relative;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.metric-list .value { position: relative; font-weight: 600; flex-shrink: 0; }
.metric-list .pct { color: var(--muted); font-weight: 400; font-size: 11.5px; margin-left: 4px; }

/* ---------- Login ---------- */

.login-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
}
.login-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(320px, 90vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
}
.login-box .brand { text-align: center; font-size: 20px; margin-bottom: 8px; }
.login-box input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.login-box button:hover { filter: brightness(1.1); }
.login-box button:disabled { opacity: 0.6; cursor: wait; }
.login-error { color: #f87171; font-size: 13px; text-align: center; }

#user-box {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 8px 2px;
  border-top: 1px solid var(--border);
}
.user-name { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
#logout-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
#logout-btn:hover { color: var(--fg); border-color: var(--muted); }

/* ---------- States ---------- */

.center-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}
.error { color: #f87171; }
.loading { color: var(--muted); font-size: 13px; padding: 8px; }

@media (max-width: 700px) {
  body { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: static; }
}
