:root {
  --bg:      #0a0810;
  --bg2:     #110e1a;
  --bg3:     #181428;
  --border:  #251e38;
  --text:    #ede8ff;
  --muted:   #7060a0;
  --purple:  #b06ef3;
  --purple2: #d8a8ff;
  --orange:  #ff7a30;
  --green:   #3ecf6e;
  --red:     #ff5a5a;
  --sans: 'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); }

input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
}

input[type=text], input[type=password], input[type=number], select, textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
}

button {
  cursor: pointer;
  border-radius: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
}
button:hover { border-color: var(--purple); }

.btn-primary {
  background: var(--purple);
  border-color: var(--purple);
  color: #12081a;
  font-weight: 600;
}
.btn-primary:hover { background: var(--purple2); }

.btn-ghost { background: transparent; }

.btn-danger { color: var(--red); border-color: var(--red); background: transparent; }

/* Auth screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 16px; margin: 0; }

.popover {
  position: fixed;
  top: 56px;
  right: 24px;
  z-index: 40;
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.popover.popover-visible { opacity: 1; transform: translateY(0) scale(1); }
.popover-box {
  background: var(--bg2);
  border: 1px solid var(--purple);
  border-radius: 10px;
  padding: 20px;
  width: 480px;
  max-width: 92vw;
  max-height: 80vh;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}
.popover-box.popover-wide { width: 720px; }
.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.popover-header h3 { margin: 0; font-size: 15px; }

.tabbar {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 12px 16px;
  white-space: nowrap;
}
.tab:hover { border-color: transparent; color: var(--text); }
.tab-active { color: var(--text); border-bottom-color: var(--purple); font-weight: 600; }
.tab-badge {
  display: inline-block;
  background: var(--purple);
  color: #12081a;
  border-radius: 20px;
  font-size: 11px;
  padding: 1px 7px;
  margin-left: 4px;
  font-weight: 700;
}

.layout {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tab-panel { display: none; flex-direction: column; gap: 24px; }
.tab-panel-active { display: flex; }

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

.panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-header h2 { font-size: 15px; margin: 0; }
.panel-primary { border-color: var(--purple); }

details.panel summary { cursor: pointer; list-style: none; }
details.panel summary::-webkit-details-marker { display: none; }
details.panel summary::before { content: "▸ "; color: var(--muted); }
details.panel[open] summary::before { content: "▾ "; }
details.panel > *:not(summary) { margin-top: 12px; }

.folder-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.folder-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-wrap { display: inline-flex; }
.chip {
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--muted);
}
.chip-active { background: var(--purple); border-color: var(--purple); color: #12081a; font-weight: 600; }
.chip-wrap .chip { border-radius: 20px 0 0 20px; }
.chip-manage {
  border-radius: 0 20px 20px 0;
  border: 1px solid var(--border);
  border-left: none;
  background: var(--bg3);
  color: var(--muted);
  padding: 5px 8px;
  font-size: 12px;
}

/* Channel list */
.channel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--bg3);
}
.channel-row.inactive { opacity: 0.5; }
.channel-main { flex: 1; min-width: 0; }
.channel-name { font-weight: 600; }
.channel-url { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  margin-right: 4px;
}
.channel-actions { display: flex; gap: 4px; }
.channel-actions button { padding: 4px 8px; font-size: 12px; }

.drag-handle {
  cursor: grab;
  color: var(--muted);
  padding: 0 4px;
  font-size: 16px;
  user-select: none;
}
.drag-handle:active { cursor: grabbing; }
.channel-row.dragging { opacity: 0.4; }

#pending-list .channel-row { flex-wrap: wrap; }
#pending-list select { padding: 4px 8px; font-size: 12px; }

/* Generate */
.generate-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
#gen-output {
  width: 100%;
  min-height: 220px;
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 12px;
  resize: vertical;
}

.popover-intro { margin-top: 0; line-height: 1.5; }
.runner-status-line { margin-bottom: 14px; }

.command-block {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-top: 16px;
}
.command-block-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
}
.command-block-header strong { color: var(--purple2); }
.command-block textarea {
  width: 100%;
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 12px;
  resize: vertical;
  margin-bottom: 10px;
  display: block;
}
.generate-actions { display: flex; gap: 8px; margin-top: 8px; }

/* Presets */
.preset-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--bg3);
}

/* Settings form */
.settings-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.settings-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.settings-form .full { grid-column: 1 / -1; }
.settings-form .checkbox { flex-direction: row; align-items: center; gap: 6px; }
.settings-form .field { grid-column: 1 / -1; }
.settings-form .field > label { margin-bottom: 2px; }
.checkbox-grid { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.checkbox-grid label { flex-direction: row; align-items: center; gap: 4px; font-size: 12px; color: var(--text); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.modal-backdrop.modal-visible { opacity: 1; }
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  width: 360px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  overflow-x: hidden;
  transform: scale(0.96) translateY(8px);
  transition: transform 0.15s ease;
}
.modal-backdrop.modal-visible .modal-box { transform: scale(1) translateY(0); }
.modal-box.modal-wide { width: 560px; }
.modal-box h3 { margin-top: 0; }
.modal-box .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.modal-box .field label { font-size: 12px; color: var(--muted); }
.modal-box .field textarea { width: 100%; font-family: inherit; }
.modal-box .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-box .actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.small { font-size: 11px; }

.inline-with-button { display: flex; gap: 6px; }
.inline-with-button input { flex: 1; min-width: 0; }
.inline-with-button button { white-space: nowrap; font-size: 12px; }

.tag-input {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg3);
  padding: 6px;
}
.tag-chip-list { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.tag-chip-list:empty { margin-bottom: 0; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--purple);
  color: #12081a;
  border-radius: 20px;
  padding: 2px 4px 2px 10px;
  font-size: 12px;
  font-weight: 600;
}
.tag-chip button {
  border: none;
  background: transparent;
  color: #12081a;
  padding: 0 4px;
  font-size: 12px;
  line-height: 1;
}
.tag-entry {
  border: none;
  background: transparent;
  width: 100%;
  padding: 4px 2px;
  color: var(--text);
}
.tag-entry:focus { outline: none; }

@media (max-width: 600px) {
  .settings-form, .modal-box .two-col { grid-template-columns: 1fr; }
  .generate-controls { flex-direction: column; }
  .modal-box.modal-wide { width: 92vw; }
  .inline-with-button { flex-direction: column; }
}

#toast-root {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--purple);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.toast-visible { opacity: 1; transform: translateY(0); }
