:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2f3f56;
  --text: #e8eef7;
  --muted: #8fa3bf;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
.hidden { display: none !important; }

.login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: radial-gradient(circle at top, #1e3a5f 0%, var(--bg) 55%);
}
.login-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem; box-shadow: var(--shadow);
}
.logo { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
.logo.compact { padding: 1.25rem 1rem 0.5rem; font-size: 1.2rem; }
.subtitle { color: var(--muted); margin: 0.25rem 0 1.5rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 1rem; }
code { background: var(--surface2); padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.85em; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; }
input, select, textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 0.65rem 0.75rem; margin-bottom: 0.85rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn {
  border: none; border-radius: 8px; padding: 0.55rem 1rem; cursor: pointer;
  font-weight: 600; font-size: 0.9rem; transition: 0.15s ease;
}
.btn.primary { background: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }
.btn.danger { background: var(--danger); color: white; }
.btn.small { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn.full { width: 100%; }

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 100vh;
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.5rem; flex: 1; }
.nav-item {
  text-align: left; background: transparent; border: none; color: var(--muted);
  padding: 0.7rem 0.85rem; border-radius: 8px; cursor: pointer; font-size: 0.95rem;
}
.nav-item:hover, .nav-item.active { background: var(--surface2); color: var(--text); }
.sidebar-footer { margin: 1rem; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.35rem; }
.view-content { padding: 1.5rem; overflow: auto; }

.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.stat-card .label { color: var(--muted); font-size: 0.85rem; }
.stat-card .value { font-size: 2rem; font-weight: 700; margin-top: 0.25rem; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin-top: 1rem;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.2rem; border-bottom: 1px solid var(--border);
}
.panel-header h2 { margin: 0; font-size: 1rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: rgba(255,255,255,0.02); }

.badge {
  display: inline-block; padding: 0.2rem 0.55rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
}
.badge.sent { background: rgba(34,197,94,0.15); color: var(--success); }
.badge.queued { background: rgba(59,130,246,0.15); color: var(--accent); }
.badge.failed { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge.pending { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge.enabled { background: rgba(34,197,94,0.15); color: var(--success); }
.badge.disabled { background: rgba(148,163,184,0.15); color: var(--muted); }

.tag-list { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 0.15rem 0.5rem; font-size: 0.78rem; color: var(--muted); }

.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.mono { font-family: ui-monospace, monospace; font-size: 0.82rem; word-break: break-all; }

.toast-area { position: fixed; top: 1rem; right: 1rem; z-index: 100; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.75rem 1rem; min-width: 240px; box-shadow: var(--shadow); animation: slideIn 0.2s ease;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

dialog {
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  color: var(--text); padding: 0; width: min(560px, 92vw); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
#modal-form { padding: 1.25rem; }
#modal-title { margin: 0 0 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

.empty { color: var(--muted); padding: 2rem; text-align: center; }
.webhook-url { background: var(--surface2); padding: 0.75rem; border-radius: 8px; margin: 0.5rem 0; }

.setup-header { margin-bottom: 1rem; }
.setup-progress { margin: 0.5rem 0 0; }
.setup-section { margin: 1rem 0; }
.setup-section h3 { font-size: 0.9rem; color: var(--muted); margin: 0 0 0.5rem; text-transform: uppercase; letter-spacing: 0.04em; }
.setup-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem 0.25rem; margin-bottom: 1rem; }
.setup-group legend { padding: 0 0.35rem; color: var(--muted); font-size: 0.85rem; }
.setup-checklist { margin: 0; padding-left: 1.25rem; color: var(--muted); font-size: 0.88rem; line-height: 1.5; }
.field-help { font-size: 0.82rem; color: var(--muted); margin: -0.5rem 0 0.85rem; }
.muted-inline { color: var(--muted); font-size: 0.85rem; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.85rem; color: var(--text); }
.checkbox-row input { width: auto; margin: 0; }
dialog { max-width: min(720px, 95vw); max-height: 90vh; overflow: auto; }

.user-chip { padding: 0.75rem 1rem; font-size: 0.85rem; border-bottom: 1px solid var(--border); color: var(--muted); }
.user-chip strong { color: var(--text); display: block; }
.context-bar { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; flex-wrap: wrap; }
.context-label { font-size: 0.85rem; color: var(--muted); display: flex; align-items: center; gap: 0.35rem; }
.context-label select { min-width: 220px; }
label.check { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
label.check input { width: auto; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
}
