/* ================================================================
   Ecolyxis Admin Dashboard — Full Stylesheet
   ================================================================ */

/* ── Reset & Variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --bg-card:     #1a1d27;
  --bg-sidebar:  #141620;
  --text:        #e2e8f0;
  --text-dim:    #8892a4;
  --border:      #2d3348;
  --accent:      #34d399;
  --red:         #f87171;
  --amber:       #fbbf24;
  --blue:        #3b82f6;
  --purple:      #a78bfa;
  --radius:      8px;
  --sidebar-w:   220px;
  --topbar-h:    52px;
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono:   'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
}

/* Light theme overrides */
[data-theme="light"] {
  --bg:          #f5f6f8;
  --bg-card:     #ffffff;
  --bg-sidebar:  #ebedf0;
  --text:        #1a202c;
  --text-dim:    #64748b;
  --border:      #d1d9e0;
  --accent:      #059669;
  --red:         #dc2626;
  --amber:       #d97706;
  --blue:        #2563eb;
  --purple:      #7c3aed;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto; z-index: 100;
  display: flex; flex-direction: column;
}
.sidebar-brand {
  padding: 16px 20px; font-size: 18px; font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand a { color: var(--text); text-decoration: none; }
.sidebar-section { padding: 12px 0; }
.sidebar-section + .sidebar-section { border-top: 1px solid var(--border); }
.sidebar-label {
  padding: 4px 20px 6px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim);
}
.sidebar-link {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 20px; color: var(--text-dim);
  font-size: 13px; transition: all .15s;
  text-decoration: none; position: relative;
}
.sidebar-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.sidebar-link.active {
  color: var(--text); background: rgba(52,211,153,0.08);
  border-right: 3px solid var(--accent);
}

/* ── Live Dot ──────────────────────────────────────────────────── */
.live-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; vertical-align: middle; margin-left: 4px;
}
.live-on  { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.live-off { background: var(--red);    box-shadow: 0 0 6px var(--red); }

/* ── Main Layout ───────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.content {
  flex: 1; padding: 20px 24px 40px;
  max-width: 1400px;
}

/* ── Sections & Grids ──────────────────────────────────────────── */
.admin-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.admin-section h2 {
  font-size: 15px; font-weight: 600;
  margin-bottom: 16px; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.admin-grid        { display: grid; gap: 12px; }
.admin-grid-2      { grid-template-columns: repeat(2, 1fr); }
.admin-grid-3      { grid-template-columns: repeat(3, 1fr); }
.admin-grid-4      { grid-template-columns: repeat(4, 1fr); }
.admin-grid-5      { grid-template-columns: repeat(5, 1fr); }
.admin-grid-6      { grid-template-columns: repeat(6, 1fr); }

/* ── Stat Cards ────────────────────────────────────────────────── */
.stat-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-card.highlight { border-color: var(--accent); border-width: 1px; }
.stat-card.error-card { border-color: var(--red); background: rgba(248,113,113,0.06); }
.stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 22px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat-sub   { font-size: 11px; color: var(--text-dim); }
.stat-bar   { height: 6px; background: var(--border); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 3px; transition: width .5s ease; }
.admin-meta  { font-size: 12px; color: var(--text-dim); margin-top: 12px; }

/* ── Tables ─────────────────────────────────────────────────────── */
.admin-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.admin-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.admin-table th {
  text-align: left; padding: 8px 10px;
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap; user-select: none;
}
.admin-table td {
  padding: 7px 10px; border-bottom: 1px solid var(--border);
  max-width: 300px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-table tr:hover td { background: rgba(255,255,255,0.02); }
.admin-table .mono { font-family: var(--font-mono); font-size: 12px; }
.sort-asc::after  { content: ' ▲'; font-size: 10px; color: var(--accent); }
.sort-desc::after { content: ' ▼'; font-size: 10px; color: var(--accent); }

/* ── Search Input ───────────────────────────────────────────────── */
.admin-search {
  width: 100%; max-width: 360px;
  padding: 8px 12px; margin-bottom: 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 13px; outline: none;
}
.admin-search:focus { border-color: var(--accent); }
.admin-search::placeholder { color: var(--text-dim); }

/* ── Pagination ─────────────────────────────────────────────────── */
.admin-pagination {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim); flex-wrap: wrap; gap: 8px;
}
.pg-controls { display: flex; gap: 4px; flex-wrap: wrap; }
.pg-btn {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); padding: 4px 10px; border-radius: 4px;
  cursor: pointer; font-size: 12px;
}
.pg-btn:hover { border-color: var(--accent); }
.pg-btn:disabled { opacity: 0.4; cursor: default; }
.pg-btn.pg-active { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.pg-ellipsis { padding: 4px 6px; color: var(--text-dim); }

/* ── Tabs ───────────────────────────────────────────────────────── */
.admin-tabs {
  display: flex; gap: 0; border-bottom: 2px solid var(--border);
  margin-bottom: 20px; overflow-x: auto;
}
.admin-tab {
  padding: 10px 18px; cursor: pointer; font-size: 13px;
  color: var(--text-dim); border-bottom: 2px solid transparent;
  margin-bottom: -2px; white-space: nowrap;
  background: none; border-top: none; border-left: none; border-right: none;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Tier Badges ────────────────────────────────────────────────── */
.tier-badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; text-transform: capitalize;
}
.tier-free     { background: rgba(52,211,153,0.15); color: var(--accent); }
.tier-premium  { background: rgba(59,130,246,0.15); color: var(--blue); }

/* ── Role Badges ────────────────────────────────────────────────── */
.role-user, .role-assistant {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}
.role-user       { background: rgba(59,130,246,0.15); color: var(--blue); }
.role-assistant  { background: rgba(167,139,250,0.15); color: var(--purple); }

/* ── Message Preview ────────────────────────────────────────────── */
.msg-preview {
  max-width: 300px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 12px; color: var(--text-dim);
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  padding: 6px 14px; border-radius: var(--radius);
  font-size: 13px; cursor: pointer; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { opacity: 0.85; }

/* ── Test Cards ─────────────────────────────────────────────────── */
.test-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 8px;
  background: var(--bg);
}
.test-pass { border-left: 3px solid var(--accent); }
.test-fail { border-left: 3px solid var(--red); }
.test-skip { border-left: 3px solid var(--amber); }
.test-header { display: flex; align-items: center; gap: 8px; }
.test-name { font-weight: 600; flex: 1; }
.test-icon { font-size: 16px; }
.test-badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.test-badge-passed  { background: rgba(52,211,153,0.15); color: var(--accent); }
.test-badge-failed  { background: rgba(248,113,113,0.15); color: var(--red); }
.test-badge-skipped { background: rgba(251,191,36,0.15); color: var(--amber); }
.test-duration { font-size: 12px; color: var(--text-dim); }
.test-error { margin-top: 8px; }
.test-error pre {
  background: var(--bg); padding: 10px; border-radius: 4px;
  font-size: 12px; overflow-x: auto; color: var(--red);
  font-family: var(--font-mono);
}

/* ── Alerts Banner ──────────────────────────────────────────────── */
.alert-banner {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 20px;
}
.alert-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius);
  font-size: 13px;
}
.alert-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.alert-text { flex: 1; }
.alert-error { background: rgba(248,113,113,0.1); border: 1px solid rgba(248,113,113,0.3); }
.alert-warn  { background: rgba(251,191,36,0.1);  border: 1px solid rgba(251,191,36,0.3); }
.alert-info  { background: rgba(59,130,246,0.1);   border: 1px solid rgba(59,130,246,0.3); }

/* ── WireGuard Peer Grid ───────────────────────────────────────── */
.wg-peer-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.wg-peer-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
  border-left: 3px solid var(--border);
  transition: border-color .2s;
}
.wg-peer-card.wg-online  { border-left-color: var(--accent); }
.wg-peer-card.wg-offline { border-left-color: var(--red); }
.wg-peer-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.wg-peer-ip { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.wg-peer-detail { font-size: 11px; color: var(--text-dim); }
.wg-peer-detail span { display: block; }

/* ── Replication Section ────────────────────────────────────────── */
.repl-status-card {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 20px; border-radius: var(--radius);
  background: var(--bg); border: 1px solid var(--border);
}
.repl-status-card.repl-healthy { border-color: var(--accent); }
.repl-status-card.repl-down    { border-color: var(--red); background: rgba(248,113,113,0.04); }
.repl-big-status { font-size: 28px; }
.repl-big-label  { font-size: 18px; font-weight: 700; }
.repl-topo { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

/* ── GPU Card Styles ────────────────────────────────────────────── */
.gpu-panel {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.gpu-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.gpu-name { font-size: 16px; font-weight: 700; }
.gpu-ip { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); }
.gpu-status-badge {
  padding: 3px 10px; border-radius: 10px; font-size: 11px;
  font-weight: 600; text-transform: capitalize;
}
.gpu-status-active  { background: rgba(52,211,153,0.15); color: var(--accent); }
.gpu-status-inactive { background: rgba(248,113,113,0.15); color: var(--red); }
.gpu-status-unknown  { background: rgba(251,191,36,0.15); color: var(--amber); }

.gpu-temp-gauge { text-align: center; margin: 12px 0; }
.gpu-temp-arc { max-width: 160px; }
.gpu-temp-value {
  font-size: 28px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.gpu-temp-label { font-size: 12px; color: var(--text-dim); }

.gpu-processes { margin-top: 12px; }
.gpu-processes h4 { font-size: 12px; color: var(--text-dim); text-transform: uppercase; margin-bottom: 6px; }

/* ── Chart Wrap ─────────────────────────────────────────────────── */
.chart-wrap {
  position: relative; height: 250px;
  background: var(--bg); border-radius: var(--radius);
  padding: 8px;
}

/* ── Toggle Switch ──────────────────────────────────────────────── */
.toggle-switch {
  position: relative; display: inline-block;
  width: 36px; height: 20px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border); border-radius: 20px;
  transition: .2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  height: 14px; width: 14px;
  left: 3px; bottom: 3px;
  background: var(--text); border-radius: 50%;
  transition: .2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Flash Messages ─────────────────────────────────────────────── */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; }
.flash-success { background: rgba(52,211,153,0.15); color: var(--accent); }
.flash-error   { background: rgba(248,113,113,0.15); color: var(--red); }
.flash-info    { background: rgba(59,130,246,0.15); color: var(--blue); }

/* ── Service Cards ──────────────────────────────────────────────── */
.service-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.service-name { font-weight: 600; font-size: 13px; flex: 1; }
.service-status { font-size: 12px; color: var(--text-dim); text-transform: capitalize; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .admin-grid-6 { grid-template-columns: repeat(3, 1fr); }
  .admin-grid-5 { grid-template-columns: repeat(3, 1fr); }
  .admin-grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .admin-grid-6, .admin-grid-5, .admin-grid-4, .admin-grid-3 { grid-template-columns: repeat(2, 1fr); }
  .admin-grid-2 { grid-template-columns: 1fr; }
  .content { padding: 14px; }
  .stat-value { font-size: 18px; }
  .wg-peer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .admin-grid-6, .admin-grid-5, .admin-grid-4, .admin-grid-3, .admin-grid-2 { grid-template-columns: 1fr; }
  .wg-peer-grid { grid-template-columns: 1fr; }
}
