    /* ─── Design Tokens ──────────────────────────────────── */
    :root {
      --primary:        #2563eb;
      --primary-hover:  #1d4ed8;
      --primary-light:  #dbeafe;
      --bg:             #f1f5f9;
      --surface:        #ffffff;
      --border:         #e2e8f0;
      --border-focus:   #93c5fd;
      --text:           #0f172a;
      --muted:          #64748b;
      --danger:         #dc2626;
      --success:        #16a34a;
      --warn-bg:        #fffbeb;
      --warn-border:    #f59e0b;
      --warn-text:      #92400e;
      --sidebar-w:      340px;
      --radius:         8px;
      --shadow-sm:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
      --shadow:         0 4px 12px rgba(0,0,0,.08);
    }

    /* ─── Reset ──────────────────────────────────────────── */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    html { height: 100%; }

    body {
      font-family: 'Inter', system-ui, sans-serif;
      background: var(--bg);
      color: var(--text);
      line-height: 1.55;
      min-height: 100%;
    }

    /* ─── Layout ─────────────────────────────────────────── */
    .app {
      display: grid;
      grid-template-columns: var(--sidebar-w) 1fr;
      grid-template-rows: auto 1fr;
      grid-template-areas:
        "header header"
        "sidebar main";
      min-height: 100vh;
    }

    /* ─── Header ─────────────────────────────────────────── */
    .app-header {
      grid-area: header;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      padding: .9rem 1.5rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 1rem;
      box-shadow: var(--shadow-sm);
      position: sticky;
      top: 0;
      z-index: 10;
    }

    .app-header h1 {
      font-size: 1.1rem;
      font-weight: 700;
      color: var(--primary);
      letter-spacing: -.02em;
    }

    .app-header .subtitle {
      font-size: .8rem;
      color: var(--muted);
      font-weight: 500;
    }

    .header-actions {
      display: flex;
      gap: .5rem;
      flex-wrap: wrap;
    }

    /* ─── Sidebar ────────────────────────────────────────── */
    .sidebar {
      grid-area: sidebar;
      background: var(--surface);
      border-right: 1px solid var(--border);
      padding: 1.25rem 1rem;
      display: flex;
      flex-direction: column;
      gap: 1.25rem;
      overflow-y: auto;
      height: calc(100vh - 57px);
      position: sticky;
      top: 57px;
    }

    /* ─── Main ───────────────────────────────────────────── */
    .main {
      grid-area: main;
      padding: 1.5rem;
      display: flex;
      flex-direction: column;
      gap: 1.25rem;
      overflow-y: auto;
    }

    /* ─── Cards ──────────────────────────────────────────── */
    .card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 1.1rem 1.2rem;
      box-shadow: var(--shadow-sm);
    }

    .card-title {
      font-size: .75rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: .07em;
      color: var(--muted);
      margin-bottom: .85rem;
      display: flex;
      align-items: center;
      gap: .4rem;
    }

    .card-title .badge {
      background: var(--primary-light);
      color: var(--primary);
      padding: .1rem .4rem;
      border-radius: 4px;
      font-size: .65rem;
      font-weight: 600;
      text-transform: none;
      letter-spacing: 0;
    }

    /* ─── Form Elements ──────────────────────────────────── */
    .field { display: flex; flex-direction: column; gap: .3rem; }

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

    input, select, textarea {
      width: 100%;
      padding: .55rem .7rem;
      border: 1px solid var(--border);
      border-radius: 6px;
      font-size: .9rem;
      font-family: inherit;
      color: var(--text);
      background: var(--surface);
      transition: border-color .15s, box-shadow .15s;
      appearance: none;
    }

    input:focus, select:focus, textarea:focus {
      outline: none;
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(37,99,235,.15);
    }

    select {
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right .75rem center;
      padding-right: 2.2rem;
      cursor: pointer;
    }

    /* ─── Variables Panel ────────────────────────────────── */
    #vars-panel {
      display: flex;
      flex-direction: column;
      gap: .75rem;
    }

    #vars-empty {
      font-size: .83rem;
      color: var(--muted);
      font-style: italic;
      text-align: center;
      padding: .5rem 0;
    }

    /* ─── Suggestion Banner ──────────────────────────────── */
    #suggestion-banner {
      display: none;
      background: var(--warn-bg);
      border: 1px solid var(--warn-border);
      border-radius: var(--radius);
      padding: .75rem 1rem;
      font-size: .82rem;
      color: var(--warn-text);
      line-height: 1.5;
    }

    #suggestion-banner strong { font-weight: 700; }

    #suggestion-banner .suggest-btn {
      display: inline-block;
      margin-top: .5rem;
      background: var(--warn-border);
      color: var(--warn-text);
      border: none;
      border-radius: 5px;
      padding: .25rem .6rem;
      font-size: .78rem;
      font-weight: 600;
      cursor: pointer;
      font-family: inherit;
      transition: background .15s;
    }

    #suggestion-banner .suggest-btn:hover { background: #f59e0b; }

    /* ─── Report Textareas ───────────────────────────────── */
    .textarea-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: .6rem;
    }

    .textarea-title {
      font-size: .78rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: .07em;
      color: var(--muted);
    }

    .char-count {
      font-size: .72rem;
      color: var(--muted);
    }

    #report-body {
      height: 320px;
      resize: vertical;
      font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
      font-size: .855rem;
      line-height: 1.7;
      background: #fafafa;
    }

    #report-conclusion {
      height: 90px;
      resize: vertical;
      font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
      font-size: .855rem;
      line-height: 1.7;
      background: #fafafa;
    }

    .placeholder-highlight {
      color: var(--primary);
    }

    /* ─── Edit Notice ────────────────────────────────────── */
    .edit-notice {
      display: none;
      font-size: .75rem;
      color: var(--muted);
      margin-top: .35rem;
    }

    .edit-notice.visible { display: block; }

    /* ─── Buttons ────────────────────────────────────────── */
    .btn {
      display: inline-flex;
      align-items: center;
      gap: .35rem;
      padding: .5rem 1rem;
      font-size: .83rem;
      font-weight: 600;
      border-radius: 6px;
      border: none;
      cursor: pointer;
      transition: background .15s, transform .1s;
      font-family: inherit;
      white-space: nowrap;
    }

    .btn:active { transform: scale(.97); }

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

    .btn-ghost {
      background: transparent;
      color: var(--muted);
      border: 1px solid var(--border);
    }
    .btn-ghost:hover { background: var(--bg); color: var(--text); }

    .btn-danger { background: #fee2e2; color: var(--danger); border: 1px solid #fecaca; }
    .btn-danger:hover { background: #fecaca; }

    .btn-sm { padding: .35rem .7rem; font-size: .78rem; }

    /* ─── Toast ──────────────────────────────────────────── */
    #toast {
      position: fixed;
      bottom: 1.5rem;
      left: 50%;
      transform: translateX(-50%) translateY(10px);
      background: #1e293b;
      color: #f8fafc;
      padding: .6rem 1.2rem;
      border-radius: 24px;
      font-size: .83rem;
      font-weight: 600;
      box-shadow: var(--shadow);
      opacity: 0;
      visibility: hidden;
      transition: all .25s ease;
      z-index: 100;
    }

    #toast.show {
      opacity: 1;
      visibility: visible;
      transform: translateX(-50%) translateY(0);
    }

    /* ─── Divider ────────────────────────────────────────── */
    .divider {
      height: 1px;
      background: var(--border);
      margin: .2rem 0;
    }

    /* ─── Stats row ──────────────────────────────────────── */
    .stats-row {
      display: flex;
      gap: 1.2rem;
      font-size: .75rem;
      color: var(--muted);
      padding: .3rem 0;
    }

    .stats-row span { font-weight: 600; color: var(--text); }

    /* ─── Keyboard hint ──────────────────────────────────── */
    .kbd-hint {
      font-size: .72rem;
      color: var(--muted);
      display: flex;
      gap: .75rem;
      flex-wrap: wrap;
    }

    .kbd-hint kbd {
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 4px;
      padding: .1rem .35rem;
      font-family: inherit;
      font-size: .7rem;
    }

    /* ─── Template indicator ─────────────────────────────── */
    #template-indicator {
      font-size: .75rem;
      color: var(--muted);
      min-height: 1.2em;
    }

    #template-indicator .tpl-name {
      font-weight: 600;
      color: var(--primary);
    }

    /* ─── Sheets / Settings Modal ───────────────────────────*/
    .modal-overlay {
      position: fixed; inset: 0;
      background: rgba(0,0,0,.4);
      z-index: 60;
      display: flex; align-items: center; justify-content: center;
      opacity: 0; visibility: hidden;
      transition: all .2s;
    }
    .modal-overlay.open { opacity: 1; visibility: visible; }

    .modal {
      background: #fff;
      border-radius: 12px;
      padding: 1.5rem;
      width: 460px; max-width: 95vw;
      box-shadow: 0 20px 40px rgba(0,0,0,.2);
      transform: translateY(8px);
      transition: transform .2s;
    }
    .modal-overlay.open .modal { transform: translateY(0); }

    .modal h3 { font-size: 1rem; font-weight: 700; margin-bottom: .25rem; }
    .modal .modal-sub { font-size: .8rem; color: var(--muted); margin-bottom: 1.1rem; line-height: 1.5; }

    .modal-field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
    .modal-field label { font-size: .78rem; font-weight: 600; color: var(--muted); }
    .modal-field input { font-size: .85rem; }

    .modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.1rem; }

    .sheets-status {
      font-size: .75rem;
      padding: .3rem .6rem;
      border-radius: 4px;
      margin-top: .4rem;
      display: none;
    }
    .sheets-status.ok  { display:block; background:#dcfce7; color:#166534; }
    .sheets-status.err { display:block; background:#fee2e2; color:#991b1b; }

    .btn-sheets {
      background: #1a73e8; color: #fff;
      border: none; border-radius: 6px;
      padding: .5rem 1rem;
      font-size: .83rem; font-weight: 600;
      cursor: pointer; font-family: inherit;
      display: inline-flex; align-items: center; gap: .35rem;
      transition: background .15s;
    }
    .btn-sheets:hover { background: #1557b0; }
    .btn-sheets:disabled { background: #93c5fd; cursor: not-allowed; }

    /* ─── Guide Panel ───────────────────────────────────────*/
    .guide-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,.25);
      z-index: 40;
      opacity: 0;
      visibility: hidden;
      transition: all .25s;
    }
    .guide-overlay.open { opacity: 1; visibility: visible; }

    .guide-panel {
      position: fixed;
      top: 0; right: 0;
      width: 400px; max-width: 96vw;
      height: 100vh;
      background: #f0fdf4;
      border-left: 2px solid #86efac;
      box-shadow: -6px 0 24px rgba(0,0,0,.13);
      z-index: 50;
      transform: translateX(100%);
      transition: transform .3s cubic-bezier(.4,0,.2,1);
      display: flex; flex-direction: column;
      overflow: hidden;
    }
    .guide-panel.open { transform: translateX(0); }

    .guide-header {
      background: #16a34a;
      color: #fff;
      padding: .85rem 1.1rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-shrink: 0;
    }
    .guide-header h2 { font-size: .95rem; font-weight: 700; }
    .guide-header .guide-tpl { font-size: .75rem; opacity: .85; margin-top: .15rem; }
    .guide-close {
      background: rgba(255,255,255,.2);
      border: none; border-radius: 50%;
      width: 28px; height: 28px;
      color: #fff; font-size: 1rem; cursor: pointer;
      display: flex; align-items: center; justify-content: center;
      transition: background .15s;
    }
    .guide-close:hover { background: rgba(255,255,255,.35); }

    .guide-body { overflow-y: auto; flex: 1; padding: 1rem; display: flex; flex-direction: column; gap: .85rem; }

    .guide-block {
      background: #fff;
      border: 1px solid #bbf7d0;
      border-radius: 8px;
      padding: .85rem 1rem;
    }
    .guide-block-title {
      font-size: .7rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: .08em;
      color: #166534;
      margin-bottom: .55rem;
      display: flex; align-items: center; gap: .35rem;
    }
    .guide-dx { font-size: .9rem; font-weight: 600; color: #0f172a; }

    .guide-riesgo {
      display: inline-block;
      margin-top: .35rem;
      padding: .2rem .6rem;
      border-radius: 4px;
      font-size: .75rem;
      font-weight: 700;
    }
    .riesgo-bajo    { background: #dcfce7; color: #166534; }
    .riesgo-mod     { background: #fef9c3; color: #854d0e; }
    .riesgo-alto    { background: #ffedd5; color: #9a3412; }
    .riesgo-muyalto { background: #fee2e2; color: #991b1b; }
    .riesgo-critico { background: #1e293b; color: #f8fafc; }

    .guide-conducta-list {
      list-style: none;
      display: flex; flex-direction: column; gap: .4rem;
    }
    .guide-conducta-list li {
      font-size: .83rem;
      color: #1e293b;
      padding-left: 1.1rem;
      position: relative;
      line-height: 1.45;
    }
    .guide-conducta-list li::before {
      content: '→';
      position: absolute; left: 0;
      color: #16a34a; font-weight: 700;
    }
    .guide-conducta-list li.warn::before { content: '⚠️'; left: -2px; }
    .guide-conducta-list li.warn { color: #991b1b; font-weight: 600; }

    .guide-seguimiento {
      font-size: .83rem;
      color: #1e293b;
      display: flex; align-items: center; gap: .4rem;
    }
    .guide-seguimiento strong { color: #166534; }

    .guide-ref-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
    .guide-ref-table tr:not(:last-child) td { border-bottom: 1px solid #dcfce7; }
    .guide-ref-table td { padding: .3rem .2rem; color: #1e293b; }
    .guide-ref-table td:last-child { font-weight: 600; text-align: right; color: #166534; }

    .guide-btn {
      width: 100%;
      padding: .6rem;
      background: #16a34a;
      color: #fff;
      border: none; border-radius: 6px;
      font-size: .85rem; font-weight: 700;
      cursor: pointer; font-family: inherit;
      display: flex; align-items: center; justify-content: center; gap: .4rem;
      transition: background .15s;
      margin-top: .25rem;
    }
    .guide-btn:hover { background: #15803d; }

    /* ─── Responsive ─────────────────────────────────────── */
    @media (max-width: 768px) {
      .app {
        grid-template-columns: 1fr;
        grid-template-areas:
          "header"
          "sidebar"
          "main";
      }

      .sidebar {
        position: static;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
      }

      .main { padding: 1rem; }

      .header-actions { display: none; }

      #report-body { height: 240px; }
    }
