*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f0f2f5;
  --surface:     #ffffff;
  --surface2:    #f5f6f8;
  --border:      #e2e5ea;
  --accent:      #ADD8E6;
  --accent-h:    #90C0D0;
  --green:       #16a34a;
  --red:         #dc2626;
  --text:        #1a1d27;
  --muted:       #6b7280;
  --sb-bg:       #1a4a5a;
  --sb-text:     #e8f4f8;
  --sb-muted:    #7aacbf;
  --sb-border:   rgba(255,255,255,.08);
  --sb-hover:    rgba(255,255,255,.07);
  --sb-active:   rgba(255,255,255,.14);
  --sidebar-w:   240px;
  --radius:      12px;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────── */
aside {
  width: var(--sidebar-w);
  background: var(--sb-bg);
  border-right: none;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--sb-border);
}

.logo-icon {
  width: 36px; height: 36px;
  background: rgba(255,255,255,.15);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .3px;
  color: var(--sb-text);
}

.logo-sub {
  font-size: 10px;
  color: var(--sb-muted);
  font-weight: 400;
  display: block;
}

nav {
  padding: 16px 12px;
  flex: 1;
  overflow-y: auto;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--sb-muted);
  text-transform: uppercase;
  padding: 0 8px;
  margin-bottom: 6px;
  margin-top: 16px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--sb-muted);
  transition: background .15s, color .15s;
  user-select: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--sb-hover); color: var(--sb-text); }
.nav-item.active { background: var(--sb-active); color: #fff; }

.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }

.nav-badge {
  margin-left: auto;
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--sb-border);
  font-size: 12px;
  color: var(--sb-muted);
}

/* ── Main ────────────────────────────────────────────── */
main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
}

.page-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-h); }
.btn-primary:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--surface2); color: var(--text); }

/* search */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--muted);
}

.search-bar input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  width: 180px;
}

.search-bar input::placeholder { color: var(--muted); }

/* ── Content ─────────────────────────────────────────── */
.content {
  padding: 32px;
  flex: 1;
}

/* Stats row */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-sub   { font-size: 11px; color: var(--green); margin-top: 4px; }

.stat-label-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.stat-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
}

.stat-label-row span:last-child {
  color: var(--accent-h);
  font-weight: 700;
}

.stat-muted-text {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
  display: block;
}

/* Section title */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
}

/* Filter pills */
.filters {
  display: flex;
  gap: 8px;
}

.pill {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  transition: all .15s;
}

.pill.active, .pill:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Flow grid */
.flow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

/* Flow card */
.flow-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color .2s, box-shadow .2s;
  position: relative;
  overflow: hidden;
}

.flow-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity .2s;
}

.flow-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 8px 32px rgba(173,216,230,.1);
}

.flow-card:hover::before { opacity: 1; }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}

.card-meta { flex: 1; }

.card-name {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 4px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.tag-purple { background: rgba(173,216,230,.2); color: var(--accent-h); }
.tag-blue   { background: rgba(59,130,246,.2); color: #93c5fd; }
.tag-green  { background: rgba(34,197,94,.2);  color: #86efac; }
.tag-orange { background: rgba(249,115,22,.2); color: #fdba74; }

.card-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.btn-delete, .btn-edit {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  width: 22px; height: 22px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  transition: color .15s, background .15s;
  line-height: 1;
}

.btn-delete:hover {
  color: var(--red);
  background: rgba(220,38,38,.1);
}

.btn-edit:hover {
  color: var(--accent);
  background: rgba(173,216,230,.12);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-gray   { background: var(--muted); }
.dot-orange { background: #f97316; box-shadow: 0 0 6px #f97316; }

.card-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}

.card-info {
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--muted);
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.card-info span { display: flex; align-items: center; gap: 4px; }

.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn-form {
  flex: 1;
  background: rgba(173,216,230,.1);
  color: var(--accent-h);
  border: 1px solid rgba(173,216,230,.25);
  justify-content: center;
  padding: 9px 12px;
}

.btn-form:hover {
  background: rgba(173,216,230,.2);
  border-color: var(--accent);
}

.btn-webhook {
  flex: 1;
  background: rgba(34,197,94,.12);
  color: #86efac;
  border: 1px solid rgba(34,197,94,.25);
  justify-content: center;
  padding: 9px 12px;
}

.btn-webhook:hover {
  background: rgba(34,197,94,.22);
  border-color: var(--green);
}

/* Add card */
.flow-card.add-card {
  border-style: dashed;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-height: 220px;
  color: var(--muted);
  transition: all .2s;
}

.flow-card.add-card:hover {
  border-color: var(--accent);
  color: var(--accent-h);
  background: rgba(173,216,230,.05);
}

.add-card-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.add-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 2px dashed currentColor;
  display: grid;
  place-items: center;
  font-size: 22px;
}

/* Toast */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  min-width: 280px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  animation: slide-in .25s ease;
}

.toast-success { background: #f0fdf4; border: 1px solid var(--green); color: #15803d; }
.toast-error   { background: #fff1f2; border: 1px solid var(--red);   color: #b91c1c; }
.toast-info    { background: #eef2ff; border: 1px solid var(--accent); color: #4338ca; }

@keyframes slide-in {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 200;
  place-items: center;
}

.modal-overlay.open { display: grid; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 480px;
  max-width: 90vw;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
}

.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

input[type=text], textarea, select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}

input[type=text]:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 80px; }

select option { background: var(--surface2); }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* Prompt text block */
.prompt-text {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
  color: var(--muted);
  max-height: 110px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.55;
}

.prompt-text--clickable {
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.prompt-text--clickable:hover {
  border-color: var(--accent);
  background: rgba(173,216,230,.08);
}

/* Prompt viewer modal */
.modal--viewer {
  width: 600px;
}

.modal-viewer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-viewer-header .modal-title {
  margin-bottom: 0;
}

.btn-close-viewer {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}

.btn-close-viewer:hover {
  color: var(--red);
  background: rgba(220,38,38,.1);
}

.prompt-viewer-text {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  color: var(--text);
  min-height: 220px;
  max-height: 420px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.65;
  margin-bottom: 20px;
}

/* Card image */
.card-image {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Viewer image */
.viewer-image {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
  background: var(--surface2);
}

/* Image upload preview */
.img-preview-wrap {
  min-height: 0;
  margin-bottom: 4px;
}

#img-preview {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  margin-top: 10px;
}

input[type=file] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--muted);
  font-family: inherit;
}

/* Image button */
.btn-img {
  flex: 1;
  background: rgba(249,115,22,.08);
  color: #fdba74;
  border: 1px solid rgba(249,115,22,.2);
  justify-content: center;
  padding: 9px 12px;
}

.btn-img:hover {
  background: rgba(249,115,22,.16);
  border-color: #f97316;
}

.btn-copy {
  flex: 1;
  background: rgba(173,216,230,.1);
  color: var(--accent-h);
  border: 1px solid rgba(173,216,230,.25);
  justify-content: center;
  padding: 9px 12px;
}

.btn-copy:hover {
  background: rgba(173,216,230,.2);
  border-color: var(--accent);
}

/* Sidebar buttons */
.sidebar-btns {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--sb-border);
}

.sidebar-btns button {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.08);
  color: var(--sb-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

.sidebar-btns button:hover {
  background: rgba(255,255,255,.14);
}

/* Responsive */
@media (max-width: 700px) {
  aside { transform: translateX(-100%); }
  main  { margin-left: 0; }
}
