/* ==========================================================================
   FIJATE TOOLS - GENERADOR DE HISTORIAS DE USUARIO Y BDD GHERKIN
   Estilos Canónicos • Modo Claro / Oscuro • Responsive & Mobile First
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-rgb: 37, 99, 235;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --success-border: rgba(16, 185, 129, 0.35);
  --warning: #f59e0b;
  --danger: #ef4444;

  /* Tema oscuro por defecto */
  --bg-body: #0b0f19;
  --bg-card: #111827;
  --bg-card-hover: #172033;
  --bg-card-muted: #1e293b;
  --bg-input: #0d1322;
  --border-color: #1f293d;
  --border-focus: #3b82f6;
  --text-main: #f3f4f6;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.35);
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-card-muted: #f1f5f9;
  --bg-input: #f8fafc;
  --border-color: #e2e8f0;
  --border-focus: #2563eb;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.08);
}

/* Reset básico */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-body);
  color: var(--text-main);
  font-family: var(--font-body);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.tool-layout {
  max-width: 1240px;
  margin: 1rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
}

/* Publicidad */
.tools-ad-banner-section {
  margin-bottom: 1.25rem;
  width: 100%;
}
.ad-banner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.ad-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}
.ad-banner-card {
  width: 100%;
  min-height: 90px;
  background-color: var(--bg-card);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Tarjeta principal */
.card-main {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
  margin-bottom: 1.75rem;
}

/* Encabezado */
.story-header-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.story-header-title h2 {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.story-header-title p {
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Layout de dos columnas: Constructor (izq) y Vista previa / Backlog (dcha) */
.story-workspace-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.5rem;
  align-items: start;
}

/* Bloques de sección */
.builder-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.section-block {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.section-block-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.6rem;
}

/* Campos del formulario */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-input,
.form-textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  outline: none;
  font-family: var(--font-body);
  transition: border-color 0.15s;
}

.form-input:focus,
.form-textarea:focus {
  border-color: var(--border-focus);
}

.form-textarea {
  min-height: 55px;
  resize: vertical;
}

/* Tarjeta estructurada "Como... Quiero... Para..." */
.story-sentence-box {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

.sentence-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sentence-prefix {
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 65px;
}

.sentence-input {
  flex: 1;
}

/* Escenarios BDD / Gherkin dinámicos */
.scenarios-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.scenario-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
}

.scenario-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.scenario-title-input {
  flex: 1;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-main);
  outline: none;
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 2px;
}

.scenario-title-input:focus {
  border-bottom-color: var(--border-focus);
}

.btn-remove-scenario {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.btn-remove-scenario:hover {
  color: var(--danger);
  background-color: var(--bg-card-muted);
}

.gherkin-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.gherkin-kw {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  min-width: 75px;
  text-transform: uppercase;
}

.kw-given { color: #60a5fa; }
.kw-when { color: #fbbf24; }
.kw-then { color: #34d399; }
.kw-and { color: #94a3b8; }

/* Selector de Story Points Fibonacci */
.fibonacci-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-fibo {
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-fibo:hover {
  border-color: var(--border-focus);
  background-color: var(--bg-card-hover);
}

.btn-fibo.active {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

/* Checklist INVEST */
.invest-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.invest-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.82rem;
  color: var(--text-muted);
  transition: all 0.15s;
}

.invest-item input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
}

.invest-item.checked {
  color: var(--text-main);
  border-color: rgba(16, 185, 129, 0.4);
  background-color: var(--success-bg);
}

.invest-progress-bar-container {
  width: 100%;
  height: 6px;
  background-color: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.4rem;
}

.invest-progress-fill {
  height: 100%;
  background-color: var(--primary);
  transition: width 0.25s ease, background-color 0.25s ease;
}

/* Columna derecha: Previsualización de código y copia */
.preview-sticky-box {
  position: sticky;
  top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.preview-card {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-tabs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.format-tabs {
  display: inline-flex;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.btn-format-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-format-tab.active {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-copy {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary);
  background-color: var(--primary);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
}

.btn-copy:hover {
  background-color: var(--primary-hover);
}

.output-pre {
  background-color: #0b0f19;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.55;
  color: #f3f4f6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 480px;
  overflow-y: auto;
}

[data-theme="light"] .output-pre {
  background-color: #f1f5f9;
  color: #0f172a;
}

/* Biblioteca de historias guardadas */
.saved-stories-card {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.saved-stories-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
}

.saved-story-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.saved-story-item:hover {
  border-color: var(--border-focus);
}

.saved-story-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-width: 220px;
}

.saved-story-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-story-meta {
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Selectores y botones canónicos */
.pm-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  appearance: none;
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 2.5rem 0.5rem 0.75rem;
  font-size: 0.88rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 14px;
  cursor: pointer;
  min-height: 40px;
}

.pm-select option,
.pm-select optgroup {
  background-color: var(--bg-card);
  color: var(--text-main);
}

.btn-pm {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
  min-height: 40px;
}

.btn-pm:hover {
  background-color: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.btn-pm-primary {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-pm-primary:hover {
  background-color: var(--primary-hover);
}

/* Responsive */
@media (max-width: 900px) {
  .story-workspace-grid {
    grid-template-columns: 1fr;
  }
  .preview-sticky-box {
    position: static;
  }
}

@media (max-width: 768px) {
  .tool-layout {
    padding: 0 0.75rem;
  }
  .card-main {
    padding: 1rem;
  }
  .story-header-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .invest-grid {
    grid-template-columns: 1fr;
  }
  .sentence-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .sentence-prefix {
    min-width: auto;
  }
  .gherkin-row {
    flex-direction: column;
    align-items: flex-start;
  }
}
