/* W001 RAIE — Workspace Jurídico
 * Look & feel basado en LookFeelServicios_RAIE.md
 * Paleta: #1a3a5c (azul corporativo), #e8a020 (dorado)
 */

:root {
  --primary: #1a3a5c;
  --primary-dark: #0f2742;
  --primary-light: #2a5080;
  --accent-gold: #e8a020;
  --accent-gold-dark: #c8881a;
  --bg-page: #f5f6f8;
  --bg-card: #ffffff;
  --bg-sidebar: #1a3a5c;
  --bg-topbar: #ffffff;
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --text-on-dark: #f8fafc;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --info: #3b82f6;
  --info-bg: #dbeafe;
  --sidebar-w: 240px;
  --topbar-h: 62px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === LAYOUT === */
.app-layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  color: var(--text-on-dark);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 50;
}
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.main-topbar {
  height: var(--topbar-h);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.main-topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
  flex: 1;
}
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.topbar-actions button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-secondary);
}
.topbar-actions button:hover {
  background: var(--bg-page);
  border-color: var(--primary);
  color: var(--primary);
}
.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.container {
  max-width: 1280px;
  margin: 0 auto;
}

/* === SIDEBAR === */
.sidebar-logo {
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.logo-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--accent-gold);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.3px;
}
.logo-text { font-size: 14px; font-weight: 700; line-height: 1.1; }
.logo-text small { display: block; font-size: 10px; opacity: 0.75; font-weight: 400; letter-spacing: 0.6px; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 2px;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.1); color: #fff; text-decoration: none; }
.sidebar-nav a.nav-active { background: var(--accent-gold); color: var(--primary-dark); font-weight: 600; }
.nav-section-title {
  padding: 14px 12px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.55);
  text-transform: uppercase;
}

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-lang {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.07);
  padding: 6px 10px;
  border-radius: 6px;
}
.sidebar-lang select {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 12px;
  flex: 1;
  outline: none;
  cursor: pointer;
}
.sidebar-lang select option { color: #000; }
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
}
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-gold);
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}
.user-info { flex: 1; min-width: 0; line-height: 1.2; }
.user-info strong {
  display: block;
  font-size: 12px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-info small { font-size: 10px; opacity: 0.7; }
.btn-sidebar-icon {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.85);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 14px;
}
.btn-sidebar-icon:hover { background: rgba(255,255,255,0.1); color: #fff; text-decoration: none; }

/* === CARDS === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { margin: 0; font-size: 16px; font-weight: 600; color: var(--primary); }
.card-header .actions { display: flex; gap: 8px; }

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-gold { background: var(--accent-gold); color: var(--primary-dark); font-weight: 600; }
.btn-gold:hover { background: var(--accent-gold-dark); color: #fff; }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-page); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* === FORMS === */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.form-group input[type=text],
.form-group input[type=email],
.form-group input[type=password],
.form-group input[type=date],
.form-group input[type=number],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text-primary);
}
.form-group textarea { min-height: 70px; resize: vertical; font-family: inherit; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 58, 92, 0.12);
}
.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }
.form-help { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* === STATS === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}
.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.stat-card.urgent .stat-value { color: var(--danger); }
.stat-card.warn .stat-value { color: var(--warning); }
.stat-card.success .stat-value { color: var(--success); }

/* === TABLES === */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border-strong);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-secondary);
  background: var(--bg-page);
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:hover td { background: var(--bg-page); }
.data-table .row-link { color: var(--primary); font-weight: 500; }

/* === BADGES === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-primary { background: var(--info-bg); color: var(--info); }
.badge-success { background: var(--success-bg); color: #047857; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger { background: var(--danger-bg); color: #991b1b; }
.badge-secondary { background: #e5e7eb; color: #4b5563; }
.badge-sens-1 { background: #d1fae5; color: #047857; }
.badge-sens-2 { background: #fef3c7; color: #92400e; }
.badge-sens-3 { background: #fed7aa; color: #9a3412; }
.badge-sens-4 { background: #fecaca; color: #991b1b; }

/* === TABS === */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 18px;
}
.tab {
  padding: 10px 16px;
  cursor: pointer;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--accent-gold); font-weight: 600; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* === ALERTS / FLASH === */
.flash {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 10px;
}
.flash-success { background: var(--success-bg); border-color: #6ee7b7; color: #047857; }
.flash-error { background: var(--danger-bg); border-color: #fca5a5; color: #991b1b; }
.flash-warning { background: var(--warning-bg); border-color: #fcd34d; color: #92400e; }
.flash-info { background: var(--info-bg); border-color: #93c5fd; color: #1e40af; }

/* === LOGIN === */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  padding: 20px;
}
.login-box {
  background: #fff;
  border-radius: 12px;
  padding: 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-box h1 {
  margin: 0 0 6px 0;
  font-size: 22px;
  color: var(--primary);
  text-align: center;
}
.login-box .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}

/* === FOLDERS === */
.carpetas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.carpeta-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.carpeta-card h3 {
  margin: 0 0 6px 0;
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
}
.carpeta-card .doc-count { font-size: 12px; color: var(--text-muted); }
.carpeta-card .doc-list { margin-top: 8px; max-height: 200px; overflow-y: auto; }
.carpeta-card .doc-list a {
  display: block;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 1px dashed var(--border);
}
.carpeta-card .doc-list a:hover { color: var(--primary); }
.carpeta-card.dropzone {
  border: 2px dashed var(--border-strong);
  background: var(--bg-page);
  text-align: center;
}
.carpeta-card form input[type=file] { width: 100%; font-size: 12px; }

/* === TIMELINE === */
.timeline { position: relative; padding-left: 30px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 9px; top: 4px; bottom: 4px;
  width: 2px;
  background: var(--border-strong);
}
.timeline-item {
  position: relative;
  margin-bottom: 18px;
  padding-bottom: 6px;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -25px; top: 4px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent-gold);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--accent-gold);
}
.timeline-item.ia::before { background: var(--info); box-shadow: 0 0 0 2px var(--info); }
.timeline-item .ts { font-size: 11px; color: var(--text-muted); }
.timeline-item .desc { margin-top: 2px; }

/* === CHAT === */
.chat-container {
  display: flex;
  gap: 16px;
  height: calc(100vh - 130px);
}
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.chat-side {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.chat-msg {
  margin-bottom: 14px;
  display: flex;
  gap: 10px;
}
.chat-msg .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--bg-page);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: var(--primary);
}
.chat-msg.ia .avatar { background: var(--info-bg); color: var(--info); }
.chat-msg .content { flex: 1; }
.chat-msg .author { font-weight: 600; font-size: 12px; }
.chat-msg .text { background: var(--bg-page); padding: 8px 12px; border-radius: 8px; margin-top: 4px; font-size: 13px; }
.chat-msg.ia .text { background: var(--info-bg); }
.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-input textarea {
  flex: 1;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 12px;
  resize: none;
  height: 56px;
  font-family: inherit;
  font-size: 13px;
}

/* === Misc === */
.text-muted { color: var(--text-muted); }
.text-small { font-size: 12px; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 8px !important; }
.mb-2 { margin-bottom: 16px !important; }
.mb-3 { margin-bottom: 24px !important; }
.mt-1 { margin-top: 8px !important; }
.mt-2 { margin-top: 16px !important; }
.flex-row { display: flex; gap: 12px; align-items: center; }
.flex-grow { flex: 1; }
.text-right { text-align: right; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* === MODALES (estándar de información en W001) ===
 * Reglas:
 *  - Información estática NO va embebida en la página → siempre modal
 *  - El acceso al modal es un icono `?` (.info-icon) junto al título de la sección
 *  - Click fuera del modal o tecla Esc lo cierra
 *  - Action feedback (success/error tras un POST) se mantiene como flash
 */
.info-icon {
  display: inline-block;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--info);
  color: #fff !important;
  text-align: center;
  line-height: 18px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  margin-left: 8px;
  vertical-align: middle;
  border: none;
  text-decoration: none;
  user-select: none;
}
.info-icon:hover { opacity: 0.85; text-decoration: none; }
.info-icon.warn { background: var(--warning); }
.info-icon.muted { background: var(--text-muted); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: modalFadeIn 0.15s ease-out;
}
.modal-overlay.active { display: flex; }
@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-box {
  background: #fff;
  border-radius: 10px;
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  position: relative;
  animation: modalSlideIn 0.18s ease-out;
}
@keyframes modalSlideIn {
  from { transform: translateY(-12px); opacity: 0.85; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-header {
  padding: 18px 22px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.modal-header h2 {
  margin: 0;
  color: var(--primary);
  font-size: 16px;
  font-weight: 600;
}
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 22px;
  color: var(--text-muted);
  line-height: 1;
  padding: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
.modal-close:hover { background: var(--bg-page); color: var(--text-primary); }
.modal-body {
  padding: 16px 22px 20px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-primary);
}
.modal-body p { margin: 0 0 10px 0; }
.modal-body p:last-child { margin-bottom: 0; }
.modal-body code { background: var(--bg-page); padding: 1px 6px; border-radius: 3px; font-size: 12px; }
.modal-body ul { margin: 6px 0 10px 18px; padding: 0; }
.modal-body ul li { margin-bottom: 4px; }
.modal-footer {
  padding: 12px 22px 18px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
}

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-row { flex-direction: column; }
  .modal-box { max-height: 95vh; }
}
