* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  background: #f3f3f5;
  color: #222;
}

main {
  width: 96vw;
  max-width: 1800px;
  margin: 24px auto;
  padding: 24px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

h1 { font-size: 1.4rem; margin-top: 0; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 8px 0;
}
.page-header h1 { margin: 0; }
.help-trigger {
  background: #fff;
  border: 1px solid #1a5fc7;
  color: #1a5fc7;
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
}
.help-trigger:hover { background: #eaf1fb; }

/* ---------- Help drawer ---------- */

.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  z-index: 9000;
  animation: helpFadeIn 0.16s ease-out;
}
.help-overlay[hidden] { display: none; }

.help-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 92vw);
  background: #fff;
  z-index: 9001;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.18);
  animation: helpSlideIn 0.22s ease-out;
}
.help-drawer[hidden] { display: none; }

@keyframes helpFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes helpSlideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.help-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e5e8;
  background: #fafafc;
}
.help-drawer-header h2 { margin: 0; font-size: 1.15rem; }
.help-close {
  border: none;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: #555;
  padding: 4px 8px;
}
.help-close:hover { color: #000; background: #ececf2; border-radius: 4px; }

.help-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 16px;
  border-bottom: 1px solid #e5e5e8;
  background: #fafafc;
}
.help-toc button {
  background: transparent;
  border: 1px solid transparent;
  color: #1a5fc7;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.help-toc button:hover { background: #eaf1fb; }
.help-toc button.active {
  background: #1a5fc7;
  color: #fff;
  border-color: #1a5fc7;
}

.help-content {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px 32px 24px;
  font-size: 0.92rem;
  line-height: 1.5;
}
.help-content section h3 {
  margin: 0 0 10px 0;
  font-size: 1.05rem;
}
.help-content section h4 {
  margin: 16px 0 6px 0;
  font-size: 0.95rem;
  color: #333;
}
.help-content p, .help-content ul, .help-content ol {
  margin: 0 0 10px 0;
}
.help-content ul, .help-content ol { padding-left: 22px; }
.help-content code {
  background: #f3f3f5;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}
.help-content kbd {
  background: #f3f3f5;
  border: 1px solid #d4d4d8;
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.8em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.help-content a { color: #1a5fc7; }

fieldset {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}

legend { font-weight: 600; padding: 0 6px; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin-bottom: 12px;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  gap: 4px;
}

input[type="text"], input:not([type]) {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid #c4c4c8;
  border-radius: 4px;
}

input[type="file"] { font: inherit; }

button {
  font: inherit;
  padding: 8px 14px;
  border: 1px solid #888;
  background: #f7f7f7;
  border-radius: 4px;
  cursor: pointer;
}
button:hover { background: #ececec; }

button.primary {
  background: #1a5fc7;
  color: #fff;
  border-color: #1a5fc7;
  font-weight: 600;
  padding: 10px 20px;
}
button.primary:hover { background: #154fa6; }

button.link {
  background: transparent;
  border: none;
  color: #1a5fc7;
  padding: 6px 4px;
  text-decoration: underline;
  cursor: pointer;
}
button.link:hover { background: transparent; color: #154fa6; }
button.link:disabled {
  color: #aaa;
  cursor: not-allowed;
  text-decoration: none;
}
button.link:disabled:hover { color: #aaa; }

button.small {
  padding: 5px 12px;
  font-size: 0.85rem;
}
button.ghost {
  background: #fff;
  border: 1px solid #b00020;
  color: #b00020;
  font-weight: 500;
}
button.ghost:hover { background: #fde7ea; }

#status {
  margin-top: 12px;
  min-height: 1.4em;
  white-space: pre-wrap;
  font-size: 0.9rem;
}
#status.error { color: #b00020; }
#status.warning { color: #8a6d00; }
#status.success { color: #1a7f3c; }

.hint {
  font-size: 0.8rem;
  color: #555;
  margin: 0 0 8px 0;
}

.csv-upload-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.csv-upload-row label { flex: 0 0 auto; }

#csv-editor { margin-top: 8px; }

.csv-editor-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.85rem;
  color: #555;
}

.csv-editor-scroll {
  max-height: 75vh;
  min-height: 400px;
  overflow: auto;
  border: 1px solid #ccc;
  border-radius: 4px;
}

#csv-editor-table {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  /* Don't lock to 100% width — let column widths sum to whatever the user
     resizes them to, which may be wider than the viewport. */
  width: max-content;
  min-width: 100%;
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#csv-editor-table thead th {
  position: sticky;
  top: 0;
  background: #ececf2;
  z-index: 1;
  padding: 4px 6px;
  border-bottom: 1px solid #aaa;
  border-right: 1px solid #ddd;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-resize {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 2;
}
.col-resize:hover, .col-resize.resizing {
  background: #1a5fc7;
  opacity: 0.45;
}
#csv-editor-table thead th { position: sticky; }
/* Re-declare relative position via a wrapper since sticky already takes
   `position` — use a span inside the th for the resize handle. */
#csv-editor-table thead th .th-inner {
  position: relative;
  display: block;
}
#csv-editor-table thead th:last-child { border-right: none; }
#csv-editor-table td {
  padding: 0;
  border-bottom: 1px solid #c4c4c8;
  border-right: 1px solid #d4d4d8;
}
#csv-editor-table td:last-child { border-right: none; }
/* Slightly darker bottom border at the very last row of the body so the
   table closes off cleanly even after the zebra stripe ends. */
#csv-editor-table tbody tr:last-child > td {
  border-bottom: 1px solid #888;
}

/* Line-number column (sticky on the left edge). */
#csv-editor-table .csv-line-num {
  background: #ececf2;
  color: #555;
  text-align: right;
  padding: 3px 6px;
  font-size: 0.78rem;
  font-weight: 500;
  position: sticky;
  left: 0;
  z-index: 1;
  user-select: none;
  border-right: 1px solid #b4b4b8;
}
#csv-editor-table thead .csv-line-num {
  z-index: 2; /* above body cells when scrolling */
}
#csv-editor-table tbody tr:hover .csv-line-num {
  background: #fff8e0;
}
#csv-editor-table tbody tr:nth-child(even) .csv-line-num {
  background: #e3e3e9;
}

/* ---- Modified / new row highlights ---- *
 * A whole row marked "new" (user added or duplicated) gets a green tint
 * across every data cell. Individual cells marked "modified" within an
 * existing row get a yellow tint. These override the zebra stripe. */
#csv-editor-table tr.row-new > td:not(.csv-line-num):not(.csv-row-action) {
  background: #d4edda; /* light green */
}
#csv-editor-table tr.row-new .csv-line-num {
  background: #b8dabf;
  color: #155724;
}
#csv-editor-table td.cell-modified > input {
  background: #fff3cd; /* light amber */
}
#csv-editor-table tr.row-new:hover > td:not(.csv-line-num):not(.csv-row-action) {
  background: #c5e7cc;
}
#csv-editor-table tr.row-new:hover .csv-line-num {
  background: #a5cdb0;
}

/* Zebra striping for the body rows. */
#csv-editor-table tbody tr:nth-child(even) > td {
  background: #f7f7fa;
}
#csv-editor-table tbody tr:nth-child(even) > td.csv-row-action {
  background: #f1f1f6;
}

/* Row highlight on hover — overrides zebra striping and the action cell's
   own background. Inputs become focused-looking too so the hovered row
   reads as one. */
#csv-editor-table tbody tr:hover > td,
#csv-editor-table tbody tr:hover > td.csv-row-action {
  background: #fff8e0;
}
#csv-editor-table input {
  width: 100%;
  border: none;
  padding: 3px 6px;
  font: inherit;
  background: transparent;
  box-sizing: border-box;
}
#csv-editor-table input:focus {
  background: #fffce8;
  outline: 1px solid #1a5fc7;
}
.csv-row-action {
  width: 132px;
  text-align: center;
  white-space: nowrap;
  background: #fafafc;
}
.csv-row-action button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  font-size: 0.95rem;
  line-height: 1;
  color: #555;
}
.csv-row-action button:hover { background: #ececf2; color: #222; }
.csv-row-action button[data-delete] { color: #b00020; }
.csv-row-action button[data-delete]:hover { background: #fde7ea; }
.csv-row-action button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

#csv-add-row {
  margin-top: 8px;
}

/* Editor + suggestions side panel layout. */
.csv-editor-layout {
  display: flex;
  gap: 12px;
  align-items: stretch;
}
.csv-editor-layout .csv-editor-scroll {
  flex: 1;
  min-width: 0; /* allow shrinking inside flex */
}
.suggestions-panel {
  width: 240px;
  flex: 0 0 240px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 0.8rem;
}
.suggestions-panel h4 {
  margin: 0 0 4px 0;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}
.suggestions-panel ul {
  list-style: none;
  margin: 0;
  padding: 2px;
  border: 1px solid #ccc;
  border-radius: 4px;
  max-height: 35vh;
  overflow-y: auto;
  background: #fff;
}
.suggestions-panel li {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 3px;
}
.suggestions-panel li:hover { background: #f3f3f5; }
.suggestions-panel li:empty,
.suggestions-panel ul:empty::after {
  content: 'No values';
  color: #888;
  font-style: italic;
  display: block;
  padding: 4px;
}
.sugg-text {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 1px 0;
}
.sugg-text:hover { color: #1a5fc7; }
.suggestions-panel li button {
  background: transparent;
  border: none;
  color: #b00020;
  cursor: pointer;
  padding: 0 4px;
  font-size: 0.95rem;
  line-height: 1;
}
.suggestions-panel li button:hover { background: #fde7ea; border-radius: 3px; }
.muted { color: #888; font-weight: normal; font-size: 0.75rem; }

/* Custom dropdown shown beneath the focused Setpoint / Unit Operating Mode
   input. Floats above everything via fixed position. */
#cell-dropdown {
  position: fixed;
  background: #fff;
  border: 1px solid #888;
  border-radius: 4px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  max-height: 260px;
  overflow-y: auto;
  z-index: 10000;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  min-width: 160px;
}
#cell-dropdown .dropdown-item {
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
#cell-dropdown .dropdown-item:hover,
#cell-dropdown .dropdown-item.active {
  background: #1a5fc7;
  color: #fff;
}
#cell-dropdown .dropdown-empty {
  padding: 6px 10px;
  color: #888;
  font-style: italic;
}
.suggestions-help {
  font-size: 0.7rem;
  margin: 0 0 4px 0 !important;
  color: #777;
}

.csv-editor-actions {
  display: inline-flex;
  gap: 4px;
}

.resume-banner {
  margin-top: 16px;
  padding: 10px 12px;
  background: #fff8e0;
  border: 1px solid #f0d97a;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
}
/* The HTML `hidden` attribute sets display:none with normal specificity,
   but a class-level `display: flex` would override it. Force display:none
   when hidden so the banner actually disappears. */
.resume-banner[hidden] { display: none; }
.resume-banner span { flex: 1; color: #5a4900; }

/* ---------- Multi-step flow ---------- */

.stepper {
  list-style: none;
  display: flex;
  gap: 8px;
  padding: 0;
  margin: 0 0 18px 0;
  font-size: 0.85rem;
  counter-reset: step;
}
.stepper li {
  flex: 1;
  padding: 8px 10px;
  border-radius: 4px;
  background: #ececf2;
  color: #777;
  counter-increment: step;
  position: relative;
}
.stepper li::before {
  content: counter(step) ".";
  font-weight: 600;
  margin-right: 6px;
}
.stepper li.active {
  background: #1a5fc7;
  color: #fff;
}
.stepper li.done {
  background: #c8e6c9;
  color: #1a7f3c;
}

.step h2 { font-size: 1.1rem; margin-top: 0; }
.step .step-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
}

.file-pick { margin-bottom: 12px; }

table.kv {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}
table.kv td {
  padding: 4px 8px;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}
table.kv td:first-child {
  color: #555;
  width: 40%;
  font-weight: 500;
}
table.kv td:last-child { font-family: monospace; }

.csv-preview-wrapper {
  margin-top: 8px;
  font-size: 0.78rem;
  overflow-x: auto;
}
.csv-preview-wrapper table { border-collapse: collapse; width: 100%; }
.csv-preview-wrapper th,
.csv-preview-wrapper td {
  border: 1px solid #ddd;
  padding: 3px 6px;
  text-align: left;
  white-space: nowrap;
}
.csv-preview-wrapper th { background: #f3f3f5; }

/* ============================================================
 * Mobile-specific UI components (defined first so they can be
 * shown/hidden via responsive rules below).
 * ============================================================ */

/* Visibility classes — desktop default. Overridden inside the mobile
   media query so each component appears in the right context. */
.mobile-only { display: none; }

/* ---- Row card list (mobile replacement for the editor table) ---- */
.csv-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 100px; /* leave room for sticky bar + FAB */
}
.csv-card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.85rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  cursor: pointer;
  transition: background 0.12s;
}
.csv-card:active { background: #f3f3f5; }
.csv-card.row-new {
  background: #d4edda;
  border-color: #80c891;
  border-left: 4px solid #2c8a4a;
}
.csv-card.row-modified {
  background: #fff8d9;
  border-color: #e6d27a;
  border-left: 4px solid #c89e1f;
}
.csv-card-empty {
  text-align: center;
  color: #777;
  padding: 20px;
  font-style: italic;
  cursor: default;
}
.csv-card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.csv-card-time {
  font-weight: 600;
  color: #1a5fc7;
  font-size: 0.85rem;
  white-space: nowrap;
}
.csv-card-num {
  font-size: 0.7rem;
  color: #888;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.csv-card-setpoint {
  margin: 4px 0 6px 0;
  color: #222;
  word-break: break-word;
}
.csv-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 0.75rem;
  color: #555;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 4px;
}
.csv-card-stats span { white-space: nowrap; }
.csv-card-mode {
  font-size: 0.78rem;
  color: #444;
  font-style: italic;
  word-break: break-word;
}

/* ---- Floating action button ---- */
.fab {
  position: fixed;
  right: 18px;
  bottom: 78px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1a5fc7;
  color: #fff;
  border: none;
  font-size: 1.6rem;
  font-weight: 300;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  z-index: 50;
}
.fab:hover { background: #154fa6; }

/* ---- Sticky bottom action bar ---- */
.mobile-action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-top: 1px solid #e5e5e8;
  z-index: 40;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.mobile-action-bar button { width: 100%; }

/* ---- Row editor modal ---- */
.row-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 9500;
  animation: helpFadeIn 0.16s ease-out;
}
.row-modal-overlay[hidden] { display: none; }

.row-modal {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 9501;
  display: flex;
  flex-direction: column;
  animation: rowModalSlide 0.18s ease-out;
}
.row-modal[hidden] { display: none; }
@keyframes rowModalSlide {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.row-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e5e8;
  background: #fafafc;
}
.row-modal-header h2 {
  font-size: 0.95rem;
  margin: 0;
  flex: 1;
  text-align: center;
}
.row-modal-close {
  background: transparent;
  border: none;
  color: #1a5fc7;
  font-size: 0.95rem;
  padding: 6px 8px;
  cursor: pointer;
}
.row-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 24px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.row-modal-body label {
  font-size: 0.8rem;
  color: #555;
  gap: 4px;
}
.row-modal-body input {
  font: inherit;
  font-size: 16px; /* iOS no-zoom */
  padding: 10px 12px;
  border: 1px solid #c4c4c8;
  border-radius: 6px;
  width: 100%;
}
.row-modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.row-modal-actions button {
  padding: 12px;
  font-size: 0.9rem;
}
.row-modal-actions button.danger {
  background: #fff;
  border: 1px solid #b00020;
  color: #b00020;
  font-weight: 500;
}
.row-modal-actions button.danger:hover { background: #fde7ea; }

/* ============================================================
 * Responsive / mobile rules
 * ============================================================ */

@media (max-width: 1024px) {
  /* Container takes the whole screen and uses tighter padding. */
  main {
    width: 100%;
    margin: 0;
    border-radius: 0;
    padding: 14px 12px 16px 12px;
    box-shadow: none;
  }

  body { background: #fff; }

  h1 { font-size: 1.05rem; }

  .page-header {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* Visibility switches. */
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }
  .mobile-only.fab { display: flex; align-items: center; justify-content: center; }
  [hidden].mobile-only { display: none !important; }

  /* Pill stepper — compact, dot-based, with text below. */
  .stepper {
    display: flex;
    flex-direction: row;
    gap: 0;
    padding: 0;
    margin-bottom: 14px;
    counter-reset: step;
    position: relative;
  }
  .stepper::before {
    content: '';
    position: absolute;
    top: 14px;
    left: 12%;
    right: 12%;
    height: 2px;
    background: #e0e0e6;
    z-index: 0;
  }
  .stepper li {
    flex: 1;
    background: transparent;
    color: #888;
    text-align: center;
    padding-top: 32px;
    position: relative;
    font-size: 0.7rem;
    z-index: 1;
  }
  .stepper li::before {
    /* Don't re-increment — the desktop .stepper li rule already does that;
       just render the same counter value as a circular badge. */
    content: counter(step);
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ececf2;
    color: #888;
    line-height: 28px;
    font-weight: 600;
    margin: 0;
  }
  .stepper li.active {
    background: transparent;
    color: #1a5fc7;
    font-weight: 600;
  }
  .stepper li.active::before {
    background: #1a5fc7;
    color: #fff;
  }
  .stepper li.done {
    background: transparent;
    color: #1a7f3c;
  }
  .stepper li.done::before {
    background: #1a7f3c;
    color: #fff;
    content: '✓';
  }

  /* Form grid collapses to a single column. */
  .grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  fieldset { padding: 12px; margin-bottom: 12px; }
  legend { font-size: 0.9rem; }

  /* Bigger inputs for fingers. */
  input[type="text"], input:not([type]) {
    padding: 10px 12px;
    font-size: 16px;
  }

  /* Step nav buttons stack instead of left/right. */
  .step .step-nav {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
  }
  .step .step-nav button { width: 100%; padding: 12px; }
  .step .step-nav button.link { padding: 10px; }

  /* Hide the desktop-only Generate button on step 3 — replaced by sticky bar. */
  .step-3-mobile #generate { display: none; }

  /* Editor: hide table, show card list. */
  .csv-editor-status {
    flex-wrap: wrap;
  }
  /* Hide the desktop "+ Add row" button on mobile — replaced by FAB. */
  #csv-add-row { display: none; }

  /* Step 2 review tables. */
  table.kv td:first-child { width: 45%; }
  table.kv { font-size: 0.85rem; }
  table.kv td { padding: 6px 8px; }

  /* Help drawer becomes a bottom sheet. */
  .help-drawer {
    top: auto;
    width: 100%;
    height: 88vh;
    max-height: 88vh;
    border-radius: 16px 16px 0 0;
    animation: helpSheetSlide 0.22s ease-out;
  }
  @keyframes helpSheetSlide {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .help-toc {
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .help-toc button { flex: 0 0 auto; white-space: nowrap; }

  /* Resume banner stacks vertically. */
  .resume-banner {
    flex-wrap: wrap;
    gap: 8px;
  }
  .resume-banner span { flex: 1 1 100%; }
  .resume-banner button { flex: 1; }

  /* CSV upload row stacks. */
  .csv-upload-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

/* Even tighter for true phone widths. */
@media (max-width: 480px) {
  main { padding: 10px 8px 16px 8px; }
  h1 { font-size: 0.95rem; }
  .csv-editor-status { flex-direction: column; align-items: flex-start; gap: 6px; }
  .csv-editor-actions { flex-wrap: wrap; }
  .row-modal-actions { grid-template-columns: 1fr; }
}

/* Inputs need 16px+ on iOS to avoid auto-zoom on focus. */
@media (max-width: 600px) {
  input[type="text"],
  input:not([type]),
  #csv-editor-table input {
    font-size: 16px;
  }
}

/* Catch-all for touch devices that may report a wide viewport but are
   physically a phone/tablet. Coarse pointer = touch primary. */
@media (pointer: coarse) and (max-width: 1280px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }
  [hidden].mobile-only { display: none !important; }
}
