:root {
  --navy: #0F172A;
  --navy-soft: #1E293B;
  --primary: #1B365D;
  --sky: #0284C7;
  --sky-light: #E0F2FE;
  --olive: #D6E3BC;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --text: #0F172A;
  --muted: #64748B;
  --success: #16A34A;
  --warning: #D97706;
  --danger: #DC2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--sky); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #F1F5F9; padding: 2px 6px; border-radius: 5px; font-size: 0.84em; color: #334155; }

/* AUTH */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top right, #0369A1 0%, #0F172A 65%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.28);
}
.auth-header { text-align: center; margin-bottom: 20px; }
.auth-logo { width: 96px; height: 96px; object-fit: contain; display: block; margin: 0 auto 10px; }
.auth-header h1 { font-size: 1.25rem; margin: 10px 0 4px; color: var(--navy); font-weight: 700; }
.auth-header p { margin: 0; font-size: 0.82rem; color: var(--muted); }
.brand-pill {
  display: inline-block;
  background: var(--sky-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 999px;
}

/* LAYOUT SHELL */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: var(--navy);
  color: #E2E8F0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}
.sidebar-brand { padding: 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); text-align: center; }
.sidebar-logo { width: 56px; height: 56px; background: #FFF; padding: 4px; border-radius: 50%; object-fit: contain; display: block; margin: 0 auto 8px; }
.sidebar-brand .inst { font-size: 0.74rem; color: #CBD5E1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav { padding: 12px 10px; flex: 1; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #CBD5E1;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.07); color: #FFF; text-decoration: none; }
.nav-link.active { background: var(--sky); color: #FFF; font-weight: 600; }
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.9; }

.sidebar-footer { padding: 12px 14px; border-top: 1px solid rgba(255, 255, 255, 0.08); display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(2, 132, 199, 0.25);
  color: #7DD3FC;
  font-weight: 700;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-user-meta { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 0.82rem; font-weight: 600; color: #FFF; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 0.7rem; color: #94A3B8; }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title { font-size: 1rem; font-weight: 700; color: var(--navy); margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-divider { width: 1px; height: 22px; background: var(--border); }
.topbar-user { display: flex; align-items: center; gap: 8px; }
.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sky-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.76rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.topbar-user-meta { line-height: 1.2; }
.topbar-user-name { font-size: 0.82rem; font-weight: 700; color: var(--navy); white-space: nowrap; }
.topbar-user-role { font-size: 0.7rem; color: var(--muted); }
.mobile-menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: 7px; padding: 5px 7px; cursor: pointer; color: var(--navy); }
.content-wrap { padding: 22px 24px; max-width: 1240px; width: 100%; margin: 0 auto; }

/* CARDS & GRIDS */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card-section { background: #F8FAFC; border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.card-header-flex { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card-title { font-size: 0.98rem; font-weight: 700; color: var(--navy); margin: 0; }

.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; align-items: center; justify-content: space-between; }
.kpi-card.sky { border-top: 3px solid var(--sky); }
.kpi-card.amber { border-top: 3px solid var(--warning); }
.kpi-card.green { border-top: 3px solid var(--success); }
.kpi-card:first-child { border-top: 3px solid var(--primary); }
.kpi-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 1.65rem; font-weight: 800; color: var(--navy); line-height: 1.1; }

/* META STRIP & MOMENT CARDS */
.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 24px;
  padding: 10px 14px;
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.84rem;
}
.meta-item { display: flex; align-items: center; gap: 6px; }
.meta-label { color: var(--muted); font-weight: 600; }
.meta-val { color: var(--navy); font-weight: 700; }

.moment-card { background: #FFF; border: 1px solid var(--border); border-left-width: 4px; border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; }
.moment-inicio { border-left-color: #3B82F6; }
.moment-desarrollo { border-left-color: #10B981; }
.moment-cierre { border-left-color: #6366F1; }
.moment-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.moment-tag { font-size: 0.8rem; font-weight: 800; letter-spacing: 0.04em; color: var(--navy); }

.clean-details { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; background: #F8FAFC; margin-top: 10px; }
.clean-details summary { font-size: 0.84rem; font-weight: 600; color: var(--primary); cursor: pointer; user-select: none; }
.clean-details[open] summary { margin-bottom: 10px; }

/* FORMS */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 0.82rem; font-weight: 600; color: #334155; margin-bottom: 5px; }
.form-control, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: inherit;
  background: #FFF;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--sky); box-shadow: 0 0 0 3px rgba(2,132,199,0.12); }
.form-textarea { min-height: 84px; resize: vertical; }
.form-hint { font-size: 0.74rem; color: var(--muted); margin-top: 3px; }

/* FILTER BAR */
.filter-bar { display: grid; grid-template-columns: 1.2fr 1fr 1.4fr auto; gap: 10px; margin-bottom: 16px; align-items: center; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  font-family: inherit;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(0.95); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; border-radius: 6px; }
.btn-icon { width: 28px; height: 28px; padding: 0; border-radius: 6px; font-size: 0.95rem; line-height: 1; }
.btn-primary { background: var(--primary); color: #FFF; }
.btn-sky { background: var(--sky); color: #FFF; }
.btn-success { background: var(--success); color: #FFF; }
.btn-warning { background: var(--warning); color: #FFF; }
.btn-danger { background: var(--danger); color: #FFF; }
.btn-outline { background: #FFF; border-color: var(--border-strong); color: #334155; }
.btn-outline:hover { background: #F8FAFC; }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: #F1F5F9; color: var(--navy); filter: none; }
.btn-ghost-dark { background: rgba(255,255,255,0.08); color: #CBD5E1; border-color: transparent; }
.btn-ghost-dark:hover { background: rgba(255,255,255,0.16); color: #FFF; filter: none; }

/* ALERTS */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 0.86rem; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: #DCFCE7; color: #166534; border-color: #86EFAC; }
.alert-danger { background: #FEE2E2; color: #991B1B; border-color: #FCA5A5; }
.alert-warning { background: #FEF3C7; color: #92400E; border-color: #FCD34D; }
.alert-info { background: #E0F2FE; color: #075985; border-color: #7DD3FC; }

/* BADGES */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 0.73rem; font-weight: 700; white-space: nowrap; }
.badge-borrador { background: #F1F5F9; color: #475569; }
.badge-revision { background: #DBEAFE; color: #1E40AF; }
.badge-observado { background: #FEF3C7; color: #92400E; }
.badge-aprobado { background: #DCFCE7; color: #166534; }
.badge-firmado { background: #065F46; color: #ECFDF5; }

/* TABLES */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th { text-align: left; color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 11px 12px; border-bottom: 1px solid #F1F5F9; vertical-align: middle; }
.data-table tbody tr:hover td { background: #F8FAFC; }
.actions-row { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }

/* STEPPER */
.stepper { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 16px; }
.step-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.step-item.active { border-color: var(--sky); background: #F0F9FF; }
.step-item.completed { border-color: #BBF7D0; background: #F0FDF4; }
.step-num { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.78rem; background: #E2E8F0; color: #475569; flex-shrink: 0; }
.step-item.active .step-num { background: var(--sky); color: #FFF; }
.step-item.completed .step-num { background: var(--success); color: #FFF; }
.step-label { font-size: 0.8rem; font-weight: 600; color: var(--navy); }
.wizard-panel { display: none; }
.wizard-panel.active { display: block; }

/* TIME BUDGET WIDGET */
.time-widget { background: #F8FAFC; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; }
.time-widget-top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.time-bar-track { width: 100%; height: 8px; background: #E2E8F0; border-radius: 999px; overflow: hidden; display: flex; margin: 9px 0; }
.time-bar-seg { height: 100%; transition: width 0.25s ease; }
.seg-inicio { background: #3B82F6; }
.seg-desarrollo { background: #10B981; }
.seg-cierre { background: #6366F1; }
.time-summary-inline { display: flex; flex-wrap: wrap; gap: 16px; font-size: 0.8rem; color: var(--muted); }

/* WEEK STRIP (DASHBOARD) */
.week-strip { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 6px; }
.week-pill {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 2px;
  text-align: center;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  background: #F8FAFC;
}
.week-pill.state-BORRADOR { background: #F1F5F9; border-color: #94A3B8; color: #334155; }
.week-pill.state-EN_REVISION { background: #DBEAFE; border-color: #60A5FA; color: #1E40AF; }
.week-pill.state-OBSERVADO { background: #FEF3C7; border-color: #FBBF24; color: #92400E; }
.week-pill.state-APROBADO,
.week-pill.state-FIRMADO { background: #DCFCE7; border-color: #4ADE80; color: #166534; }

/* MODALS */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); display: none; align-items: center; justify-content: center; padding: 18px; z-index: 60; }
.modal-backdrop.open { display: flex; }
.modal-dialog { background: var(--surface); border-radius: 12px; width: 100%; max-width: 600px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 25px 50px rgba(0,0,0,0.25); overflow: hidden; }
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; font-size: 0.96rem; color: var(--navy); }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.35rem; cursor: pointer; line-height: 1; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: #F8FAFC; }

/* TOAST */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 90; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.toast { padding: 10px 14px; border-radius: 8px; color: #FFF; font-size: 0.84rem; font-weight: 600; box-shadow: 0 10px 25px rgba(0,0,0,0.2); animation: slideIn 0.2s ease; }
.toast-success { background: #15803D; }
.toast-error { background: #B91C1C; }
.toast-info { background: #0369A1; }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* HOJA OFICIAL A4 (PREVIEW & PRINT) */
.a4-sheet { background: #FFF; max-width: 820px; margin: 0 auto; padding: 26px 32px; border: 1px solid #CBD5E1; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08); font-family: Arial, Calibri, sans-serif; color: #111827; font-size: 11px; line-height: 1.35; }
.doc-banner { width: 100%; max-height: 95px; object-fit: contain; display: block; margin: 0 auto 6px; }
.doc-inst-title { text-align: center; font-weight: 700; font-size: 11px; line-height: 1.3; }
.doc-session-title { text-align: center; font-weight: 700; font-size: 13px; margin: 6px 0 10px; }
.doc-sec-title { font-weight: 700; font-size: 11px; margin: 10px 0 4px; text-transform: uppercase; }
.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; table-layout: fixed; }
.doc-table th, .doc-table td { border: 1px solid #334155; padding: 4px 6px; vertical-align: middle; font-size: 10.5px; word-wrap: break-word; }
.doc-table .doc-th { background: var(--olive); font-weight: 700; text-align: left; }
.doc-table .doc-th-center { background: var(--olive); font-weight: 700; text-align: center; }
.doc-bib-list { margin: 4px 0 0 18px; padding: 0; font-size: 10.5px; }
.doc-bib-list li { margin-bottom: 3px; }
.doc-signatures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 38px; text-align: center; font-size: 10.5px; }
.doc-sign-line { border-top: 1px solid #1E293B; padding-top: 5px; font-weight: 700; }
.doc-sign-meta { font-size: 9.5px; color: #334155; margin-top: 2px; }
.doc-qr-box { margin-top: 14px; padding-top: 10px; border-top: 1px dashed #CBD5E1; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 9.5px; color: #475569; }

/* DEMO CREDENTIALS */
.demo-list { margin: 8px 0 0 18px; padding: 0; font-size: 0.84rem; }
.demo-list li { margin-bottom: 4px; }
.demo-quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }

@media (max-width: 960px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left 0.2s; }
  .sidebar.open { left: 0; }
  .mobile-menu-btn { display: inline-flex; }
  .grid-4, .grid-3, .grid-2, .stepper, .filter-bar { grid-template-columns: 1fr; }
  .week-strip { grid-template-columns: repeat(8, 1fr); }
  .demo-quick-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .topbar-user-meta, .topbar-divider { display: none; }
}
