:root {
  --primary: #001442;
  --primary-2: #1a3b73;
  --accent: #2563eb;
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-light: #64748b;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --info: #2563eb;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Loading ---------- */
.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; color: var(--text-light); }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.login-box { background: var(--card); border-radius: 14px; padding: 2.2rem 2.4rem; width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
.login-box h1 { font-size: 1.3rem; color: var(--primary); margin-bottom: 0.2rem; }
.login-box .sub { color: var(--text-light); font-size: 0.85rem; margin-bottom: 1.5rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-light); margin-bottom: 0.3rem; }
.field input { width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: 8px; outline: none; }
.field input:focus { border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: 8px; padding: 0.6rem 1.1rem; font-weight: 600; transition: filter 0.15s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-ghost { background: #eef2ff; color: var(--primary-2); }
.btn-danger { background: var(--err); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.form-msg { margin-top: 0.8rem; font-size: 0.85rem; }
.form-msg.err { color: var(--err); }
.form-msg.ok { color: var(--ok); }
.forgot { display: block; margin-top: 0.9rem; text-align: center; font-size: 0.82rem; color: var(--accent); text-decoration: none; }
.forgot:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; min-width: 240px; background: var(--primary); color: #cbd5e1;
  padding: 1.4rem 1rem; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1.8rem; color: #fff; }
.sidebar .brand .logo { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1rem; }
.sidebar .brand b { font-size: 0.95rem; display: block; line-height: 1.2; }
.sidebar .brand small { font-size: 0.7rem; color: #94a3b8; }
.sidebar nav a {
  display: flex; align-items: center; gap: 0.6rem; color: #cbd5e1; text-decoration: none;
  padding: 0.55rem 0.8rem; border-radius: 8px; margin-bottom: 0.2rem; font-size: 0.9rem;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; font-weight: 600; }
.sidebar .user-box { margin-top: 1.4rem; padding: 0.8rem; background: rgba(255,255,255,0.06); border-radius: 8px; font-size: 0.8rem; }
.sidebar .user-box b { color: #fff; display: block; }
.sidebar .logout { color: #fca5a5; cursor: pointer; }

.content { flex: 1; padding: 2rem 2.4rem 4rem; max-width: 1100px; }
.page-title { font-size: 1.4rem; color: var(--primary); margin-bottom: 1.4rem; }

/* ---------- Cards / tables ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.6rem; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.2rem; }
.stat .num { font-size: 1.7rem; font-weight: 800; color: var(--primary); }
.stat .lbl { color: var(--text-light); font-size: 0.8rem; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.2rem 1.4rem; margin-bottom: 1.4rem; }
.card h3 { font-size: 1rem; color: var(--primary); margin-bottom: 0.9rem; }

table.tbl { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.tbl th { background: #f1f5f9; text-align: left; padding: 0.65rem 1rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-light); border-bottom: 2px solid var(--border); }
.tbl td { padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover { background: #f8fafc; }

.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700; }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.off { background: #fee2e2; color: var(--err); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.info { background: #dbeafe; color: var(--info); }
.badge.sys { background: #e2e8f0; color: var(--text-light); }

.msgbar { padding: 0.7rem 1rem; border-radius: 8px; margin: 0.6rem 0 1rem; font-size: 0.85rem; display: none; }
.msgbar.err { background: #fee2e2; color: var(--err); display: block; }
.msgbar.ok { background: #dcfce7; color: var(--ok); display: block; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } .layout { flex-direction: column; } .sidebar { width: 100%; min-width: 0; height: auto; position: static; } }

.hidden { display: none; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.82rem; }
pre.result { background: #0f172a; color: #e2e8f0; border-radius: 8px; padding: 0.9rem 1rem; overflow: auto; max-height: 360px; font-size: 0.78rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }

.filter-row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.filter-row input, .filter-row select { padding: 0.45rem 0.7rem; border: 1px solid var(--border); border-radius: 8px; }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.6rem; }
a.dlink { color: var(--accent); font-weight: 600; text-decoration: none; }

.toolbar { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.toolbar input[type=search] { flex: 1; min-width: 220px; padding: 0.55rem 0.85rem; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem; }
