/*
 * Qertia — sistema visual (manual de identidad, docs/branding/)
 * Petróleo #0D3B44 · Oliva #7E9A1A · Marfil #FAF9F0 · Pizarra #3B5257
 * Plus Jakarta Sans (UI/títulos) · JetBrains Mono (kickers/metadatos)
 */
@layer reset, tokens, base, layout, components, utilities;

@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("/assets/plus-jakarta-sans-latin-wght-normal-d2ff26bc.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/assets/jetbrains-mono-latin-wght-normal-7c88d0cc.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  img, svg { display: block; max-width: 100%; }
  input, button, textarea, select { font: inherit; color: inherit; }
  p, h1, h2, h3, h4 { overflow-wrap: break-word; }
}

@layer tokens {
  :root {
    --petrol: #0D3B44;
    --petrol-dark: #0B353F;
    --olive: #7E9A1A;
    --olive-hover: #6E8815;
    --ivory: #FAF9F0;
    --ivory-dark: #F2F0E2;
    --slate: #3B5257;
    --ink: #24393F;
    --border: #DFDCCB;
    --white: #FFFFFF;
    --danger: #A4322A;
    --danger-bg: #FBEDEB;
    --warning: #8A5A00;
    --warning-bg: #FBF3DF;
    --success-bg: #EEF3DC;
    --info-bg: #E6EEF0;

    --font-sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgb(13 59 68 / .06), 0 4px 16px rgb(13 59 68 / .06);
    --max: 72rem;
    --grid-line: rgb(13 59 68 / .045);
  }
}

@layer base {
  html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
  body {
    font-family: var(--font-sans);
    color: var(--petrol);
    background-color: var(--ivory);
    background-image:
      linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
      linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
    background-size: 32px 32px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
  }
  h1, h2, h3, h4 { line-height: 1.15; letter-spacing: -0.015em; font-weight: 800; }
  h1 { font-size: clamp(1.6rem, 2.5vw, 2.1rem); }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.05rem; font-weight: 700; }
  p { color: var(--slate); }
  a { color: var(--petrol); text-decoration-color: var(--olive); text-underline-offset: 3px; }
  a:hover { color: var(--olive-hover); }
  :focus-visible { outline: 3px solid var(--olive); outline-offset: 2px; border-radius: 4px; }
  ::selection { background: rgb(126 154 26 / .25); }
  code, .mono { font-family: var(--font-mono); }
  hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
  .turbo-progress-bar { background-color: var(--olive); height: 3px; }
}

@layer layout {
  .container { width: min(100% - 2.5rem, var(--max)); margin-inline: auto; }
  .stack > * + * { margin-top: var(--gap, 1rem); }
  .cluster { display: flex; flex-wrap: wrap; gap: var(--gap, .75rem); align-items: center; }
  .between { justify-content: space-between; }
  .grid { display: grid; gap: var(--gap, 1.25rem); grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--min, 15rem)), 1fr)); }
  .split { display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  @media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

  /* Header público */
  .site-header { position: sticky; top: 0; z-index: 40; background: rgb(250 249 240 / .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
  .site-header .container { display: flex; align-items: center; justify-content: space-between; height: 4.5rem; gap: 1rem; }
  .brand { display: inline-flex; align-items: center; gap: .65rem; text-decoration: none; }
  .brand img { width: 2.25rem; height: 2.25rem; }
  .brand-name { font-weight: 800; letter-spacing: .14em; font-size: 1.15rem; color: var(--petrol); }
  .site-nav { display: flex; align-items: center; gap: .25rem; }
  .site-nav a { padding: .5rem .8rem; border-radius: var(--radius-sm); text-decoration: none; font-weight: 600; font-size: .92rem; color: var(--slate); }
  .site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--petrol); background: var(--ivory-dark); }
  .nav-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .4rem .6rem; cursor: pointer; }
  @media (max-width: 820px) {
    .nav-toggle { display: inline-flex; }
    .site-nav { display: none; position: absolute; top: 4.5rem; left: 0; right: 0; flex-direction: column; align-items: stretch; background: var(--ivory); border-bottom: 1px solid var(--border); padding: .75rem 1.25rem 1.25rem; }
    .site-nav.is-open { display: flex; }
  }

  .site-footer { border-top: 1px solid var(--border); padding: 2.5rem 0; margin-top: 4rem; background: rgb(250 249 240 / .7); }
  .site-footer .container { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1.5rem; }
  .site-footer nav { display: flex; flex-wrap: wrap; gap: 1.25rem; }
  .site-footer a { text-decoration: none; color: var(--slate); font-size: .9rem; }

  /* App privada */
  .app-shell { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100vh; }
  .sidebar { background: var(--petrol); color: var(--ivory); padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: 1.5rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
  .sidebar .brand-name { color: var(--ivory); }
  .sidebar .brand img { background: var(--ivory); border-radius: 50%; padding: 3px; }
  .side-nav { display: flex; flex-direction: column; gap: .15rem; }
  .side-nav .label { font-family: var(--font-mono); font-size: .65rem; letter-spacing: .12em; text-transform: uppercase; color: rgb(250 249 240 / .55); margin: .9rem .6rem .3rem; }
  .side-nav a { color: rgb(250 249 240 / .85); text-decoration: none; padding: .5rem .65rem; border-radius: var(--radius-sm); font-weight: 500; font-size: .92rem; }
  .side-nav a:hover { background: rgb(255 255 255 / .08); color: var(--white); }
  .side-nav a[aria-current="page"] { background: var(--olive); color: var(--white); }
  .sidebar .user-box { margin-top: auto; font-size: .82rem; border-top: 1px solid rgb(255 255 255 / .15); padding-top: 1rem; }
  .sidebar .user-box p { color: rgb(250 249 240 / .7); }
  .sidebar .user-box button { background: none; border: 0; color: var(--ivory); text-decoration: underline; cursor: pointer; padding: 0; margin-top: .35rem; }
  .main { padding: 1.75rem clamp(1rem, 3vw, 2.5rem) 3rem; min-width: 0; }
  .topbar { display: none; }
  @media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: 16rem; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
    .sidebar.is-open { transform: none; }
    .topbar { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-bottom: 1px solid var(--border); background: var(--ivory); position: sticky; top: 0; z-index: 30; }
  }
  .page-header { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; justify-content: space-between; margin-bottom: 1.5rem; }
  .page-header .kicker { margin-bottom: .25rem; }
}

@layer components {
  .kicker { font-family: var(--font-mono); font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--olive); font-weight: 600; }
  .muted { color: var(--slate); font-size: .9rem; }
  .lead { font-size: 1.15rem; color: var(--slate); max-width: 42rem; }

  /* Botones */
  .btn { display: inline-flex; align-items: center; gap: .45rem; justify-content: center; padding: .65rem 1.15rem; border-radius: var(--radius-sm); font-weight: 700; font-size: .92rem; text-decoration: none; border: 1.5px solid transparent; cursor: pointer; line-height: 1.2; transition: background-color .15s, color .15s, border-color .15s; }
  .btn-primary { background: var(--olive); color: var(--white); }
  .btn-primary:hover { background: var(--olive-hover); color: var(--white); }
  .btn-secondary { background: transparent; color: var(--petrol); border-color: var(--petrol); }
  .btn-secondary:hover { background: var(--petrol); color: var(--ivory); }
  .btn-ghost { background: transparent; color: var(--petrol); border-color: var(--border); }
  .btn-ghost:hover { background: var(--ivory-dark); color: var(--petrol); }
  .btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
  .btn-sm { padding: .35rem .7rem; font-size: .8rem; }
  .btn[disabled], .btn[aria-busy="true"] { opacity: .6; cursor: progress; }
  .button_to { display: inline; }

  /* Tarjetas */
  .card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.35rem; box-shadow: var(--shadow); }
  .card > h2, .card > h3, .card-title { margin-bottom: .75rem; }
  .card-title { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; }
  .card-title h2, .card-title h3 { margin: 0; }
  .card.accent { border-top: 3px solid var(--olive); }

  /* Métricas */
  .stat { display: flex; flex-direction: column; gap: .2rem; text-decoration: none; }
  .stat .value { font-size: 2rem; font-weight: 800; color: var(--petrol); line-height: 1; }
  .stat .label { font-family: var(--font-mono); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--slate); }
  .stat.alert .value { color: var(--danger); }

  /* Tablas */
  .table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--white); }
  table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
  table.data th { background: var(--petrol); color: var(--ivory); font-family: var(--font-mono); font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; text-align: left; padding: .6rem .75rem; font-weight: 600; white-space: nowrap; }
  table.data td { padding: .6rem .75rem; border-top: 1px solid var(--border); vertical-align: top; color: var(--ink); }
  table.data tr:nth-child(even) td { background: var(--ivory); }
  table.data td a { font-weight: 600; }
  table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

  /* Definiciones */
  dl.props { display: grid; grid-template-columns: minmax(8rem, max-content) 1fr; gap: .45rem 1.25rem; font-size: .92rem; }
  dl.props dt { font-family: var(--font-mono); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--slate); padding-top: .15rem; }
  dl.props dd { margin: 0; color: var(--ink); white-space: pre-line; }

  /* Badges */
  .badge { display: inline-flex; align-items: center; gap: .3rem; font-family: var(--font-mono); font-size: .68rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: .2rem .5rem; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
  .badge-neutral { color: var(--slate); background: var(--ivory-dark); border-color: var(--border); }
  .badge-info { color: var(--petrol); background: var(--info-bg); border-color: #B9CDD1; }
  .badge-success { color: #4E6110; background: var(--success-bg); border-color: #C7D58F; }
  .badge-warning { color: var(--warning); background: var(--warning-bg); border-color: #E8CF8F; }
  .badge-danger { color: var(--danger); background: var(--danger-bg); border-color: #E5B3AE; }

  /* Formularios */
  .form { display: grid; gap: 1rem; max-width: 46rem; }
  .form .row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
  .field { display: flex; flex-direction: column; gap: .35rem; }
  .field label, .label { font-weight: 600; font-size: .88rem; color: var(--petrol); }
  .field .hint { font-size: .8rem; color: var(--slate); }
  .field .error { font-size: .82rem; color: var(--danger); font-weight: 600; }
  .input, .field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .field select, .field textarea {
    width: 100%; padding: .6rem .75rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--white); color: var(--ink); }
  .field textarea { min-height: 7rem; resize: vertical; }
  .field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: none; border-color: var(--olive); box-shadow: 0 0 0 3px rgb(126 154 26 / .2); }
  .field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
  .field-inline { flex-direction: row; align-items: center; gap: .5rem; }
  .form-actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; padding-top: .5rem; }
  .honeypot { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

  /* Filtros */
  .filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; padding: .85rem; background: rgb(255 255 255 / .7); border: 1px solid var(--border); border-radius: var(--radius); }
  .filters .field { min-width: 10rem; }
  .filters input, .filters select { padding: .45rem .6rem !important; font-size: .88rem; }

  /* Mensajes */
  .flash { padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.25rem; font-weight: 600; font-size: .92rem; border: 1px solid; display: flex; justify-content: space-between; gap: 1rem; }
  .flash-notice { background: var(--success-bg); color: #4E6110; border-color: #C7D58F; }
  .flash-alert { background: var(--danger-bg); color: var(--danger); border-color: #E5B3AE; }
  .flash button { background: none; border: 0; cursor: pointer; color: inherit; font-weight: 700; }
  .error-summary { background: var(--danger-bg); border: 1px solid #E5B3AE; color: var(--danger); border-radius: var(--radius-sm); padding: .85rem 1rem; font-size: .9rem; }
  .error-summary ul { margin: .35rem 0 0 1.1rem; padding: 0; }

  /* Estado vacío */
  .empty { text-align: center; padding: 2.5rem 1rem; border: 1.5px dashed var(--border); border-radius: var(--radius); background: rgb(255 255 255 / .6); }
  .empty p { margin: .4rem auto 1rem; max-width: 32rem; }

  /* Paginación */
  .pagination { display: flex; gap: .5rem; align-items: center; justify-content: space-between; margin-top: 1rem; font-size: .88rem; color: var(--slate); }

  /* Barra de progreso */
  .meter { height: .5rem; border-radius: 999px; background: var(--ivory-dark); overflow: hidden; min-width: 6rem; }
  .meter > span { display: block; height: 100%; background: var(--olive); }

  /* Línea de tiempo (seguimiento) */
  .timeline { list-style: none; padding: 0; display: grid; gap: .75rem; }
  .timeline li { border-left: 3px solid var(--olive); padding: .35rem 0 .35rem .85rem; }
  .timeline .meta { font-family: var(--font-mono); font-size: .7rem; color: var(--slate); text-transform: uppercase; letter-spacing: .05em; }
  .timeline p { color: var(--ink); white-space: pre-line; }

  /* Checklist de auditoría */
  .req-row form { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
  .req-row select { padding: .3rem .45rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: .82rem; }
  .req-row input[type="text"] { padding: .3rem .45rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: .82rem; min-width: 12rem; flex: 1; }
  .req-code { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; }

  /* Token API */
  .secret-box { font-family: var(--font-mono); background: var(--petrol); color: var(--ivory); padding: .75rem 1rem; border-radius: var(--radius-sm); word-break: break-all; }

  /* ===== Sitio público ===== */
  .hero { padding: clamp(3.5rem, 8vw, 6.5rem) 0 4rem; }
  .hero h1 { font-size: clamp(2.5rem, 6.5vw, 4.25rem); line-height: 1.05; letter-spacing: -0.03em; margin: 1rem 0 1.25rem; max-width: 14ch; }
  .hero .lead { font-size: clamp(1.05rem, 1.6vw, 1.25rem); }
  .cert-note { margin: 2rem 0; padding: 1rem 1.25rem; border-left: 3px solid var(--olive); background: rgb(255 255 255 / .7); max-width: 40rem; }
  .facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1.5rem; margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border); }
  .facts .value { font-size: 1.6rem; font-weight: 800; color: var(--petrol); }
  .facts p { font-size: .88rem; }
  .section { padding: clamp(3.5rem, 7vw, 5.5rem) 0; border-top: 1px solid var(--border); }
  .section.alt { background: rgb(250 249 240 / .65); }
  .section-head { max-width: 44rem; margin-bottom: 2.5rem; }
  .section-head h2 { font-size: clamp(1.8rem, 3.5vw, 2.5rem); margin: .6rem 0 .8rem; }
  .service-card { display: flex; flex-direction: column; gap: .6rem; }
  .service-card .num { font-family: var(--font-mono); color: var(--olive); font-weight: 700; }
  .service-card h3 { font-size: 1.2rem; }
  .iso-card { display: flex; flex-direction: column; gap: .75rem; text-decoration: none; transition: transform .15s, box-shadow .15s; }
  .iso-card:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgb(13 59 68 / .12); }
  .iso-card h3 { font-size: 1.35rem; color: var(--petrol); }
  .steps { counter-reset: step; display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1.25rem; }
  .steps li { list-style: none; counter-increment: step; }
  .steps li::before { content: "0" counter(step); font-family: var(--font-mono); font-weight: 700; color: var(--olive); display: block; margin-bottom: .5rem; }
  .check-list { list-style: none; padding: 0; display: grid; gap: .55rem; }
  .check-list li { padding-left: 1.6rem; position: relative; color: var(--ink); }
  .check-list li::before { content: ""; position: absolute; left: 0; top: .3rem; width: 1rem; height: .55rem; border-left: 3px solid var(--olive); border-bottom: 3px solid var(--olive); transform: rotate(-45deg); }
  .cta-band { background: var(--petrol); color: var(--ivory); border-radius: var(--radius); padding: clamp(2rem, 5vw, 3rem); display: flex; flex-wrap: wrap; gap: 1.5rem; justify-content: space-between; align-items: center; }
  .cta-band h2 { color: var(--ivory); font-size: clamp(1.5rem, 3vw, 2rem); }
  .cta-band p { color: rgb(250 249 240 / .8); }
  .tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
  .tabs button { background: transparent; border: 1.5px solid var(--border); border-radius: 999px; padding: .45rem 1rem; font-weight: 700; cursor: pointer; color: var(--slate); }
  .tabs button[aria-selected="true"] { background: var(--petrol); border-color: var(--petrol); color: var(--ivory); }
  .prose { max-width: 46rem; }
  .prose h2 { margin: 2rem 0 .75rem; }
  .prose p, .prose li { color: var(--ink); margin-bottom: .75rem; }
  .prose ul { padding-left: 1.25rem; }
  .auth-card { max-width: 26rem; margin: clamp(2rem, 8vw, 5rem) auto; }
}

@layer utilities {
  .mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; } .mt-4 { margin-top: 2.5rem; }
  .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
  .text-right { text-align: right; }
  .nowrap { white-space: nowrap; }
  .small { font-size: .85rem; }
  .danger { color: var(--danger); }
  .w-full { width: 100%; }
  [hidden] { display: none !important; }
  @media print {
    .sidebar, .topbar, .site-header, .site-footer, .no-print { display: none !important; }
    .app-shell { display: block; }
    body { background: #fff; }
  }
}
