/* =====================================================================
   Bedside Onboarding Dashboard — Stylesheet
   ===================================================================== */

:root {
  --navy-900: #0F2847;
  --navy-800: #163556;
  --navy-700: #1F4068;
  --teal-700: #0D9488;
  --teal-600: #14B8A6;
  --teal-200: #99F6E4;
  --mint:     #5BE5CA;

  --ink:      #1A2533;
  --ink-soft: #5B6B7A;
  --slate-500:#64748B;
  --slate-300:#CBD5E1;

  --bg:       #FFFFFF;
  --bg-soft:  #F4F7F9;
  --bg-mute:  #EEF2F5;
  --line:     #D6DCE0;
  --line-soft:#E5EAEE;

  --danger:   #DC2626;
  --warn:     #D97706;
  --success:  #059669;

  --radius:    10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(15,40,71,.06), 0 1px 3px rgba(15,40,71,.04);
  --shadow:    0 4px 10px rgba(15,40,71,.06), 0 2px 4px rgba(15,40,71,.04);
  --shadow-lg: 0 12px 32px rgba(15,40,71,.10), 0 4px 12px rgba(15,40,71,.06);

  --font-body:    'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --font-mono:    'Geist Mono', ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg-soft);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--navy-900);
  margin: 0 0 .6rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

p { margin: 0 0 .85rem; color: var(--ink-soft); }
a { color: var(--teal-700); }

code, .mono { font-family: var(--font-mono); font-size: .85em; }

/* =====================================================================
   Topbar
   ===================================================================== */
.topbar {
  background: var(--navy-900);
  color: #fff;
  padding: .9rem 0;
}
.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .75rem; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, var(--teal-600), var(--mint));
  display: flex; align-items: center; justify-content: center;
  color: var(--navy-900);
  font-family: var(--font-display); font-weight: 700; font-size: 1.15rem;
}
.brand-name { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; }
.brand-tagline { font-size: .78rem; color: rgba(255,255,255,.6); letter-spacing: .05em; text-transform: uppercase; }

.topbar-right { display: flex; align-items: center; gap: .75rem; }
.conn-status {
  display: flex; align-items: center; gap: .5rem;
  font-size: .85rem; color: rgba(255,255,255,.75);
}
.conn-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #FBBF24; box-shadow: 0 0 8px #FBBF24;
}
.conn-status.is-ok    .dot { background: var(--mint);  box-shadow: 0 0 8px var(--mint); }
.conn-status.is-error .dot { background: #F87171;      box-shadow: 0 0 8px #F87171; }

.btn-ghost.btn-sm {
  color: rgba(255,255,255,.9);
  border-color: rgba(255,255,255,.18);
  background: rgba(255,255,255,.04);
}
.btn-ghost.btn-sm:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.3); }

/* =====================================================================
   Stats strip
   ===================================================================== */
.stats-strip {
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.stats-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
}
@media (max-width: 900px) { .stats-inner { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .stats-inner { grid-template-columns: 1fr; } }
.stat-card {
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: .85rem 1rem;
}
.stat-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-soft);
  font-weight: 600;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--navy-900);
  margin-top: .15rem;
}
.stat-sub { font-size: .8rem; color: var(--ink-soft); }

/* =====================================================================
   Layout
   ===================================================================== */
.layout {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }

/* =====================================================================
   Sidebar
   ===================================================================== */
.sidebar {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
}
@media (max-width: 1000px) { .sidebar { position: static; max-height: none; } }

.sidebar-controls {
  padding: 1rem;
  border-bottom: 1px solid var(--line-soft);
  display: flex; flex-direction: column; gap: .65rem;
}
.search-input { font-size: .92rem; }
.filter-row { display: flex; gap: .35rem; }
.chip {
  flex: 1;
  padding: .4rem .55rem;
  font: inherit; font-size: .8rem; font-weight: 500;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
  color: var(--ink);
}
.chip:hover { border-color: var(--teal-600); }
.chip.is-on { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }

.submission-list {
  list-style: none; padding: 0; margin: 0;
  overflow-y: auto;
  flex: 1;
}
.sub-item {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background .15s;
  display: block;
}
.sub-item:hover { background: var(--bg-soft); }
.sub-item.is-active {
  background: rgba(13,148,136,.08);
  border-left: 3px solid var(--teal-700);
  padding-left: calc(1rem - 3px);
}

.sub-item-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .25rem;
}
.sub-item .name {
  font-weight: 500;
  color: var(--navy-900);
  font-size: .93rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1;
}
.sub-item .email {
  font-size: .8rem;
  color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sub-item-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: .35rem; gap: .5rem;
}

.status-badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.status-badge.submitted { background: rgba(5,150,105,.12); color: var(--success); }
.status-badge.draft     { background: rgba(217,119,6,.12); color: var(--warn); }
.status-badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

.pct-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-mute);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}
.pct-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--teal-700), var(--mint));
}
.pct-text { font-size: .75rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.sub-item .time { font-size: .72rem; color: var(--slate-500); }

.empty-list {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: .9rem;
}

/* =====================================================================
   Detail panel
   ===================================================================== */
.detail {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.75rem 2rem;
  min-height: 70vh;
  box-shadow: var(--shadow-sm);
}
@media (max-width: 600px) { .detail { padding: 1.25rem 1rem; } }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--ink-soft);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: .6; }
.empty-state h2 { color: var(--navy-900); margin-bottom: .25rem; }

/* Detail header card */
.detail-header {
  background: linear-gradient(135deg, var(--navy-900), var(--navy-700));
  color: #fff;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1.5rem; flex-wrap: wrap;
}
.detail-header h1 {
  color: #fff;
  margin-bottom: .3rem;
  font-size: 1.5rem;
}
.detail-header .sub-email { color: rgba(255,255,255,.8); font-size: .92rem; }
.detail-header .meta {
  display: flex; gap: 1.25rem; flex-wrap: wrap;
  margin-top: .85rem;
  font-size: .85rem;
  color: rgba(255,255,255,.7);
}
.detail-header .meta strong { color: #fff; font-weight: 500; }
.detail-header .meta .id { font-family: var(--font-mono); font-size: .78rem; }
.detail-header .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.detail-header .actions .btn {
  background: rgba(255,255,255,.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,.2);
}
.detail-header .actions .btn:hover { background: rgba(255,255,255,.22); }

.detail-pct {
  display: flex; align-items: center; gap: .85rem;
  margin-top: 1rem;
}
.detail-pct .pct-bar { background: rgba(255,255,255,.15); }
.detail-pct .pct-text { color: rgba(255,255,255,.85); font-size: .9rem; font-weight: 500; }

/* Step blocks */
.step-block {
  margin-bottom: 1.75rem;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  overflow: hidden;
}
.step-block-head {
  background: var(--bg-soft);
  padding: .85rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--line-soft);
}
.step-block-head:hover { background: var(--bg-mute); }
.step-block.is-collapsed .step-block-head { border-bottom-color: transparent; }
.step-block.is-collapsed .step-block-body { display: none; }
.step-block-head .num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--navy-900); color: #fff;
  font-size: .75rem; font-weight: 700;
  margin-right: .75rem;
}
.step-block-head h2 {
  margin: 0; font-size: 1.05rem;
  display: inline; vertical-align: middle;
}
.step-block-head .summary {
  font-size: .82rem; color: var(--ink-soft);
  font-weight: 400;
}
.step-block-head .caret {
  color: var(--ink-soft);
  font-size: .9rem;
  transition: transform .15s;
}
.step-block.is-collapsed .step-block-head .caret { transform: rotate(-90deg); }

.step-block-body { padding: 1.25rem 1.5rem; }

/* Sub-sections */
.sub-block { margin-bottom: 1.5rem; }
.sub-block:last-child { margin-bottom: 0; }
.sub-block h3 {
  font-size: .95rem;
  color: var(--navy-800);
  margin-bottom: .85rem;
  padding-bottom: .35rem;
  border-bottom: 1px dashed var(--line-soft);
  font-family: var(--font-display);
}

/* Field rows */
.field-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.25rem;
  padding: .55rem 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: .91rem;
}
.field-row:last-child { border-bottom: 0; }
@media (max-width: 700px) {
  .field-row { grid-template-columns: 1fr; gap: .25rem; }
}
.field-row .label {
  color: var(--ink-soft);
  font-size: .85rem;
  font-weight: 500;
  line-height: 1.45;
  padding-top: .15rem;
}
.field-row .value {
  color: var(--ink);
  line-height: 1.55;
  word-wrap: break-word;
}
.field-row .value.is-empty { color: var(--slate-500); font-style: italic; font-size: .85rem; }
.field-row .value pre {
  font-family: inherit;
  white-space: pre-wrap;
  margin: 0;
}

/* Chip list for checkboxes */
.chip-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip-item {
  background: var(--teal-200);
  color: var(--navy-900);
  padding: .2rem .6rem;
  border-radius: 99px;
  font-size: .82rem;
  font-weight: 500;
}
.radio-chip {
  display: inline-block;
  background: rgba(15,40,71,.08);
  color: var(--navy-900);
  padding: .2rem .65rem;
  border-radius: 99px;
  font-size: .85rem;
  font-weight: 500;
}

/* Files */
.file-row {
  display: flex; align-items: center; gap: .65rem;
  padding: .5rem .75rem;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  margin-bottom: .35rem;
  font-size: .87rem;
}
.file-row:last-child { margin-bottom: 0; }
.file-icon { font-size: 1rem; }
.file-row .name { flex: 1; color: var(--navy-900); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .size { color: var(--ink-soft); font-size: .8rem; }
.file-row .open {
  font-size: .8rem;
  color: var(--teal-700);
  text-decoration: none;
  padding: .25rem .55rem;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
}
.file-row .open:hover { border-color: var(--teal-700); background: #fff; }

.image-thumb {
  width: 48px; height: 48px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line-soft);
  object-fit: cover;
  flex-shrink: 0;
}

/* Audio */
.audio-row {
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: .65rem .85rem;
  margin-top: .5rem;
  display: flex; align-items: center; gap: .6rem;
  flex-wrap: wrap;
}
.audio-row .mic-label {
  font-size: .78rem;
  color: var(--teal-700);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  display: flex; align-items: center; gap: .3rem;
}
.audio-row audio {
  flex: 1; min-width: 200px;
  height: 36px;
}

/* Data table (for table fields) */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .87rem;
  margin-top: .35rem;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  overflow: hidden;
}
.data-table thead th {
  background: var(--navy-900);
  color: #fff;
  padding: .55rem .75rem;
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.data-table tbody td {
  border-top: 1px solid var(--line-soft);
  padding: .5rem .75rem;
  vertical-align: top;
  color: var(--ink);
  background: #fff;
}
.data-table tbody tr:nth-child(even) td { background: var(--bg-soft); }

/* JSON export modal-ish view */
.json-pane {
  background: var(--navy-900);
  color: #E5EAEE;
  font-family: var(--font-mono);
  font-size: .82rem;
  padding: 1rem 1.25rem;
  border-radius: 10px;
  max-height: 70vh;
  overflow: auto;
  white-space: pre;
}

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem;
  padding: .55rem 1rem;
  border-radius: 99px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  font-size: .88rem;
  font-family: var(--font-body);
}
.btn-primary { background: var(--navy-900); color: #fff; }
.btn-primary:hover { background: var(--navy-800); }
.btn-accent  { background: var(--teal-700); color: #fff; }
.btn-accent:hover { background: var(--teal-600); }
.btn-ghost   { background: transparent; color: var(--navy-900); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--navy-900); background: var(--bg-soft); }
.btn-sm { padding: .35rem .75rem; font-size: .82rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius);
  padding: .55rem .8rem;
  font: inherit;
  color: var(--ink);
  font-size: .92rem;
  font-family: var(--font-body);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--teal-700);
  box-shadow: 0 0 0 3px rgba(13,148,136,.15);
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235B6B7A' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.25rem;
}

/* =====================================================================
   Gate
   ===================================================================== */
.gate-screen { max-width: 420px; margin: 8vh auto 0; padding: 0 1.5rem; }
.gate-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.gate-card .brand-mark { margin: 0 auto 1rem; width: 56px; height: 56px; font-size: 1.6rem; }
.gate-card h1 { font-size: 1.5rem; margin-bottom: .15rem; }
.gate-card .form-row { margin-top: 1.5rem; }
.gate-error { color: var(--danger); font-size: .85rem; margin-top: .5rem; min-height: 1.2em; }

/* =====================================================================
   Toast
   ===================================================================== */
.toast-stack {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  display: flex; flex-direction: column; gap: .5rem;
  z-index: 999; max-width: 340px;
}
.toast {
  background: var(--navy-900); color: #fff;
  border-radius: 10px; padding: .7rem 1rem;
  font-size: .88rem; box-shadow: var(--shadow-lg);
  animation: toast-in .25s ease-out;
}
.toast.success { background: var(--success); }
.toast.warn    { background: var(--warn); }
.toast.error   { background: var(--danger); }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* =====================================================================
   Spinner
   ===================================================================== */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--ink-soft); }
.text-sm { font-size: .85rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.ico { font-size: 1rem; }

/* Form-type badges */
.form-badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  vertical-align: middle;
}
.form-badge.main   { background: rgba(13,148,136,.15); color: #0d9488; }
.form-badge.excel  { background: rgba(217,119,6,.15);  color: #b45309; }

h1 .form-badge {
  font-size: .65rem;
  margin-left: .5rem;
  vertical-align: middle;
}

/* Sub-item foot includes form badge */
.sub-item-foot {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .35rem;
}
.sub-item-foot .pct-bar { flex: 1; }

/* Repeater detail cards */
.rep-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.rep-card {
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 8px;
  background: rgba(13,148,136,.03);
  overflow: hidden;
}
.rep-card-head {
  padding: .5rem .75rem;
  background: rgba(13,148,136,.08);
  font-weight: 600;
  font-size: .85rem;
  color: #0d9488;
  border-bottom: 1px solid var(--line, #e5e7eb);
}
.rep-card-body {
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.field-row.sub {
  grid-template-columns: 180px 1fr;
  padding-top: .35rem;
  padding-bottom: .35rem;
  border-bottom: 1px dashed rgba(0,0,0,.06);
}
.field-row.sub:last-child { border-bottom: none; }
.field-row.sub .label {
  font-size: .8rem;
  color: var(--ink-soft, #6b7280);
}
