:root {
  --bg: #f7f8fa;
  --bg-elevated: #ffffff;
  --text: #1a1f29;
  --text-muted: #5b6472;
  --border: #e3e6ea;
  --accent: #3457d5;
  --accent-hover: #2943ad;
  --accent-soft: #eaefff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-hover: 0 4px 10px rgba(16, 24, 40, 0.08), 0 2px 4px rgba(16, 24, 40, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --bg-elevated: #171c24;
    --text: #e8eaed;
    --text-muted: #9aa3b2;
    --border: #262c37;
    --accent: #6d8bff;
    --accent-hover: #849dff;
    --accent-soft: #1b2338;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 6px 16px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2rem);
}

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-top: 1.1rem;
  padding-bottom: 1.1rem;
}

.brand-mark {
  color: var(--accent);
  font-size: 1.1rem;
}

.brand-name {
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Main / hero */
main {
  flex: 1;
}

.hero {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(2.5rem, 6vw, 5rem) clamp(1rem, 4vw, 2rem) clamp(1.5rem, 4vw, 2.5rem);
  text-align: center;
}

.hero h1 {
  margin: 0 0 0.6rem;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  margin: 0 0 2rem;
  color: var(--text-muted);
  font-size: clamp(0.95rem, 2vw, 1.05rem);
}

.search-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 0.5rem 0.5rem 1.1rem;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.search-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}

.search-form input[type="search"] {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  padding: 0.6rem 0;
}

.search-form input[type="search"]::placeholder {
  color: var(--text-muted);
}

.search-form button {
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.65rem 1.4rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.search-form button:hover {
  background: var(--accent-hover);
}

.hero-help {
  margin: 1.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Categories */
.categories {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2rem) clamp(3rem, 6vw, 5rem);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
}

@media (max-width: 960px) {
  .categories {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .categories {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 420px) {
  .categories {
    grid-template-columns: 1fr;
  }
}

.card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.4rem 1.2rem;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}

.card-icon {
  font-size: 1.6rem;
}

.card h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Header nav (shared across authenticated pages) */
.site-header .wrap {
  gap: 1.5rem;
}

.site-nav {
  display: flex;
  gap: 1.25rem;
  margin-left: 0.5rem;
}

.site-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.15s ease;
}

.site-nav a:hover,
.site-nav a.is-active {
  color: var(--text);
}

.header-spacer {
  margin-left: auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border);
}

/* Page shell for non-hero pages (forms, details, lists) */
.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 3rem) clamp(1rem, 4vw, 2rem) clamp(3rem, 6vw, 4rem);
  width: 100%;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-size: clamp(1.3rem, 3vw, 1.7rem);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.page-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* Cards (forms, detail panels) */
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: clamp(1.25rem, 3vw, 1.75rem);
  box-shadow: var(--shadow);
}

.panel + .panel {
  margin-top: 1.25rem;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

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

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

.field input[type="text"],
.field input[type="email"],
.field input[type="number"],
.field select,
.field textarea,
.auth-shell input[type="email"],
.auth-shell input[type="text"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 0.7rem;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.auth-shell input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field textarea {
  resize: vertical;
  min-height: 4.5rem;
  font-family: inherit;
  line-height: 1.5;
}

.field input[type="file"] {
  border: none;
  background: transparent;
  padding: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.field input[type="file"]::file-selector-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  margin-right: 0.7rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.field input[type="file"]::file-selector-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.form-footer {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.6rem;
}

/* Alerts */
.alert {
  border-radius: 10px;
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
  border: 1px solid transparent;
}

.alert-error {
  background: color-mix(in srgb, #e5484d 12%, var(--bg-elevated));
  border-color: color-mix(in srgb, #e5484d 35%, var(--border));
  color: #e5484d;
}

.alert-success {
  background: color-mix(in srgb, #30a46c 12%, var(--bg-elevated));
  border-color: color-mix(in srgb, #30a46c 35%, var(--border));
  color: #30a46c;
}

.alert ul {
  margin: 0;
  padding-left: 1.1rem;
}

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-borrador {
  background: var(--accent-soft);
  color: var(--text-muted);
}

.status-en-revision {
  background: color-mix(in srgb, #f5a524 18%, transparent);
  color: #b6740a;
}

.status-publicado {
  background: color-mix(in srgb, #30a46c 16%, transparent);
  color: #237a53;
}

.status-archivado {
  background: color-mix(in srgb, #6b7280 18%, transparent);
  color: var(--text-muted);
}

@media (prefers-color-scheme: dark) {
  .status-en-revision { color: #f5a524; }
  .status-publicado { color: #3dd68c; }
}

/* Incident meta row (detail page) */
.meta-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.75rem;
}

.meta-row .sep {
  color: var(--border);
}

.meta-row form {
  display: inline-flex;
  align-items: center;
}

/* Detail sections */
.detail-section {
  margin-bottom: 1.5rem;
}

.detail-section:last-child {
  margin-bottom: 0;
}

.detail-section h2 {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.detail-section p {
  margin: 0;
  white-space: pre-wrap;
}

/* Rendered Markdown answer (search) */
.answer-content > *:first-child {
  margin-top: 0;
}

.answer-content > *:last-child {
  margin-bottom: 0;
}

.answer-content p,
.answer-content ul,
.answer-content ol {
  margin: 0 0 0.9rem;
  line-height: 1.6;
}

.answer-content ul,
.answer-content ol {
  padding-left: 1.4rem;
}

.answer-content li + li {
  margin-top: 0.3rem;
}

.answer-content strong {
  color: var(--text);
}

.code-block {
  margin: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 0.9rem;
  font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 0.85rem;
  overflow-x: auto;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 600;
  margin: 0 0.3rem 0.3rem 0;
}

/* Incident list */
.incident-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.incident-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1.1rem;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.incident-row:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}

.incident-row-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.incident-code {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.incident-title {
  font-size: 0.95rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.incident-row-link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  text-decoration: none;
  color: inherit;
}

/* Feedback widget */
.feedback-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.feedback-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.radio-group {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 14px;
}

/* Auth pages (login / verify) */
.auth-shell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
  font-weight: 600;
}

.auth-brand .brand-mark {
  font-size: 1.1rem;
}

.auth-card h1 {
  margin: 0 0 0.4rem;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-card p.auth-subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: left;
}

.auth-card form + form {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.auth-card label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.auth-card .btn {
  width: 100%;
}

.auth-resend {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.auth-resend:hover {
  color: var(--accent);
}

.document-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0 0 1rem;
}

.document-row {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.document-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.document-row > a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  margin-right: 0.6rem;
}

.document-row > a:hover {
  text-decoration: underline;
}

.status-pendiente,
.status-procesando {
  background: var(--accent-soft);
  color: var(--text-muted);
}

.status-completado {
  background: color-mix(in srgb, #30a46c 16%, transparent);
  color: #237a53;
}

.status-error {
  background: color-mix(in srgb, #e5484d 12%, transparent);
  color: #e5484d;
}

@media (prefers-color-scheme: dark) {
  .status-completado { color: #3dd68c; }
}

.extraction-suggestion {
  margin-top: 0.6rem;
  padding: 0.9rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.extraction-suggestion dl {
  margin: 0 0 0.9rem;
  display: grid;
  gap: 0.5rem;
}

.extraction-suggestion dt {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.extraction-suggestion dd {
  margin: 0.15rem 0 0;
  white-space: pre-wrap;
}
