:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --border: #334155;
  --critical: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Nav */
header {
  background-color: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #38bdf8 0%, #6366f1 100%);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: bold;
  color: white;
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #f8fafc, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.tenant-selector-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-secondary);
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.tenant-selector-box select {
  background: transparent;
  color: var(--text-main);
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

.btn-sm {
  background: var(--accent);
  color: #0f172a;
  border: none;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-sm:hover {
  background: #7dd3fc;
}

.role-pill-group {
  display: flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.role-pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.role-pill.active {
  background: var(--accent);
  color: #0f172a;
  font-weight: 700;
}

/* Nav Tabs */
.nav-tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.7);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(51, 65, 85, 0.4);
}

.tab-btn.active {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
}

/* Main Container */
main {
  flex: 1;
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
}

.kpi-card.danger::before { background: var(--critical); }
.kpi-card.warn::before { background: var(--warning); }
.kpi-card.success::before { background: var(--success); }

.kpi-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-value {
  font-size: 1.85rem;
  font-weight: 700;
  margin: 0.25rem 0;
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Alerts Feed */
.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.alert-feed {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.alert-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 1.25rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.alert-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

.alert-card.critical { border-left-color: var(--critical); }
.alert-card.warning { border-left-color: var(--warning); }
.alert-card.ok { border-left-color: var(--success); }

.alert-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.alert-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  display: inline-block;
}

.badge-critical { background: rgba(239, 68, 68, 0.2); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.4); }
.badge-warning { background: rgba(245, 158, 11, 0.2); color: #fde68a; border: 1px solid rgba(245, 158, 11, 0.4); }
.badge-ok { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.4); }

.alert-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.alert-desc {
  font-size: 0.9rem;
  color: #cbd5e1;
  margin-bottom: 0.6rem;
}

.alert-citation {
  background: rgba(15, 23, 42, 0.6);
  border-left: 3px solid #64748b;
  padding: 0.5rem 0.8rem;
  font-size: 0.82rem;
  font-style: italic;
  color: #94a3b8;
  border-radius: 4px;
  margin-bottom: 0.6rem;
}

.alert-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.alert-recom {
  background: rgba(56, 189, 248, 0.1);
  color: #bae6fd;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.82rem;
  margin-top: 0.5rem;
}

/* Upload Dropzone */
.dropzone {
  border: 2px dashed #475569;
  background: rgba(30, 41, 59, 0.5);
  border-radius: 12px;
  padding: 3rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 1.5rem;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.05);
}

.dropzone-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  color: var(--accent);
}

.dropzone-text h3 {
  font-size: 1.15rem;
  margin-bottom: 0.25rem;
}

.dropzone-text p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Document Table */
.doc-table-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

th {
  background: rgba(15, 23, 42, 0.5);
  padding: 0.85rem 1rem;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: rgba(51, 65, 85, 0.3);
}

/* Chat & Copilot */
.chat-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.25rem;
  height: 680px;
}

.chat-sidebar {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.quick-prompts-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
}

.quick-prompt-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.82rem;
  text-align: left;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
}

.quick-prompt-btn:hover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
}

.chat-main {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-bubble {
  max-width: 80%;
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.5;
}

.bubble-user {
  align-self: flex-end;
  background: var(--accent-hover);
  color: white;
  border-bottom-right-radius: 2px;
}

.bubble-assistant {
  align-self: flex-start;
  background: var(--bg-tertiary);
  color: var(--text-main);
  border-bottom-left-radius: 2px;
}

.citation-chip {
  display: inline-block;
  margin-top: 0.5rem;
  margin-right: 0.4rem;
  padding: 0.2rem 0.5rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid #475569;
  border-radius: 4px;
  font-size: 0.75rem;
  color: #38bdf8;
}

.chat-input-bar {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.4);
}

.chat-input-bar input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 1rem;
  color: var(--text-main);
  font-size: 0.9rem;
  outline: none;
}

.chat-input-bar input:focus {
  border-color: var(--accent);
}

.chat-input-bar button {
  background: var(--accent);
  color: #0f172a;
  border: none;
  font-weight: 700;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 90%;
  max-width: 520px;
  padding: 1.5rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.form-group input, .form-group textarea {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

/* Modal Visor de Documentos */
.modal-content.doc-viewer-modal {
  max-width: 1000px;
  width: 95%;
  padding: 1.25rem;
}

.doc-viewer-body {
  margin-top: 0.75rem;
}

/* Panel Dinámico de Roles */
.role-hub-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  position: relative;
  overflow: hidden;
}

.role-hub-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  margin-bottom: 0.75rem;
}

.badge-role-propietario { background: rgba(56, 189, 248, 0.2); color: #38bdf8; border: 1px solid rgba(56, 189, 248, 0.4); }
.badge-role-junta { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
.badge-role-admin { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }

.role-hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}

.role-box {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.role-box h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-main);
}

.role-box p, .role-box li {
  font-size: 0.83rem;
  color: #cbd5e1;
  line-height: 1.45;
}

.role-box ul {
  padding-left: 1.2rem;
  margin-top: 0.4rem;
}

.btn-action-view {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.btn-action-view:hover {
  background: #38bdf8;
  color: #0f172a;
}


/* Pantalla de Bienvenida y Acceso Privado (Gate) */
.gate-hero-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 3rem 1rem;
  min-height: calc(85vh - 70px);
}
.gate-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 520px;
  width: 100%;
  padding: 2.2rem;
  box-shadow: 0 25px 30px -10px rgba(0, 0, 0, 0.6), 0 10px 15px -5px rgba(0, 0, 0, 0.4);
}
.gate-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  margin-bottom: 0.85rem;
}
.gate-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}
.gate-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1.5rem;
}
.btn-primary-gate {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.85rem;
  background: var(--accent);
  color: #0f172a;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-primary-gate:hover {
  background: var(--accent-hover);
  color: #ffffff;
  transform: translateY(-1px);
}