/* =============================================================
   URASECUR — styles.css
   Multi-tenant SaaS — Water & Sanitation Safety Platform
   ============================================================= */

/* ---------- CSS Variables ---------- */
:root {
  --c-blue:        #1a3a6b;
  --c-blue-mid:    #1e4d9b;
  --c-cyan:        #00a8e8;
  --c-cyan-dark:   #0087c0;
  --c-green:       #2ecc71;
  --c-green-dark:  #27ae60;
  --c-orange:      #e67e22;
  --c-red:         #e74c3c;
  --c-purple:      #8e44ad;
  --c-blue-light:  #dbeafe;
  --c-green-light: #dcfce7;
  --c-orange-light:#fef3c7;
  --c-red-light:   #fee2e2;
  --c-purple-light:#f3e8ff;
  --sidebar-w:     260px;
  --topbar-h:      60px;
  --radius:        10px;
  --radius-lg:     16px;
  --shadow:        0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:     0 8px 32px rgba(0,0,0,0.16);
  --transition:    0.2s ease;
  --font:          'Inter', system-ui, sans-serif;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: var(--font); color: #1e293b; background: #f1f5f9; min-height: 100vh; }
a { color: var(--c-cyan); text-decoration: none; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: var(--font); }

/* ---------- Pages (login / app) ---------- */
.page { display: none; }
.page.active { display: block; }
/* Si déjà connecté (token en localStorage) : masque login, montre app immédiatement */
html.preauth #page-auth { display: none !important; }
html.preauth #page-app { display: block; }

/* ============================================================
   AUTH PAGE
   ============================================================ */
#page-auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #0d2448 0%, #1a3a6b 50%, #00a8e8 100%);
}
.auth-bg {
  position: absolute; inset: 0; pointer-events: none;
}
.auth-waves {
  position: absolute; bottom: -2px; left: 0; right: 0; height: 200px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 200'%3E%3Cpath fill='rgba(255,255,255,0.06)' d='M0,80L60,90C120,100,240,120,360,110C480,100,600,60,720,55C840,50,960,80,1080,90C1200,100,1320,90,1380,85L1440,80L1440,200L0,200Z'/%3E%3Cpath fill='rgba(255,255,255,0.04)' d='M0,120L80,110C160,100,320,80,480,90C640,100,800,140,960,145C1120,150,1280,120,1360,105L1440,90L1440,200L0,200Z'/%3E%3C/svg%3E") no-repeat bottom center / cover;
}

#page-auth.active { display: flex; }

.auth-container {
  width: 100%; max-width: 800px; display: flex; flex-direction: column; align-items: center; gap: 20px; position: relative; z-index: 1;
}
.auth-card {
  width: 100%; max-width: 460px;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-banner { width: 100%; max-height: 190px; object-fit: contain; display: block; margin: 0 auto 8px; }
@media (min-width: 480px) { .auth-banner { width: 350px; } }
.auth-banner-outside { width: 800px; max-width: 100%; max-height: 100px; object-fit: contain; display: block; margin-bottom: 16px; filter: brightness(0) invert(1); }
.auth-logo-fallback {
  display: flex; align-items: center; justify-content: center; gap: 12px;
}
.logo-icon { position: relative; font-size: 40px; color: var(--c-cyan); }
.logo-drop { position: absolute; top: 4px; left: 50%; transform: translateX(-50%) scale(0.5); color: #fff; }
.logo-text { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.logo-ura { color: var(--c-blue); }
.logo-secur { color: var(--c-cyan); }
.auth-tagline { font-size: 12px; color: #64748b; margin-top: 8px; font-style: italic; }

.auth-tabs { display: flex; gap: 0; border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; margin-bottom: 24px; }
.auth-tab { flex: 1; padding: 10px; font-size: 14px; font-weight: 600; color: #64748b; background: #f8fafc; transition: var(--transition); }
.auth-tab.active { background: var(--c-blue); color: #fff; }

/* ---------- Form elements ---------- */
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 600; color: #475569; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid #e2e8f0;
  border-radius: 8px; font-size: 14px; color: #1e293b;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--c-cyan); box-shadow: 0 0 0 3px rgba(0,168,232,0.12);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-reveal { position: relative; display: block; }
.input-reveal input { padding-right: 44px; width: 100%; box-sizing: border-box; }
.reveal-btn { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: #94a3b8; font-size: 14px; background: none; border: none; padding: 4px 6px; cursor: pointer; z-index: 5; line-height: 1; pointer-events: all; }
.form-error { font-size: 13px; color: var(--c-red); background: var(--c-red-light); padding: 10px 14px; border-radius: 8px; }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, var(--c-blue), var(--c-cyan));
  color: #fff; font-weight: 700; font-size: 14px; padding: 11px 20px;
  border-radius: 8px; transition: opacity var(--transition), transform var(--transition);
  box-shadow: 0 3px 10px rgba(26,58,107,0.25);
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-full { width: 100%; }
.btn-secondary {
  display: inline-flex; align-items: center; gap: 8px;
  background: #e2e8f0; color: #475569; font-weight: 600; font-size: 14px;
  padding: 10px 18px; border-radius: 8px;
}
/* Bouton essai */
.btn-trial {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: transparent; color: var(--c-blue); font-weight: 600; font-size: 14px;
  padding: 10px 20px; border-radius: 8px; border: 2px solid var(--c-blue);
  margin-top: 10px; transition: background var(--transition), color var(--transition);
  cursor: pointer;
}
.btn-trial:hover { background: var(--c-blue); color: #fff; }
/* Modale essai */
.trial-card {
  background: #fff; border-radius: 16px; padding: 28px 28px 24px;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.trial-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.trial-header h2 { font-size: 18px; font-weight: 700; color: var(--c-blue); display: flex; align-items: center; gap: 8px; }
.trial-close { background: none; border: none; font-size: 18px; color: #94a3b8; cursor: pointer; padding: 4px; }
.trial-close:hover { color: var(--c-red); }
.btn-outline {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent; color: #64748b; font-weight: 600; font-size: 14px;
  padding: 10px 18px; border-radius: 8px; border: 1.5px solid #e2e8f0;
}
.btn-outline:hover { border-color: var(--c-cyan); color: var(--c-cyan); }
.btn-sm { font-size: 12px !important; padding: 6px 12px !important; }

/* Edit user modal */
.edit-avatar-row { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; padding: 16px; background: #f8fafc; border-radius: 10px; }
.edit-avatar-preview { width: 64px; height: 64px; border-radius: 50%; background: var(--c-blue-light); color: var(--c-blue); font-weight: 700; font-size: 20px; display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; border: 2px solid #e2e8f0; }
.edit-avatar-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.btn-icon { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 6px; font-size: 13px; font-weight: 600; transition: var(--transition); }
.btn-danger { background: var(--c-red-light); color: var(--c-red); }
.btn-danger:hover { background: var(--c-red); color: #fff; }

.auth-features {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}
.feature-item {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.12); border-radius: 10px; padding: 12px 8px;
  color: #fff; font-size: 12px; font-weight: 500; text-align: center;
  backdrop-filter: blur(4px);
}
.feature-item i { font-size: 18px; color: var(--c-cyan); }

/* ============================================================
   APP LAYOUT
   ============================================================ */
#page-app { display: none; flex-direction: column; min-height: 100vh; }
#page-app.active { display: flex; }

/* ---------- Topbar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--topbar-h); background: #fff; border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; padding: 0 16px; gap: 12px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  display: none; /* shown on mobile only */
}
.topbar-logo { height: 36px; object-fit: contain; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.topbar-btn {
  width: 38px; height: 38px; border-radius: 8px; color: #64748b;
  background: #f1f5f9; display: flex; align-items: center; justify-content: center;
  font-size: 15px; transition: var(--transition);
}
.topbar-btn:hover { background: var(--c-blue); color: #fff; }
.burger { display: flex; flex-direction: column; gap: 5px; padding: 8px; }
.burger span { width: 22px; height: 2px; background: #334155; border-radius: 2px; transition: var(--transition); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--c-blue); display: flex; flex-direction: column;
  z-index: 300; overflow-y: auto; transition: transform var(--transition);
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.sidebar-header { padding: 20px 16px 16px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-logo { height: 40px; object-fit: contain; margin-bottom: 16px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--c-cyan);
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0;
}
.user-name { font-size: 14px; font-weight: 700; color: #fff; }
.user-role { font-size: 11px; color: rgba(255,255,255,0.6); text-transform: uppercase; letter-spacing: 0.5px; }
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-section-label { font-size: 10px; font-weight: 700; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 1px; padding: 8px 10px 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; font-size: 14px; font-weight: 500; color: rgba(255,255,255,0.75);
  width: 100%; text-align: left; transition: var(--transition); position: relative;
}
.nav-item:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.15); color: #fff; }
.nav-item i { width: 18px; flex-shrink: 0; }
.nav-badge { margin-left: auto; background: var(--c-cyan); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: flex; align-items: center; justify-content: center; padding: 0 5px; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid rgba(255,255,255,0.1); }
.logout-btn { color: rgba(255,255,255,0.6); }
.logout-btn:hover { background: rgba(231,76,60,0.2); color: #e74c3c; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 250; }

/* ---------- Main content ---------- */
.main-content {
  margin-left: var(--sidebar-w);
  padding: 28px 28px 60px;
  min-height: 100vh;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.page-header h1 { font-size: 24px; font-weight: 800; color: var(--c-blue); display: flex; align-items: center; gap: 10px; }
.page-header h1 i { color: var(--c-cyan); }
.page-subtitle { font-size: 14px; color: #64748b; margin-top: 4px; }
.chapter-desc { font-size: 14px; color: #64748b; max-width: 400px; }
.section-title { font-size: 18px; font-weight: 700; color: var(--c-blue); margin: 28px 0 16px; }

/* ---------- KPI Grid ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 32px; }
.kpi-card {
  background: #fff; border-radius: var(--radius-lg); padding: 20px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow); border-left: 4px solid transparent;
}
.kpi-blue { border-left-color: var(--c-blue); }
.kpi-orange { border-left-color: var(--c-orange); }
.kpi-green { border-left-color: var(--c-green); }
.kpi-purple { border-left-color: var(--c-purple); }
.kpi-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.kpi-blue .kpi-icon { background: var(--c-blue-light); color: var(--c-blue); }
.kpi-orange .kpi-icon { background: var(--c-orange-light); color: var(--c-orange); }
.kpi-green .kpi-icon { background: var(--c-green-light); color: var(--c-green); }
.kpi-purple .kpi-icon { background: var(--c-purple-light); color: var(--c-purple); }
.kpi-value { font-size: 28px; font-weight: 800; color: #1e293b; line-height: 1; }
.kpi-label { font-size: 13px; color: #64748b; margin-top: 4px; }

/* ---------- Chapter cards ---------- */
.chapter-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 28px; }
.chapter-card {
  background: #fff; border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow); cursor: pointer; display: flex; gap: 14px;
  transition: box-shadow var(--transition), transform var(--transition);
  border: 1.5px solid transparent;
}
.chapter-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: var(--c-cyan); }
.chapter-card-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.chapter-card-body h3 { font-size: 15px; font-weight: 700; color: var(--c-blue); margin-bottom: 6px; }
.chapter-card-body p { font-size: 13px; color: #64748b; margin-bottom: 10px; line-height: 1.5; }
.chapter-tips { display: flex; flex-direction: column; gap: 5px; }
.tip { font-size: 12px; display: flex; align-items: flex-start; gap: 6px; color: #475569; }
.tip i { color: var(--c-green); margin-top: 2px; flex-shrink: 0; }
.tip.warning i { color: var(--c-orange); }
.tip.danger i { color: var(--c-red); }

/* ---------- Alert banner ---------- */
.alert-banner {
  display: flex; align-items: flex-start; gap: 16px;
  background: linear-gradient(135deg, #fff8ed, #fef3c7); border: 1.5px solid #fde68a;
  border-radius: var(--radius-lg); padding: 16px 20px; margin-bottom: 28px;
}
.alert-banner > i { color: var(--c-orange); font-size: 22px; flex-shrink: 0; margin-top: 2px; }
.alert-banner strong { font-size: 14px; color: #92400e; }
.risk-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.risk-chip { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.risk-chip.danger { background: var(--c-red-light); color: var(--c-red); }
.risk-chip.warning { background: var(--c-orange-light); color: var(--c-orange); }
.risk-chip.info { background: var(--c-blue-light); color: var(--c-blue); }

/* ---------- Chapter summary bar ---------- */
.chapter-summary-bar {
  background: var(--c-blue-light); border-radius: 8px; padding: 10px 16px;
  margin-bottom: 20px;
}
.chapter-summary-bar.warning { background: var(--c-orange-light); }
.summary-tip { font-size: 13px; font-weight: 600; color: var(--c-blue); display: flex; align-items: center; gap: 8px; }
.chapter-summary-bar.warning .summary-tip { color: #92400e; }

/* ---------- Forms list ---------- */
.forms-list-container { min-height: 120px; }
.forms-empty { text-align: center; padding: 48px 20px; color: #94a3b8; }
.forms-empty i { font-size: 40px; margin-bottom: 12px; }
.forms-empty p { font-size: 14px; line-height: 1.6; }
.forms-table {
  background: #fff; border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow); width: 100%; border-collapse: collapse;
}
.forms-table th {
  background: #f8fafc; color: #64748b; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; padding: 12px 16px; text-align: left;
  border-bottom: 1px solid #e2e8f0;
}
.forms-table td { padding: 14px 16px; border-bottom: 1px solid #f1f5f9; font-size: 14px; color: #334155; vertical-align: middle; }
.forms-table tr:last-child td { border-bottom: none; }
.forms-table tr:hover td { background: #f8fafc; }
.status-badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.status-draft { background: #f1f5f9; color: #64748b; }
.status-pending { background: var(--c-orange-light); color: var(--c-orange); }
.status-validated { background: var(--c-green-light); color: var(--c-green-dark); }
.status-archived { background: #f1f5f9; color: #94a3b8; }
.table-actions { display: flex; gap: 6px; flex-wrap: nowrap; }

/* ---------- Document form modal ---------- */
.form-section { margin-bottom: 28px; }
.form-section-title {
  font-size: 14px; font-weight: 700; color: var(--c-blue); padding: 10px 14px;
  background: var(--c-blue-light); border-radius: 8px; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.checkboxes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.checkbox-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checkbox-item input[type="checkbox"] { accent-color: var(--c-cyan); width: 16px; height: 16px; }
.risk-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: #f8fafc; border-radius: 8px; margin-bottom: 6px; font-size: 13px; }
.risk-row.critical { background: var(--c-red-light); color: #7f1d1d; }
.risk-row.high { background: var(--c-orange-light); color: #92400e; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.form-grid .form-group { margin: 0; }
textarea { resize: vertical; min-height: 80px; }

/* ---------- Cloud tab ---------- */
.cloud-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.cloud-card { background: #fff; border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px; }
.cloud-card-full { grid-column: 1 / -1; }
.cloud-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cloud-header h3 { font-size: 16px; font-weight: 700; color: var(--c-blue); flex: 1; }
.cloud-status { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; background: #f1f5f9; color: #64748b; }
.cloud-status.connected { background: var(--c-green-light); color: var(--c-green-dark); }
.cloud-info { font-size: 13px; color: #64748b; line-height: 1.6; }

/* ---------- Settings tab ---------- */
.settings-grid { display: grid; grid-template-columns: 260px 1fr; gap: 24px; align-items: start; }
.settings-section { background: #fff; border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow); }
.settings-section h2 { font-size: 16px; font-weight: 700; color: var(--c-blue); margin-bottom: 16px; border-bottom: 1px solid #e2e8f0; padding-bottom: 12px; }
.info-block { font-size: 14px; color: #334155; line-height: 1.8; }
.info-block strong { color: var(--c-blue); }
.users-list { display: flex; flex-direction: column; gap: 8px; }
.users-list-header {
  display: grid;
  grid-template-columns: 36px 1fr 110px 100px;
  gap: 12px;
  padding: 4px 14px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid #e2e8f0;
  margin-bottom: 4px;
}
.user-item {
  display: grid;
  grid-template-columns: 36px 1fr 110px 100px;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #f8fafc;
  border-radius: 8px;
}
.user-item--inactive { opacity: .65; }
.user-item-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--c-blue-light); color: var(--c-blue); font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.user-item-info { min-width: 0; }
.user-item-name { font-size: 14px; font-weight: 600; color: #334155; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-item-email { font-size: 12px; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-item-role { font-size: 12px; color: #94a3b8; }
.user-item-role-select { display: flex; align-items: center; }
.user-item-role-select select { width: 100%; font-size: 12px; padding: 4px 6px; border: 1px solid #e2e8f0; border-radius: 6px; background: #fff; cursor: pointer; }
.user-item-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.btn-icon { background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; color: #64748b; font-size: 1rem; transition: background .15s; }
.btn-icon:hover { background: #e2e8f0; }
.btn-icon--danger { color: #ef4444; }
.btn-icon--danger:hover { background: #fee2e2; }
.badge-me { font-size: 10px; font-weight: 600; background: var(--c-blue-light); color: var(--c-blue); padding: 1px 5px; border-radius: 10px; vertical-align: middle; margin-left: 4px; }
.role-badge { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.role-badge--admin    { color: #1e40af; background: #dbeafe; }
.role-badge--manager  { color: #065f46; background: #d1fae5; }
.role-badge--operator { color: #92400e; background: #fef3c7; }
.role-badge--viewer   { color: #6b7280; background: #f3f4f6; }
@media (max-width: 600px) {
  .settings-grid { grid-template-columns: 1fr; }
  .users-list-header { grid-template-columns: 36px 1fr 80px 40px; }
  .user-item { grid-template-columns: 36px 1fr 80px 40px; }
  .user-item-actions .btn-icon--danger,
  .user-item-actions .btn-icon:not(.btn-edit) { display: none; }
}
@media (min-width: 601px) and (max-width: 900px) {
  .settings-grid { grid-template-columns: 1fr; }
}
.mt-16 { margin-top: 16px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 600px) { .modal { align-items: center; } }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); backdrop-filter: blur(2px); }
.modal-dialog {
  position: relative; z-index: 10; background: #fff; width: 100%; max-width: 560px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 90vh;
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}
@media (min-width: 600px) {
  .modal-dialog { border-radius: var(--radius-lg); max-height: 85vh; }
  .modal-lg { max-width: 780px; }
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid #e2e8f0; flex-shrink: 0; }
.modal-header h2 { font-size: 17px; font-weight: 700; color: var(--c-blue); }
.modal-close { width: 32px; height: 32px; border-radius: 8px; color: #94a3b8; background: #f1f5f9; display: flex; align-items: center; justify-content: center; transition: var(--transition); font-size: 14px; }
.modal-close:hover { background: var(--c-red-light); color: var(--c-red); }
.modal-body { flex: 1; overflow-y: auto; padding: 24px; scrollbar-width: thin; }
.modal-footer { padding: 16px 24px; border-top: 1px solid #e2e8f0; display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0; flex-wrap: wrap; }

/* ---------- Doc type picker ---------- */
.doc-type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.doc-type-btn {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 20px 12px;
  background: #f8fafc; border: 1.5px solid #e2e8f0; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; color: #334155; transition: var(--transition); cursor: pointer;
}
.doc-type-btn i { font-size: 22px; color: var(--c-cyan); }
.doc-type-btn:hover { border-color: var(--c-cyan); background: var(--c-blue-light); color: var(--c-blue); }

/* ---------- Toast ---------- */
#toast-container { position: fixed; top: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 280px; max-width: 360px; padding: 14px 18px; border-radius: 10px;
  background: #1e293b; color: #fff; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.3s ease;
}
@keyframes toastIn { from { transform: translateX(50px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.success { background: var(--c-green-dark); }
.toast.error { background: var(--c-red); }
.toast.warning { background: var(--c-orange); }

/* ---------- Footer ---------- */
.app-footer {
  background: var(--c-blue); color: rgba(255,255,255,0.6); font-size: 12px;
  display: flex; align-items: center; justify-content: center; gap: 20px;
  padding: 10px 20px; margin-left: var(--sidebar-w);
  flex-wrap: wrap; text-align: center;
}
.app-footer a { color: rgba(255,255,255,0.8); }

/* ---------- Form view (read mode) ---------- */
.view-section { margin-bottom: 20px; }
.view-section-title { font-size: 13px; font-weight: 700; color: var(--c-blue); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; border-bottom: 1px solid #e2e8f0; padding-bottom: 6px; }
.view-field { display: flex; gap: 8px; font-size: 13px; padding: 6px 0; }
.view-label { min-width: 160px; color: #94a3b8; font-weight: 500; flex-shrink: 0; }
.view-value { color: #334155; font-weight: 500; }
.view-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.view-chip { background: var(--c-blue-light); color: var(--c-blue); padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.view-chip.checked { background: var(--c-green-light); color: var(--c-green-dark); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .topbar { display: flex; }
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main-content { margin-left: 0; padding: 80px 16px 80px; }
  .app-footer { margin-left: 0; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chapter-cards { grid-template-columns: 1fr; }
  .cloud-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; } /* override desktop 2-col */
  .page-header { flex-direction: column; }
  .forms-table { font-size: 12px; }
  .forms-table th, .forms-table td { padding: 10px 10px; }
  .table-actions { flex-direction: column; }
  #toast-container { top: 70px; right: 12px; left: 12px; }
  .toast { min-width: auto; width: 100%; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 18px; }
  .modal-dialog { max-height: 95vh; }
  .doc-type-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Scrollbar styling (desktop) ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.3); }

/* ---------- Loading spinner ---------- */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Utilities ---------- */
.text-muted { color: #94a3b8; font-size: 13px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; display: inline-block; vertical-align: bottom; }
