/* =============================================
   HAZOPNexus — Main Stylesheet
   InstruNexus Ecosystem
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

:root {
  --navy:      #182D46;
  --slate:     #414F5E;
  --offwhite:  #F6F5F2;
  --warm-grey: #C8C2C2;
  --white:     #ffffff;
  --success:   #27ae60;
  --warning:   #f39c12;
  --danger:    #e74c3c;
  --info:      #2980b9;
  --orange:    #e67e22;

  --sidebar-width: 240px;
  --topbar-height: 58px;
  --border-radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.16);
  --transition: 0.2s ease;

  --font-main: 'Poppins', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Consolas', 'Monaco', monospace;
}

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

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: var(--font-main);
  background: var(--offwhite);
  color: var(--slate);
  line-height: 1.5;
  min-height: 100vh;
}

/* =============================================
   LAYOUT
   ============================================= */
.app-layout { display: flex; flex-direction: column; min-height: 100vh; }

.app-body {
  display: flex;
  flex: 1;
  margin-top: var(--topbar-height);
}

/* =============================================
   TOPBAR
   ============================================= */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}

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

.sidebar-toggle {
  background: none; border: none; cursor: pointer;
  padding: 8px; border-radius: 6px; color: rgba(255,255,255,.7);
  transition: var(--transition);
}
.sidebar-toggle:hover { background: rgba(255,255,255,.1); color: white; }
.hamburger, .hamburger::before, .hamburger::after {
  display: block; width: 18px; height: 2px;
  background: currentColor; border-radius: 2px;
  transition: var(--transition);
}
.hamburger::before { content: ''; margin-top: -5px; }
.hamburger::after  { content: ''; margin-top: 3px; }

.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: white;
}
.brand-logo {
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, #2d5a8e, #182D46);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; color: white;
  border: 1px solid rgba(255,255,255,.2);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-size: 16px; font-weight: 700; color: white; }
.brand-by   { font-size: 10px; color: rgba(255,255,255,.5); letter-spacing: .05em; }

/* Breadcrumb */
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: rgba(255,255,255,.6);
}
.breadcrumb a { color: rgba(255,255,255,.7); text-decoration: none; }
.breadcrumb a:hover { color: white; }
.bc-sep { color: rgba(255,255,255,.4); }

/* User menu */
.user-menu { position: relative; }
.user-menu-btn {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px; padding: 6px 10px; cursor: pointer; color: white;
  transition: var(--transition);
}
.user-menu-btn:hover { background: rgba(255,255,255,.2); }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, #2980b9, #182D46);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: white;
}
.user-name { font-size: 13px; font-weight: 500; }

.user-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 8px);
  background: white; border: 1px solid var(--warm-grey);
  border-radius: 10px; box-shadow: var(--shadow-lg);
  min-width: 200px; overflow: hidden; z-index: 9999;
}
.user-dropdown.show { display: block; }
.dropdown-header { padding: 14px 16px; background: var(--offwhite); }
.dropdown-header strong { display: block; font-size: 13px; color: var(--navy); }
.dropdown-header small { font-size: 11px; color: var(--slate); opacity: .7; }
.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; font-size: 13px; color: var(--slate);
  text-decoration: none; transition: var(--transition);
}
.dropdown-item:hover { background: var(--offwhite); color: var(--navy); }
.dropdown-item.text-danger { color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--warm-grey); opacity: .5; }

/* Row actions menu (View/Edit/Report/Delete consolidated per table row) */
.row-actions { position: relative; display: inline-block; }
.row-actions-btn {
  background: none; border: 1px solid var(--warm-grey); border-radius: 6px;
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--slate); transition: var(--transition);
}
.row-actions-btn:hover { background: var(--offwhite); border-color: var(--slate); }
.row-actions-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px);
  background: white; border: 1px solid var(--warm-grey); border-radius: 8px;
  box-shadow: var(--shadow-lg); min-width: 150px; overflow: hidden; z-index: 500;
}
.row-actions-menu.show { display: block; }
.row-actions-menu .dropdown-item { cursor: pointer; border: none; background: none; width: 100%; text-align: left; font-family: inherit; }

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
  width: var(--sidebar-width);
  background: var(--navy);
  min-height: calc(100vh - var(--topbar-height));
  position: sticky;
  top: var(--topbar-height);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition);
  overflow: hidden;
}

.sidebar.collapsed { width: 56px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 2px; }

.nav-section { margin-bottom: 4px; }
.nav-section-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: rgba(255,255,255,.35);
  padding: 10px 18px 4px;
  white-space: nowrap;
}
.sidebar.collapsed .nav-section-title { opacity: 0; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px; color: rgba(255,255,255,.65);
  text-decoration: none; font-size: 13px; font-weight: 500;
  transition: var(--transition); border-radius: 0;
  white-space: nowrap; overflow: hidden;
}
.nav-item:hover { background: rgba(255,255,255,.1); color: white; }
.nav-item.active {
  background: rgba(255,255,255,.15); color: white;
  border-left: 3px solid #4a9eff;
}
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-label { overflow: hidden; text-overflow: ellipsis; }

.sidebar.collapsed .nav-item { justify-content: center; padding: 9px 0; }
.sidebar.collapsed .nav-label { display: none; }

.sidebar-footer {
  padding: 12px 18px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.version-info { font-size: 11px; color: rgba(255,255,255,.3); }

/* =============================================
   MAIN CONTENT
   ============================================= */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.page-header {
  padding: 24px 28px 16px;
  border-bottom: 1px solid rgba(200,194,194,.4);
  background: white;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
}
.page-header-left {}
.page-title { font-size: 22px; font-weight: 700; color: var(--navy); line-height: 1.2; }
.page-subtitle { font-size: 13px; color: var(--slate); opacity: .7; margin-top: 4px; }
.page-header-actions { display: flex; gap: 8px; flex-shrink: 0; align-items: center; }

.page-body { padding: 24px 28px; flex: 1; }

/* =============================================
   CARDS
   ============================================= */
.card {
  background: white; border: 1px solid rgba(200,194,194,.4);
  border-radius: var(--border-radius); box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid rgba(200,194,194,.3);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--navy); }
.card-body { padding: 20px; }
.card-footer {
  padding: 12px 20px; border-top: 1px solid rgba(200,194,194,.3);
  background: var(--offwhite); border-radius: 0 0 var(--border-radius) var(--border-radius);
}

/* Stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stat-card {
  background: white; border: 1px solid rgba(200,194,194,.4);
  border-radius: var(--border-radius); padding: 20px;
  box-shadow: var(--shadow-sm); text-align: center;
}
.stat-number { font-size: 32px; font-weight: 800; color: var(--navy); line-height: 1; }
.stat-label { font-size: 12px; color: var(--slate); opacity: .7; margin-top: 6px; text-transform: uppercase; letter-spacing: .05em; }
.stat-icon { font-size: 28px; margin-bottom: 8px; }

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; font-size: 13px; font-weight: 500;
  border-radius: 7px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none;
  transition: var(--transition); line-height: 1;
  white-space: nowrap;
}
.btn:focus { outline: 2px solid #4a9eff; outline-offset: 2px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: 8px; }

.btn-primary { background: var(--navy); color: white; border-color: var(--navy); }
.btn-primary:hover { background: #1e3a5a; border-color: #1e3a5a; color: white; }

.btn-secondary { background: var(--slate); color: white; border-color: var(--slate); }
.btn-secondary:hover { background: #333f4e; color: white; }

.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover { background: #219a52; color: white; }

.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #c0392b; color: white; }

.btn-warning { background: var(--warning); color: white; border-color: var(--warning); }
.btn-warning:hover { background: #d68910; color: white; }

.btn-outline {
  background: transparent; color: var(--navy);
  border-color: var(--warm-grey);
}
.btn-outline:hover { background: var(--offwhite); border-color: var(--navy); }

.btn-ghost { background: transparent; color: var(--slate); border-color: transparent; }
.btn-ghost:hover { background: var(--offwhite); color: var(--navy); }

/* =============================================
   FORMS
   ============================================= */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--navy); margin-bottom: 6px; }
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%; padding: 9px 12px; font-size: 13px;
  border: 1px solid var(--warm-grey); border-radius: 7px;
  background: white; color: var(--slate);
  transition: var(--transition); font-family: var(--font-main);
}
.form-control:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(24,45,70,.1); }
.form-control::placeholder { color: rgba(65,79,94,.4); }
textarea.form-control { min-height: 90px; resize: vertical; }
select.form-control { appearance: none; 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 d='M1 1l5 5 5-5' stroke='%23414F5E' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.form-hint { font-size: 12px; color: var(--slate); opacity: .65; margin-top: 4px; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* =============================================
   TABLES
   ============================================= */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid rgba(200,194,194,.3); font-size: 13px; }
th { background: var(--offwhite); font-weight: 600; color: var(--navy); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tr:hover td { background: rgba(246,245,242,.8); }
td { color: var(--slate); vertical-align: middle; }
.td-actions { white-space: nowrap; }

/* =============================================
   BADGES
   ============================================= */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; font-size: 11px; font-weight: 600;
  border-radius: 20px; white-space: nowrap;
}
.badge-green  { background: #d4edda; color: #155724; }
.badge-yellow { background: #fff3cd; color: #856404; }
.badge-orange { background: #ffe0b2; color: #7c4100; }
.badge-red    { background: #f8d7da; color: #721c24; }
.badge-blue   { background: #d1ecf1; color: #0c5460; }
.badge-grey   { background: #e2e3e5; color: #383d41; }
.badge-dark   { background: #d6d8d9; color: #1b1e21; }
.badge-navy   { background: var(--navy); color: white; }

/* =============================================
   FLASH MESSAGES
   ============================================= */
.flash {
  padding: 14px 48px 14px 18px; font-size: 13px;
  position: fixed; top: 66px; right: 16px; z-index: 1100;
  border-radius: 8px; box-shadow: var(--shadow-md);
  max-width: 400px; cursor: pointer;
  transition: opacity .5s ease;
}
.flash-success { background: #d4edda; color: #155724; border-left: 4px solid var(--success); }
.flash-error   { background: #f8d7da; color: #721c24; border-left: 4px solid var(--danger); }
.flash-warning { background: #fff3cd; color: #856404; border-left: 4px solid var(--warning); }
.flash-info    { background: #d1ecf1; color: #0c5460; border-left: 4px solid var(--info); }
.flash-close { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 18px; cursor: pointer; opacity: .5; }

/* =============================================
   MODAL
   ============================================= */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 2000;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: white; border-radius: 12px;
  width: 100%; max-width: 600px; max-height: 90vh;
  overflow: hidden; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
}
.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1200px; }
.modal-header {
  padding: 18px 24px; border-bottom: 1px solid rgba(200,194,194,.3);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--navy); }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: #5A6B7D; line-height: 1; }
.modal-close:hover { color: var(--slate); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid rgba(200,194,194,.3); display: flex; justify-content: flex-end; gap: 8px; }

/* =============================================
   RISK MATRIX (visual display)
   ============================================= */
.risk-matrix-display { display: inline-block; }
.risk-matrix-table { border-collapse: collapse; font-size: 12px; }
.risk-matrix-table td, .risk-matrix-table th {
  width: 70px; height: 50px;
  text-align: center; vertical-align: middle;
  border: 1px solid rgba(0,0,0,.15); font-weight: 600;
  cursor: default;
}
.risk-cell-green  { background: #27ae60; color: white; }
.risk-cell-yellow { background: #f39c12; color: white; }
.risk-cell-orange { background: #e67e22; color: white; }
.risk-cell-red    { background: #e74c3c; color: white; }
.risk-cell-grey   { background: #95a5a6; color: white; }
.risk-axis-label  { background: var(--offwhite); color: var(--navy); font-weight: 600; font-size: 11px; }

/* Risk badge inline */
.risk-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 700;
}
.risk-badge-green  { background: #d4edda; color: #155724; }
.risk-badge-yellow { background: #fff3cd; color: #856404; }
.risk-badge-orange { background: #ffe0b2; color: #7c4100; }
.risk-badge-red    { background: #f8d7da; color: #721c24; }

/* =============================================
   TABS
   ============================================= */
.tabs { display: flex; border-bottom: 2px solid rgba(200,194,194,.4); gap: 0; }
.tab {
  padding: 12px 18px; font-size: 13px; font-weight: 500;
  color: var(--slate); cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: var(--transition); text-decoration: none;
}
.tab:hover { color: var(--navy); }
.tab.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 700; }
.tab-content { display: none; padding-top: 20px; }
.tab-content.active { display: block; }

/* =============================================
   SEARCH & FILTERS
   ============================================= */
.filters-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; padding: 14px 20px;
  background: var(--offwhite); border-bottom: 1px solid rgba(200,194,194,.3);
}
.search-box { position: relative; }
.search-box input { padding-left: 34px; }
.search-box .search-icon {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); color: #5A6B7D;
  width: 16px; height: 16px;
}

/* =============================================
   PAGINATION
   ============================================= */
.pagination { display: flex; gap: 4px; align-items: center; }
.page-btn {
  min-width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--warm-grey); border-radius: 6px;
  font-size: 13px; color: var(--slate); text-decoration: none;
  transition: var(--transition); background: white;
}
.page-btn:hover { background: var(--offwhite); color: var(--navy); border-color: var(--navy); }
.page-btn.active { background: var(--navy); color: white; border-color: var(--navy); }
.page-btn.disabled { opacity: .4; pointer-events: none; }

/* =============================================
   UTILITY CLASSES
   ============================================= */
.text-navy   { color: var(--navy); }
.text-slate  { color: var(--slate); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-muted  { color: #5A6B7D; }
.text-sm     { font-size: 12px; }
.text-lg     { font-size: 16px; }
.text-bold   { font-weight: 700; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex-1 { flex: 1; }
.hidden { display: none; }

/* =============================================
   EMPTY STATE
   ============================================= */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--slate);
}
.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: .3; }
.empty-state h3 { font-size: 18px; color: var(--navy); margin-bottom: 8px; }
.empty-state p { font-size: 13px; opacity: .7; max-width: 380px; margin: 0 auto 20px; }

/* =============================================
   FOOTER
   ============================================= */
.app-footer {
  background: white; border-top: 1px solid rgba(200,194,194,.3);
  padding: 12px 28px;
}
.footer-inner { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--slate); opacity: .6; }

/* =============================================
   LOGIN PAGE
   ============================================= */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--navy) 0%, #1e3a5a 50%, #2d5a8e 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-box {
  background: white; border-radius: 16px;
  padding: 48px 40px; width: 100%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo-icon {
  width: 64px; height: 64px; border-radius: 14px;
  background: var(--navy); display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 32px; font-weight: 900; color: white;
  margin-bottom: 12px;
}
.login-logo h1 { font-size: 26px; font-weight: 800; color: var(--navy); }
.login-logo p { font-size: 12px; color: var(--slate); opacity: .7; }
.login-tagline {
  font-size: 12px; color: var(--slate); opacity: .6;
  text-align: center; margin-bottom: 28px; font-style: italic;
}
.login-footer { text-align: center; margin-top: 24px; font-size: 12px; color: var(--slate); opacity: .6; }

/* =============================================
   WORKSHEET PAGE (special layout)
   ============================================= */
.worksheet-layout {
  display: flex;
  gap: 0;
  height: calc(100vh - var(--topbar-height) - 60px);
}

.worksheet-nodes-panel {
  width: 220px;
  flex-shrink: 0;
  background: white;
  border-right: 1px solid rgba(200,194,194,.4);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.nodes-panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(200,194,194,.3);
  font-weight: 700; font-size: 13px; color: var(--navy);
  display: flex; align-items: center; justify-content: space-between;
}
.node-item {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(200,194,194,.2);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  display: block;
  color: var(--slate);
  font-size: 13px;
}
.node-item:hover { background: var(--offwhite); color: var(--navy); }
.node-item.active { background: var(--navy); color: white; }
.node-item .node-num {
  font-size: 11px; opacity: .6;
  display: block; margin-bottom: 2px;
}
.node-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; margin-right: 6px;
}
.dot-pending   { background: var(--warm-grey); }
.dot-in_progress { background: var(--warning); }
.dot-completed { background: var(--success); }

.worksheet-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.worksheet-toolbar {
  padding: 10px 16px;
  background: white;
  border-bottom: 1px solid rgba(200,194,194,.3);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.worksheet-content {
  flex: 1;
  overflow: auto;
}

/* HAZOP Worksheet Table */
.ws-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.ws-table th {
  background: var(--navy); color: white;
  padding: 10px 12px; position: sticky; top: 0; z-index: 10;
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  border-right: 1px solid rgba(255,255,255,.15);
}
.ws-table td {
  padding: 8px 10px;
  border: 1px solid rgba(200,194,194,.3);
  vertical-align: top;
  background: white;
}
.ws-table tr:hover td { background: rgba(246,245,242,.6); }
.ws-table .col-num    { width: 50px; text-align: center; color: #5A6B7D; }
.ws-table .col-dev    { min-width: 150px; max-width: 200px; }
.ws-table .col-causes { min-width: 200px; }
.ws-table .col-cons   { min-width: 200px; }
.ws-table .col-safe   { min-width: 200px; }
.ws-table .col-risk   { width: 120px; text-align: center; }
.ws-table .col-recs   { min-width: 200px; }
.ws-table .col-status { width: 120px; }
.ws-table .col-acts   { width: 80px; text-align: center; }

/* Editable cells */
.editable-cell {
  min-height: 40px;
  cursor: text;
  border-radius: 4px;
  padding: 4px;
  transition: var(--transition);
  outline: none;
}
.editable-cell:focus, .editable-cell:hover {
  background: rgba(24,45,70,.04);
  box-shadow: inset 0 0 0 1px var(--navy);
}
.editable-cell ul { padding-left: 16px; }
.editable-cell li { margin-bottom: 2px; }

/* AI Suggest panel */
.ai-panel {
  width: 280px;
  flex-shrink: 0;
  background: white;
  border-left: 1px solid rgba(200,194,194,.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ai-panel-header {
  padding: 14px 16px;
  background: var(--navy);
  color: white;
  font-weight: 700; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.ai-panel-body { flex: 1; overflow-y: auto; padding: 12px; }
.ai-suggest-section { margin-bottom: 16px; }
.ai-suggest-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--slate); margin-bottom: 8px; }
.ai-suggest-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 10px; border: 1px solid rgba(200,194,194,.4);
  border-radius: 6px; margin-bottom: 6px; font-size: 12px;
  cursor: pointer; transition: var(--transition); color: var(--slate);
}
.ai-suggest-item:hover { border-color: var(--navy); background: var(--offwhite); color: var(--navy); }
.ai-suggest-item .add-icon { color: var(--success); flex-shrink: 0; margin-top: 1px; }

/* =============================================
   RISK SELECTOR (inline in worksheet)
   ============================================= */
.risk-selector { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.risk-selects { display: flex; gap: 4px; }
.risk-selects select { width: 52px; padding: 4px 6px; font-size: 12px; text-align: center; }
.risk-result {
  font-size: 12px; font-weight: 700; padding: 3px 10px;
  border-radius: 12px; text-align: center;
  min-width: 80px;
}

/* =============================================
   REPORT PAGE
   ============================================= */
.report-preview {
  background: white;
  box-shadow: 0 0 0 1px rgba(0,0,0,.1), 0 8px 32px rgba(0,0,0,.1);
  max-width: 900px;
  margin: 0 auto;
  padding: 60px;
  min-height: 1100px;
}
.report-cover {
  text-align: center;
  padding: 80px 40px;
  border: 2px solid var(--navy);
  margin-bottom: 40px;
}
.report-title { font-size: 28px; font-weight: 800; color: var(--navy); margin-bottom: 10px; }
.report-subtitle { font-size: 16px; color: var(--slate); }
.report-meta-table { width: 100%; margin-top: 40px; }
.report-meta-table td { padding: 8px 12px; border: 1px solid var(--warm-grey); font-size: 13px; }
.report-meta-table td:first-child { font-weight: 600; background: var(--offwhite); width: 180px; color: var(--navy); }

.report-section { margin-bottom: 40px; }
.report-section-title {
  font-size: 16px; font-weight: 700; color: var(--navy);
  padding: 10px 16px; background: var(--navy);
  color: white; border-radius: 4px 4px 0 0;
  margin-bottom: 0;
}
.report-section-body { border: 1px solid var(--warm-grey); border-top: none; padding: 20px; border-radius: 0 0 4px 4px; }

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 768px) {
  .sidebar { width: 56px; }
  .sidebar .nav-section-title, .sidebar .nav-item > span { display: none; }
  .page-body { padding: 16px; }
  .page-header { padding: 16px; flex-direction: column; }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .worksheet-nodes-panel { width: 160px; }
  .ai-panel { display: none; }
  .report-preview { padding: 20px; }
}

/* =============================================
   PRINT STYLES
   ============================================= */
@media print {
  .topbar, .sidebar, .app-footer, .worksheet-toolbar,
  .ai-panel, .page-header-actions, .btn, .no-print { display: none !important; }
  .app-body { display: block; margin-top: 0; }
  .main-content { padding: 0; }
  .report-preview { box-shadow: none; padding: 0; max-width: 100%; }
  .ws-table th { background: var(--navy) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { background: white; }
  .card { break-inside: avoid; }
}

/* =============================================
   SCROLLBAR
   ============================================= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(65,79,94,.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(65,79,94,.5); }

/* =============================================
   ANIMATIONS
   ============================================= */
@keyframes fadeIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn .2s ease; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
.pulse { animation: pulse 1.5s ease-in-out infinite; }

/* =============================================
   AI AGENT MODAL (shared: AI Study Generator, etc.)
   ============================================= */
.agent-modal-overlay { position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:1000;display:flex;align-items:center;justify-content:center;padding:16px; }
.agent-modal { background:#fff;border-radius:12px;width:100%;max-width:860px;max-height:92vh;display:flex;flex-direction:column;box-shadow:0 24px 80px rgba(0,0,0,.35); }
.agent-modal-step { display:flex;flex-direction:column;min-height:0;flex:1; }
.agent-modal-header { padding:18px 22px 14px;border-bottom:1px solid rgba(200,194,194,.3);display:flex;align-items:center;gap:12px; }
.agent-modal-header h2 { font-size:17px;font-weight:800;color:var(--navy);margin:0;flex:1; }
.agent-modal-body { flex:1;overflow-y:auto;padding:20px 22px; }
.agent-modal-footer { padding:14px 22px;border-top:1px solid rgba(200,194,194,.3);display:flex;justify-content:flex-end;gap:10px; }
.agent-progress { display:flex;flex-direction:column;align-items:center;justify-content:center;padding:48px 20px;gap:14px; }
.agent-spinner { width:52px;height:52px;border:4px solid rgba(24,45,70,.12);border-top-color:#4a9eff;border-radius:50%;animation:spin .9s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }
.agent-progress-text { font-size:14px;color:var(--slate);text-align:center;max-width:340px; }
.agent-progress-step { font-size:12px;color:var(--navy);font-weight:600; }
.agent-node-summary { background:rgba(74,158,255,.07);border:1px solid rgba(74,158,255,.25);border-radius:7px;padding:10px 14px;font-size:13px;color:var(--navy);margin-bottom:14px;line-height:1.5; }
.progress-bar-track { width:100%;height:10px;background:rgba(200,194,194,.35);border-radius:6px;overflow:hidden; }
.progress-bar-fill { height:100%;background:linear-gradient(90deg,#4a9eff,#2d5a8e);border-radius:6px;transition:width .3s ease; }

/* Autosave indicator */
.autosave-indicator {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--slate); opacity: .6;
}
.autosave-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--success); display: inline-block;
}
.autosave-dot.saving { background: var(--warning); animation: pulse 1s infinite; }
