/* ============================================================
   RaizIntel — Shared Brand Styles
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@400;500;600;700&family=Source+Sans+3:wght@300;400;600;700&display=swap');

/* ── RESET & BASE ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --black:        #0a0a0a;
  --near-black:   #111111;
  --dark:         #1a1a1a;
  --dark-mid:     #252525;
  --mid:          #3a3a3a;
  --muted:        #666666;
  --border:       #2e2e2e;
  --border-light: #e0e0e0;
  --surface:      #161616;
  --surface-2:    #1e1e1e;
  --surface-3:    #242424;

  --red:          #c41e1e;
  --red-dim:      #9b1818;
  --red-glow:     rgba(196,30,30,0.15);

  --white:        #ffffff;
  --off-white:    #f4f4f4;
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-dim:     #6a6a6a;

  --success:      #2d7a3a;
  --warning:      #c47c1e;
  --error:        #c41e1e;
  --info:         #1e5fa0;

  --font-display: 'Oswald', 'Arial Narrow', Arial, sans-serif;
  --font-body:    'Source Sans 3', 'Segoe UI', Arial, sans-serif;

  --radius:       4px;
  --radius-sm:    2px;
  --radius-lg:    8px;

  --shadow:       0 2px 12px rgba(0,0,0,0.5);
  --shadow-heavy: 0 4px 24px rgba(0,0,0,0.7);

  --transition:   0.18s ease;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  background: var(--black);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── TYPOGRAPHY ── */
h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  line-height: 1.1;
}

/* ── PORTAL TOPBAR ── */
.portal-topbar {
  background: var(--near-black);
  border-bottom: 2px solid var(--red);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.portal-topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.portal-topbar .brand-wordmark {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.portal-topbar .brand-badge {
  font-size: 0.6rem;
  font-weight: 700;
  background: var(--red);
  color: white;
  padding: 2px 7px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
}

.portal-topbar .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.portal-topbar .investigator-name {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.btn-logout {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: color var(--transition), border-color var(--transition);
}

.btn-logout:hover {
  color: var(--red);
  border-color: var(--red);
}

/* ── SIDEBAR NAV (canonical / shared) ──
   Single source for the RaizNav sidebar appearance so every internal page
   renders identical gray nav links (NON-NEGOTIABLE UI RULE 11 — Consistent
   Layout). Copied verbatim from public/home/index.html. Pages that still carry
   their own inline .nav-item block keep it (identical values; their inline copy
   wins by cascade order) — this default reaches pages that omitted it, which
   previously fell back to browser-default blue links. */
.nav-section-label {
  font-family: var(--font-display); font-size: 0.62rem; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-dim); padding: 16px 16px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; font-size: 0.85rem; font-weight: 600;
  color: var(--text-secondary); cursor: pointer;
  border-left: 3px solid transparent;
  transition: all var(--transition); text-decoration: none; user-select: none;
}
.nav-item:hover { color: var(--text-primary); background: rgba(255,255,255,0.03); }
.nav-item.active { color: var(--white); border-left-color: var(--red); background: rgba(196,30,30,0.08); }
.nav-item .nav-icon { font-size: 0.8rem; width: 16px; text-align: center; opacity: 0.7; }
.sidebar-footer { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--border); }

/* ── FORM COMPONENTS ── */
.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.form-section-header {
  background: var(--dark);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.form-section-header .section-num {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--red);
  color: white;
  padding: 2px 7px;
  letter-spacing: 0.1em;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.form-section-header .section-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-primary);
  flex: 1;
}

.form-section-header .section-chevron {
  color: var(--text-dim);
  font-size: 1rem;
  transition: transform var(--transition);
  flex-shrink: 0;
}

.form-section-header.collapsed .section-chevron {
  transform: rotate(-90deg);
}

.form-section-body {
  padding: 14px;
}

.form-section-body.hidden { display: none; }

/* ── FIELD ROWS ── */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.field-row.triple {
  grid-template-columns: 1fr 1fr 1fr;
}

.field-row.quad {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}

.field-row.full {
  grid-template-columns: 1fr;
}

@media (max-width: 480px) {
  .field-row,
  .field-row.triple,
  .field-row.quad {
    grid-template-columns: 1fr 1fr;
  }
  .field-row.full { grid-template-columns: 1fr; }
}

/* Wide tables: scroll horizontally instead of overflowing the viewport.
   No-op on desktop (only scrolls when content exceeds the container width). */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Phone/tablet touch sizing. Scoped to <=768px so desktop/laptop is untouched.
   16px inputs prevent iOS Safari from auto-zooming on field focus. */
@media (max-width: 768px) {
  input[type="text"], input[type="email"], input[type="password"], input[type="number"],
  input[type="search"], input[type="date"], select, textarea { font-size: 16px; }
  .btn { padding: 13px 20px; }
  .btn-sm { padding: 10px 16px; }
  .btn-logout { padding: 9px 14px; }
  .toggle-btn { padding: 10px 8px; }
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-group label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.field-group label .required {
  color: var(--red);
  margin-left: 2px;
}

/* ── INPUTS ── */
input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 9px 10px;
  transition: border-color var(--transition), background var(--transition);
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--red);
  background: var(--surface-3);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-dim);
  font-style: italic;
}

select {
  cursor: pointer;
  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 fill='%23666' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.5;
}

/* Disabled state */
input:disabled, select:disabled, textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── TOGGLE / RADIO GROUP ── */
.toggle-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.toggle-btn {
  flex: 1;
  min-width: 60px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition);
  -webkit-user-select: none;
  user-select: none;
}

.toggle-btn:active { transform: scale(0.97); }

.toggle-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: white;
}

.toggle-btn.active-green {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

/* ── BUTTONS ── */
.btn {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
  background: var(--red);
  color: white;
}

.btn-primary:hover { background: var(--red-dim); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-3);
  color: var(--text-primary);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-outline-red {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
}

.btn-outline-red:hover {
  background: var(--red-glow);
}

.btn-sm {
  font-size: 0.78rem;
  padding: 7px 14px;
}

.btn-full { width: 100%; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── ALERTS ── */
.alert {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border-left: 3px solid;
  margin-bottom: 12px;
}

.alert-error {
  background: rgba(196,30,30,0.12);
  border-color: var(--red);
  color: #ff8080;
}

.alert-success {
  background: rgba(45,122,58,0.15);
  border-color: var(--success);
  color: #7dcf8a;
}

.alert-info {
  background: rgba(30,95,160,0.15);
  border-color: var(--info);
  color: #7ab4e8;
}

/* ── LOADING SPINNER ── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── UTILITY ── */
.text-muted { color: var(--text-dim); }
.text-red   { color: var(--red); }
.text-sm    { font-size: 0.8rem; }
.mt-8       { margin-top: 8px; }
.mt-12      { margin-top: 12px; }
.mt-16      { margin-top: 16px; }
.hidden     { display: none !important; }

/* ── STATUS BADGES (canonical / shared) ──
   Phase 4 Batch 4-1: single source of truth for status pills. Page-level
   <style> blocks load after this file, so existing pages keep their own
   geometry via the cascade — these defaults apply to new markup and to the
   opt-in client-visibility classes below. Geometry matches the majority of
   pages (0.62rem text, 5px dot, gap 5px, padding 3px 8px). */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.status-badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

/* Canonical color map (palette verbatim from existing pages) */
.badge-active,
.badge-approved,
.badge-stored,
.badge-allow            { background: rgba(45,122,58,0.18);  color: #7dcf8a; }
.badge-submitted,
.badge-info,
.badge-intake           { background: rgba(30,95,160,0.18);  color: #7ab4e8; }
.badge-reviewed,
.badge-on_hold,
.badge-duplicate        { background: rgba(196,124,30,0.18); color: #e8c07a; }
.badge-returned,
.badge-locked,
.badge-restricted,
.badge-deny,
.badge-entered_in_error { background: rgba(196,30,30,0.18);  color: #e87a7a; }
.badge-draft,
.badge-closed,
.badge-pending,
.badge-archived         { background: rgba(106,106,106,0.18); color: #aaa; }
.badge-void             { background: rgba(106,106,106,0.20); color: #c9c9c9; }

/* Client-visibility disclosure pills (reusable; replaces inline styles) */
.badge-client-visible   { background: rgba(125,207,138,0.12); color: #7dcf8a; }
.badge-client-hidden    { background: rgba(170,170,170,0.12); color: var(--text-dim); }

/* Lock / immutability indicator. Markup carries the "Locked" text label, so
   the lock glyph degrades gracefully if the emoji font is unavailable. */
.lock-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-display);
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #e8c07a;
  white-space: nowrap;
}

/* Wraps a row of badges/tags so they stay tidy instead of overflowing.
   Opt-in helper — not auto-applied to existing rows in this batch. */
.badge-cluster {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  row-gap: 4px;
}

/* ── EMPTY STATES (canonical / shared) ── */
.empty-state      { padding: 48px 24px; text-align: center; }
.empty-state-icon { font-size: 2rem; margin-bottom: 10px; opacity: 0.3; }
.empty-state-text {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-dim);
}
.empty-state-sub  { font-size: 0.8rem; color: var(--text-dim); margin-top: 6px; opacity: 0.7; }

/* Narrow-phone badge handling (separate from the 768px layout block).
   Keeps badge clusters wrapping cleanly and stops glyph+word splitting. */
@media (max-width: 500px) {
  .badge-cluster { gap: 4px; row-gap: 3px; }
  .status-badge,
  .lock-tag,
  .pub-badge { white-space: nowrap; }
}
