/* ══════════════════════════════════════════════════════════════
   SST PANEL — Seguridad y Salud en el Trabajo
   ══════════════════════════════════════════════════════════════ */
:root {
  --sst-primary: #1A7AF8;
  --sst-primary-dark: #1565d8;
  --sst-primary-light: #e8f1fe;
  --sst-accent: #1A7AF8;
  --sst-danger: #dc2626;
  --sst-success: #16a34a;
  --sst-warning: #e5890a;
  --sst-bg: #f7f8fc;
  --sst-card: #ffffff;
  --sst-text: #1B2A4A;
  --sst-text-secondary: #4a5578;
  --sst-border: #e2e5ef;
  --sst-sidebar-bg: #0b1628;
  --sst-sidebar-text: #c8d6e8;
  --sst-radius: 10px;
  --sst-shadow: 0 1px 3px rgba(27,42,74,0.06);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--sst-bg); color: var(--sst-text); line-height: 1.5; }
.hidden { display: none !important; }

/* ── LOGIN ──────────────────────────────────────────── */
#loginScreen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0b1628 0%, #0f2042 50%, #1A7AF8 100%); padding: 20px; }
.login-wrap { width: 100%; max-width: 400px; }
.login-card { background: #fff; border-radius: 16px; padding: 40px 32px; box-shadow: 0 20px 60px rgba(0,0,0,0.15); }
.login-brand { text-align: center; margin-bottom: 32px; }
.login-icon { width: 56px; height: 56px; margin: 0 auto 12px; background: var(--sst-primary-light); border-radius: 14px; display: flex; align-items: center; justify-content: center; color: var(--sst-primary); }
.login-icon svg { width: 32px; height: 32px; }
.login-brand h1 { font-size: 28px; font-weight: 700; color: var(--sst-primary); letter-spacing: 2px; }
.login-brand p { font-size: 13px; color: var(--sst-text-secondary); margin-top: 4px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--sst-text-secondary); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 10px 14px; border: 1.5px solid var(--sst-border); border-radius: 8px; font-size: 14px; transition: border-color 0.2s; outline: none; background: #fff; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--sst-primary); box-shadow: 0 0 0 3px rgba(26,122,248,0.1); }
.alert-error { background: #fef2f2; color: #dc2626; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; border: 1px solid #fecaca; }
.btn-primary { background: var(--sst-primary); color: #fff; border: none; padding: 11px 20px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.2s; }
.btn-primary:hover { background: var(--sst-primary-dark); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }
.btn-outline { background: transparent; color: var(--sst-primary); border: 1.5px solid var(--sst-primary); padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-outline:hover { background: var(--sst-primary-light); }
.btn-danger { background: var(--sst-danger); color: #fff; border: none; padding: 8px 16px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--sst-success); color: #fff; border: none; padding: 8px 16px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.login-footer { text-align: center; margin-top: 24px; font-size: 12px; color: var(--sst-text-secondary); }

/* ── LAYOUT ─────────────────────────────────────────── */
#mainLayout { display: flex; min-height: 100vh; }
#sidebar { width: 260px; background: var(--sst-sidebar-bg); color: var(--sst-sidebar-text); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; transform: translateX(-100%); transition: transform 0.25s ease; }
#sidebar.open { transform: translateX(0); }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 99; }
#sidebar.open ~ .sidebar-backdrop { display: block; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: #fff; border-bottom: 1px solid var(--sst-border); }
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.sidebar-logo { width: 100%; max-width: 180px; height: auto; }
.sidebar-close { background: none; border: none; color: var(--sst-text-secondary); font-size: 24px; cursor: pointer; display: block; }
#sidebarNav { flex: 1; overflow-y: auto; padding: 12px 0; }
.nav-section { padding: 8px 20px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px; color: rgba(255,255,255,0.4); font-weight: 600; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 20px; color: rgba(255,255,255,0.75); font-size: 13px; cursor: pointer; transition: all 0.15s; text-decoration: none; border-left: 3px solid transparent; }
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.12); color: #fff; border-left-color: var(--sst-accent); font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,0.1); }
.sidebar-user { font-size: 13px; margin-bottom: 8px; opacity: 0.8; }
.btn-logout { background: rgba(255,255,255,0.1); border: none; color: rgba(255,255,255,0.8); padding: 8px 16px; border-radius: 6px; font-size: 12px; cursor: pointer; width: 100%; }
.btn-logout:hover { background: rgba(255,255,255,0.2); }

#mainContent { flex: 1; min-width: 0; }
#topBar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--sst-border); position: sticky; top: 0; z-index: 50; }
.hamburger { background: none; border: none; cursor: pointer; color: var(--sst-text); padding: 4px; }
#pageTitle { font-size: 18px; font-weight: 600; flex: 1; }
#topBarActions { display: flex; gap: 8px; }
#pageContainer { padding: 20px; max-width: 1200px; margin: 0 auto; }

/* ── CARDS & STATS ──────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--sst-card); border-radius: var(--sst-radius); padding: 20px; box-shadow: var(--sst-shadow); border: 1px solid var(--sst-border); }
.stat-card .stat-label { font-size: 12px; color: var(--sst-text-secondary); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; color: var(--sst-text); }
.stat-card .stat-sub { font-size: 12px; color: var(--sst-text-secondary); margin-top: 2px; }
.stat-card.danger { border-left: 4px solid var(--sst-danger); }
.stat-card.success { border-left: 4px solid var(--sst-success); }
.stat-card.warning { border-left: 4px solid var(--sst-warning); }
.stat-card.info { border-left: 4px solid var(--sst-primary); }

.card { background: var(--sst-card); border-radius: var(--sst-radius); padding: 20px; box-shadow: var(--sst-shadow); border: 1px solid var(--sst-border); margin-bottom: 20px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; }

/* ── TABLE ──────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; background: #f8fafc; color: var(--sst-text-secondary); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 2px solid var(--sst-border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--sst-border); vertical-align: middle; }
tr:hover { background: rgba(26,122,248,0.03); }

/* ── BADGES ─────────────────────────────────────────── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-danger { background: #fef2f2; color: #dc2626; }
.badge-warning { background: #fffbeb; color: #d97706; }
.badge-success { background: #f0fdf4; color: #16a34a; }
.badge-info { background: #e8f1fe; color: #1565d8; }
.badge-neutral { background: #f1f5f9; color: #64748b; }
.badge-critical { background: #dc2626; color: #fff; }

/* ── RISK MATRIX GRID ──────────────────────────────── */
.risk-grid { display: grid; grid-template-columns: auto repeat(4, 1fr); gap: 2px; margin: 16px 0; font-size: 12px; }
.risk-grid .risk-header { background: #f1f5f9; padding: 8px; text-align: center; font-weight: 600; }
.risk-grid .risk-label { background: #f1f5f9; padding: 8px; font-weight: 600; display: flex; align-items: center; }
.risk-grid .risk-cell { padding: 12px 8px; text-align: center; font-weight: 600; color: #fff; border-radius: 4px; cursor: pointer; }
.risk-cell.level-iv { background: #22c55e; }
.risk-cell.level-iii { background: #f59e0b; }
.risk-cell.level-ii { background: #f97316; }
.risk-cell.level-i { background: #ef4444; }

/* ── FILTERS ────────────────────────────────────────── */
.filters-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.filters-bar select, .filters-bar input { padding: 7px 12px; border: 1.5px solid var(--sst-border); border-radius: 6px; font-size: 13px; background: #fff; }

/* ── MODAL ──────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--sst-border); }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--sst-text-secondary); padding: 4px; }
.modal-body { padding: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--sst-border); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── TOAST ──────────────────────────────────────────── */
#toastContainer { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: 8px; font-size: 13px; color: #fff; animation: slideIn 0.3s ease; min-width: 250px; }
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
.toast-info { background: var(--sst-primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── LOADING ────────────────────────────────────────── */
.loading { text-align: center; padding: 40px 20px; color: var(--sst-text-secondary); font-size: 14px; }

/* ── STAT CARD VARIANTS ────────────────────────────── */
.stat-card .stat-title { font-size: 13px; color: var(--sst-text-secondary); margin-top: 4px; font-weight: 500; }
.stat-card .stat-subtitle { font-size: 11px; color: var(--sst-text-secondary); margin-top: 2px; opacity: 0.8; }
.stat-card.stat-danger { border-left: 4px solid var(--sst-danger); }
.stat-card.stat-success { border-left: 4px solid var(--sst-success); }
.stat-card.stat-warning { border-left: 4px solid var(--sst-warning); }
.stat-card.stat-info { border-left: 4px solid var(--sst-primary); }

/* ── GRID LAYOUTS ──────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

/* ── FORM ELEMENTS ─────────────────────────────────── */
.form-input, .form-select { width: 100%; padding: 10px 14px; border: 1.5px solid var(--sst-border); border-radius: 8px; font-size: 14px; transition: border-color 0.2s; outline: none; background: #fff; font-family: inherit; }
.form-input:focus, .form-select:focus { border-color: var(--sst-primary); box-shadow: 0 0 0 3px rgba(26,122,248,0.1); }
textarea.form-input { resize: vertical; min-height: 60px; }

/* ── CARD HEADER / BODY ────────────────────────────── */
.card-header { padding-bottom: 12px; border-bottom: 1px solid var(--sst-border); margin-bottom: 16px; }
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { }

/* ── TABLE CONTAINER ───────────────────────────────── */
.table-container { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; padding: 10px 12px; background: #f8fafc; color: var(--sst-text-secondary); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 2px solid var(--sst-border); white-space: nowrap; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--sst-border); vertical-align: middle; }
.data-table tr:hover { background: rgba(26,122,248,0.03); }
.td-truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-warning { background: #fffbeb !important; }

/* ── TEXT UTILITIES ─────────────────────────────────── */
.text-muted { color: var(--sst-text-secondary); }
.text-center { text-align: center; }

/* ── TABS ──────────────────────────────────────────── */
.tab-bar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; border-bottom: 2px solid var(--sst-border); padding-bottom: 0; }
.tab-btn { background: none; border: none; padding: 8px 16px; font-size: 13px; font-weight: 500; color: var(--sst-text-secondary); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; border-radius: 6px 6px 0 0; }
.tab-btn:hover { color: var(--sst-primary); background: var(--sst-primary-light); }
.tab-btn.active { color: var(--sst-primary); border-bottom-color: var(--sst-primary); font-weight: 600; }

/* ── SECTION ACTIONS ───────────────────────────────── */
.section-actions { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 16px; }

/* ── ALERT WARNING ─────────────────────────────────── */
.alert-warning { background: #fffbeb; color: #92400e; padding: 10px 14px; border-radius: 8px; font-size: 13px; border: 1px solid #fde68a; }

/* ── RISK BARS (Dashboard) ─────────────────────────── */
.risk-bars { display: flex; flex-direction: column; gap: 12px; }
.risk-bar-row { display: flex; align-items: center; gap: 12px; }
.risk-bar-label { font-size: 12px; font-weight: 600; min-width: 120px; white-space: nowrap; }
.risk-bar-track { flex: 1; height: 24px; background: #f1f5f9; border-radius: 6px; overflow: hidden; }
.risk-bar-fill { height: 100%; border-radius: 6px; transition: width 0.4s ease; min-width: 4px; }
.risk-bar-count { font-size: 14px; font-weight: 700; min-width: 30px; text-align: right; }

/* ── CHART BARS (Dashboard) ────────────────────────── */
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 20px; }
.chart-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.chart-bar-value { font-size: 11px; font-weight: 600; color: var(--sst-text-secondary); margin-bottom: 4px; }
.chart-bar-track { width: 100%; max-width: 32px; height: 120px; display: flex; align-items: flex-end; }
.chart-bar-fill { width: 100%; background: var(--sst-primary); border-radius: 4px 4px 0 0; transition: height 0.4s ease; min-height: 2px; }
.chart-bar-label { font-size: 10px; color: var(--sst-text-secondary); margin-top: 6px; white-space: nowrap; }

/* ── CHECKBOX ROW ──────────────────────────────────── */
.checkbox-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; cursor: pointer; }
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--sst-primary); }

/* ── SMALL BUTTON COMBOS ───────────────────────────── */
.btn-sm.btn-outline { background: transparent; color: var(--sst-primary); border: 1.5px solid var(--sst-primary); cursor: pointer; }
.btn-sm.btn-outline:hover { background: var(--sst-primary-light); }
.btn-sm.btn-primary { background: var(--sst-primary); color: #fff; border: none; cursor: pointer; }
.btn-sm.btn-primary:hover { background: var(--sst-primary-dark); }
.btn-sm.btn-danger { background: transparent; color: var(--sst-danger); border: 1.5px solid var(--sst-danger); cursor: pointer; }
.btn-sm.btn-danger:hover { background: #fef2f2; }

/* ── DETAIL GRID SPACING ──────────────────────────── */
.detail-grid div { padding: 6px 0; }
.detail-grid div strong { color: var(--sst-text-secondary); font-size: 12px; }

/* ── EMPTY STATE ────────────────────────────────────── */
.empty-state { text-align: center; padding: 40px 20px; color: var(--sst-text-secondary); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ── RESPONSIVE ─────────────────────────────────────── */
@media (min-width: 900px) {
  #sidebar { transform: translateX(0); }
  .sidebar-close { display: none; }
  .sidebar-backdrop { display: none !important; }
  .hamburger { display: none; }
  #mainContent { margin-left: 260px; }
  #pageContainer { padding: 24px 32px; }
  .form-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card .stat-value { font-size: 22px; }
  .form-row { grid-template-columns: 1fr; }
  #pageContainer { padding: 16px; }
  .modal { max-width: 100%; margin: 10px; }
}
