:root {
  --navy: #0f1e2e;
  --navy-mid: #1a3048;
  --navy-light: #254060;
  --gold: #c9a84c;
  --gold-light: #e8c96e;
  --white: #ffffff;
  --off-white: #f5f7fa;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e2e8f0;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #059669;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--off-white); }

/* ── Login screen ── */
#login-screen {
  position: fixed; inset: 0; background: var(--navy);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
#login-box {
  width: 380px; padding: 40px 36px;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
#login-box .brand { color: var(--gold); font-weight: 800; letter-spacing: 2px; }
#login-box .tagline { color: rgba(255,255,255,.5); font-size: 12px; }
#login-box input {
  width: 100%; padding: 10px 12px; border-radius: 6px;
  border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.07);
  color: #fff; font-size: 14px; margin-top: 4px;
}
#login-box input::placeholder { color: rgba(255,255,255,.3); }
#login-box input:focus { outline: none; border-color: var(--gold); }
.login-tab {
  padding: 8px 16px; border: none; background: none; cursor: pointer;
  color: rgba(255,255,255,.45); font-size: 13px; border-bottom: 2px solid transparent;
}
.login-tab.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ── Layout ── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
#sidebar {
  width: 280px; min-width: 220px; background: var(--navy);
  display: flex; flex-direction: column; overflow: hidden;
  border-right: 1px solid var(--navy-mid);
}
#sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--navy-light);
}
#sidebar-header .brand { color: var(--gold); font-size: 20px; font-weight: 700; letter-spacing: 1px; }
#sidebar-header .brand span { color: rgba(255,255,255,.5); font-weight: 300; font-size: 12px; margin-left: 4px; }
#sidebar-header .tagline { color: rgba(255,255,255,.4); font-size: 11px; margin-top: 2px; }

#sidebar-actions { padding: 12px 16px; border-bottom: 1px solid var(--navy-light); }

#exp-list { flex: 1; overflow-y: auto; padding: 8px 0; }
#exp-list::-webkit-scrollbar { width: 4px; }
#exp-list::-webkit-scrollbar-thumb { background: var(--navy-light); border-radius: 2px; }

.exp-item {
  padding: 10px 16px; cursor: pointer; border-left: 3px solid transparent;
  transition: background .15s;
}
.exp-item:hover { background: rgba(255,255,255,.06); }
.exp-item.active { background: rgba(201,168,76,.12); border-left-color: var(--gold); }
.exp-item .exp-titulo { color: var(--white); font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-item .exp-meta { color: rgba(255,255,255,.4); font-size: 11px; margin-top: 2px; }
.exp-item .exp-badges { display: flex; gap: 4px; margin-top: 4px; }
.badge { font-size: 10px; padding: 1px 5px; border-radius: 3px; font-weight: 600; }
.badge-doc { background: rgba(201,168,76,.2); color: var(--gold-light); }
.badge-pen { background: rgba(220,38,38,.2); color: #fca5a5; }
.badge-borr { background: rgba(5,150,105,.2); color: #6ee7b7; }

.sidebar-empty { color: rgba(255,255,255,.3); font-size: 12px; text-align: center; padding: 24px 16px; }

/* Main panel */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#topbar {
  height: 56px; background: var(--white); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 12px;
  flex-shrink: 0;
}
#topbar h1 { font-size: 16px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.estado-badge {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 12px;
  background: #d1fae5; color: #065f46;
}
.estado-badge.archivado { background: #fef3c7; color: #92400e; }
.estado-badge.cerrado { background: #f1f5f9; color: #64748b; }

/* Tabs */
#tabs-bar {
  display: flex; background: var(--white); border-bottom: 1px solid var(--border);
  padding: 0 24px; gap: 4px; flex-shrink: 0;
}
.tab-btn {
  padding: 10px 14px; font-size: 13px; color: var(--text-muted); cursor: pointer;
  border: none; background: none; border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s; white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--navy); border-bottom-color: var(--gold); font-weight: 600; }

/* Content area */
#content { flex: 1; overflow-y: auto; padding: 24px; }
#content::-webkit-scrollbar { width: 6px; }
#content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

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

/* Welcome */
#welcome {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; text-align: center; padding: 40px;
}
#welcome .welcome-icon { font-size: 48px; margin-bottom: 16px; }
#welcome h2 { font-size: 22px; font-weight: 700; color: var(--navy); margin-bottom: 8px; }
#welcome p { color: var(--text-muted); max-width: 380px; line-height: 1.6; margin-bottom: 24px; }

/* Cards */
.card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-title { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px; }

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* Stat cards */
.stat-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-align: center; box-shadow: var(--shadow);
}
.stat-card .stat-num { font-size: 28px; font-weight: 700; color: var(--navy); }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius); font-size: 13px;
  font-weight: 600; cursor: pointer; border: none; transition: all .15s;
  text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: var(--navy-mid); }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover { background: var(--gold-light); }
.btn-outline { background: transparent; color: var(--navy); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--navy); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-success { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }
.btn-success:hover { background: #d1fae5; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }
.btn-sidebar {
  width: 100%; background: var(--gold); color: var(--navy);
  padding: 9px 16px; border: none; border-radius: var(--radius);
  font-size: 13px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; gap: 6px; justify-content: center;
}
.btn-sidebar:hover { background: var(--gold-light); }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 8px 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius); font-size: 13px; font-family: inherit;
  transition: border-color .15s; background: var(--white);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none; border-color: var(--navy);
}
.form-group textarea { min-height: 90px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Docs */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--off-white); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.doc-icon { font-size: 20px; }
.doc-info { flex: 1; min-width: 0; }
.doc-info .doc-nombre { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-info .doc-meta { font-size: 11px; color: var(--text-muted); }
.doc-actions { display: flex; gap: 6px; }

/* Borrador */
.borrador-card {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.borrador-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.borrador-tipo { font-size: 12px; font-weight: 700; color: #92400e; text-transform: uppercase; letter-spacing: .5px; }
.borrador-fecha { font-size: 11px; color: var(--text-muted); }
.borrador-revisado { font-size: 11px; color: var(--success); font-weight: 600; }
.borrador-texto {
  background: var(--white); border: 1px solid #fde68a; border-radius: 4px;
  padding: 12px; font-size: 12px; line-height: 1.7; white-space: pre-wrap;
  max-height: 300px; overflow-y: auto; font-family: 'Courier New', monospace;
  color: var(--text);
}
.borrador-disclaimer {
  font-size: 11px; color: #92400e; font-style: italic; margin-top: 8px;
}

/* Pendientes */
.pendiente-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px;
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 6px;
}
.pendiente-item.hecho { opacity: .5; }
.pendiente-prioridad {
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 3px; white-space: nowrap; margin-top: 2px;
}
.prio-alta { background: #fef2f2; color: #dc2626; }
.prio-media { background: #fffbeb; color: #d97706; }
.prio-baja { background: #f0fdf4; color: #16a34a; }
.pendiente-desc { flex: 1; font-size: 13px; line-height: 1.4; }
.pendiente-actions { display: flex; gap: 4px; }

/* Cronología */
.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 16px; }
.timeline-item::before {
  content: ''; position: absolute; left: -17px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%; background: var(--gold); border: 2px solid var(--white);
  box-shadow: 0 0 0 2px var(--gold);
}
.timeline-fecha { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.timeline-hecho { font-size: 13px; margin-top: 2px; }
.timeline-fuente { font-size: 11px; color: var(--text-muted); font-style: italic; }

/* Riesgos */
.riesgo-item { display: flex; gap: 8px; padding: 8px 12px; border-radius: var(--radius); margin-bottom: 6px; }
.riesgo-item.alto { background: #fef2f2; border-left: 3px solid #dc2626; }
.riesgo-item.medio { background: #fffbeb; border-left: 3px solid #d97706; }
.riesgo-item.bajo { background: #f0fdf4; border-left: 3px solid #16a34a; }
.riesgo-icon { font-size: 16px; }
.riesgo-texto { font-size: 13px; line-height: 1.4; }

/* AI Action panel */
.ai-action-panel {
  background: var(--navy); border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.ai-action-title { color: var(--gold); font-size: 13px; font-weight: 700; margin-bottom: 12px; }
.ai-action-desc { color: rgba(255,255,255,.6); font-size: 12px; margin-bottom: 14px; line-height: 1.5; }
.ai-result {
  background: var(--white); border-radius: var(--radius); padding: 16px; margin-top: 14px;
  font-size: 13px; line-height: 1.6; white-space: pre-wrap; max-height: 400px; overflow-y: auto;
}
.ai-result.json-result { font-family: 'Courier New', monospace; font-size: 12px; }

/* Partes */
.partes-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.parte-card { background: var(--off-white); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.parte-rol { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 4px; }
.parte-nombre { font-size: 14px; font-weight: 600; }

/* Spinner */
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.3); border-top-color: var(--white);
  border-radius: 50%; animation: spin .7s linear infinite;
}
.spinner.dark { border-color: rgba(0,0,0,.15); border-top-color: var(--navy); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--white); border-radius: 12px; padding: 28px;
  width: 100%; max-width: 500px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-title { font-size: 18px; font-weight: 700; color: var(--navy); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* Toast */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--navy); color: var(--white); padding: 10px 16px;
  border-radius: var(--radius); font-size: 13px; box-shadow: var(--shadow);
  animation: slideIn .2s ease; max-width: 320px;
}
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; cursor: pointer; transition: border-color .15s;
}
.upload-zone:hover, .upload-zone.drag { border-color: var(--gold); background: #fffbeb; }
.upload-zone p { color: var(--text-muted); font-size: 13px; }
.upload-zone input { display: none; }

/* Section divider */
.section-title {
  font-size: 12px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 12px; margin-top: 20px;
}
.section-title:first-child { margin-top: 0; }

/* Chip */
.chip {
  display: inline-block; font-size: 11px; padding: 3px 8px;
  border-radius: 12px; font-weight: 600; background: var(--off-white);
  color: var(--text-muted); border: 1px solid var(--border);
}

/* Empty state */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 36px; margin-bottom: 8px; }
.empty-state p { font-size: 13px; }

/* Select redact */
.redact-select-group { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.redact-option {
  padding: 8px 14px; border: 1.5px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-size: 12px; font-weight: 600; background: var(--white);
  transition: all .15s;
}
.redact-option:hover { border-color: var(--navy); }
.redact-option.selected { border-color: var(--gold); background: #fffbeb; color: var(--navy); }
