/* Risk Navigator — Shared Styles
   Brand: Deep Navy / Rich Gold / Warm Cream
   Font: DM Sans
*/

:root {
  --navy: #1E3A5F;
  --navy-dark: #152a45;
  --navy-light: #2b517e;
  --gold: #C5A572;
  --gold-dark: #a88a57;
  --cream: #F5F3EF;
  --white: #FFFFFF;
  --success: #2D5A4A;
  --success-bg: #e3ede9;
  --warning: #E65100;
  --warning-bg: #fbe4d4;
  --danger: #722F37;
  --danger-bg: #f0dfe1;
  --info: #0D47A1;
  --info-bg: #d9e2f0;
  --charcoal: #2C3E50;
  --muted: #6B7280;
  --border: #E5E7EB;
  --border-strong: #d1d5db;
  --shadow-sm: 0 1px 2px rgba(30, 58, 95, 0.06);
  --shadow: 0 2px 8px rgba(30, 58, 95, 0.08);
  --shadow-lg: 0 8px 24px rgba(30, 58, 95, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
}

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

html, body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--cream);
  color: var(--charcoal);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { color: var(--navy); font-weight: 700; line-height: 1.2; }
h1 { font-size: 1.875rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.0625rem; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.tiny { font-size: 0.75rem; }
.bold { font-weight: 600; }

/* ============================================
   LAYOUT
   ============================================ */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: var(--navy);
  color: var(--white);
  padding: 24px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  padding: 0 24px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar .brand .logo {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--white);
}
.sidebar .brand .logo .gold { color: var(--gold); }
.sidebar .brand .tagline { font-size: 0.75rem; color: rgba(255,255,255,0.6); margin-top: 4px; }

.sidebar nav { flex: 1; padding: 16px 0; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  color: rgba(255,255,255,0.8);
  font-weight: 500;
  font-size: 0.9375rem;
  transition: background 0.15s, color 0.15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.05); color: var(--white); text-decoration: none; }
.sidebar nav a.active { background: var(--navy-dark); color: var(--gold); border-left: 3px solid var(--gold); padding-left: 21px; }
.sidebar nav a .icon { width: 20px; text-align: center; }

.sidebar .user-card {
  padding: 16px 24px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.875rem;
}
.sidebar .user-card .name { color: var(--white); font-weight: 600; }
.sidebar .user-card .role { color: rgba(255,255,255,0.6); font-size: 0.75rem; }
.sidebar .user-card .signout { color: var(--gold); font-size: 0.8125rem; margin-top: 8px; display: inline-block; cursor: pointer; }

.main {
  padding: 32px 40px;
  max-width: 1400px;
  width: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
}
.page-header .title h1 { margin-bottom: 4px; }
.page-header .title .subtitle { color: var(--muted); font-size: 0.9375rem; }

/* Tablet — narrow sidebar, tighter padding */
@media (max-width: 1024px) and (min-width: 769px) {
  .app-shell { grid-template-columns: 200px 1fr; }
  .main { padding: 24px 24px; }
  .sidebar nav a { padding: 10px 16px; font-size: 0.875rem; }
  .sidebar .brand { padding: 0 16px 16px; }
  .sidebar .user-card { padding: 12px 16px; }
}

/* ============================================
   CARDS
   ============================================ */

.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.card.compact { padding: 16px; }
.card h2, .card h3 { margin-bottom: 16px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  border-left: 4px solid var(--navy);
}
.stat-card.success { border-left-color: var(--success); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.gold { border-left-color: var(--gold); }
.stat-card .label { color: var(--muted); font-size: 0.8125rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card .value { color: var(--navy); font-size: 2rem; font-weight: 700; margin: 8px 0 4px; }
.stat-card .delta { font-size: 0.875rem; color: var(--muted); }
.stat-card .delta.up { color: var(--success); }
.stat-card .delta.down { color: var(--danger); }

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1;
}
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: var(--navy-dark); text-decoration: none; }
.btn-gold { background: var(--gold); color: var(--white); }
.btn-gold:hover { background: var(--gold-dark); text-decoration: none; }
.btn-success { background: var(--success); color: var(--white); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-ghost { background: transparent; color: var(--navy); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--cream); text-decoration: none; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-sm { padding: 6px 12px; font-size: 0.8125rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================
   FORMS
   ============================================ */

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--charcoal);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9375rem;
  background: var(--white);
  color: var(--charcoal);
  transition: border-color 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(30,58,95,0.1);
}
.field textarea { min-height: 96px; resize: vertical; }
.field .hint { font-size: 0.8125rem; color: var(--muted); margin-top: 4px; }
.field .error { font-size: 0.8125rem; color: var(--danger); margin-top: 4px; }

/* ============================================
   BADGES
   ============================================ */

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: var(--border); color: var(--muted); }
.badge-gold { background: rgba(197,165,114,0.15); color: var(--gold-dark); }

/* ============================================
   TABLES / LISTS
   ============================================ */

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row .main-col { flex: 1; }
.list-row .main-col .title { font-weight: 600; color: var(--charcoal); }
.list-row .main-col .meta { font-size: 0.8125rem; color: var(--muted); margin-top: 2px; }
.list-row .side-col { display: flex; align-items: center; gap: 12px; }

.progress {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress .bar {
  height: 100%;
  background: var(--success);
  border-radius: 999px;
  transition: width 0.3s;
}
.progress .bar.warning { background: var(--warning); }
.progress .bar.danger { background: var(--danger); }

/* ============================================
   ALERTS / TOASTS
   ============================================ */

.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border-left: 4px solid;
  margin-bottom: 16px;
  font-size: 0.9375rem;
}
.alert-success { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.alert-danger { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.alert-info { background: var(--info-bg); border-color: var(--info); color: var(--info); }

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--white);
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--navy);
  min-width: 280px;
  animation: slideIn 0.2s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

@keyframes slideIn {
  from { transform: translateX(120%); }
  to { transform: translateX(0); }
}

/* ============================================
   MODALS
   ============================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30,58,95,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal h2 { margin-bottom: 16px; }
.modal .actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* ============================================
   AUTH PAGE
   ============================================ */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--cream) 0%, #e8e3d5 100%);
}
.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.auth-card .brand {
  text-align: center;
  margin-bottom: 32px;
}
.auth-card .brand .logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
}
.auth-card .brand .logo .gold { color: var(--gold); }
.auth-card .brand .tagline {
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 6px;
  font-style: italic;
}
.auth-card h1 { font-size: 1.5rem; margin-bottom: 8px; text-align: center; }
.auth-card .subtitle { text-align: center; color: var(--muted); margin-bottom: 28px; font-size: 0.9375rem; }
.auth-card .footer {
  text-align: center;
  margin-top: 24px;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* ============================================
   UTILITIES
   ============================================ */

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 700px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.5; }

/* ============================================
   MOBILE RESPONSIVENESS (≤ 768px)
   ============================================ */

/* Mobile top bar with hamburger — hidden on desktop */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--navy);
  color: var(--white);
  z-index: 100;
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.mobile-topbar .hamburger {
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px 12px;
  line-height: 1;
  border-radius: 6px;
}
.mobile-topbar .hamburger:hover { background: rgba(255,255,255,0.1); }
.mobile-topbar .brand {
  font-size: 1rem;
  font-weight: 700;
  color: var(--white);
}
.mobile-topbar .brand .gold { color: var(--gold); }
.mobile-topbar .spacer { width: 44px; } /* balance the layout */

/* Sidebar backdrop when open on mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
}
.sidebar-backdrop.open { display: block; }

@media (max-width: 768px) {
  .mobile-topbar { display: flex; }

  .app-shell {
    grid-template-columns: 1fr;
    padding-top: 56px; /* space for fixed top bar */
  }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 280px;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease-out;
    box-shadow: 4px 0 16px rgba(0,0,0,0.2);
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar nav { display: block; padding: 16px 0; overflow-x: visible; }
  .sidebar nav a {
    padding: 14px 24px;
    font-size: 1rem;
    border-left: none;
    white-space: normal;
  }
  .sidebar nav a.active { border-left: 3px solid var(--gold); padding-left: 21px; }

  /* Main content */
  .main { padding: 16px 14px; }

  /* Page header stacks */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 20px;
  }
  .page-header h1 { font-size: 1.5rem; }
  .page-header .btn,
  .page-header .btn-gold,
  .page-header .btn-primary { width: 100%; }

  /* Stat grid — 2 columns on mobile (or 1 if very narrow) */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: 1.5rem; }
  .stat-card .label { font-size: 0.6875rem; }

  /* Force any inline grid-2/grid-3 to single column */
  .grid-2, .grid-3 { grid-template-columns: 1fr !important; gap: 12px; }

  /* Cards */
  .card { padding: 16px; }
  .card.compact { padding: 12px; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.0625rem; }

  /* List rows stack */
  .list-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .list-row .side-col {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Modals — full screen */
  .modal-backdrop { padding: 0; align-items: flex-start; }
  .modal {
    border-radius: 0;
    max-width: 100%;
    width: 100%;
    max-height: 100vh;
    height: 100vh;
    padding: 20px 16px;
  }
  .modal .actions {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .modal .actions .btn { width: 100%; }

  /* Forms — prevent iOS zoom on focus */
  .field input,
  .field select,
  .field textarea {
    font-size: 16px;  /* iOS won't zoom if ≥16px */
    padding: 12px 14px;
  }

  /* Bigger tap targets */
  .btn { padding: 12px 18px; min-height: 44px; }
  .btn-sm { min-height: 36px; padding: 8px 14px; }

  /* Toast — full width on mobile */
  .toast-container { left: 12px; right: 12px; top: 64px; }
  .toast { min-width: 0; width: 100%; }

  /* Auth page */
  .auth-card { padding: 28px 20px; }

  /* Filter tabs scroll horizontally — keep readable */
  .filter-tabs button { padding: 10px 14px; font-size: 0.875rem; }

  /* Checklist answer buttons — keep 3 across but more compact */
  .answer-btns { gap: 8px; }
  .answer-btns button { padding: 14px 8px; font-size: 0.9375rem; }

  /* Progress dots in checklist — smaller */
  .progress-dots .dot { width: 18px; height: 18px; font-size: 0.625rem; }

  /* Tabs in settings */
  .tabs button { padding: 10px 14px; font-size: 0.875rem; }
}

/* ============================================
   TOUCH DEVICES — disable hover effects
   ============================================ */

@media (hover: none) {
  .btn:hover,
  .sidebar nav a:hover,
  .answer-btns button:hover,
  .filter-tabs button:hover { transform: none; box-shadow: inherit; }
}

/* ============================================
   PRINT (for compliance reports)
   ============================================ */

@media print {
  .sidebar, .mobile-topbar, .sidebar-backdrop, .toast-container,
  .btn, .page-header .btn { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; max-width: 100%; }
  .card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
}

/* ============================================
   MOBILE — prevent horizontal overflow
   ============================================ */

@media (max-width: 768px) {
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  .app-shell {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .main {
    max-width: 100vw;
    overflow-x: hidden;
    min-width: 0;
  }

  /* Long titles, meta text, and emails should wrap */
  .list-row,
  .list-row .main-col,
  .list-row .title,
  .list-row .meta,
  .card,
  .stat-card,
  h1, h2, h3, p {
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  /* Filter tabs scroll horizontally without pushing page width */
  .filter-tabs {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Inspection summary score circle could be too big */
  .card > div[style*="conic-gradient"] {
    max-width: 100%;
  }

  /* Pre-formatted text and code shouldn't push width */
  pre, code, textarea {
    max-width: 100%;
    word-wrap: break-word;
    white-space: pre-wrap;
  }

  /* Tables overflow with their own scroll, not page scroll */
  table { max-width: 100%; display: block; overflow-x: auto; }
}
