/* =========================================================
   SAFIRION — GLOBAL DESIGN SYSTEM v3
   Single source of truth stylesheet
   ========================================================= */

/* =========================================================
   GOOGLE FONT
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* =========================================================
   ROOT VARIABLES
   ========================================================= */
:root {

  /* =========================
     BRAND
     ========================= */
  --primary: #1e40af;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;

  /* =========================
     RAG STATUS
     ========================= */
  --rag-green: #16a34a;
  --rag-green-bg: #dcfce7;

  --rag-amber: #d97706;
  --rag-amber-bg: #fef3c7;

  --rag-red: #dc2626;
  --rag-red-bg: #fee2e2;

  --rag-critical: #7c2d12;
  --rag-critical-bg: #fef2f2;

  /* =========================
     SURFACES
     ========================= */
  --surface: #ffffff;
  --surface2: #f8fafc;
  --surface3: #f1f5f9;
  --surface4: #e2e8f0;

  --border: #e2e8f0;

  /* =========================
     TEXT
     ========================= */
  --text: #0f172a;
  --text2: #475569;
  --text3: #94a3b8;

  /* =========================
     SHADOWS
     ========================= */
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --shadow-lg: 0 12px 30px rgba(0,0,0,.15);

  /* =========================
     SHAPE
     ========================= */
  --radius: 14px;
  --radius-sm: 10px;

  --max-w: 1440px;

  /* =========================
     TRANSITIONS
     ========================= */
  --transition: 180ms ease;

  /* =========================
     TOUCH TARGETS
     ========================= */
  --touch: 48px;

  /* =========================
     HEADER
     ========================= */
  --header-height: 74px;

  /* =========================
     Z-INDEX
     ========================= */
  --z-header: 100;
  --z-modal: 300;
  --z-toast: 400;
}

/* =========================================================
   RESET
   ========================================================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  background: var(--surface2);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  padding-top: var(--header-height);
}

img {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

ul {
  list-style: none;
}

/* =========================================================
   GLOBAL LAYOUT
   ========================================================= */
.container {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.page-title h1 {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.1;
}

.page-title p {
  margin-top: 6px;
  color: var(--text2);
  font-size: 15px;
}

/* =========================================================
   APP HEADER
   ========================================================= */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--header-height);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-header);
}

.header-inner {
  height: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 22px;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 20px;
}

.logo svg {
  flex-shrink: 0;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  margin-left: 30px;
}

.nav-link {
  height: 44px;
  padding: 0 16px;
  border-radius: 10px;

  display: flex;
  align-items: center;

  color: var(--text2);
  font-size: 14px;
  font-weight: 600;

  transition: var(--transition);
}

.nav-link:hover {
  background: var(--surface3);
  color: var(--text);
}

.nav-link.active {
  background: var(--primary-light);
  color: var(--primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* =========================================================
   VOICE BUTTON
   ========================================================= */
.voice-fab {
  width: 48px;
  height: 48px;
  border-radius: 999px;

  border: none;
  background: var(--primary);
  color: white;

  font-size: 20px;
  cursor: pointer;

  box-shadow: var(--shadow-md);

  transition: var(--transition);
}

.voice-fab:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.voice-fab.active {
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(30,64,175,.45);
  }
  70% {
    box-shadow: 0 0 0 14px rgba(30,64,175,0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(30,64,175,0);
  }
}

/* =========================================================
   SITE SELECTOR
   ========================================================= */
.site-select {
  height: 46px;
  min-width: 240px;

  border-radius: 12px;
  border: 1px solid var(--border);

  padding: 0 14px;

  background: white;
  color: var(--text);

  font-size: 14px;
  font-weight: 600;

  cursor: pointer;
}

/* =========================================================
   USER MENU
   ========================================================= */
.user-btn {
  border: none;
  background: transparent;

  display: flex;
  align-items: center;
  gap: 10px;

  cursor: pointer;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 999px;

  background: var(--primary);
  color: white;

  display: flex;
  align-items: center;
  justify-content: center;

  font-size: 14px;
  font-weight: 700;
}

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
  min-height: var(--touch);

  border: none;
  border-radius: 12px;

  padding: 0 18px;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;

  cursor: pointer;

  font-size: 14px;
  font-weight: 700;

  transition: var(--transition);
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: white;
  border: 1px solid var(--border);
}

.btn-outline:hover {
  background: var(--surface3);
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover {
  background: var(--surface3);
}

.btn-danger {
  background: var(--rag-red);
  color: white;
}

.btn-danger:hover {
  opacity: .9;
}

.btn-sm {
  min-height: 40px;
  padding: 0 14px;
  font-size: 13px;
}

.btn-lg {
  min-height: 56px;
  padding: 0 24px;
  font-size: 16px;
}

/* =========================================================
   CARDS
   ========================================================= */
.card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);

  box-shadow: var(--shadow);

  overflow: hidden;
}

.card-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);

  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 18px;
  font-weight: 800;
}

.card-body {
  padding: 20px;
}

/* =========================================================
   GRID
   ========================================================= */
.grid {
  display: grid;
  gap: 20px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0,1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0,1fr));
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0,1fr));
}

/* =========================================================
   STAT CARDS
   ========================================================= */
.stat-card {
  padding: 22px;
  border-radius: var(--radius);

  background: white;
  border: 1px solid var(--border);

  display: flex;
  flex-direction: column;
  gap: 10px;

  min-height: 140px;
}

.stat-label {
  color: var(--text2);
  font-size: 14px;
  font-weight: 600;
}

.stat-value {
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
}

.stat-sub {
  font-size: 13px;
  color: var(--text2);
}

.stat-green {
  background: var(--rag-green-bg);
}

.stat-amber {
  background: var(--rag-amber-bg);
}

.stat-red {
  background: var(--rag-red-bg);
}

.stat-critical {
  background: var(--rag-critical-bg);
}

/* =========================================================
   RAG BADGES
   ========================================================= */
.badge {
  height: 32px;
  padding: 0 12px;

  border-radius: 999px;

  display: inline-flex;
  align-items: center;
  gap: 8px;

  font-size: 13px;
  font-weight: 700;
}

.badge-green {
  background: var(--rag-green-bg);
  color: var(--rag-green);
}

.badge-amber {
  background: var(--rag-amber-bg);
  color: var(--rag-amber);
}

.badge-red {
  background: var(--rag-red-bg);
  color: var(--rag-red);
}

.badge-critical {
  background: var(--rag-critical-bg);
  color: var(--rag-critical);
}

/* =========================================================
   FORMS
   ========================================================= */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  margin-bottom: 8px;

  font-size: 14px;
  font-weight: 700;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: var(--touch);

  border-radius: 12px;
  border: 1px solid var(--border);

  background: white;

  padding: 0 16px;

  font-size: 15px;

  transition: var(--transition);
}

.textarea {
  padding: 14px 16px;
  resize: vertical;
  min-height: 140px;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(30,64,175,.12);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 12px;

  min-height: 50px;
}

/* =========================================================
   TABLES
   ========================================================= */
.table-wrap {
  overflow: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  background: var(--surface3);

  text-align: left;

  padding: 14px 16px;

  font-size: 13px;
  font-weight: 800;
  color: var(--text2);

  white-space: nowrap;
}

.table td {
  padding: 16px;
  border-top: 1px solid var(--border);

  font-size: 14px;
}

.table tr:hover td {
  background: rgba(248,250,252,.7);
}

/* =========================================================
   ALLERGEN MATRIX
   ========================================================= */
.allergen-matrix {
  overflow-x: auto;
}

.allergen-table {
  min-width: 1200px;
}

.allergen-ok {
  color: var(--rag-green);
  font-weight: 800;
}

.allergen-warning {
  color: var(--rag-amber);
  font-weight: 800;
}

.allergen-none {
  color: var(--text3);
}

/* =========================================================
   ALERTS
   ========================================================= */
.alert {
  border-radius: 14px;
  padding: 18px 20px;

  display: flex;
  gap: 14px;
  align-items: flex-start;

  margin-bottom: 20px;
}

.alert-title {
  font-weight: 800;
  margin-bottom: 4px;
}

.alert-danger {
  background: var(--rag-red-bg);
  color: var(--rag-red);
}

.alert-warning {
  background: var(--rag-amber-bg);
  color: var(--rag-amber);
}

.alert-info {
  background: var(--primary-light);
  color: var(--primary);
}

/* =========================================================
   MODALS
   ========================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;

  background: rgba(15,23,42,.45);

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 20px;

  z-index: var(--z-modal);
}

.modal {
  width: 100%;
  max-width: 640px;

  background: white;

  border-radius: 18px;

  box-shadow: var(--shadow-lg);

  overflow: hidden;
}

.modal-header {
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);

  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 22px;
}

.modal-footer {
  padding: 18px 22px;
  border-top: 1px solid var(--border);

  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* =========================================================
   VOICE MODE PANEL
   ========================================================= */
.voice-panel {
  background: var(--primary-light);
  border: 1px solid rgba(30,64,175,.15);

  padding: 18px;

  border-radius: 16px;

  display: flex;
  align-items: center;
  gap: 16px;
}

.voice-wave {
  width: 50px;
  height: 50px;

  border-radius: 999px;

  background: var(--primary);

  display: flex;
  align-items: center;
  justify-content: center;

  color: white;
  font-size: 22px;
}

/* =========================================================
   BODY MAP
   ========================================================= */
.body-map {
  width: 260px;
  margin: 0 auto;
}

.body-map svg {
  width: 100%;
  height: auto;
}

.body-part {
  fill: #dbeafe;
  cursor: pointer;
  transition: var(--transition);
}

.body-part:hover {
  fill: var(--primary);
}

/* =========================================================
   TASK STATES
   ========================================================= */
.task-overdue {
  border-left: 6px solid var(--rag-red);
}

.task-due {
  border-left: 6px solid var(--rag-amber);
}

.task-ok {
  border-left: 6px solid var(--rag-green);
}

/* =========================================================
   LOADING STATES
   ========================================================= */
.skeleton {
  background: linear-gradient(
    90deg,
    #f1f5f9 25%,
    #e2e8f0 37%,
    #f1f5f9 63%
  );

  background-size: 400% 100%;

  animation: skeleton-loading 1.4s ease infinite;
}

@keyframes skeleton-loading {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* =========================================================
   EMPTY STATES
   ========================================================= */
.empty-state {
  padding: 60px 20px;

  text-align: center;
}

.empty-state h3 {
  margin-top: 16px;
  font-size: 22px;
  font-weight: 800;
}

.empty-state p {
  margin-top: 10px;
  color: var(--text2);
}

/* =========================================================
   MOBILE RESPONSIVE
   ========================================================= */
@media (max-width: 768px) {

  body {
    padding-top: 66px;
  }

  .app-header {
    height: 66px;
  }

  .header-inner {
    padding: 0 12px;
  }

  .main-nav {
    display: none;
  }

  .site-select {
    min-width: 140px;
  }

  .container {
    padding: 16px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-title h1 {
    font-size: 24px;
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .card-body,
  .card-header {
    padding: 16px;
  }

  .table th,
  .table td {
    padding: 12px;
  }

  .btn {
    width: 100%;
  }

  .voice-panel {
    flex-direction: column;
    align-items: flex-start;
  }

  .modal {
    max-width: 100%;
  }
}

/* =========================================================
   SAFIRION — GOVERNANCE / MODAL FIX PATCH
   Adds mobile-safe modals, sticky footer, approval UI
   ========================================================= */

/* Modal must fit small screens */
.modal {
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
}

/* Header/footer stay visible */
.modal-header,
.modal-footer {
  flex-shrink: 0;
}

/* Body scrolls instead of trapping the submit button off screen */
.modal-body {
  overflow-y: auto;
  max-height: calc(100vh - 180px);
}

/* Submit/cancel buttons remain reachable */
.modal-footer {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  z-index: 2;
}

/* Better mobile modal behaviour */
@media (max-width: 768px) {
  .modal-overlay {
    align-items: flex-start;
    padding: 12px;
    overflow-y: auto;
  }

  .modal {
    max-height: calc(100vh - 24px);
  }

  .modal-body {
    max-height: calc(100vh - 170px);
  }

  .modal-footer {
    flex-direction: column;
  }
}

/* Approval workflow badges */
.badge-draft {
  background: var(--surface3);
  color: var(--text2);
}

.badge-pending {
  background: var(--rag-amber-bg);
  color: var(--rag-amber);
}

.badge-approved {
  background: var(--rag-green-bg);
  color: var(--rag-green);
}

.badge-rejected {
  background: var(--rag-red-bg);
  color: var(--rag-red);
}

/* Accountability / attribution panel */
.audit-meta {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text2);
  font-size: 13px;
  line-height: 1.5;
}

.audit-meta strong {
  color: var(--text);
}

/* Permission warning */
.permission-banner {
  background: var(--rag-amber-bg);
  color: var(--rag-amber);
  border: 1px solid rgba(217,119,6,.25);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-weight: 700;
}

/* Disabled governance controls */
.locked-control {
  opacity: .55;
  pointer-events: none;
}

/* =========================================================
   SAFIRION — MOBILE NAVIGATION PATCH
   Keeps all pages accessible on mobile instead of hiding nav.
   ========================================================= */

@media (max-width: 768px) {
  body {
    padding-top: 132px;
  }

  .app-header {
    height: auto;
    min-height: 66px;
  }

  .header-inner {
    flex-wrap: wrap;
    align-content: center;
    gap: 10px;
    padding: 10px 12px;
  }

  .logo {
    flex: 1 1 auto;
  }

  .header-right {
    flex: 1 1 100%;
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 10px;
  }

  .header-right .user-btn {
    display: none;
  }

  .site-select {
    width: 100%;
    min-width: 0;
  }

  .main-nav {
    order: 3;
    flex: 1 1 100%;
    display: flex !important;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 4px;
    margin-left: 0;
    -webkit-overflow-scrolling: touch;
  }

  .main-nav::-webkit-scrollbar {
    height: 6px;
  }

  .main-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
  }

  .nav-link {
    flex: 0 0 auto;
    height: 40px;
    padding: 0 13px;
    font-size: 13px;
    white-space: nowrap;
  }

  .container {
    padding-top: 18px;
  }
}

/* =========================================================
   SAFIRION — MOBILE HEADER SPACING FIX
   Prevents fixed mobile header from covering page headings.
   ========================================================= */

@media (max-width: 768px) {
  body {
    padding-top: 168px !important;
  }

  .container {
    padding-top: 24px !important;
  }
}

/* =========================================================
   SAFIRION — MOBILE NAV + CONTENT RESPONSIVE FIX
   Fixes landscape menu overflow and portrait content width.
   ========================================================= */

@media (max-width: 768px) {
  body {
    padding-top: 178px !important;
    overflow-x: hidden;
  }

  .header-inner {
    max-width: 100%;
    overflow: hidden;
  }

  .main-nav {
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    overflow-y: hidden;
    scrollbar-width: thin;
    padding-right: 18px;
  }

  .main-nav::after {
    content: "";
    flex: 0 0 18px;
  }

  .container,
  .card,
  .card-body,
  .page-header,
  .grid {
    max-width: 100%;
    min-width: 0;
  }

  .grid {
    grid-template-columns: 1fr !important;
  }

  .table-wrap,
  .allergen-matrix {
    max-width: 100%;
    overflow-x: auto;
  }

  .stat-value {
    word-break: break-word;
  }

  .modal {
    width: 100%;
    max-width: calc(100vw - 24px);
  }
}

/* Landscape phones need less height but same scrollable nav */
@media (max-width: 900px) and (orientation: landscape) {
  body {
    padding-top: 142px !important;
  }

  .app-header {
    max-height: 138px;
  }

  .main-nav {
    overflow-x: auto !important;
    white-space: nowrap;
  }

  .container {
    padding-top: 20px !important;
  }
}

/* =========================================================
   SAFIRION — MOBILE LANDSCAPE HEADER v4
   Fixes mic/logo overlap.
   ========================================================= */

@media (max-width: 900px) and (orientation: landscape) {
  body {
    padding-top: 108px !important;
    overflow-x: hidden;
  }

  .app-header {
    height: auto !important;
    min-height: 102px;
  }

  .header-inner {
    display: grid !important;
    grid-template-columns: 40px 40px 1fr 40px;
    grid-template-rows: 42px 40px;
    gap: 6px;
    padding: 8px 10px;
    align-items: center;
  }

  /* Logo */
  .logo {
    grid-column: 1;
    grid-row: 1;
    justify-content: center;
  }

  .logo span {
    display: none;
  }

  /* Mic button gets own column */
  .voice-fab {
    grid-column: 2;
    grid-row: 1;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    font-size: 17px;
  }

  .header-right {
    display: contents !important;
  }

  /* Site selector shortened slightly */
  .site-selector,
  .site-select {
    grid-column: 3;
    grid-row: 1;
    width: 100% !important;
    min-width: 0 !important;
    height: 40px;
    font-size: 12px;
  }

  /* User avatar */
  .user-btn {
    grid-column: 4;
    grid-row: 1;
    display: flex !important;
    justify-content: flex-end;
    align-items: center;
    padding: 0;
    background: transparent;
    border: none;
    min-width: 40px;
  }

  .user-btn span {
    display: none !important;
  }

  .avatar {
    width: 34px;
    height: 34px;
    font-size: 11px;
  }

  /* Navigation */
  .main-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex !important;
    width: 100%;
    overflow-x: auto !important;
    overflow-y: hidden;
    white-space: nowrap;
    gap: 6px;
    margin: 0;
    padding: 0 26px 4px 0;
    scrollbar-width: thin;
  }

  .main-nav::after {
    content: "";
    flex: 0 0 34px;
  }

  .main-nav::-webkit-scrollbar {
    height: 6px;
  }

  .main-nav::-webkit-scrollbar-thumb {
    background: var(--text3);
    border-radius: 999px;
  }

  .nav-link {
    flex: 0 0 auto;
    height: 36px;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .container {
    padding-top: 14px !important;
  }
}

/* =========================================================
   SAFIRION — MOBILE PORTRAIT USER AVATAR FIX
   Restores user initials button in portrait header.
   ========================================================= */

@media (max-width: 768px) and (orientation: portrait) {
  .header-right {
    display: grid !important;
    grid-template-columns: 48px 1fr 42px;
    align-items: center;
    gap: 10px;
  }

  .voice-fab {
    grid-column: 1;
  }

  .site-select {
    grid-column: 2;
    width: 100% !important;
    min-width: 0 !important;
  }

  .user-btn {
    grid-column: 3;
    display: flex !important;
    justify-content: center;
    align-items: center;
    padding: 0;
  }

  .user-btn span {
    display: none !important;
  }

  .avatar {
    width: 38px;
    height: 38px;
    font-size: 12px;
  }
}

/* =========================================================
   SAFIRION — INTERACTIVE DASHBOARD ELEMENTS
   ========================================================= */

.dashboard-tile,
.dashboard-card,
.dashboard-alert,
.dashboard-list-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  transition: var(--transition);
}

.dashboard-tile:hover,
.dashboard-card:hover,
.dashboard-alert:hover,
.dashboard-list-item:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.dashboard-alert {
  margin-bottom: 20px;
}

.dashboard-list-item {
  display: block;
  background: white;
  margin-bottom: 12px;
  border-radius: var(--radius);
  overflow: hidden;
}

.dashboard-card {
  background: white;
}

/* =========================================================
   SAFIRION — MODAL COMPATIBILITY FIX
   Fixes compliance temp modal appearing bottom-left / unclosable.
   ========================================================= */

.modal-backdrop,
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.modal-backdrop.hidden,
.modal-overlay.hidden {
  display: none !important;
}

.modal-backdrop .modal,
.modal-overlay .modal {
  width: min(720px, 100%);
  max-height: calc(100vh - 40px);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-close {
  border: 0;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  color: var(--text2);
  min-width: 44px;
  min-height: 44px;
}

.form-input,
.form-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font: inherit;
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* =========================================================
   SAFIRION — HIGHLIGHTED RECORD FROM DASHBOARD
   ========================================================= */

.highlight-pulse {
  outline: 3px solid var(--primary);
  box-shadow: 0 0 0 6px rgba(30,64,175,.12);
}

/* =========================================================
   SAFIRION — RISK MATRIX
   ========================================================= */

.matrix-grid{
  display:grid;
  grid-template-columns:50px repeat(5,1fr);
  gap:6px;
}

.matrix-corner{
  height:50px;
}

.matrix-axis-top,
.matrix-axis-left{
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:800;
  min-height:50px;
}

.matrix-cell{
  min-height:64px;
  border:none;
  border-radius:12px;
  font-weight:800;
  cursor:pointer;
  transition:.18s ease;
}

.matrix-cell:hover{
  transform:translateY(-2px);
}

.matrix-low{
  background:#dcfce7;
  color:#166534;
}

.matrix-medium{
  background:#fef3c7;
  color:#92400e;
}

.matrix-high{
  background:#fecaca;
  color:#991b1b;
}

.matrix-critical{
  background:#7f1d1d;
  color:white;
}

/* =========================================================
   SAFIRION — DESKTOP/TABLET HEADER NAV FIX v2
   Uses available gaps and keeps all controls visible.
   ========================================================= */

@media (min-width: 901px) {
  .header-inner {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
  }

  .logo {
    min-width: 0;
    flex-shrink: 0;
  }

  .main-nav {
    min-width: 0;
    width: 100%;
    display: flex !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    white-space: nowrap;
    gap: 6px;
    padding: 0 4px 4px 4px;
    margin: 0;
    scrollbar-width: thin;
  }

  .main-nav::-webkit-scrollbar {
    height: 6px;
  }

  .main-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
  }

  .nav-link {
    flex: 0 0 auto;
    padding-left: 10px;
    padding-right: 10px;
  }

  .header-right {
    flex-shrink: 0;
    display: flex !important;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .site-select {
    width: 160px;
    min-width: 140px;
    max-width: 170px;
  }

  .user-btn {
    flex-shrink: 0;
    max-width: 150px;
  }

  .user-btn span {
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Slightly tighter nav on medium screens */
@media (min-width: 901px) and (max-width: 1180px) {
  .logo span {
    display: none;
  }

  .nav-link {
    height: 38px;
    font-size: 13px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .site-select {
    width: 135px;
    min-width: 125px;
  }

  .user-btn span {
    display: none;
  }
}

/* =========================================================
   SAFIRION — REPORTS
   ========================================================= */

.report-grid{
  display:grid;
  gap:14px;
}

.report-card{
  width:100%;
  text-align:left;
  border:1px solid var(--border);
  background:white;
  border-radius:16px;
  padding:18px;
  transition:.18s ease;
  cursor:pointer;
}

.report-card:hover{
  transform:translateY(-2px);
  box-shadow:0 10px 24px rgba(0,0,0,.08);
}

.report-icon{
  font-size:28px;
  margin-bottom:12px;
}

.report-card p{
  margin-top:8px;
  color:var(--text2);
  line-height:1.5;
}

/* =========================================================
   SAFIRION — REPORT ACTIVITY TEXT ALIGN FIX
   ========================================================= */

#reportActivity .dashboard-list-item{
  padding-left:18px;
}

/* =========================================================
   SAFIRION — MESSAGE RECIPIENT LIST ALIGNMENT FIX
   ========================================================= */

#recipientSuggestions .dashboard-list-item{
  padding-left:18px;
}

/* =========================================================
   SAFIRION — MOBILE RECIPIENT SUGGESTIONS FIX
   ========================================================= */

@media (max-width: 768px) {
  #specificRecipientPanel {
    width: 100%;
    display: none;
  }

  #specificRecipientPanel .card-body {
    padding: 14px;
  }

  #recipientSuggestions {
    display: block;
    width: 100%;
  }

  #recipientSuggestions .dashboard-list-item {
    display: flex;
    width: 100%;
    min-height: 56px;
    padding: 14px 16px 14px 18px;
    margin-bottom: 10px;
    align-items: center;
    justify-content: space-between;
  }

  #recipientSuggestions .dashboard-list-item div {
    min-width: 0;
  }

  #recipientSuggestions .dashboard-list-item p {
    white-space: normal;
  }
}

/* SAFIRION — RECIPIENT SUGGESTION ALIGNMENT FINAL */

#recipientSuggestions .dashboard-list-item {
  padding-left: 12px !important;
  overflow: visible !important;
}

#recipientSuggestions .dashboard-list-item > div {
  margin-left: 0 !important;
  padding-left: 0 !important;
}

#recipientSuggestions .dashboard-list-item strong,
#recipientSuggestions .dashboard-list-item p {
  margin-left: 4px !important;
  padding-left: 4px !important;
}

@media (max-width: 900px) {
  #recipientSuggestions {
    padding-left: 6px !important;
  }

  #recipientSuggestions .dashboard-list-item {
    margin-left: 4px !important;
    width: calc(100% - 4px) !important;
  }
}

/* SAFIRION — DASHBOARD LIST TEXT ALIGNMENT FIX */

#commandFeed .dashboard-list-item,
#calendarFeed .dashboard-list-item,
#messageFeed .dashboard-list-item,
#siteHealth .dashboard-list-item,
#recentIncidents .dashboard-list-item {
  padding-left: 18px !important;
}

/* SAFIRION — DESKTOP ALLERGEN MATRIX FIT FIX */

@media (min-width: 1024px) {
  .allergen-matrix {
    table-layout: fixed;
    width: 100%;
    font-size: 12px;
  }

  .allergen-matrix th,
  .allergen-matrix td {
    padding: 8px 4px;
    text-align: center;
    white-space: nowrap;
  }

  .allergen-matrix th:first-child,
  .allergen-matrix td:first-child {
    width: 130px;
    text-align: left;
    white-space: normal;
  }

  .allergen-matrix th:nth-child(2),
  .allergen-matrix td:nth-child(2) {
    width: 72px;
  }

  .allergen-matrix th:last-child,
  .allergen-matrix td:last-child {
    width: 90px;
  }

  .allergen-matrix th:nth-last-child(2),
  .allergen-matrix td:nth-last-child(2) {
    width: 90px;
    white-space: normal;
  }

  .allergen-matrix .badge {
    font-size: 11px;
    padding: 4px 7px;
  }
}

/* SAFIRION — MOBILE ALLERGEN MATRIX ALIGNMENT FIX */

.allergen-matrix th,
.allergen-matrix td {
  text-align: center;
  vertical-align: middle;
}

.allergen-matrix th {
  min-width: 44px;
}

.allergen-matrix th:first-child,
.allergen-matrix td:first-child {
  text-align: left;
}

@media (max-width: 768px) {
  .allergen-matrix {
    font-size: 11px;
  }

  .allergen-matrix th,
  .allergen-matrix td {
    padding: 6px 4px !important;
    min-width: 42px;
  }

  .allergen-matrix th:first-child,
  .allergen-matrix td:first-child {
    min-width: 120px;
  }
}

/* SAFIRION — SITE CONFIG CARD ALIGNMENT FIX */

#equipmentList .card-body,
#zoneList .dashboard-list-item,
#serviceList .dashboard-list-item,
#haccpList .dashboard-list-item,
#contactList .dashboard-list-item {
  padding-left: 18px !important;
}

#zoneList .dashboard-list-item strong,
#serviceList .dashboard-list-item strong,
#haccpList .dashboard-list-item strong,
#contactList .dashboard-list-item strong {
  margin-left: 4px !important;
  display: inline-block;
}

/* SAFIRION — LOGIN PAGE POLISH */

.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(30,64,175,.18), transparent 34%),
    linear-gradient(135deg, #f8fafc 0%, #eef4ff 45%, #f8fafc 100%);
}

.login-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 520px) 1fr;
}

.login-panel {
  padding: 42px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-brand {
  margin-bottom: 28px;
}

.login-brand h1 {
  font-size: 42px;
  font-weight: 900;
  margin-top: 16px;
  letter-spacing: -1px;
}

.login-brand p {
  color: var(--text2);
  margin-top: 8px;
  font-size: 16px;
}

.login-logo {
  width: 58px;
  height: 58px;
}

.login-side {
  padding: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-side-inner {
  width: 100%;
  min-height: calc(100vh - 84px);
  border-radius: 32px;
  background:
    linear-gradient(135deg, rgba(30,64,175,.96), rgba(15,23,42,.96)),
    radial-gradient(circle at top right, rgba(255,255,255,.2), transparent 35%);
  color: white;
  display: flex;
  align-items: center;
  padding: 56px;
  box-shadow: 0 24px 70px rgba(15,23,42,.28);
}

.login-side-content {
  max-width: 720px;
}

.login-side h2 {
  font-size: 42px;
  line-height: 1.08;
  margin-top: 24px;
  font-weight: 900;
  letter-spacing: -1px;
}

.login-side p {
  margin-top: 18px;
  font-size: 18px;
  line-height: 1.6;
  color: rgba(255,255,255,.82);
}

.login-side .stat-card {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.18);
  color: white;
}

.login-side .stat-label,
.login-side .stat-sub {
  color: rgba(255,255,255,.78);
}

@media (max-width: 900px) {
  .login-layout {
    grid-template-columns: 1fr;
  }

  .login-panel {
    padding: 24px;
  }

  .login-side {
    display: none;
  }

  .login-brand h1 {
    font-size: 34px;
  }
}

/* SAFIRION — LOGIN COMPACT POLISH v2 */

.login-layout {
  min-height: 100vh;
  grid-template-columns: minmax(340px, 460px) 1fr;
}

.login-panel {
  padding: 28px 36px;
}

.login-brand {
  margin-bottom: 18px;
}

.login-brand h1 {
  font-size: 34px;
  margin-top: 12px;
}

.login-brand p {
  font-size: 14px;
}

.login-panel .card-body {
  padding: 20px;
}

.login-panel .form-group {
  margin-bottom: 12px;
}

.login-panel .alert {
  padding: 12px 14px;
}

.login-panel .alert p {
  font-size: 13px;
}

.login-side {
  padding: 28px;
}

.login-side-inner {
  min-height: calc(100vh - 56px);
  padding: 40px;
  border-radius: 26px;
}

.login-side h2 {
  font-size: 34px;
}

.login-side p {
  font-size: 15px;
}

.login-side .stat-card {
  padding: 16px;
}

.login-side .stat-value {
  font-size: 22px;
}

@media (max-width: 900px) {
  .login-layout {
    display: block;
  }

  .login-panel {
    min-height: 100vh;
    padding: 18px;
    justify-content: flex-start;
  }

  .login-brand {
    text-align: center;
  }

  .login-logo {
    margin: 0 auto;
  }

  .login-brand h1 {
    font-size: 30px;
  }

  .login-side {
    display: none;
  }

  .login-panel .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* SAFIRION — LOGIN ONE-PAGE FIT v3 */

.login-page {
  overflow: auto;
}

.login-layout {
  min-height: 100vh;
}

.login-panel {
  padding: 16px 28px !important;
}

.login-brand {
  margin-bottom: 10px !important;
}

.login-logo,
.login-logo svg {
  width: 46px !important;
  height: 46px !important;
}

.login-brand h1 {
  font-size: 28px !important;
  margin-top: 8px !important;
}

.login-brand p {
  font-size: 13px !important;
  margin-top: 4px !important;
}

.login-panel .card-header {
  padding: 14px 18px !important;
}

.login-panel .card-body {
  padding: 14px 18px !important;
}

.login-panel .form-group {
  margin-bottom: 8px !important;
}

.login-panel .form-label {
  margin-bottom: 4px !important;
  font-size: 12px !important;
}

.login-panel .input,
.login-panel .select {
  min-height: 38px !important;
  height: 38px !important;
}

.login-panel .alert {
  padding: 10px 12px !important;
  margin-bottom: 10px !important;
}

.login-panel .alert-title {
  font-size: 13px !important;
}

.login-panel .alert p {
  font-size: 12px !important;
  line-height: 1.35 !important;
}

.login-side {
  padding: 18px !important;
}

.login-side-inner {
  min-height: calc(100vh - 36px) !important;
  padding: 30px !important;
}

.login-side h2 {
  font-size: 30px !important;
}

.login-side p {
  font-size: 14px !important;
  line-height: 1.45 !important;
}

.login-side .grid-2 {
  gap: 12px !important;
}

.login-side .stat-card {
  padding: 12px !important;
}

.login-side .stat-value {
  font-size: 20px !important;
}

/* SAFIRION — LOGIN TOP GAP / SCROLL FIX */

html,
body.login-page {
  margin: 0 !important;
  padding: 0 !important;
  overflow-x: hidden;
}

body.login-page {
  min-height: 100vh;
}

.login-layout {
  min-height: 100vh;
  overflow: hidden;
}

/* SAFIRION — MODAL BACKGROUND SCROLL FIX */

.modal-overlay {
  position: fixed !important;
  inset: 0 !important;
  overflow-y: auto !important;
  overscroll-behavior: contain !important;
  touch-action: pan-y;
}

.modal {
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

body:has(.modal-overlay:not(.hidden)) {
  overflow: hidden;
}

/* SAFIRION — MODAL FINAL SCROLL + HEADER FIX */

.modal-overlay {
  position: fixed !important;
  inset: 0 !important;
  display: flex !important;
  align-items: flex-start !important;
  justify-content: center !important;
  padding: 16px 16px 24px 16px !important;
  overflow: hidden !important;
  overscroll-behavior: contain !important;
}

.modal {
  width: min(920px, 100%) !important;
  max-height: calc(100dvh - 40px) !important;
  margin: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  border-radius: 22px !important;
}

.modal-header {
  flex: 0 0 auto !important;
  position: static !important;
  padding: 18px 22px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
}

.modal-body {
  flex: 1 1 auto !important;
  overflow-y: auto !important;
  min-height: 0 !important;
  padding-bottom: 24px !important;
  overscroll-behavior: contain !important;
}

.modal-footer {
  flex: 0 0 auto !important;
}

.modal-close {
  width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.modal-footer {
  padding: 14px 22px 18px 22px !important;
  background: var(--card);
  border-top: 1px solid var(--border);
}