:root {
  --bg: #08090d;
  --surface: rgba(18, 20, 28, 0.86);
  --surface-strong: rgba(24, 26, 36, 0.96);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --accent: #00e5ff;
  --accent-2: #6ee7b7;
  --accent-3: #ff8fb8;
  --text: #ffffff;
  --text-muted: #a5adbd;
  --warn: #ffd166;
  --danger: #ff6b6b;
  --font: 'Space Grotesk', system-ui, sans-serif;
}

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

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 15% 8%, rgba(0, 229, 255, 0.14), transparent 28%),
    radial-gradient(circle at 85% 16%, rgba(255, 143, 184, 0.08), transparent 25%),
    linear-gradient(180deg, #08090d 0%, #0b0d14 100%);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px;
  background: rgba(8, 9, 13, 0.76);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand span {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: var(--bg);
  background: var(--accent);
  border-radius: 8px;
  font-weight: 800;
}

.brand strong {
  font-size: 1.05rem;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.nav-item,
.ghost-button,
.primary-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-muted);
}

.nav-item {
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  transition: 0.2s ease;
}

.nav-item:hover,
.nav-item.active {
  color: var(--accent);
  border-color: rgba(0, 229, 255, 0.45);
  background: rgba(0, 229, 255, 0.08);
}

.workspace-card,
.panel,
.kpi-card,
.doc-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.workspace-card {
  margin-top: auto;
  padding: 16px;
}

.workspace-card strong {
  display: block;
  margin-top: 8px;
}

.workspace-card p,
.panel p,
.doc-card p {
  color: var(--text-muted);
  line-height: 1.55;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 16px rgba(255, 209, 102, 0.6);
}

.status-dot.connected {
  background: var(--accent-2);
  box-shadow: 0 0 16px rgba(110, 231, 183, 0.55);
}

.main-panel {
  min-width: 0;
  padding: 28px clamp(18px, 3vw, 44px) 44px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 24px;
}

.topbar h1 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(2rem, 4vw, 4.4rem);
  line-height: 1.02;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar-actions,
.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.ghost-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 13px;
  white-space: nowrap;
}

.ghost-button:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.05);
}

.primary-button {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.kpi-card {
  padding: 16px;
}

.kpi-card span {
  display: block;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.kpi-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.8rem;
}

.overview-grid,
.metrics-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-header,
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 16px;
}

.panel h2,
.editor-header h2 {
  margin: 0;
  font-size: clamp(1.25rem, 2vw, 2rem);
}

.mini-label {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  color: var(--text-muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.75rem;
}

.system-map {
  height: 430px;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 28px 28px;
}

.system-map--fallback {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 14px;
  overflow: auto;
}

.week-stack,
.script-list,
.checklist {
  display: grid;
  gap: 10px;
}

.item-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.item-card strong {
  display: block;
  margin-bottom: 5px;
}

.item-card small,
.tag {
  color: var(--text-muted);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  display: inline-flex;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.75rem;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.segmented button {
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-muted);
  background: transparent;
}

.segmented button.active {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

.data-table th,
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--accent);
  background: #10121a;
  font-size: 0.78rem;
}

.data-table td {
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.script-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100vh - 150px);
}

.script-list-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 154px);
}

.script-list {
  overflow: auto;
  padding-right: 4px;
}

.script-button {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  text-align: left;
}

.script-button.active,
.script-button:hover {
  border-color: rgba(0, 229, 255, 0.45);
  background: rgba(0, 229, 255, 0.08);
}

.script-button span {
  display: block;
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.search-input {
  width: min(220px, 100%);
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  min-height: 660px;
}

.editor-status {
  margin-bottom: 12px;
  padding: 10px 12px;
  color: var(--text-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  font-size: 0.86rem;
}

.editor-status.saved {
  color: var(--accent-2);
  border-color: rgba(110, 231, 183, 0.35);
}

.editor-status.dirty {
  color: var(--warn);
  border-color: rgba(255, 209, 102, 0.35);
}

.editor-surface {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  flex: 1;
  min-height: 540px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

#markdown-editor {
  display: block;
  width: 100%;
  min-height: 100%;
  padding: 18px;
  resize: none;
  color: var(--text);
  background: rgba(7, 9, 14, 0.92);
  border: 0;
  outline: 0;
  line-height: 1.65;
}

.markdown-preview {
  display: block;
  overflow: auto;
  padding: 22px;
  color: var(--text-muted);
  background: rgba(13, 15, 22, 0.92);
  line-height: 1.72;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
  color: var(--text);
  line-height: 1.15;
}

.markdown-preview blockquote {
  margin-left: 0;
  padding-left: 14px;
  color: var(--text);
  border-left: 3px solid var(--accent);
}

.markdown-preview code {
  color: var(--accent-2);
}

.docs-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.doc-card {
  display: flex;
  flex-direction: column;
  min-height: 220px;
  padding: 18px;
}

.doc-card h2 {
  margin: 0 0 10px;
}

.doc-card .ghost-button {
  margin-top: auto;
}

.checklist label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text-muted);
}

.checklist input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .side-nav {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  }

  .overview-grid,
  .metrics-layout,
  .script-layout,
  .docs-grid {
    grid-template-columns: 1fr;
  }

  .script-list-panel {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .main-panel,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .panel-header,
  .editor-header {
    display: grid;
  }

  .topbar-actions,
  .editor-actions {
    justify-content: stretch;
  }

  .topbar-actions > *,
  .editor-actions > * {
    width: 100%;
  }

  .side-nav,
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .editor-surface {
    grid-template-columns: 1fr;
  }
}

/* ---------- Producción · Tablero Scrum ---------- */

.board-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.board-hint {
  margin: -4px 0 16px;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(232px, 1fr);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 10px;
  align-items: start;
}

.board-column {
  display: flex;
  flex-direction: column;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.board-column.drop-target {
  border-color: rgba(0, 229, 255, 0.55);
  background: rgba(0, 229, 255, 0.07);
}

.board-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.board-column-header strong {
  font-size: 0.92rem;
}

.board-column-header .board-count {
  min-width: 22px;
  padding: 2px 8px;
  text-align: center;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.74rem;
}

.board-column-body {
  display: grid;
  align-content: start;
  gap: 10px;
  flex: 1;
  padding: 12px;
  min-height: 90px;
}

.board-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--card-accent, var(--line-strong));
  border-radius: 8px;
  background: var(--surface-strong);
  cursor: grab;
  transition: border-color 0.15s ease, transform 0.05s ease;
}

.board-card:hover {
  border-color: var(--line-strong);
}

.board-card:active {
  cursor: grabbing;
}

.board-card.dragging {
  opacity: 0.45;
}

.board-card-id {
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.board-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 0.92rem;
  line-height: 1.35;
}

.board-card .tag-row {
  margin-top: 0;
}

.board-empty {
  padding: 14px;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

/* ---------- Modal de edición ---------- */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  place-items: center;
  padding: 20px;
  background: rgba(4, 5, 8, 0.72);
  backdrop-filter: blur(6px);
}

.modal-backdrop.is-open {
  display: grid;
}

.modal {
  width: min(640px, 100%);
  max-height: 88vh;
  overflow: auto;
  padding: 22px;
  background: var(--surface-strong);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.4rem;
}

.modal-close {
  min-height: 34px;
  padding: 6px 11px;
}

.modal-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-form .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.modal-form .field.full {
  grid-column: 1 / -1;
}

.modal-form label {
  color: var(--text-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-form input,
.modal-form select,
.modal-form textarea {
  width: 100%;
  padding: 9px 10px;
  color: var(--text);
  background: rgba(7, 9, 14, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
}

.modal-form textarea {
  min-height: 68px;
  resize: vertical;
  line-height: 1.5;
}

.modal-form input:focus,
.modal-form select:focus,
.modal-form textarea:focus {
  border-color: rgba(0, 229, 255, 0.5);
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions-spacer {
  flex: 1;
}

.modal-delete {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.35);
}

.modal-delete:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(255, 107, 107, 0.08);
}

@media (max-width: 720px) {
  .modal-form {
    grid-template-columns: 1fr;
  }

  .board-toolbar {
    justify-content: stretch;
  }
}

/* ---------- Serie pill, calendario clicable, render Markdown enriquecido ---------- */

.serie-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--pill-color, var(--text-muted));
  border: 1px solid color-mix(in srgb, var(--pill-color, var(--line-strong)) 45%, transparent);
  background: color-mix(in srgb, var(--pill-color, #ffffff) 12%, transparent);
}

.board-card .serie-pill {
  margin-bottom: 8px;
}

.calendar-row {
  cursor: pointer;
}

.calendar-row:hover td {
  background: rgba(0, 229, 255, 0.06);
}

.calendar-script-btn {
  padding: 5px 9px;
  white-space: nowrap;
}

.markdown-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.9rem;
}

.markdown-preview th,
.markdown-preview td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-preview th {
  color: var(--accent);
  background: rgba(255, 255, 255, 0.04);
}

.markdown-preview hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}

.markdown-preview ul,
.markdown-preview ol {
  padding-left: 20px;
}

.markdown-preview a {
  color: var(--accent);
  text-decoration: underline;
}

.markdown-preview em {
  color: var(--text);
  font-style: italic;
}

.markdown-preview pre {
  padding: 12px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.markdown-preview p {
  margin: 8px 0;
}

/* ---------- Modales sm / lg y modal de guión ---------- */

.modal.modal-sm {
  width: min(460px, 100%);
}

.modal.modal-lg {
  width: min(1120px, 100%);
}

.script-modal-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 14px;
}

.script-edit {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 56vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

#script-editor {
  display: block;
  width: 100%;
  min-height: 56vh;
  padding: 16px;
  resize: none;
  color: var(--text);
  background: rgba(7, 9, 14, 0.92);
  border: 0;
  outline: 0;
  line-height: 1.6;
  font-family: inherit;
}

.script-preview {
  display: block;
  min-height: 56vh;
  max-height: 72vh;
  margin: 0;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: rgba(13, 15, 22, 0.92);
}

.script-versions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  max-height: 66vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.script-versions-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.script-version-new {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.script-version-new input {
  padding: 9px 10px;
  color: var(--text);
  background: rgba(7, 9, 14, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
}

.script-version-list {
  display: grid;
  gap: 8px;
}

.script-version {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.script-version-open {
  flex: 1;
  padding: 9px 10px;
  text-align: left;
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.script-version-open:hover {
  border-color: rgba(0, 229, 255, 0.45);
  background: rgba(0, 229, 255, 0.06);
}

.script-version-open strong {
  display: block;
  font-size: 0.86rem;
}

.script-version-open small {
  color: var(--text-muted);
}

.script-version-del {
  width: 34px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.script-version-del:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.script-modal-status {
  margin: 12px 0 0;
  min-height: 1.2em;
  color: var(--accent-2);
  font-size: 0.84rem;
}

@media (max-width: 900px) {
  .script-modal-body {
    grid-template-columns: 1fr;
  }

  .script-edit {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  #script-editor,
  .script-preview {
    min-height: 38vh;
  }
}
