:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --sidebar: #141a2e;
  --sidebar-hover: #1f2740;
  --sidebar-active: #2a3556;
  --border: #e4e8f0;
  --text: #1c2333;
  --muted: #8b93a7;
  --primary: #4f7cff;
  --primary-dark: #3a64e0;
  --ok: #1f9e7a;
  --ok-bg: #e3f6ee;
  --warn: #c2410c;
  --warn-bg: #fdeee3;
  --danger: #e11d48;
  --info: #2563eb;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.10);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef1f7; padding: 1px 5px; border-radius: 4px; font-size: .85em; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--sidebar);
  color: #c7cde0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 18px;
  font-weight: 700; font-size: 16px; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-mark { color: var(--primary); font-size: 18px; }
.brand-mark.big { font-size: 34px; }

.nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.07); display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 8px;
  color: #c7cde0; font-weight: 500; font-size: 14px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item.small { font-size: 13px; padding: 8px 12px; color: #9aa3bd; }
.nav-item .ic { width: 18px; text-align: center; opacity: .9; font-size: 15px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-size: 18px; font-weight: 650; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-chip {
  background: #eef1f8; color: #3a445e; padding: 5px 12px;
  border-radius: 20px; font-weight: 600; font-size: 13px;
}
.content { padding: 26px 28px 60px; max-width: 1280px; width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 8px;
  padding: 9px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .12s, border-color .12s; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #f6f8fc; }
.btn-danger { background: #fff; border-color: #f3c2cd; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: radial-gradient(1200px 600px at 50% -10%, #1f2740, var(--bg));
  padding: 20px;
}
.login-card {
  background: var(--surface); width: 100%; max-width: 380px;
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow-lg);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand h1 { font-size: 20px; margin: 8px 0 4px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label, .form-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
.login-form input, .form-card input, .form-card textarea, .filters input, .filters select, .code-area {
  font: inherit; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--text); width: 100%;
}
.login-form input:focus, .form-card input:focus, .filters input:focus, .code-area:focus, .form-card textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,124,255,.15);
}
.login-foot { font-size: 12px; }

/* ---------- Flash ---------- */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; font-size: 13px; }
.flash-error { background: var(--warn-bg); color: var(--warn); border: 1px solid #f3d3bd; }
.flash-success { background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe8d6; }

/* ---------- Cards & stats ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }
.card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.card-row .card { margin-bottom: 0; }
.card-row + .card-row { margin-top: 20px; }

.stat-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 22px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat-value .unit { font-size: 14px; color: var(--muted); font-weight: 600; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat-warn { border-color: #f3d3bd; }
.stat-warn .stat-value { color: var(--warn); }
.stat-ok .stat-value { color: var(--ok); }

.chart-card.wide { grid-column: 1 / -1; }
.chart-card canvas { max-height: 240px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--border); background: #fafbfe; white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
.table tbody tr:last-child td { border-bottom: none; }
.table.compact th, .table.compact td { padding: 8px 12px; }
.row-link { cursor: pointer; }
.row-link:hover { background: #f6f8fd; }
.table .strong, .table .row-link .strong { font-weight: 650; }
.nowrap-ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.muted { color: var(--muted); }
.strong { font-weight: 650; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-soft { background: #eef1f8; color: #51607e; }
.badge-info { background: #e6efff; color: var(--info); }
.badge-crit { background: #fde4e7; color: #e11d48; }
.badge-muted { background: #f1f3f8; color: #98a0b3; }

/* ---------- Filters ---------- */
.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.filter-search { flex: 1; min-width: 240px; }
.filter-search.sm { flex: none; width: 220px; }
.filters select { min-width: 150px; }
.result-count { color: var(--muted); font-size: 13px; margin-left: auto; }

/* ---------- Detail ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
.detail-head-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-head-actions { display: flex; gap: 8px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 4px; }
.detail-grid .card { margin-bottom: 0; }
dl.kv { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 8px 14px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13px; }
dl.kv dd { margin: 0; font-size: 13px; word-break: break-word; }
.card-head-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head-row h3 { margin: 0; }
.raw-card summary { cursor: pointer; list-style: none; }
.raw-card summary::-webkit-details-marker { display: none; }
.raw-json {
  background: #0f1525; color: #c8d2ee; padding: 16px; border-radius: 8px;
  overflow: auto; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px;
  max-height: 460px; margin: 12px 0 0;
}

/* ---------- Forms ---------- */
.form-card { max-width: 920px; }
.form-card.narrow { max-width: 460px; }
.form-card fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px 18px; margin: 0 0 18px; }
.form-card legend { font-weight: 650; padding: 0 8px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.form-card label { margin-bottom: 0; }
.code-area { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; resize: vertical; }
.post-actions { display: flex; gap: 10px; margin-top: 6px; }

/* ---------- Upload ---------- */
.upload-form { display: flex; flex-direction: column; gap: 14px; }
.dropzone { display: block; border: 2px dashed var(--border); border-radius: 12px; padding: 30px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: #f5f8ff; }
.dropzone-icon { font-size: 30px; color: var(--primary); }
.dropzone-text { font-weight: 600; margin-top: 8px; }
.dropzone-files { margin-top: 6px; font-size: 13px; }
.hint-card { background: #fbfcfe; }

/* ---------- Alerts panel ---------- */
.alert-block + .alert-block { margin-top: 14px; }
.alert-head { font-weight: 650; font-size: 13px; margin-bottom: 6px; }
.alert-list { margin: 0; padding-left: 18px; font-size: 13px; }
.alert-list li { margin-bottom: 3px; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 70px 20px; }
.empty-state.small { padding: 40px 20px; }
.empty-icon { font-size: 44px; color: var(--muted); opacity: .5; }
.empty-state h2 { margin: 10px 0 4px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .sidebar { width: 64px; }
  .brand-text, .nav-item span:not(.ic) { display: none; }
  .card-row, .detail-grid, .form-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
