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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f4f6fb;
  color: #1e293b;
  min-height: 100vh;
}

/* ── Layout ── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow: hidden;
}

.logo {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 20px 20px 20px 18px;
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.logo-icon {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  overflow: hidden;
}

.logo-icon svg,
.logo-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.logo-text {
  font-size: 16px;
  font-weight: 700;
  color: white;
  letter-spacing: 0.2px;
}

/* ── Nav ── */
.nav {
  padding: 12px 0;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 18px;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: color 0.18s, background 0.18s;
  border-left: 3px solid transparent;
  margin: 1px 0;
  user-select: none;
}

.nav-item:hover {
  color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.08);
  border-left-color: #38bdf8;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.18s;
}

.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
  opacity: 1;
}

/* ── Main Content ── */
.content {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header {
  background: white;
  padding: 0 32px;
  height: 58px;
  border-bottom: 1px solid #e8edf4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

.page-title {
  font-size: 17px;
  font-weight: 600;
  color: #0f172a;
  letter-spacing: -0.2px;
}

/* ── Pages ── */
.page {
  display: none;
  flex: 1;
  flex-direction: column;
}

.page.active {
  display: flex;
  flex: 1;
  flex-direction: column;
}

/* ── Generator Page ── */
.textarea-wrap {
  position: relative;
}

.line-count {
  display: block;
  font-size: 11px;
  color: #b0bac8;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  user-select: none;
  min-height: 16px;
}

.output-stats {
  display: block;
  font-size: 11px;
  color: #b0bac8;
  text-align: right;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  user-select: none;
  min-height: 16px;
  padding: 3px 2px 0;
}

.generator-layout {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 28px 32px;
}

.generator-textarea {
  width: 100%;
  height: 150px;
  min-height: 80px;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 16px 18px;
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
  font-family: inherit;
  color: #374151;
  outline: none;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
}

.generator-textarea::placeholder {
  color: #a0aec0;
}

.generator-textarea:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}

.generator-controls {
  background: white;
  border-radius: 10px;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
  border: 1px solid #e8edf4;
}

.controls-row {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.control-group.region {
  flex: 0 0 88px;
}

.control-label {
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  white-space: nowrap;
}

.control-select,
.control-input {
  height: 38px;
  padding: 0 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13.5px;
  color: #374151;
  background: #f8fafc;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}

.control-input::placeholder {
  color: #c8d5e3;
  font-style: normal;
}

.control-select:focus,
.control-input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
  background: white;
}

.control-select {
  cursor: pointer;
}

.btn-generate {
  margin-left: auto;
  height: 40px;
  padding: 0 28px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.35);
  letter-spacing: 0.1px;
}

.btn-generate:hover {
  opacity: 0.9;
}

.btn-generate:active {
  transform: scale(0.98);
}

/* ── Input / Output sections ── */
.input-section {
  background: white;
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.08);
  border: 1px solid #e2e8f0;
}

.input-section .generator-textarea {
  box-shadow: none;
  border-color: #e8edf4;
}

.input-section .generator-controls {
  box-shadow: none;
  border-color: #e8edf4;
  padding: 14px 16px;
}

.output-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.output-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #b0bac8;
  padding: 0 2px;
}

.output-cost-badge {
  margin-left: auto;
  font-size: 11px; font-weight: 600; letter-spacing: 0;
  text-transform: none;
  background: #f0fdf4; color: #16a34a;
  border: 1px solid #bbf7d0;
  padding: 2px 9px; border-radius: 20px;
}

/* ── Raw Data Row ── */
.raw-data-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.raw-data-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.raw-data-group:focus-within .raw-data-textarea {
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}

.raw-data-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
}

.raw-data-textarea {
  width: 100%;
  min-height: 80px;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.6;
  resize: vertical;
  font-family: inherit;
  color: #374151;
  background: white;
  outline: none;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
  transition: border-color 0.2s, box-shadow 0.2s;
}

/* ── Prompts Page ── */
.prompts-layout {
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
}

.prompts-save-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 18px;
}

.btn-save {
  height: 38px;
  padding: 0 24px;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-save:hover {
  opacity: 0.9;
}

.btn-save:active {
  transform: scale(0.98);
}

/* ── Accordion ── */
.accordion {
  background: white;
  border-radius: 10px;
  border: 1px solid #e8edf4;
  overflow: hidden;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
  transition: box-shadow 0.2s;
}

.accordion.open {
  box-shadow: 0 3px 12px rgba(15, 23, 42, 0.1);
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.accordion-header:hover {
  background: #f8fafc;
}

.accordion-title {
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 12px;
}

.accordion-badge {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.accordion-badge svg {
  width: 15px;
  height: 15px;
}

.accordion-arrow {
  color: #cbd5e1;
  transition: transform 0.28s ease, color 0.2s;
  flex-shrink: 0;
}

.accordion.open .accordion-arrow {
  transform: rotate(180deg);
  color: #94a3b8;
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.32s ease;
}

.accordion.open .accordion-body {
  max-height: 600px;
}

.accordion-content {
  padding: 2px 22px 20px;
}

.prompt-textarea {
  width: 100%;
  height: 180px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Courier New', monospace;
  color: #374151;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  background: #f8fafc;
}

.prompt-textarea:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
  background: white;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  transform: translateY(70px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 9px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* ── Settings ── */
.settings-layout {
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.settings-section {
  background: white;
  border-radius: 12px;
  border: 1px solid #e8edf4;
  box-shadow: 0 1px 4px rgba(15,23,42,0.06);
  overflow: hidden;
}

.settings-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid #f1f5f9;
}

.settings-section-title {
  font-size: 14px;
  font-weight: 600;
  color: #0f172a;
}

.settings-section-sub {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 3px;
}

.models-table {
  padding: 0 24px 20px;
}

.models-table-head {
  display: grid;
  grid-template-columns: 1fr 1fr 36px;
  gap: 12px;
  padding: 12px 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.model-row {
  display: grid;
  grid-template-columns: 1fr 1fr 36px;
  gap: 12px;
  align-items: center;
  padding: 5px 0;
}

.btn-add-model {
  height: 36px;
  padding: 0 16px;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-add-model:hover { background: #e2e8f0; }

.btn-remove-model {
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.btn-remove-model:hover { color: #ef4444; background: #fef2f2; }

/* ── Copy button ── */
.btn-copy {
  width: 26px; height: 26px;
  border: none; background: none;
  color: #cbd5e1; cursor: pointer;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.btn-copy svg { width: 14px; height: 14px; }
.btn-copy:hover { color: #3b82f6; background: #eff6ff; }

/* ── Generation loader ── */
.gen-loader {
  background: white;
  border: 1px solid #e8edf4;
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: 0 1px 4px rgba(15,23,42,0.06);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.gen-loader-rows { display: flex; flex-direction: column; gap: 10px; }

.gen-loader-row {
  display: grid;
  grid-template-columns: 24px 160px 1fr auto;
  align-items: center;
  gap: 12px;
}

.gen-loader-icon { display: flex; align-items: center; justify-content: center; }

.gen-spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid #e2e8f0;
  border-top-color: #94a3b8;
  border-radius: 50%;
}
.gen-spinner.active {
  border-top-color: #3b82f6;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gen-check { font-size: 14px; color: #10b981; font-weight: 700; }
.gen-error-icon { font-size: 14px; color: #ef4444; font-weight: 700; }

.gen-loader-label { font-size: 12.5px; font-weight: 500; color: #475569; white-space: nowrap; }

.gen-loader-bar-wrap {
  height: 5px; background: #f1f5f9; border-radius: 3px; overflow: hidden;
}
.gen-loader-bar {
  height: 100%; width: 0; border-radius: 3px;
  background: linear-gradient(90deg, #3b82f6, #6366f1);
  transition: width 0.4s ease;
}
.gen-loader-bar.active {
  background: linear-gradient(90deg, #3b82f6, #6366f1);
}
.gen-loader-bar.done { background: linear-gradient(90deg, #10b981, #059669); }
.gen-loader-bar.error { background: #ef4444; }

.gen-loader-info { font-size: 11.5px; color: #94a3b8; white-space: nowrap; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 7px; }
.gen-error-msg { color: #ef4444; }
.btn-loader-retry {
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 4px;
  border: 1px solid #6366f1; color: #6366f1;
  background: none; cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn-loader-retry:hover { background: #6366f1; color: #fff; }

.gen-loader-total {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  gap: 12px;
}
.gen-total-label { font-size: 12px; font-weight: 600; color: #64748b; }
.gen-total-tokens { font-size: 12px; color: #94a3b8; }
.gen-total-cost { font-size: 15px; font-weight: 700; color: #0f172a; margin-left: auto; }

/* disabled state for textareas */
.raw-data-textarea:disabled { background: #f8fafc; color: #94a3b8; cursor: not-allowed; }

/* ── Page title with icon ── */
.page-title-wrap { display: flex; align-items: center; gap: 9px; }
.page-title-icon { width: 20px; height: 20px; flex-shrink: 0; }

/* ── Regen mini progress bar ── */
.regen-bar-wrap {
  height: 3px;
  background: #e8edf4;
  border-radius: 2px;
  overflow: hidden;
  margin: 0 0 6px;
}
.regen-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #6366f1, #0ea5e9);
  border-radius: 2px;
  transition: width 0.25s ease;
}

/* ── Regen button ── */
.btn-regen {
  width: 26px; height: 26px;
  border: none; background: none;
  color: #cbd5e1; cursor: pointer;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.btn-regen svg { width: 14px; height: 14px; }
.btn-regen:hover { color: #f59e0b; background: #fffbeb; }
.btn-regen:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── New Raw Data button (Dashboard) ── */
.btn-new-raw-data {
  height: 34px; padding: 0 18px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: white; border: none; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center;
  box-shadow: 0 2px 8px rgba(14,165,233,0.3);
  transition: opacity 0.2s;
}
.btn-new-raw-data:hover { opacity: 0.9; }

/* ── Header actions ── */
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-project-info { display: flex; align-items: center; gap: 12px; }

.save-name-hint { font-size: 12px; color: #94a3b8; }
.save-name-hint.error { color: #ef4444; font-weight: 500; }

.btn-save-project {
  height: 34px; padding: 0 20px;
  background: #e2e8f0; color: #94a3b8;
  border: none; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: not-allowed;
  transition: background 0.2s, color 0.2s;
}
.btn-save-project:not(:disabled),
.btn-save-project.active {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white; cursor: pointer;
  box-shadow: 0 2px 8px rgba(16,185,129,0.3);
}
.btn-save-project:not(:disabled):hover { opacity: 0.9; }

.btn-abort-gen {
  display: none; align-items: center; gap: 7px;
  height: 34px; padding: 0 16px;
  background: #fff0f0; color: #dc2626;
  border: 1.5px solid #fca5a5; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-abort-gen:hover { background: #fee2e2; border-color: #f87171; }
.btn-abort-gen:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Status badge ── */
.project-status-badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.project-status-badge.green { background: #dcfce7; color: #15803d; }
.project-status-badge.yellow { background: #fef9c3; color: #a16207; }
.project-status-badge.generating {
  background: #eff6ff; color: #2563eb;
  animation: badge-pulse 1.4s ease-in-out infinite;
}
.project-status-badge.red { background: #fee2e2; color: #dc2626; }
.project-status-badge.orange { background: #fff7ed; color: #c2410c; }
@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ── Projects table ── */
.projects-layout { padding: 28px 32px; }

.projects-table-wrap {
  background: white; border-radius: 12px;
  border: 1px solid #e8edf4;
  box-shadow: 0 1px 4px rgba(15,23,42,0.06);
  overflow: hidden;
}

.projects-table { width: 100%; border-collapse: collapse; }

.projects-table thead tr {
  border-bottom: 1px solid #f1f5f9;
}
.projects-table th {
  padding: 12px 20px; text-align: left;
  font-size: 11px; font-weight: 600;
  color: #94a3b8; text-transform: uppercase; letter-spacing: 0.7px;
}
.projects-table td {
  padding: 13px 20px;
  font-size: 13.5px; color: #1e293b;
  border-bottom: 1px solid #f8fafc;
}
.projects-row { cursor: pointer; transition: background 0.12s; }
.projects-row:hover { background: #f8fafc; }
.projects-row:last-child td { border-bottom: none; }
.projects-id { font-family: monospace; font-size: 12px; color: #94a3b8; }
.projects-name { font-weight: 600; }
.projects-loading { text-align: center; color: #94a3b8; padding: 40px !important; }

/* ── Project row action buttons ── */
.projects-actions { width: 72px; text-align: right; white-space: nowrap; }
.btn-proj-action {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 7px; border: none;
  background: transparent; cursor: pointer; transition: background 0.13s, color 0.13s;
  color: #94a3b8;
}
.btn-proj-action svg { width: 15px; height: 15px; }
.btn-proj-dup:hover { background: #eff6ff; color: #3b82f6; }
.btn-proj-del:hover { background: #fef2f2; color: #ef4444; }

/* ── Confirm modal ── */
.confirm-overlay {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(15,23,42,0.45); backdrop-filter: blur(2px);
  align-items: center; justify-content: center;
}
.confirm-overlay.show { display: flex; }
.confirm-modal {
  background: white; border-radius: 16px;
  padding: 32px 28px 24px;
  width: 380px; max-width: calc(100vw - 40px);
  box-shadow: 0 20px 60px rgba(15,23,42,0.18);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  animation: modalIn 0.18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.93) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.confirm-icon { font-size: 36px; line-height: 1; margin-bottom: 4px; }
.confirm-title { font-size: 17px; font-weight: 700; color: #1e293b; text-align: center; }
.confirm-body { font-size: 13.5px; color: #64748b; text-align: center; line-height: 1.55; margin-bottom: 6px; }
.confirm-actions { display: flex; gap: 10px; width: 100%; margin-top: 6px; }
.confirm-btn-cancel, .confirm-btn-ok {
  flex: 1; padding: 10px 0; border-radius: 9px; font-size: 14px;
  font-weight: 600; cursor: pointer; border: none; transition: background 0.13s;
}
.confirm-btn-cancel { background: #f1f5f9; color: #475569; }
.confirm-btn-cancel:hover { background: #e2e8f0; }
.confirm-btn-ok { background: #6366f1; color: white; }
.confirm-btn-ok:hover { background: #4f46e5; }
.confirm-btn-ok.danger { background: #ef4444; }
.confirm-btn-ok.danger:hover { background: #dc2626; }
