:root {
  --bg: #f5f7fa;
  --panel: #fff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --online: #059669;
  --warning: #d97706;
  --error: #dc2626;
  --shadow: 0 16px 38px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 22px 28px;
  color: #fff;
  background: #172033;
}
.topbar h1 { margin: 0 0 5px; font-size: 26px; letter-spacing: 0; }
.topbar p { margin: 0; color: rgba(255,255,255,.72); }
.toolbar, .actions, .button-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input { width: 220px; }

button, input, select, textarea {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
button { min-height: 38px; padding: 0 14px; font-weight: 750; cursor: pointer; }
button.primary { color: #fff; border-color: var(--primary); background: var(--primary); }
button.danger { color: #fff; border-color: var(--error); background: var(--error); }
input, select { min-height: 38px; padding: 0 10px; }
textarea { width: 100%; min-height: 455px; padding: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(145deg, rgba(23, 32, 51, .96), rgba(31, 41, 55, .92)),
    radial-gradient(circle at 20% 0%, rgba(37, 99, 235, .35), transparent 36%);
}
.login-card {
  width: min(440px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0,0,0,.24);
}
.login-card h1 { margin: 0; font-size: 30px; }
.login-card p { margin: 0; color: var(--muted); line-height: 1.45; }
.login-error { min-height: 20px; color: var(--error); font-size: 13px; font-weight: 800; }

.shell { padding: 22px 28px 44px; }
.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.kpis article, .metric-grid article, .panel, .subpanel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.kpis article { padding: 15px 16px; }
.kpis span, .metric-grid span, .node-card span, .section-head p, .hint { color: var(--muted); font-size: 13px; }
.kpis strong { display: block; margin-top: 5px; font-size: 27px; }

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.panel { padding: 16px; }
.node-pane { min-height: 620px; }
.detail-pane { min-height: 720px; }
.section-head, .detail-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}
h2, h3 { margin: 0; letter-spacing: 0; }
.node-list { display: grid; gap: 10px; }
.node-card {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 13px;
  text-align: left;
  border-color: var(--line);
}
.node-card.selected { border-color: var(--primary); outline: 2px solid rgba(37, 99, 235, .12); }
.node-title { display: flex; justify-content: space-between; align-items: center; }
.dot { width: 10px; height: 10px; border-radius: 999px; display: inline-block; }
.online, .dot.online { color: #065f46; background: #d1fae5; }
.warning, .dot.warning { color: #92400e; background: #fef3c7; }
.offline, .dot.offline, .error, .dot.error { color: #991b1b; background: #fee2e2; }
.dot.online { background: var(--online); }
.dot.warning { background: var(--warning); }
.dot.offline, .dot.error { background: var(--error); }

.pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.pill.muted, .muted { color: #374151; background: #f3f4f6; }
.pill.queued { color: #1d4ed8; background: #dbeafe; }
.pill.processing, .pill.deferred { color: #92400e; background: #fef3c7; }
.pill.processed, .pill.done { color: #065f46; background: #d1fae5; }
.pill.failed { color: #991b1b; background: #fee2e2; }

.empty { padding: 90px 24px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); }
.empty-small { padding: 14px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); }
.hidden { display: none !important; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.metric-grid article { padding: 14px; box-shadow: none; }
.metric-grid strong { display: block; margin-top: 4px; font-size: 18px; }
.split {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr);
  gap: 16px;
  margin-bottom: 16px;
}
.subpanel { padding: 15px; box-shadow: none; }
canvas { width: 100%; border: 1px solid var(--line); border-radius: 8px; }

.event-list, .template-list, .table-list { display: grid; gap: 10px; }
.event, .template-row, .row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: #fbfcff;
}
.event div, .template-row, .row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 10px;
  align-items: center;
}
.event p { margin: 6px 0 0; color: #374151; }
.template-row div { display: grid; gap: 4px; }
.template-row span, .row span { color: var(--muted); font-size: 13px; }
.row { grid-template-columns: minmax(180px, 1fr) auto auto auto auto; }
.row pre { max-height: 130px; overflow: auto; margin: 0; white-space: pre-wrap; }

.tabs { display: flex; gap: 8px; margin: 8px 0 14px; border-bottom: 1px solid var(--line); }
.tab { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom: 0; }
.tab.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.config-form { display: grid; gap: 14px; align-content: start; }
.config-topline {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.config-topline p { margin: 4px 0 0; }
.config-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.config-tab {
  min-width: max-content;
  background: #f9fafb;
}
.config-tab.active {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}
.config-page {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcff;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}
label { display: grid; gap: 5px; color: #374151; font-weight: 700; font-size: 13px; }
label input[type="checkbox"] { width: 18px; min-height: 18px; }
.sticker-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}
.sticker-editor-head h4 { margin: 0; }
.sticker-rows { display: grid; gap: 10px; margin-top: 10px; }
.sticker-row {
  display: grid;
  grid-template-columns: 140px 180px minmax(220px, 1fr) 88px auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
dialog { width: min(480px, calc(100vw - 32px)); border: 0; border-radius: 8px; padding: 18px; box-shadow: var(--shadow); }
dialog menu { display: flex; justify-content: flex-end; gap: 10px; padding: 0; margin: 16px 0 0; }

@media (max-width: 1120px) {
  .topbar, .workspace, .split { display: block; }
  .toolbar { margin-top: 14px; }
  .node-pane { margin-bottom: 16px; }
  .kpis, .metric-grid, .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sticker-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .kpis, .metric-grid, .form-grid, .sticker-row { grid-template-columns: 1fr; }
  .config-topline { display: grid; }
}
