:root {
  --bg: #f4f7f7;
  --panel: #ffffff;
  --text: #172124;
  --muted: #657174;
  --line: #d9e1e3;
  --line-strong: #bdc9cc;
  --accent: #0f766e;
  --accent-dark: #0a5d57;
  --danger: #b42318;
  --soft: #edf3f3;
  --shadow: 0 18px 42px rgba(23, 33, 36, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  place-items: center;
  padding: 24px;
  background: #eef3f3;
}

.login-screen.show { display: grid; }

.login-panel {
  width: min(420px, 100%);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
  display: grid;
  gap: 16px;
}

.login-panel h1 { font-size: 22px; }
.login-brand { padding: 0; }
.login-fields { display: grid; gap: 12px; }

.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #172326;
  color: #f7fbfb;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  align-items: center;
  padding: 0 6px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #27b3a4;
  color: #052c29;
  display: grid;
  place-items: center;
  font-weight: 850;
}

.brand strong { display: block; font-size: 16px; }
.brand span, .sidebar-note { color: #a9b8bb; font-size: 12px; }

.nav { display: grid; gap: 6px; }

.nav button {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 12px;
  background: transparent;
  color: #d6e0e2;
  text-align: left;
  font-weight: 700;
}

.nav button.active {
  background: #243236;
  color: #ffffff;
}

.sidebar-note {
  margin-top: auto;
  word-break: break-all;
  padding: 0 6px;
  display: grid;
  gap: 6px;
}

.sidebar-note strong { color: #f7fbfb; font-size: 12px; }

.shell { min-width: 0; padding-bottom: 28px; }

.topbar {
  min-height: 72px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

h1, h2, p { margin: 0; }
h1 { font-size: 22px; line-height: 1.15; }
h2 { font-size: 15px; line-height: 1.2; }
p { color: var(--muted); font-size: 12px; margin-top: 4px; }

.top-actions, .toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-actions select {
  width: auto;
  min-width: 150px;
}

.section {
  display: none;
  padding: 24px;
}

.section.active {
  display: grid;
  gap: 18px;
}

.notice {
  display: none;
  margin: 16px 24px 0;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 10px 12px;
  color: var(--muted);
}

.notice.show { display: block; }
.notice.ok { color: #0d6b45; border-color: #bde4d5; background: #f0fbf6; }
.notice.error { color: var(--danger); border-color: #f0c8c1; background: #fff5f3; }

.builder-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
  gap: 18px;
  align-items: start;
}

.bottom-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-head {
  min-height: 58px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-body { padding: 16px; }

.empty-state {
  min-width: 220px;
  color: var(--muted);
  align-self: center;
  padding: 18px;
}

.btn {
  min-height: 36px;
  border-radius: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
}

.btn.primary { color: white; background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); background: #fff5f3; border-color: #f0c8c1; }
.btn.small { min-height: 30px; font-size: 12px; padding: 0 9px; }

input, select, textarea {
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

textarea {
  min-height: 104px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

label {
  color: #435053;
  font-size: 12px;
  font-weight: 750;
}

.field { display: grid; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }

.table-wrap { overflow: auto; }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 12px; text-align: left; font-size: 13px; vertical-align: middle; }
th { color: var(--muted); text-transform: uppercase; font-size: 11px; background: #fbfcfc; }
tr.selected { background: #edf8f6; }
tr:hover { background: #f7fbfa; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }

.canvas-strip {
  min-height: 142px;
  padding: 16px;
  display: flex;
  gap: 12px;
  overflow: auto;
  background: linear-gradient(180deg, #fbfcfc, #f1f6f6);
  border-bottom: 1px solid var(--line);
}

.node-card {
  flex: 0 0 180px;
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.node-card strong { font-size: 13px; }
.node-card span { color: var(--muted); font-size: 12px; }
.node-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }

.editor-grid, .settings-grid, .test-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chat {
  grid-column: 1 / -1;
  min-height: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 12px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.bubble {
  max-width: 78%;
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--soft);
}

.bubble.bot {
  justify-self: end;
  background: #dff5ef;
}

.events {
  max-height: 282px;
  overflow: auto;
  display: grid;
}

.events.wide { max-height: none; }

.event {
  display: grid;
  grid-template-columns: 150px 120px 1fr;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.switch { position: relative; width: 42px; height: 24px; display: inline-block; }
.switch input { opacity: 0; position: absolute; inset: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #cfd8da; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: white; transition: transform 140ms ease; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { padding: 14px; }
  .nav { display: flex; overflow: auto; }
  .nav button { flex: 0 0 auto; }
  .sidebar-note { display: none; }
  .builder-grid, .bottom-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar { align-items: flex-start; flex-direction: column; padding: 16px; }
  .section { padding: 16px; }
  .editor-grid, .settings-grid, .test-grid { grid-template-columns: 1fr; }
}
