:root {
  color-scheme: dark;
  --bg: #080b12;
  --surface: #111722;
  --surface-2: #171f2d;
  --surface-3: #0d121b;
  --border: #293244;
  --text: #f3f6fb;
  --muted: #98a3b5;
  --primary: #5b8cff;
  --primary-strong: #3867e8;
  --warning: #f4b740;
  --critical: #f05b67;
  --ok: #43c58a;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: radial-gradient(circle at 15% -10%, rgba(67, 98, 180, .22), transparent 33%), var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.45rem, 3vw, 2.15rem); }
h2 { margin-bottom: 6px; font-size: 1.08rem; }
.eyebrow { margin-bottom: 5px; color: #7da2ff; font-size: .7rem; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
.muted { color: var(--muted); line-height: 1.55; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 17px clamp(18px, 4vw, 58px); border-bottom: 1px solid rgba(41,50,68,.85); background: rgba(8,11,18,.88); backdrop-filter: blur(18px); }
.topbar-actions, .button-row, .dialog-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dashboard-shell { width: min(1600px, 100%); margin: 0 auto; padding: 26px clamp(15px, 3.8vw, 58px) 64px; }

.button { min-height: 42px; padding: 10px 16px; border: 1px solid transparent; border-radius: 11px; color: var(--text); background: var(--surface-2); font-weight: 760; transition: transform .15s ease, border-color .15s ease, background .15s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--primary-strong); }
.button-secondary { border-color: var(--border); }
.button-danger { border-color: rgba(240,91,103,.45); background: rgba(116,29,39,.42); }
.icon-button { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); background: var(--surface-2); font-size: 1.5rem; }

.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 999px; font-size: .82rem; font-weight: 700; }
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; }
.status-live { color: #7be3ad; }
.status-waiting { color: #ffd479; }
.status-error { color: #ff929b; }

.hero-panel, .panel, .metric-card, .push-panel { border: 1px solid var(--border); border-radius: var(--radius); background: linear-gradient(145deg, rgba(23,31,45,.97), rgba(15,21,31,.98)); box-shadow: 0 20px 55px rgba(0,0,0,.16); }
.hero-panel { display: flex; justify-content: space-between; align-items: center; gap: 30px; padding: 24px; margin-bottom: 16px; }
.hero-panel p:last-child { margin-bottom: 0; }
.live-meta { display: grid; grid-template-columns: repeat(3, minmax(110px, 1fr)); gap: 10px; min-width: min(520px, 100%); }
.live-meta span { display: grid; gap: 4px; padding: 13px 15px; border: 1px solid var(--border); border-radius: 13px; color: var(--muted); background: rgba(8,11,18,.36); font-size: .78rem; }
.live-meta strong { color: var(--text); font-size: .92rem; font-variant-numeric: tabular-nums; }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 13px; }
.metric-card { min-width: 0; padding: 18px; }
.metric-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 13px; }
.metric-head span { color: var(--muted); font-size: .86rem; }
.metric-head strong { font-size: 1.28rem; font-variant-numeric: tabular-nums; }
.progress-track { height: 9px; overflow: hidden; border-radius: 999px; background: #070a10; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #4e79ed, #74a4ff); transition: width .9s cubic-bezier(.2,.8,.2,1), background .25s ease; }
.progress-bar.warning { background: linear-gradient(90deg, #d99b25, #f6c85a); }
.progress-bar.critical { background: linear-gradient(90deg, #d94352, #ff7782); }
.metric-detail { min-height: 1.15em; margin: 10px 0 0; overflow: hidden; color: var(--muted); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }

.content-grid { display: grid; gap: 16px; margin-top: 16px; }
.live-grid { grid-template-columns: minmax(0, 2fr) minmax(300px, .8fr); }
.management-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); }
.panel { min-width: 0; padding: 21px; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 14px; }
.chart-panel canvas, .history-panel canvas { display: block; width: 100%; }
.legend { display: flex; gap: 13px; color: var(--muted); font-size: .76rem; }
.legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 5px; border-radius: 50%; }
.legend-cpu::before { background: #6593ff; }
.legend-memory::before { background: #b180ff; }
.legend-load::before { background: #45cf9a; }
.facts-list { margin: 0; }
.facts-list div { display: flex; justify-content: space-between; gap: 20px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.facts-list div:last-child { border-bottom: 0; }
.facts-list dt { color: var(--muted); }
.facts-list dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.history-panel, .process-panel, .push-panel { margin-top: 16px; }
.history-heading { align-items: flex-end; }
.history-controls { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.history-controls select { min-height: 40px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 11px; color: var(--text); background: var(--surface-3); outline: none; }
.segmented-control { display: flex; flex-wrap: wrap; gap: 5px; padding: 4px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-3); }
.range-button { min-width: 44px; padding: 7px 10px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: .78rem; font-weight: 750; }
.range-button.active { color: var(--text); background: var(--primary-strong); }
.empty-state { margin: 16px 0 0; padding: 18px; border: 1px dashed var(--border); border-radius: 12px; color: var(--muted); text-align: center; }

.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th, td { padding: 12px 11px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
td { font-size: .87rem; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .2s ease; }
tbody tr:hover { background: rgba(91,140,255,.06); }

.rule-list, .event-list { display: grid; gap: 10px; max-height: 620px; overflow: auto; padding-right: 3px; }
.rule-card, .event-card { padding: 15px; border: 1px solid var(--border); border-radius: 13px; background: rgba(8,11,18,.28); }
.rule-card-head, .event-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; }
.rule-card h3, .event-card h3 { margin-bottom: 4px; font-size: .96rem; }
.rule-card p, .event-card p { margin-bottom: 0; }
.rule-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.rule-meta span, .severity-badge { display: inline-flex; align-items: center; padding: 5px 8px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: .7rem; }
.rule-actions { display: flex; gap: 7px; }
.rule-actions button { padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); background: var(--surface-2); font-size: .74rem; }
.severity-badge.warning { border-color: rgba(244,183,64,.45); color: #ffd476; }
.severity-badge.critical { border-color: rgba(240,91,103,.45); color: #ff929b; }
.severity-badge.ok { border-color: rgba(67,197,138,.45); color: #7be3ad; }
.event-time { color: var(--muted); font-size: .72rem; }

.push-panel { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 22px; }
.push-panel p:last-child { margin-bottom: 0; }

.rule-dialog { width: min(720px, calc(100% - 28px)); padding: 0; border: 1px solid var(--border); border-radius: 20px; color: var(--text); background: var(--surface); box-shadow: 0 30px 100px rgba(0,0,0,.55); }
.rule-dialog::backdrop { background: rgba(2,4,8,.72); backdrop-filter: blur(4px); }
.rule-dialog form { padding: 24px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-wide { grid-column: 1 / -1; }
.form-grid label { display: grid; gap: 7px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.form-grid input, .form-grid select { width: 100%; min-height: 43px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); background: var(--surface-3); outline: none; }
.form-grid input:focus, .form-grid select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91,140,255,.14); }
.checkbox-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin: 18px 0; }
.checkbox-grid label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .84rem; }
.dialog-actions { justify-content: flex-end; margin-top: 18px; }
.notice { margin: 16px 0; padding: 12px 14px; border-radius: 11px; }
.notice-error { border: 1px solid rgba(240,91,103,.45); color: #ffc0c5; background: rgba(116,29,39,.28); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(450px, 100%); padding: 32px; border: 1px solid var(--border); border-radius: 23px; background: rgba(17,23,34,.96); box-shadow: 0 30px 90px rgba(0,0,0,.38); }
.brand-mark { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 22px; border-radius: 15px; background: linear-gradient(135deg, #3867e8, #7a56db); font-weight: 900; }
.login-form { display: grid; gap: 16px; margin-top: 24px; }
.login-form label { display: grid; gap: 7px; color: var(--muted); font-size: .88rem; font-weight: 700; }
.login-form input { width: 100%; min-height: 46px; padding: 12px 13px; border: 1px solid var(--border); border-radius: 11px; color: var(--text); background: var(--surface-3); outline: none; }
.login-form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91,140,255,.14); }

@media (max-width: 1280px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .hero-panel, .push-panel { align-items: flex-start; flex-direction: column; }
  .live-meta { width: 100%; min-width: 0; }
  .live-grid, .management-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .topbar { align-items: flex-start; }
  .topbar, .history-heading { flex-direction: column; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .dashboard-shell { padding-top: 16px; }
  .hero-panel, .panel, .metric-card, .push-panel { border-radius: 14px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live-meta { grid-template-columns: 1fr; }
  .history-controls { width: 100%; align-items: stretch; flex-direction: column; }
  .history-controls select, .segmented-control { width: 100%; }
  .range-button { flex: 1; }
  .form-grid, .checkbox-grid { grid-template-columns: 1fr; }
  .form-wide { grid-column: auto; }
  .button-row { width: 100%; }
  .button-row .button { flex: 1 1 100%; }
}
@media (max-width: 440px) {
  .metric-grid { grid-template-columns: 1fr; }
}
