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

/* Lock document to viewport — only .content scrolls */
html, body { height: 100%; overflow: hidden; }

body {
  background: #f5f6f8;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  color: #1f2937;
}

/* ── Layout ──────────────────────────────────────────── */

:root { --sb-w: 220px; }
.shell { display: flex; height: 100%; }
.content { flex: 1; min-width: 0; overflow-y: auto; overflow-x: hidden; }

/* ── Sidebar ─────────────────────────────────────────── */

#sidebar {
  width: var(--sb-w);
  flex-shrink: 0;
  height: 100%;
  overflow: hidden;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease;
  z-index: 100;
}

.sb-top {
  display: flex;
  align-items: center;
  padding: 0 14px;
  height: 56px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

.sb-pip {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #0d9488;
  color: #fff;
  font-size: .85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sb-lbl {
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.15s, max-width 0.2s;
  max-width: 180px;
}
#sidebar.collapsed .sb-lbl { opacity: 0; max-width: 0; }

.sb-brand .sb-lbl { color: #f1f5f9; font-size: .95rem; font-weight: 600; letter-spacing: .01em; }

.sb-toggle {
  background: none;
  border: none;
  border-top: 1px solid rgba(255,255,255,.06);
  color: #475569;
  cursor: pointer;
  height: 44px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 18px;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.sb-toggle:hover { color: #94a3b8; background: rgba(255,255,255,.06); }
.sb-toggle svg { transition: transform 0.2s; }
#sidebar.collapsed .sb-toggle { justify-content: center; padding: 0; }
#sidebar.collapsed .sb-toggle svg { transform: rotate(180deg); }

.sb-nav { flex: 1; padding: 8px; overflow-y: auto; overflow-x: hidden; }
.sb-nav ul { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.sb-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 6px;
  text-decoration: none;
  color: #94a3b8;
  font-size: .875rem;
  font-weight: 500;
  overflow: hidden;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
  background: none;
  border: none;
  width: 100%;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.sb-link:hover { color: #e2e8f0; background: rgba(255,255,255,.06); }
.sb-link.active { color: #0d9488; background: rgba(13,148,136,.12); }
.sb-icon { flex-shrink: 0; display: flex; align-items: center; }

.sb-footer {
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,.06);
  overflow: hidden;
}

.sb-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  overflow: hidden;
}

.sb-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #0d9488;
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: .04em;
}

.sb-email { font-size: .78rem; color: #64748b; text-overflow: ellipsis; flex: 1; min-width: 0; }

.sb-avatar-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  transition: opacity 0.15s;
}
.sb-avatar-btn:hover { opacity: 0.8; }

.sb-user-menu {
  position: fixed;
  min-width: 160px;
  background: #1e293b;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 6px;
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  display: none;
  z-index: 200;
}
.sb-user-menu.open { display: block; }

.sb-user-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 4px;
  color: #cbd5e1;
  font-size: .85rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.sb-user-menu-item:hover { background: rgba(255,255,255,.08); color: #f1f5f9; }

/* ── Sidebar client zone ─────────────────────────────── */

.sb-client-zone {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
  overflow: visible;
}

.sb-client-static {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 6px;
  color: #94a3b8;
  font-size: .8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
}

.sb-client-picker { position: relative; }

.sb-client-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border-radius: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: #e2e8f0;
  font-size: .8rem;
  font-weight: 500;
  font-family: inherit;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.15s;
}
.sb-client-btn:hover { background: rgba(255,255,255,.06); }

.sb-client-btn-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-client-chevron {
  flex-shrink: 0;
  color: #475569;
  display: flex;
  align-items: center;
  transition: transform 0.15s;
}
.sb-client-picker.open .sb-client-chevron { transform: rotate(180deg); }

.sb-client-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  background: #1e293b;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px;
  padding: 4px;
  z-index: 200;
  display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  min-width: 140px;
}
.sb-client-picker.open .sb-client-dropdown { display: block; }

.sb-client-option {
  display: block;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: none;
  border-radius: 4px;
  text-align: left;
  font-size: .82rem;
  color: #94a3b8;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.1s, color 0.1s;
}
.sb-client-option:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.sb-client-option.selected { color: #0d9488; }

/* ── Dashboard iframe overlay ────────────────────────── */

.dash-frame {
  display: none;
  position: fixed;
  top: 0;
  left: var(--sb-w);
  right: 0;
  bottom: 0;
  z-index: 50;
  background: #fff;
  transition: left 0.2s ease;
}
.dash-frame.visible { display: block; }
.dash-frame iframe { width: 100%; height: 100%; border: none; display: block; }

/* ── Buttons ─────────────────────────────────────────── */

.btn-primary {
  padding: 0.55rem 1.2rem;
  background: #0d9488;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary:hover { background: #0f766e; }
.btn-primary:disabled { background: #9ca3af; cursor: not-allowed; }

.btn-secondary {
  padding: 0.5rem 1rem;
  background: #ffffff;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

/* ── Toast notification ──────────────────────────────── */

#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  max-width: 400px;
  padding: 0.9rem 1.1rem;
  background: #111827;
  color: #ffffff;
  font-size: 0.88rem;
  border-radius: 6px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 1200;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { background: #991b1b; }

/* ── Modals ──────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 2rem;
}
.modal-overlay.show { display: flex; }

.modal {
  background: #ffffff;
  border-radius: 10px;
  width: 100%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 500; color: #0f172a; }
.modal-header button { border: none; background: transparent; font-size: 1.2rem; color: #6b7280; cursor: pointer; }

.modal-body { flex: 1; display: flex; min-height: 0; }

.modal-footer {
  padding: 0.9rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f9fafb;
}
.modal-footer .count { font-size: 0.85rem; color: #6b7280; }

.mini-modal {
  background: #ffffff;
  border-radius: 10px;
  max-width: 440px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.mini-modal h3 { font-size: 1.02rem; font-weight: 500; color: #0f172a; margin-bottom: 0.9rem; }
.mini-modal label { display: block; font-size: 0.8rem; color: #6b7280; margin-bottom: 0.3rem; }
.mini-modal input[type=text],
.mini-modal input[type=number],
.mini-modal select { width: 100%; padding: 0.55rem 0.7rem; font-size: 0.9rem; border: 1px solid #d1d5db; border-radius: 6px; color: #1f2937; }
.mini-modal .actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; }

/* ── Form fields ─────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; color: #6b7280; text-transform: uppercase; }
.field input,
.field select { width: 100%; box-sizing: border-box; padding: 0.55rem 0.7rem; font-size: 0.9rem; border: 1px solid #d1d5db; border-radius: 6px; color: #1f2937; background: #ffffff; }
.field input:focus,
.field select:focus { outline: 2px solid #0d9488; outline-offset: 1px; border-color: transparent; }

/* Larger, easier-to-read variant — reusable anywhere a field needs emphasis. */
.field--lg label { font-size: 0.78rem; }
.field--lg input,
.field--lg select { padding: 0.7rem 0.85rem; font-size: 1.02rem; border-radius: 8px; }

/* Invalid state + inline error text — reusable on any .field. */
.field.is-invalid input,
.field.is-invalid select { border-color: #dc2626; }
.field.is-invalid input:focus,
.field.is-invalid select:focus { outline-color: #dc2626; }
.field-error { font-size: 0.78rem; color: #b91c1c; }

/* ── Spinner ─────────────────────────────────────────── */

@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 36px; height: 36px; border: 3px solid rgba(255,255,255,0.2); border-top-color: #ffffff; border-radius: 50%; animation: spin 0.8s linear infinite; }
.spinner.dark { border-color: rgba(13,148,136,0.18); border-top-color: #0d9488; }
.spinner.small { width: 20px; height: 20px; border-width: 2.5px; }

/* ── Upload progress indicator ───────────────────────── */

.upload-progress { display: flex; flex-direction: column; align-items: center; gap: 0.7rem; padding: 0.6rem 0; }
.upload-progress .pct { font-size: 1.3rem; font-weight: 600; color: #0d9488; font-variant-numeric: tabular-nums; min-height: 1.6rem; }
.upload-progress .verb { font-size: 0.82rem; color: #6b7280; transition: opacity 0.3s; min-height: 1.1rem; }

/* ── Utility ─────────────────────────────────────────── */

/* Muted body text */
.text-muted { color: #6b7280; }

/* Empty-state message — use on <p> or <td> */
.cell-empty { padding: 1.25rem 1rem; color: #6b7280; font-size: 0.88rem; }

/* ── Status badges ───────────────────────────────────── */

.status-badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.status-pending_upload         { background: #f3f4f6; color: #4b5563; }
.status-pending_classification { background: #dbeafe; color: #1d4ed8; }
.status-pending_chunks         { background: #e0e7ff; color: #3730a3; }
.status-ingesting              { background: #fef3c7; color: #92400e; }
.status-ingested               { background: #d1fae5; color: #065f46; }
.status-failed                 { background: #fee2e2; color: #b91c1c; }
