/* ═══════════════════════════════════════════════
   APP ROOT
   ═══════════════════════════════════════════════ */
#app-root { height: 100vh; display: flex; flex-direction: column; min-height: 0; }
html, body { height: 100%; }
body { overflow: hidden; }

/* ═══════════════════════════════════════════════
   PAGE CONTAINER
   ═══════════════════════════════════════════════ */
.page {
  padding: 18px 20px 24px 20px;
  min-width: 0;
  min-height: 0;
  width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  flex: 1 1 auto;
  overflow: auto;
  scrollbar-gutter: stable;
}

.page > * {
  max-width: 1420px;
  width: 100%;
  margin: 0 auto;
}

/* ═══════════════════════════════════════════════
   GRID HELPERS
   ═══════════════════════════════════════════════ */
.grid-2 {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: var(--gap);
}
.grid-1 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
}
.vstack {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 0;
}
.wide-split { grid-template-columns: 1.7fr 0.9fr; }

@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════
   PAGE HEADER
   ═══════════════════════════════════════════════ */
.page-head .search-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.spacer { flex: 1; }

/* ═══════════════════════════════════════════════
   TOP NAVIGATION HEADER
   ═══════════════════════════════════════════════ */
.top-header {
  height: var(--nav-h);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-2);
  background: rgba(9, 13, 17, 0.80);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  position: sticky;
  top: 0;
  z-index: 1000;
  /* Frameless window drag */
  -webkit-app-region: drag;
}
.top-header button,
.top-header a,
.top-header input { -webkit-app-region: no-drag; }

html[data-theme="light"] .top-header {
  background: rgba(248, 250, 252, 0.85);
  border-bottom-color: var(--border);
}

/* ── Brand ── */
.brand { display: flex; gap: 10px; align-items: center; }
.logo-dot {
  width: 20px; height: 20px;
  border-radius: 7px;
  background: radial-gradient(circle at 32% 28%, rgba(255,255,255,0.38), transparent 55%), var(--green);
  box-shadow: 0 0 0 4px var(--green-3), 0 2px 8px rgba(24,192,143,0.35);
  flex-shrink: 0;
}
html[data-theme="light"] .logo-dot { box-shadow: 0 0 0 4px var(--green-3), 0 2px 6px rgba(22,163,74,0.25); }
.brand-text { line-height: 1.1; }
.brand-title { font-weight: 700; font-size: 14px; letter-spacing: 0.1px; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ── Nav actions ── */
.top-actions { display: flex; align-items: center; gap: 4px; }

/* ── Nav buttons (override generic .btn for nav context) ── */
.top-actions .btn[data-nav] {
  height: 30px;
  padding: 0 12px;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 8px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  transition: color 0.12s ease, background 0.12s ease;
}
.top-actions .btn[data-nav]:hover {
  color: var(--text);
  background: rgba(255,255,255,0.06);
  border-color: transparent;
}
.top-actions .btn[data-nav].is-active {
  color: var(--text);
  background: rgba(255,255,255,0.08);
  border-color: var(--border-2);
  font-weight: 600;
  box-shadow: none;
}
html[data-theme="light"] .top-actions .btn[data-nav]:hover {
  background: rgba(15,23,42,0.05);
}
html[data-theme="light"] .top-actions .btn[data-nav].is-active {
  background: rgba(15,23,42,0.06);
  border-color: var(--border);
}

/* ── Window controls ── */
.window-controls { display: flex; gap: 5px; margin-left: 10px; }
.win-btn {
  width: 32px; height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
  -webkit-app-region: no-drag;
}
.win-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.win-close { border-color: rgba(255,90,95,0.30); }
.win-close:hover { background: rgba(255,90,95,0.18); color: #ff7b7e; border-color: rgba(255,90,95,0.55); }

html[data-theme="light"] .win-btn { background: rgba(15,23,42,0.04); border-color: var(--border); }
html[data-theme="light"] .win-btn:hover { background: rgba(15,23,42,0.08); color: var(--text); }
html[data-theme="light"] .win-close:hover { background: rgba(220,38,38,0.10); }

/* ═══════════════════════════════════════════════
   KANBAN LAYOUT
   ═══════════════════════════════════════════════ */
.kanban {
  display: flex;
  gap: 12px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 10px;
  scroll-snap-type: x proximity;
}

.kanban-col {
  min-width: 310px;
  max-width: 310px;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px);
  scroll-snap-align: start;
}

.kanban-col-head {
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-auto-rows: auto;
  gap: 8px 10px;
  border-bottom: 1px solid var(--border-2);
}

.kanban-col-title { font-weight: 800; font-size: 13px; letter-spacing: -0.1px; }
.kanban-col-meta { display: flex; gap: 6px; align-items: center; justify-self: end; }
.kanban-col-tags {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 2px;
}
.kanban-col-tags::-webkit-scrollbar { height: 5px; }
.kanban-col-tags::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.10); border-radius: 999px; }
html[data-theme="dark"] .kanban-col-tags::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); }

.kanban-col-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow: auto;
}

/* ═══════════════════════════════════════════════
   AUTOMATIONS PAGE
   ═══════════════════════════════════════════════ */
body[data-page="automations"] #app-root { height: 100%; }
body[data-page="automations"] .page {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 14px 18px 18px 18px;
  gap: 12px;
}
body[data-page="automations"] .page > * { max-width: none; width: auto; margin: 0; }
body[data-page="automations"] .page-head { flex: 0 0 auto; }

body[data-page="automations"] .flow-help {
  margin-top: 10px;
  border: 1px solid var(--border-2);
  background: var(--panel-2);
  border-radius: 14px;
  padding: 10px 14px;
}
body[data-page="automations"] .flow-help > summary {
  cursor: pointer;
  color: var(--text);
  list-style: none;
  font-size: 13px;
}
body[data-page="automations"] .flow-help > summary::-webkit-details-marker { display: none; }
body[data-page="automations"] .flow-help-body {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}

body[data-page="automations"] .automations-grid {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(220px, 280px) minmax(520px, 1fr) minmax(240px, 320px);
  overflow: auto;
  padding-bottom: 2px;
}

@media (max-width: 1250px) {
  body[data-page="automations"] .automations-grid {
    grid-template-columns: minmax(210px, 260px) minmax(480px, 1fr) minmax(220px, 300px);
  }
}
@media (max-width: 900px) {
  body[data-page="automations"] .automations-grid { grid-template-columns: 1fr; }
}

body[data-page="automations"] .automations-panel {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Left panel: 2 zones — flows (fixed small) + blocks (fills rest) */
body[data-page="automations"] .automations-panel {
  overflow: hidden; /* outer panel never scrolls */
}

body[data-page="automations"] #flows-list {
  /* Compact: just enough to show ~3 flows; user scrolls if more */
  flex: 0 0 auto;
  max-height: 180px;
  min-height: 48px;
  overflow-y: auto;
  overflow-x: hidden;
}

body[data-page="automations"] .blocks-section {
  /* Takes remaining vertical space; blocks scroll inside */
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body[data-page="automations"] .blocks-section-title {
  flex: 0 0 auto;
}

body[data-page="automations"] .automations-panel .block-tiles {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  align-content: start;
  padding-right: 4px;
  padding-bottom: 8px;
}

/* No more fixed max-height — let flex handle it */
@media (max-height: 760px) {
  body[data-page="automations"] #flows-list { max-height: 140px; }
}
@media (max-height: 680px) {
  body[data-page="automations"] #flows-list { max-height: 100px; }
}

body[data-page="automations"] .automations-scroll { flex: 1; min-height: 0; overflow: auto; }
body[data-page="automations"] .automations-canvas-panel {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body[data-page="automations"] .automations-canvas {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 14px;
  background:
    radial-gradient(rgba(255,255,255,0.055) 1px, transparent 1px) 0 0 / 24px 24px,
    rgba(255,255,255,0.018);
  overflow: hidden;
  cursor: grab;
}
body[data-page="automations"] .automations-canvas.is-panning { cursor: grabbing; }

/* pointer-events: nodes only (not container) */
body[data-page="automations"] #flow-nodes { pointer-events: none; }
body[data-page="automations"] #flow-nodes .flow-node { pointer-events: auto; }

body[data-page="automations"] .flow-hud {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  font-size: 11.5px;
  color: rgba(255,255,255,0.60);
  background: rgba(0,0,0,0.38);
  border: 1px solid rgba(255,255,255,0.10);
  padding: 7px 10px;
  border-radius: 10px;
  backdrop-filter: blur(10px);
  pointer-events: none;
}

/* ═══════════════════════════════════════════════
   BOT PAGE LAYOUT
   ═══════════════════════════════════════════════ */
body[data-page="bot"] .bot-flow-grid { min-height: 0; align-items: start; }
body[data-page="bot"] .bot-flow-card { min-height: 0; overflow: visible; }
body[data-page="bot"] .bot-flow-grid > .vstack { min-height: auto; }

body[data-page="bot"] .card-title { font-size: 15px; font-weight: 700; letter-spacing: 0.1px; }
body[data-page="bot"] .card-sub { font-size: 12px; line-height: 1.4; }
body[data-page="bot"] .section-title { font-size: 13px; font-weight: 800; margin-top: 2px; }
body[data-page="bot"] .section-sub { font-size: 11.5px; }
body[data-page="bot"] .label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
body[data-page="bot"] .muted { font-size: 11.5px; line-height: 1.4; margin-top: 5px; }
body[data-page="bot"] .input,
body[data-page="bot"] .select { border-radius: 12px; height: 38px; }
body[data-page="bot"] .textarea { border-radius: 10px; resize: none; }
body[data-page="bot"] .textarea.textarea-code { font-size: 12px; min-height: 180px; }
body[data-page="bot"] .setting-row { align-items: flex-start; gap: 12px; }
body[data-page="bot"] .setting-title { font-size: 14px; font-weight: 800; }
body[data-page="bot"] .setting-desc { font-size: 12px; }
body[data-page="bot"] .form-grid { gap: 12px; }
body[data-page="bot"] .form-grid-2 { gap: 14px 18px; }

body[data-page="bot"] .afterhours-times {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
  align-items: end;
}
body[data-page="bot"] .afterhours-reply { margin-top: 10px; }

@media (max-width: 980px) {
  body[data-page="bot"] .afterhours-times { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE (header)
   ═══════════════════════════════════════════════ */
@media (max-width: 900px) {
  .top-header { height: auto; padding: 10px 14px; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
}
