:root {
  --bg: #0d0d0f;
  --bg2: #16161a;
  --bg3: #1e1e24;
  --border: #2a2a35;
  --text: #e8e8f0;
  --text2: #8888a0;
  --accent: #7c6fff;
  --accent-hover: #9080ff;
  --success: #3ecf8e;
  --warning: #f5a623;
  --error: #e53e3e;
  --sidebar-w: 230px;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ---- Layout ---- */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- Loading ---- */
#loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 16px;
  color: var(--text2);
  font-size: 13px;
}
#loading-screen.active { display: flex; }

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Sidebar ---- */
aside#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 12px;
}

#workspace-selector {
  display: flex;
  gap: 6px;
  align-items: center;
}

#ws-select {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  min-width: 0;
}
#ws-select:focus { outline: none; border-color: var(--accent); }

nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--text2);
  text-decoration: none;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#credits-display {
  font-size: 12px;
  color: var(--text2);
}
#credits-value { color: var(--success); font-weight: 600; }

/* ---- Main ---- */
main#main {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  max-width: 900px;
}

.view { display: block; }
.view.hidden { display: none !important; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 24px;
}

h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* ---- Cards ---- */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

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

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text2); opacity: 0.7; }

.hint {
  font-size: 11px;
  color: var(--text2);
}

/* ---- Buttons ---- */
button, .btn-primary, .btn-secondary, .btn-ghost {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
  padding: 9px 16px;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  font-size: 14px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--text2); }

.btn-icon {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: var(--radius);
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.btn-icon:hover { color: var(--text); border-color: var(--text2); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---- Output card ---- */
.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.output-actions {
  display: flex;
  gap: 8px;
}

pre#output-text {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 500px;
  overflow-y: auto;
  color: var(--text);
}

.meta-row {
  font-size: 12px;
  color: var(--text2);
  margin-top: 12px;
}

/* ---- Filter row ---- */
.filter-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}
.filter-row select { width: auto; flex: 1; }

/* ---- History ---- */
.history-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}
.history-item:hover { border-color: var(--accent); }

.history-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.history-workflow {
  font-weight: 600;
  font-size: 13px;
}

.history-date {
  font-size: 11px;
  color: var(--text2);
  margin-left: auto;
}

.history-preview {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.5;
  margin-bottom: 10px;
  white-space: pre-wrap;
}

.history-actions {
  display: flex;
  gap: 8px;
}

/* ---- Badges ---- */
.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-draft     { background: rgba(136,136,160,0.15); color: var(--text2); }
.badge-approved  { background: rgba(62,207,142,0.15); color: var(--success); }
.badge-published { background: rgba(124,111,255,0.15); color: var(--accent); }
.badge-failed    { background: rgba(229,62,62,0.15); color: var(--error); }
.badge-type      { background: rgba(124,111,255,0.1); color: var(--accent); }

/* ---- Workflows list ---- */
.workflow-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.workflow-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.workflow-header h3 { font-size: 14px; font-weight: 600; flex: 1; }
.workflow-meta { font-size: 12px; color: var(--text2); margin-top: 8px; }

/* ---- Empty state ---- */
.empty-state {
  color: var(--text2);
  font-size: 13px;
  text-align: center;
  padding: 40px 0;
}

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text2);
}

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 420px;
}
.modal-box h2 { margin-bottom: 20px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}
.modal-actions button { width: auto; margin-top: 0; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--error);   color: var(--error); }

/* ---- Utils ---- */
.hidden { display: none !important; }
