
  :root {
    --blue:       #0056b3;
    --blue-light: #1a6fc4;
    --blue-dark:  #003d82;
    --blue-xdark: #002559;
    --blue-pale:  #e8f0fb;
    --blue-mid:   #b5d4f4;
    --ink:        #0f1520;
    --cream:      #f4f7fb;
    --gray-100:   #eef2f8;
    --gray-200:   #d8e2f0;
    --gray-400:   #8fa3c0;
    --gray-600:   #4a5e78;
    --green:      #1a7a4a;
    --red:        #c0392b;
    --shadow:     0 2px 12px rgba(0,62,140,0.10);
    --radius:     8px;
  }

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

  body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--cream);
    color: var(--ink);
    min-height: 100vh;
  }

  /* HEADER */
  .app-header {
    background: var(--blue-xdark);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 16px rgba(0,0,0,0.3);
  }
  .app-header-inner {
    max-width: 900px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .app-header h1 {
    font-family: Consolas, 'Courier New', monospace;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  .app-header p {
    font-size: 0.73rem;
    opacity: 0.65;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-top: 2px;
  }

  /* AUTOSAVE BADGE */
  .autosave-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    font-family: Consolas, 'Courier New', monospace;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 20px;
    padding: 4px 10px;
    color: rgba(255,255,255,0.8);
    transition: background 0.4s;
  }
  .autosave-badge.saved { background: rgba(26,122,74,0.5); border-color: rgba(26,122,74,0.7); }
  .autosave-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: rgba(255,255,255,0.4);
  }
  .autosave-badge.saved .autosave-dot { background: #4ddc8e; }

  /* PROGRESS */
  .progress-bar-wrap {
    background: var(--blue-xdark);
    padding: 0 24px 12px;
  }
  .progress-steps {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    gap: 6px;
    align-items: center;
  }
  .step-dot {
    flex: 1;
    height: 3px;
    background: rgba(255,255,255,0.18);
    border-radius: 2px;
    transition: background 0.4s;
  }
  .step-dot.active { background: #fff; }
  .step-dot.done { background: rgba(255,255,255,0.5); }
  .step-label {
    font-family: Consolas, 'Courier New', monospace;
    font-size: 0.6rem;
    color: rgba(255,255,255,0.55);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
  }

  /* MAIN */
  .form-wrap {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 24px 80px;
  }

  /* SECTIONS */
  .form-section { display: none; }
  .form-section.active { display: block; -webkit-animation: fadeUp 0.3s ease; animation: fadeUp 0.3s ease; }
  @-webkit-keyframes fadeUp {
    from { opacity: 0; -webkit-transform: translateY(10px); transform: translateY(10px); }
    to   { opacity: 1; -webkit-transform: translateY(0);    transform: translateY(0); }
  }
  @keyframes fadeUp {
    from { opacity: 0; -webkit-transform: translateY(10px); transform: translateY(10px); }
    to   { opacity: 1; -webkit-transform: translateY(0);    transform: translateY(0); }
  }

  /* SECTION HEADER */
  .section-header {
    border-left: 5px solid var(--blue);
    padding: 4px 0 4px 16px;
    margin-bottom: 28px;
  }
  .section-header h2 {
    font-family: Consolas, 'Courier New', monospace;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--blue-dark);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .section-header p {
    font-size: 0.78rem;
    color: var(--gray-600);
    margin-top: 3px;
  }

  /* INTRO BOX */
  .intro-box {
    background: var(--blue-dark);
    color: #fff;
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 28px;
    font-size: 0.86rem;
    line-height: 1.6;
  }

  /* FIELD GROUP */
  .field-group { margin-bottom: 20px; }
  .field-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--blue-dark);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 7px;
  }
  .field-label .req { color: var(--blue); margin-left: 3px; }

  input[type="text"], input[type="email"], input[type="number"], select, textarea {
    width: 100%;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.9rem;
    color: var(--ink);
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
  }
  input[readonly] {
    background: var(--gray-100);
    color: var(--gray-600);
    cursor: not-allowed;
  }
  input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0,86,179,0.1);
  }
  textarea { min-height: 80px; resize: vertical; }

  /* RADIO GROUP */
  .radio-group { display: flex; flex-direction: column; gap: 7px; }
  .radio-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    background: #fff;
  }
  .radio-item:hover { border-color: var(--blue-light); background: var(--blue-pale); }
  .radio-item input[type="radio"] { accent-color: var(--blue); width: 16px; height: 16px; }
  .radio-item.selected { border-color: var(--blue); background: var(--blue-pale); }

  /* CHECKBOX GROUP */
  .checkbox-group { display: flex; flex-direction: column; gap: 7px; }
  .checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
    background: #fff;
    transition: border-color 0.2s;
  }
  .checkbox-item input[type="checkbox"] { accent-color: var(--blue); width: 16px; height: 16px; }
  .checkbox-item.selected { border-color: var(--blue); background: var(--blue-pale); }

  /* TOGGLE SWITCH */
  .toggle-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: #fff;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    margin-bottom: 14px;
  }
  .toggle-label { font-size: 0.9rem; font-weight: 500; color: var(--ink); flex: 1; }
  .switch {
    position: relative;
    display: inline-block;
    width: 46px; height: 24px;
    flex-shrink: 0;
  }
  .switch input { opacity: 0; width: 0; height: 0; }
  .slider {
    position: absolute;
    inset: 0;
    background: var(--gray-200);
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.3s;
  }
  .slider::before {
    content: '';
    position: absolute;
    width: 18px; height: 18px;
    left: 3px; top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  }
  .switch input:checked + .slider { background: var(--blue); }
  .switch input:checked + .slider::before { transform: translateX(22px); }
  .toggle-status {
    font-size: 0.75rem;
    font-weight: 600;
    font-family: Consolas, 'Courier New', monospace;
    color: var(--gray-400);
    min-width: 30px;
  }
  .toggle-row.active-toggle { border-color: var(--blue); background: var(--blue-pale); }
  .toggle-row.active-toggle .toggle-status { color: var(--blue); }

  /* MATRIX TABLE */
  .matrix-wrap { overflow-x: auto; margin-bottom: 4px; }
  .matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83rem;
    background: #fff;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
  }
  .matrix-table th {
    background: var(--blue-dark);
    color: #fff;
    padding: 9px 12px;
    text-align: center;
    font-family: Consolas, 'Courier New', monospace;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
  }
  .matrix-table th.row-header { background: var(--blue); text-align: left; min-width: 180px; }
  .matrix-table td { padding: 8px 11px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
  .matrix-table tr:last-child td { border-bottom: none; }
  .matrix-table tr:nth-child(even) td { background: var(--gray-100); }
  .matrix-table td.row-label {
    font-weight: 500;
    color: var(--ink);
    background: #fff;
    border-right: 2px solid var(--gray-200);
    font-size: 0.8rem;
  }
  .matrix-table tr:nth-child(even) td.row-label { background: var(--gray-100); }
  .matrix-table td input[type="number"],
  .matrix-table td input[type="text"],
  .matrix-table td select {
    padding: 5px 9px;
    font-size: 0.8rem;
    min-width: 80px;
  }
  .matrix-table td.radio-cell { text-align: center; }
  .matrix-table td input[type="radio"] { accent-color: var(--blue); width: 17px; height: 17px; cursor: pointer; }
  .matrix-table td input[type="checkbox"] { accent-color: var(--blue); width: 18px; height: 18px; cursor: pointer; }
  .matrix-table td.check-cell { text-align: center; }

  /* CHECK TABLE — last column narrow, centered */
  .check-table th:last-child,
  .check-table td:last-child {
    width: 44px;
    text-align: center;
    padding-left: 4px;
    padding-right: 4px;
  }

  /* SUPERSACO VISUAL */
  .supersaco-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
  }
  .saco-wrap {
    position: relative;
    width: 44px;
    height: 52px;
    flex-shrink: 0;
  }
  .saco-svg { width: 44px; height: 52px; }
  .saco-fill-rect {
    transition: height 0.4s, y 0.4s;
  }
  .saco-pct-label {
    font-family: Consolas, 'Courier New', monospace;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--blue-dark);
    min-width: 34px;
    text-align: center;
  }
  .saco-slider-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
  }
  input[type="range"].saco-range {
    -webkit-appearance: none;
    width: 160px;
    height: 4px;
    background: var(--gray-200);
    border-radius: 2px;
    border: none;
    padding: 0;
    box-shadow: none;
    outline: none;
  }
  input[type="range"].saco-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--blue);
    cursor: pointer;
  }
  input[type="range"].saco-range:focus { box-shadow: none; border: none; }

  /* PHOTO CAPTURE */
  .photo-field {
    border: 2px dashed var(--gray-200);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
    background: #fff;
    transition: border-color 0.2s;
  }
  .photo-field:hover { border-color: var(--blue); }
  .photo-preview {
    display: none;
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 6px;
    margin-bottom: 10px;
    border: 1px solid var(--gray-200);
  }
  .photo-preview.visible { display: block; }
  .photo-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
  }
  .photo-btn:hover { background: var(--blue-light); }
  .photo-btn.retake { background: var(--gray-600); margin-left: 8px; }
  .photo-ok-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.73rem;
    color: var(--green);
    font-weight: 600;
    margin-top: 5px;
  }

  /* INSTRUCTIVE CARD */
  .instr-card {
    background: var(--gray-100);
    border-left: 4px solid var(--blue);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 12px 16px;
    margin-bottom: 20px;
  }
  .instr-card p { font-size: 0.81rem; color: var(--gray-600); line-height: 1.7; }
  .instr-card strong { color: var(--blue-dark); }

  /* NAV BUTTONS */
  .nav-btns {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 34px;
    padding-top: 18px;
    border-top: 1px solid var(--gray-200);
  }
  .btn-prev, .btn-next, .btn-submit {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 11px 26px;
    border: none;
    border-radius: var(--radius);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
  }
  .btn-prev { background: var(--gray-200); color: var(--ink); }
  .btn-prev:hover { background: var(--gray-400); color: #fff; }
  .btn-next { background: var(--blue); color: #fff; }
  .btn-next:hover { background: var(--blue-light); }
  .btn-submit { background: var(--green); color: #fff; }
  .btn-submit:hover { opacity: 0.88; }

  .cond-hidden { display: none; }

  .divider { height: 3px; background: var(--blue); border-radius: 2px; margin: 26px 0; }

  /* SUCCESS */
  .success-screen { display: none; text-align: center; padding: 60px 24px; }
  .success-screen.show { display: block; }
  .success-icon { font-size: 4rem; margin-bottom: 14px; }
  .success-screen h2 { font-family: Consolas, 'Courier New', monospace; color: var(--blue-dark); font-size: 1.5rem; }
  .success-screen p { color: var(--gray-600); margin: 10px 0 26px; }

  /* NOTIFICATIONS STACK */
  .notif-stack {
    position: fixed;
    bottom: 24px;
    bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
    right: 24px;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    z-index: 9999;
    max-width: 340px;
    pointer-events: none;
  }
  .notif {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px 12px 12px;
    border-radius: 10px;
    font-size: 0.84rem;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.45;
    box-shadow: 0 4px 20px rgba(0,0,0,0.18);
    pointer-events: all;
    animation: notifIn 0.3s ease;
    border-left: 4px solid transparent;
    position: relative;
    overflow: hidden;
  }
  @keyframes notifIn {
    from { transform: translateX(20px) scale(0.97); opacity: 0; }
    to   { transform: translateX(0) scale(1); opacity: 1; }
  }
  @keyframes notifOut {
    from { transform: translateX(0) scale(1); opacity: 1; max-height: 120px; margin-bottom: 0; }
    to   { transform: translateX(20px) scale(0.95); opacity: 0; max-height: 0; margin-bottom: -10px; }
  }
  .notif.leaving { animation: notifOut 0.3s ease forwards; }
  .notif-progress {
    position: absolute;
    bottom: 0; left: 0;
    height: 3px;
    border-radius: 0 0 0 10px;
    animation: notifProgress linear forwards;
  }
  @keyframes notifProgress { from { width: 100%; } to { width: 0%; } }

  /* SUCCESS */
  .notif.success { background: #f0faf5; border-left-color: #16a85a; color: #0d5c30; }
  .notif.success .notif-icon { color: #16a85a; }
  .notif.success .notif-progress { background: #16a85a; }
  /* ERROR */
  .notif.error { background: #fef2f2; border-left-color: #dc2626; color: #7f1d1d; }
  .notif.error .notif-icon { color: #dc2626; }
  .notif.error .notif-progress { background: #dc2626; }
  /* WARNING */
  .notif.warning { background: #fffbeb; border-left-color: #d97706; color: #78350f; }
  .notif.warning .notif-icon { color: #d97706; }
  .notif.warning .notif-progress { background: #d97706; }
  /* INFO */
  .notif.info { background: #eff6ff; border-left-color: #2563eb; color: #1e3a8a; }
  .notif.info .notif-icon { color: #2563eb; }
  .notif.info .notif-progress { background: #2563eb; }

  .notif-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
  .notif-body { flex: 1; }
  .notif-title { font-weight: 600; font-size: 0.85rem; margin-bottom: 2px; }
  .notif-msg { font-size: 0.8rem; opacity: 0.85; }
  .notif-close {
    flex-shrink: 0;
    background: none; border: none;
    font-size: 1rem; cursor: pointer;
    opacity: 0.4; padding: 0 0 0 6px;
    color: inherit; line-height: 1;
    align-self: flex-start;
    margin-top: 1px;
  }
  .notif-close:hover { opacity: 0.8; }

  /* CONFIRM MODAL */
  .confirm-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,20,60,0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }
  .confirm-overlay.open { display: flex; animation: fadeOverlay 0.2s ease; }
  @keyframes fadeOverlay { from { opacity: 0; } to { opacity: 1; } }
  .confirm-box {
    background: #fff;
    border-radius: 14px;
    padding: 28px 28px 22px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 8px 40px rgba(0,0,0,0.2);
    animation: confirmIn 0.25s ease;
  }
  @keyframes confirmIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
  .confirm-box h3 {
    font-family: Consolas, 'Courier New', monospace;
    font-size: 1.05rem;
    color: var(--blue-dark);
    margin-bottom: 8px;
  }
  .confirm-box p { font-size: 0.88rem; color: var(--gray-600); margin-bottom: 6px; line-height: 1.55; }
  .confirm-summary {
    background: var(--gray-100);
    border-radius: 8px;
    padding: 10px 14px;
    margin: 14px 0;
    font-size: 0.82rem;
    color: var(--ink);
    line-height: 1.7;
  }
  .confirm-summary strong { color: var(--blue-dark); }
  .confirm-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
  .confirm-cancel {
    padding: 9px 20px;
    background: var(--gray-100); color: var(--gray-600);
    border: none; border-radius: 7px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 0.88rem; font-weight: 600;
    cursor: pointer; transition: background 0.2s;
  }
  .confirm-cancel:hover { background: var(--gray-200); }
  .confirm-ok {
    padding: 9px 22px;
    background: var(--green); color: #fff;
    border: none; border-radius: 7px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 0.88rem; font-weight: 600;
    cursor: pointer; transition: opacity 0.2s;
  }
  .confirm-ok:hover { opacity: 0.88; }

  /* PDF GENERATION OVERLAY */
  .gen-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,20,60,0.72);
    z-index: 1100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
  }
  .gen-overlay.open { display: flex; }
  .gen-spinner {
    width: 52px; height: 52px;
    border: 4px solid rgba(255,255,255,0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  .gen-label {
    color: #fff;
    font-family: Consolas, 'Courier New', monospace;
    font-size: 0.88rem;
    letter-spacing: 0.04em;
    opacity: 0.85;
  }

  /* RELOAD WARNING BANNER */
  .reload-warn {
    background: #fff3cd;
    border: 1.5px solid #ffc107;
    border-radius: var(--radius);
    padding: 10px 16px;
    font-size: 0.82rem;
    color: #7a5600;
    margin-bottom: 20px;
    display: none;
    align-items: center;
    gap: 10px;
  }
  .reload-warn.show { display: flex; }
  .reload-warn strong { color: #5c3d00; }

  /* RESTORE MODAL */
  .restore-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,20,60,0.65);
    z-index: 1200;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(2px);
  }
  .restore-overlay.open { display: flex; animation: fadeOverlay 0.25s ease; }
  .restore-box {
    background: #fff;
    border-radius: 16px;
    padding: 30px 28px 24px;
    max-width: 460px;
    width: 100%;
    box-shadow: 0 12px 50px rgba(0,0,0,0.25);
    animation: confirmIn 0.28s ease;
  }
  .restore-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 16px;
  }
  .restore-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    background: #fffbeb;
    border: 1.5px solid #fcd34d;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
  }
  .restore-header h3 {
    font-family: Consolas, 'Courier New', monospace;
    font-size: 1rem;
    color: var(--blue-dark);
    margin-bottom: 4px;
  }
  .restore-header p { font-size: 0.83rem; color: var(--gray-600); line-height: 1.5; }
  .restore-data {
    background: var(--gray-100);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 14px;
    font-size: 0.82rem;
    line-height: 1.8;
    color: var(--ink);
  }
  .restore-data strong { color: var(--blue-dark); font-weight: 600; }
  .restore-photos {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 0.8rem;
    color: #78350f;
    line-height: 1.6;
  }
  .restore-photos-title { font-weight: 600; margin-bottom: 4px; color: #92400e; }
  .restore-btns { display: flex; gap: 10px; }
  .btn-restore-yes {
    flex: 1;
    padding: 11px 16px;
    background: var(--blue); color: #fff;
    border: none; border-radius: 8px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
    transition: background 0.2s;
  }
  .btn-restore-yes:hover { background: var(--blue-light); }
  .btn-restore-no {
    flex: 1;
    padding: 11px 16px;
    background: var(--gray-100); color: var(--gray-600);
    border: 1.5px solid var(--gray-200); border-radius: 8px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
    transition: all 0.2s;
  }
  .btn-restore-no:hover { background: var(--gray-200); }

  .sublabel { font-size: 0.73rem; color: var(--gray-400); margin-top: 3px; }

  /* WIDE TABLES — fit on screen without horizontal scroll */
  .matrix-table.wide-table {
    table-layout: fixed;
    width: 100%;
    font-size: 0.75rem;
  }
  .matrix-table.wide-table th {
    font-size: 0.62rem;
    padding: 7px 4px;
    white-space: normal;
    word-break: break-word;
    line-height: 1.25;
  }
  .matrix-table.wide-table th.row-header { min-width: 60px; width: 60px; }
  .matrix-table.wide-table td { padding: 5px 3px; }
  .matrix-table.wide-table td.row-label { font-size: 0.74rem; padding: 5px 5px; }
  .matrix-table.wide-table td select,
  .matrix-table.wide-table td input[type="text"],
  .matrix-table.wide-table td input[type="number"] {
    padding: 4px 3px;
    font-size: 0.74rem;
    min-width: unset;
    width: 100%;
    -webkit-appearance: none;
  }

  /* Lote formatted display */
  .lote-fmt {
    font-size: 0.71rem;
    font-weight: 600;
    color: var(--blue-dark);
    font-family: Consolas, 'Courier New', monospace;
    margin-top: 3px;
    min-height: 13px;
    display: block;
    letter-spacing: 0.02em;
  }

  /* COMPACT FIELD GRIDS */
  .compact-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
  }
  .compact-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
  .compact-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }
  .compact-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .compact-field input:not([type="checkbox"]):not([type="radio"]),
  .compact-field select {
    padding: 8px 10px;
    font-size: 0.85rem;
    border: 1.5px solid var(--gray-200);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: border-color 0.2s;
    width: 100%;
    -webkit-appearance: none;
  }
  .compact-field input:focus,
  .compact-field select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0,86,179,0.1);
  }
  @media (max-width: 600px) {
    .compact-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .compact-grid-3 { grid-template-columns: repeat(2, 1fr); }
    .compact-field[style*="span 2"] { grid-column: span 2; }
  }

  @media (max-width: 600px) {
    .form-wrap { padding: 18px 12px 60px; }
    .app-header-inner { flex-direction: column; align-items: flex-start; gap: 6px; }
    .matrix-table th, .matrix-table td { padding: 6px 7px; font-size: 0.76rem; }
  }

  /* ============================================================
     MOBILE (PHONE) — touch targets, no-zoom inputs, stacked actions
     ============================================================ */
  @media (max-width: 480px) {

    html { -webkit-text-size-adjust: 100%; }

    /* Avoid iOS auto-zoom-on-focus: any input the user types into needs >=16px */
    input[type="text"], input[type="email"], input[type="number"],
    input[type="date"], input[type="datetime-local"],
    select, textarea,
    .compact-field input, .compact-field select,
    .matrix-table td input, .matrix-table td select {
      font-size: 16px;
    }

    /* Bigger, calmer tap targets everywhere */
    button, .radio-item, .checkbox-item, .toggle-row, .photo-btn,
    .btn-prev, .btn-next, .btn-submit, a.btn-next {
      touch-action: manipulation;
      -webkit-tap-highlight-color: transparent;
    }

    /* HEADER */
    .app-header-inner { padding: 12px 14px; gap: 8px; }
    .app-header-inner > div:first-child { gap: 8px; }
    .app-header-inner a { padding: 3px 8px !important; font-size: 0.68rem !important; }
    .app-header h1 { font-size: 0.92rem; }
    .app-header p { font-size: 0.62rem; }
    #headerTime { font-size: 0.66rem; }
    .autosave-badge { font-size: 0.6rem; padding: 3px 8px; }

    /* PROGRESS — horizontally swipeable so every step label stays reachable */
    .progress-bar-wrap { padding: 0 10px 10px; }
    .progress-steps {
      overflow-x: auto;
      flex-wrap: nowrap;
      scrollbar-width: none;
      -webkit-overflow-scrolling: touch;
      padding-bottom: 2px;
    }
    .progress-steps::-webkit-scrollbar { display: none; }
    .step-dot { flex: 0 0 20px; }
    .step-label { flex: 0 0 auto; font-size: 0.56rem; }

    /* MAIN CONTENT */
    .form-wrap { padding: 14px 10px 70px; }
    .section-header h2 { font-size: 1.05rem; }
    .section-header p { font-size: 0.72rem; }
    .intro-box, .instr-card { font-size: 0.8rem; padding: 12px 14px; }
    .field-label { font-size: 0.74rem; }

    .radio-item, .checkbox-item { padding: 12px 14px; min-height: 44px; }

    /* NAV BUTTONS — full width, stacked, thumb-reachable */
    .nav-btns { flex-direction: column-reverse; gap: 10px; align-items: stretch; margin-top: 26px; }
    .btn-prev, .btn-next, .btn-submit, a.btn-next {
      width: 100%;
      justify-content: center;
      padding: 13px 18px;
      font-size: 0.92rem;
    }

    /* MATRIX TABLES → TARJETAS VERTICALES (default, non-compact) */
    .matrix-wrap { overflow-x: visible; }
    .matrix-table:not(.compact-table),
    .matrix-table:not(.compact-table) tbody,
    .matrix-table:not(.compact-table) tr,
    .matrix-table:not(.compact-table) th,
    .matrix-table:not(.compact-table) td {
      display: block;
      width: 100%;
    }
    .matrix-table:not(.compact-table) { box-shadow: none; border-radius: 0; background: transparent; }
    .matrix-table:not(.compact-table) tr:first-child { display: none; }
    .matrix-table:not(.compact-table) tr {
      background: #fff;
      border: 1.5px solid var(--gray-200);
      border-radius: var(--radius);
      margin-bottom: 10px;
      overflow: hidden;
      box-shadow: var(--shadow);
    }
    .matrix-table:not(.compact-table) tr:last-child { margin-bottom: 0; }

    .matrix-table:not(.compact-table) td {
      padding: 10px 12px !important;
      border-bottom: 1px solid var(--gray-100) !important;
      background: #fff !important;
      font-size: 0.85rem !important;
    }
    .matrix-table:not(.compact-table) tr td:last-child { border-bottom: none !important; }

    .matrix-table:not(.compact-table) td.row-label {
      background: var(--blue-dark) !important;
      color: #fff;
      font-weight: 700;
      font-size: 0.86rem !important;
    }
    .matrix-table:not(.compact-table) td.row-label::before { color: rgba(255,255,255,0.65); }

    .matrix-table:not(.compact-table) td::before {
      content: attr(data-label);
      display: block;
      font-size: 0.64rem;
      font-weight: 700;
      color: var(--gray-600);
      text-transform: uppercase;
      letter-spacing: 0.05em;
      margin-bottom: 5px;
    }
    .matrix-table:not(.compact-table) td:not([data-label])::before,
    .matrix-table:not(.compact-table) td[data-label=""]::before { content: none; margin-bottom: 0; }

    .matrix-table:not(.compact-table) td input[type="number"],
    .matrix-table:not(.compact-table) td input[type="text"],
    .matrix-table:not(.compact-table) td select {
      min-width: 0;
      width: 100%;
      font-size: 16px !important;
    }

    /* COMPACT-TABLE: stays as real table on mobile — no card layout */
    .matrix-wrap:has(.compact-table) { overflow-x: auto; }
    .matrix-table.compact-table,
    .matrix-table.compact-table thead,
    .matrix-table.compact-table tbody,
    .matrix-table.compact-table tr,
    .matrix-table.compact-table th,
    .matrix-table.compact-table td {
      display: revert;
    }
    .matrix-table.compact-table {
      display: table;
      box-shadow: var(--shadow);
      border-radius: var(--radius);
      background: #fff;
    }
    .matrix-table.compact-table tr { display: table-row; }
    .matrix-table.compact-table th { display: table-cell; }
    .matrix-table.compact-table td { display: table-cell; }
    .matrix-table.compact-table tr:first-child { display: table-row; }
    .matrix-table.compact-table td::before { content: none !important; display: none !important; }
    .matrix-table.compact-table td input[type="number"],
    .matrix-table.compact-table td input[type="text"],
    .matrix-table.compact-table td select {
      font-size: 16px !important;
      min-width: 0;
      width: 100%;
    }
    .matrix-table.compact-table td {
      padding: 6px 5px !important;
      font-size: 0.78rem !important;
    }
    .matrix-table.compact-table th {
      padding: 7px 5px !important;
      font-size: 0.62rem !important;
    }
    /* Slider on mobile */
    .saco-slider-wrap { gap: 2px; }
    input[type="range"].saco-range { width: 100px; }

    /* COMPACT GRIDS */
    .compact-grid-4, .compact-grid-3 { grid-template-columns: repeat(2, 1fr); gap: 8px; }

    /* PHOTO CAPTURE — full-width stacked buttons */
    .photo-field { padding: 14px 10px; }
    .photo-btn { width: 100%; margin-bottom: 8px; }
    .photo-btn.retake { margin-left: 0; }

    /* MODALS — fit small screens, stacked actions */
    .confirm-box, .restore-box { padding: 22px 18px 18px; max-width: 100%; }
    .confirm-btns { flex-direction: column-reverse; }
    .confirm-cancel, .confirm-ok { width: 100%; padding: 12px; }
    .restore-btns { flex-direction: column; }

    /* NOTIFICATIONS — full width near the bottom, thumb reachable */
    .notif-stack { left: 12px; right: 12px; bottom: 12px; bottom: max(12px, calc(env(safe-area-inset-bottom) + 8px)); max-width: none; }

    /* SUCCESS SCREEN */
    .success-screen { padding: 40px 16px; }
    .success-screen > div[style*="max-width:480px"] > div[style*="display:flex"] { flex-direction: column; }
    .success-screen a.btn-next, .success-screen button.btn-next { width: 100%; }
  }

/* VIDEO MODAL */
  .camera-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    z-index: 999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
  }
  .camera-modal.open { display: flex; }
  .camera-modal video {
    width: 100%;
    max-width: 500px;
    border-radius: 10px;
    border: 3px solid var(--blue);
  }
  .camera-modal-btns { display: flex; gap: 12px; margin-top: 16px; }
  .cam-btn {
    padding: 11px 26px;
    border: none;
    border-radius: 8px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
  }
  .cam-btn-capture { background: var(--blue); color: #fff; }
  .cam-btn-cancel { background: #333; color: #fff; }
