*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --info: #0891b2;
  --info-light: #ecfeff;
  --sidebar-w: 220px;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  padding: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
}

.brand-icon {
  background: var(--primary);
  color: #fff;
  border-radius: 6px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}

.nav-list { list-style: none; padding: 8px 0; flex: 1; }
.nav-list li { margin: 2px 8px; }

.nav-link {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: var(--primary-light); color: var(--primary); font-weight: 500; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.sidebar-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.sidebar-user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}
.sidebar-user-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-logout {
  font-size: 11px;
  color: var(--danger);
  text-decoration: none;
}
.sidebar-logout:hover { text-decoration: underline; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}
.status-ok { background: var(--success); }
.status-warn { background: var(--warning); }
.status-err { background: var(--danger); }

/* ── Main Content ─────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  max-width: 1200px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 { font-size: 22px; font-weight: 600; }
.page-subtitle { font-size: 12px; color: var(--text-muted); }

/* ── Cards ────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 15px; font-weight: 600; }

/* ── Stats Grid ───────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 600; }
.stat-value.success { color: var(--success); }
.stat-value.danger  { color: var(--danger);  }
.stat-value.info    { color: var(--info);    }
.stat-value.warning { color: var(--warning); }

/* ── Content Grid ─────────────────────────── */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .content-grid { grid-template-columns: 1fr; } }

/* ── Buttons ──────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-link { background: none; border: none; color: var(--primary); font-size: 12px; cursor: pointer; text-decoration: none; padding: 0; }
.btn-link:hover { text-decoration: underline; }

/* ── Badges ───────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}
.badge-success  { background: var(--success-light); color: var(--success); }
.badge-danger   { background: var(--danger-light);  color: var(--danger);  }
.badge-warning  { background: var(--warning-light); color: var(--warning); }
.badge-info     { background: var(--info-light);    color: var(--info);    }
.badge-default  { background: var(--bg);            color: var(--text-muted); }

/* ── Tables ───────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-muted); font-weight: 500; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* ── Forms ────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg-card);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.form-control:focus { border-color: var(--primary); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Log List ─────────────────────────────── */
.log-list { font-size: 12px; font-family: monospace; max-height: 320px; overflow-y: auto; }
.log-item { padding: 4px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
.log-item:last-child { border-bottom: none; }
.log-time { color: var(--text-muted); flex-shrink: 0; }
.log-event { font-weight: 500; }
.log-detail { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Item List ────────────────────────────── */
.item-list { display: flex; flex-direction: column; gap: 1px; }
.item-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.item-row:last-child { border-bottom: none; }
.item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* ── Empty State ──────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state p { font-size: 13px; margin-top: 8px; }

/* ── Modal ────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-card);
  border-radius: 12px;
  width: 100%; max-width: 580px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px 24px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding-top: 16px; margin-top: 8px;
  border-top: 1px solid var(--border);
}
.btn-icon {
  background: none; border: none; cursor: pointer;
  font-size: 16px; color: var(--text-muted); padding: 4px 8px;
  border-radius: 6px;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Toast ────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--text); color: #fff;
  padding: 10px 18px; border-radius: var(--radius);
  font-size: 13px; display: none; z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
