/* ── Variables ─────────────────────────────────────────────────── */
:root {
  --bg:       #0d0f14;
  --surface:  #13161d;
  --surface2: #1a1e27;
  --border:   #252a36;
  --border2:  #2e3444;
  --accent:   #e8ff47;
  --accent2:  #47c2ff;
  --accent3:  #ff6b47;
  --text:     #eef0f5;
  --text2:    #8b90a0;
  --text3:    #555b6e;
  --green:    #4dffb4;
  --red:      #ff4d6a;
  --mono:     'Space Mono', monospace;
  --sans:     'DM Sans', sans-serif;
  --radius:   8px;
  --radius-lg:14px;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── App shell ─────────────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Topbar ────────────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.topbar-logo {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .04em;
}
.topbar-logo span { color: var(--text2); font-weight: 400; }
.topbar-spacer { flex: 1; }

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2.5s infinite;
}
.status-dot.off { background: var(--text3); box-shadow: none; animation: none; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

.status-label { font-size: 12px; color: var(--text2); font-family: var(--mono); }

.topbar-btn {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text2);
  font-family: var(--sans);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.topbar-btn:hover { border-color: var(--accent); color: var(--accent); }
.topbar-btn.danger:hover { border-color: var(--red); color: var(--red); }

/* ── Countdown ring ────────────────────────────────────────────── */
.countdown-wrap {
  position: relative;
  width: 34px; height: 34px;
  flex-shrink: 0;
}
.countdown-wrap svg { transform: rotate(-90deg); }
.count-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  overflow-y: auto;
}
.nav-section {
  padding: 0 12px 6px;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text3);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-top: 16px;
}
.nav-section:first-child { margin-top: 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text2);
  font-size: 13px;
  transition: background .1s, color .1s;
  margin: 1px 8px;
  border-radius: var(--radius);
  user-select: none;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--accent); }
.nav-icon { font-size: 14px; width: 18px; text-align: center; }
.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-family: var(--mono);
  background: var(--accent);
  color: #000;
  padding: 1px 6px;
  border-radius: 20px;
  font-weight: 700;
}
.nav-badge.red { background: var(--red); color: #fff; }

/* ── Main area ─────────────────────────────────────────────────── */
.main {
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Panels ────────────────────────────────────────────────────── */
.panel { display: none; flex-direction: column; gap: 20px; }
.panel.visible { display: flex; }

/* ── Page header ───────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.page-title {
  font-family: var(--mono);
  font-size: 18px;
  color: var(--text);
  letter-spacing: -.02em;
}
.page-subtitle {
  font-size: 12px;
  color: var(--text3);
  font-family: var(--mono);
  margin-top: 2px;
}

/* ── Stat cards ────────────────────────────────────────────────── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.stat-label {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.stat-value {
  font-size: 24px;
  font-family: var(--mono);
  font-weight: 700;
  margin-top: 4px;
  color: var(--text);
}
.stat-value.accent { color: var(--accent); }
.stat-value.green  { color: var(--green); }
.stat-value.red    { color: var(--red); }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.card-title {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  letter-spacing: .02em;
}

/* ── Tables ────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text3);
  padding: 10px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th:last-child { text-align: right; }
td {
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
td.mono  { font-family: var(--mono); font-size: 12px; }
td.right { text-align: right; }
td.green { color: var(--green); font-family: var(--mono); }
td.red   { color: var(--red);   font-family: var(--mono); }
td.dim   { color: var(--text2); }

.item-name { font-weight: 500; color: var(--text); }
.item-id   { font-size: 10px; font-family: var(--mono); color: var(--text3); }

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 10px;
  font-family: var(--mono);
  padding: 3px 8px;
  border-radius: 20px;
  letter-spacing: .04em;
  text-transform: uppercase;
  font-weight: 700;
}
.badge-watching  { background: rgba(71,194,255,.12);  color: var(--accent2); border: 1px solid rgba(71,194,255,.25); }
.badge-triggered { background: rgba(255,77,106,.12);  color: var(--red);     border: 1px solid rgba(255,77,106,.25); animation: badge-flash 1.5s infinite; }
.badge-active    { background: rgba(77,255,180,.10);  color: var(--green);   border: 1px solid rgba(77,255,180,.20); }
.badge-cooldown  { background: rgba(232,255,71,.08);  color: var(--accent);  border: 1px solid rgba(232,255,71,.20); }
.badge-none      { background: transparent; color: var(--text3); border: 1px solid var(--border); }

@keyframes badge-flash { 0%,100%{opacity:1} 50%{opacity:.5} }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text2);
  font-family: var(--sans);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover          { border-color: var(--text2); color: var(--text); }
.btn.primary        { background: var(--accent); border-color: var(--accent); color: #000; font-weight: 600; }
.btn.primary:hover  { background: #f5ff80; border-color: #f5ff80; }
.btn.danger         { border-color: rgba(255,77,106,.3); color: var(--red); }
.btn.danger:hover   { background: rgba(255,77,106,.1); border-color: var(--red); }
.btn.small          { padding: 4px 10px; font-size: 11px; }

/* ── Form elements ─────────────────────────────────────────────── */
.input-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hint { margin-top: 8px; font-size: 11px; color: var(--text3); font-family: var(--mono); }

input[type="text"],
input[type="number"],
input[type="password"],
select {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  padding: 7px 12px;
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s;
  min-width: 0;
}
input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
select:focus { border-color: var(--accent); }

input::placeholder { color: var(--text3); }
select { cursor: pointer; }
select option { background: var(--surface2); }

/* ── Alert form ────────────────────────────────────────────────── */
.alert-form {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.form-row label { min-width: 120px; font-size: 12px; color: var(--text2); white-space: nowrap; }
.form-row input, .form-row select { flex: 1; min-width: 120px; }

/* ── Alert list items ──────────────────────────────────────────── */
.alert-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}
.alert-item:last-child { border-bottom: none; }
.alert-item-info { flex: 1; min-width: 0; }
.alert-item-name { font-weight: 500; font-size: 13px; }
.alert-item-rule { font-size: 11px; font-family: var(--mono); color: var(--text3); margin-top: 3px; }
.alert-item-meta { font-size: 11px; color: var(--text3); font-family: var(--mono); margin-top: 2px; }

/* ── Settings ──────────────────────────────────────────────────── */
.settings-section { display: flex; flex-direction: column; }
.setting-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.setting-row:last-child { border-bottom: none; }
.setting-info { flex: 1; min-width: 160px; }
.setting-label { font-size: 13px; font-weight: 500; }
.setting-desc  { font-size: 11px; color: var(--text3); margin-top: 3px; font-family: var(--mono); }

/* ── Toggle ────────────────────────────────────────────────────── */
.toggle {
  position: relative;
  width: 38px; height: 20px;
  background: var(--border2);
  border-radius: 20px;
  transition: background .2s;
  flex-shrink: 0;
  cursor: pointer;
  border: none;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text3);
  transition: transform .2s, background .2s;
}
.toggle.on { background: rgba(232,255,71,.2); }
.toggle.on::after { transform: translateX(18px); background: var(--accent); }

/* ── Activity log ──────────────────────────────────────────────── */
.log-area {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text2);
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 12px 14px;
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.log-entry     { display: flex; gap: 10px; }
.log-time      { color: var(--text3); flex-shrink: 0; }
.log-msg       { color: var(--text2); }
.log-msg.ok    { color: var(--green); }
.log-msg.warn  { color: var(--accent); }
.log-msg.err   { color: var(--red); }
.log-msg.notif { color: var(--accent2); }

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text3);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 2;
}

/* ── Toast notifications ───────────────────────────────────────── */
#toast-wrap {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text);
  max-width: 280px;
  animation: toast-in .2s ease;
  pointer-events: auto;
}
.toast.ok    { border-color: rgba(77,255,180,.3); }
.toast.err   { border-color: rgba(255,77,106,.3); color: var(--red); }
.toast.notif { border-color: rgba(71,194,255,.3); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 52px auto 1fr;
  }
  .sidebar {
    grid-row: 2;
    display: flex;
    flex-direction: row;
    padding: 8px;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .nav-section { display: none; }
  .nav-item {
    flex-direction: column;
    gap: 3px;
    font-size: 10px;
    padding: 6px 10px;
    min-width: 60px;
    text-align: center;
  }
  .nav-badge { margin: 0; }
  .stat-row  { grid-template-columns: 1fr 1fr; }
  .main      { padding: 14px; }
}
