:root {
  --primary: #0047FF;
  --primary-dark: #0033CC;
  --primary-light: #3B82F6;
  --primary-gradient: linear-gradient(135deg, #3B82F6, #0033CC);
  --sidebar-bg: #07102B;
  --sidebar-hover: #0D1F4A;
  --sidebar-active: #0047FF;
  --surface: #FFFFFF;
  --surface-2: #F5F7FF;
  --surface-3: #EEF2FF;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --info: #3B82F6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 10px 40px rgba(0,0,0,.1);
  --shadow-lg: 0 20px 60px rgba(0,71,255,.15);
  --transition: .2s cubic-bezier(.4,0,.2,1);
}

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

html { font-size: 15px; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--surface-2);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
a { color: var(--primary); text-decoration: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: 4px;
  font-size: .875rem; font-weight: 600; cursor: pointer;
  border: none; transition: var(--transition); text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--surface-3); color: var(--primary); }
.btn-secondary:hover { filter: brightness(.96); }
.btn-ghost { background: var(--surface-3); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost.btn-icon { background: transparent; border: none; }
.btn-ghost.btn-icon:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-sm { padding: 6px 14px; font-size: .8rem; }
.btn-icon { padding: 8px; border-radius: 4px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Inputs ── */
.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label { font-size: .8rem; font-weight: 600; color: var(--text-secondary); letter-spacing: .4px; }
.input-hint { font-size: .72rem; color: var(--text-muted); line-height: 1.4; }
.input, select.input, textarea.input {
  padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: .9rem; color: var(--text);
  background: var(--surface); transition: var(--transition); outline: none; width: 100%;
  font-family: inherit;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,71,255,.1); }
.form-fields { display: flex; flex-direction: column; gap: 18px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: .875rem; }
.checkbox-row input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ── Form page (crear/editar de página completa) ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid .span2 { grid-column: span 2; }
.form-page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ── Cards ── */
.card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.card + .card { margin-top: 16px; }

/* ── Card grid (listados en tarjetas) ── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card-grid > .card { margin-top: 0; }
.card-clickable { cursor: pointer; transition: border-color .15s; }
.card-clickable:hover { border-color: var(--primary); }

/* ── Stats grid (dashboard) ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat-card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.stat-card .stat-icon { width: 40px; height: 40px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-card .stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; }

/* ── Badge ── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-blue { background: #EEF2FF; color: var(--primary); }
.badge-green { background: #ECFDF5; color: var(--success); }
.badge-yellow { background: #FFFBEB; color: var(--warning); }
.badge-red { background: #FEF2F2; color: var(--danger); }
.badge-gray { background: var(--surface-3); color: var(--text-secondary); }
.badge-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ── Avatar ── */
.avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .8rem; flex-shrink: 0; background: var(--primary-gradient); color: #fff; }
.avatar-lg { width: 44px; height: 44px; font-size: .95rem; }
.avatar-sm { width: 28px; height: 28px; font-size: .7rem; }

/* ── App shell / sidebar ── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--sidebar-bg); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-logo { padding: 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.07); flex-shrink: 0; }
.sidebar-logo-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--primary-gradient); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; flex-shrink: 0; }
.sidebar-logo-text { font-size: 1.05rem; font-weight: 800; color: #fff; white-space: nowrap; overflow: hidden; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 8px; }
.nav-section-label { padding: 8px 10px 4px; font-size: .65rem; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: rgba(255,255,255,.3); }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); color: rgba(255,255,255,.6); text-decoration: none; font-size: .8125rem; font-weight: 500; cursor: pointer; transition: var(--transition); white-space: nowrap; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: 0 4px 12px rgba(0,71,255,.4); }
.nav-item svg { flex-shrink: 0; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid rgba(255,255,255,.07); position: relative; }
.user-pill { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition); }
.user-pill:hover { background: var(--sidebar-hover); }
.user-info { overflow: hidden; flex: 1; }
.user-info .name { font-size: .85rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role { font-size: .72rem; color: rgba(255,255,255,.4); white-space: nowrap; }
.user-menu { position: absolute; bottom: calc(100% + 6px); left: 8px; right: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: 0 -4px 16px rgba(0,0,0,.15); z-index: 200; overflow: hidden; }
.user-menu-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; font-size: .875rem; color: var(--text); cursor: pointer; transition: background .15s; }
.user-menu-item:hover { background: var(--surface-3); }
.user-menu-danger { color: #ef4444 !important; }
.user-menu-danger:hover { background: rgba(239,68,68,.08) !important; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { height: 60px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 24px; gap: 16px; flex-shrink: 0; }
.topbar-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.topbar-spacer { flex: 1; }
.page { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Filter pills ── */
.filter-bar { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-pill { padding: 5px 14px; border-radius: 99px; font-size: .8rem; font-weight: 600; cursor: pointer; border: 1.5px solid var(--border); background: var(--surface); color: var(--text-secondary); white-space: nowrap; transition: var(--transition); }
.filter-pill:hover { border-color: var(--primary); color: var(--primary); }
.filter-pill.active { border-color: var(--primary); background: #EEF2FF; color: var(--primary); }

/* ── Tables ── */
/* `.table-wrap` solo maneja el scroll horizontal; el borde/fondo/radio los da
   `.card` (o `.table-card` si la tabla no está ya dentro de una) para que la
   barra de paginación quede dentro de la misma caja, como en OmniPRIT. */
.table-card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th { padding: 10px 16px; text-align: left; font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); color: var(--text); white-space: nowrap; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
/* Columna de acciones fija a la derecha al hacer scroll horizontal — se
   reconoce por los botones que contiene, no por ser la última columna (una
   tabla sin acciones no debe quedar con la última columna fija). */
.table-wrap thead:has(~ tbody td:last-child :is(button, .btn)) th:last-child,
.table-wrap tbody td:last-child:has(:is(button, .btn)) { position: sticky; right: 0; z-index: 2; box-shadow: -2px 0 6px rgba(0,0,0,.06); text-align: center; }
.table-wrap thead:has(~ tbody td:last-child :is(button, .btn)) th:last-child { background: var(--surface-2); }
.table-wrap tbody td:last-child:has(:is(button, .btn)) { background: var(--surface); }
.table-wrap tbody tr:hover td:last-child:has(:is(button, .btn)) { background: var(--surface-2); }
.table-wrap tbody td:last-child:has(:is(button, .btn)) > div { justify-content: center; }
.row-link { cursor: pointer; }
.row-actions { display: flex; gap: 6px; }
.empty-state { padding: 48px 24px; text-align: center; color: var(--text-muted); }

/* ── Paginación ── */
.pg-bar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--border); font-size: .8rem; color: var(--text-muted); flex-wrap: wrap; }
.pg-info { margin-right: auto; }
.pg-size { display: flex; align-items: center; gap: 6px; }
.pg-size select { padding: 3px 6px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .8rem; background: var(--surface); color: var(--text); cursor: pointer; }
.pg-nav { display: flex; align-items: center; gap: 2px; }
.pg-nav span { padding: 0 8px; font-size: .82rem; }
.pg-nav button { width: 28px; height: 28px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition); }
.pg-nav button:hover:not(:disabled) { background: var(--surface-2); }
.pg-nav button:disabled { opacity: .35; cursor: not-allowed; }

/* ── Línea de tiempo del proyecto (modal) ── */
.tl-axis { display: flex; justify-content: space-between; margin: 4px 0 12px 158px; font-size: .75rem; color: var(--text-muted); font-weight: 600; }
.tl-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.tl-label { width: 148px; flex-shrink: 0; font-size: .8rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-track { flex: 1; position: relative; height: 22px; background: var(--surface-2); border-radius: 6px; }
.tl-bar { position: absolute; top: 0; height: 100%; border-radius: 6px; min-width: 6px; }
.tl-bar.tl-completado { background: var(--success); }
.tl-bar.tl-en-curso { background: var(--primary-gradient); }
.tl-bar.tl-proximo { background: var(--text-muted); opacity: .55; }
.tl-legend { display: flex; gap: 18px; margin-top: 16px; font-size: .78rem; color: var(--text-secondary); flex-wrap: wrap; }
.tl-legend .tl-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

/* ── Progress bar ── */
.progress { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; max-width: 320px; }
.progress-fill { height: 100%; border-radius: 99px; background: var(--primary-gradient); }

/* ── Checklist ── */
.checklist { list-style: none; }
.checklist li { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.checklist li:last-child { border-bottom: none; }
.checklist input[type=checkbox] { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.checklist label { flex: 1; font-size: .9rem; cursor: pointer; }
.checklist .meta { display: block; font-size: .75rem; color: var(--text-muted); margin-top: 2px; }

/* ── Evidencias ── */
.evidence-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.evidence-card { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.evidence-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; transition: var(--transition); }
.evidence-card img:hover { transform: scale(1.03); }
.evidence-card figcaption { padding: 8px 10px; font-size: .78rem; color: var(--text-secondary); }

/* ── Comentarios ── */
.comment-list { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.comment-item { display: flex; gap: 10px; }
.comment-body { flex: 1; }
.comment-meta { font-size: .78rem; color: var(--text-muted); margin-bottom: 2px; }
.comment-text { font-size: .875rem; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; pointer-events: none; transition: var(--transition); }
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-box, .modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 28px; width: 90%; max-width: 480px; transform: translateY(12px); transition: var(--transition); text-align: center; }
.modal-overlay.open .modal-box, .modal-overlay.open .modal { transform: translateY(0); }
.modal-icon { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.modal-icon.danger { background: #FEF2F2; color: var(--danger); }
.modal-icon.info { background: #EEF2FF; color: var(--primary); }
.modal-title { font-weight: 700; margin-bottom: 6px; }
.modal-msg { color: var(--text-secondary); font-size: .9rem; margin-bottom: 20px; }
.modal-actions, .modal-footer { display: flex; justify-content: center; gap: 10px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; text-align: left; }
.modal-form { text-align: left; }
.modal-form .form-fields { margin-bottom: 20px; }

/* ── Login ── */
.login-screen { min-height: 100vh; display: flex; align-items: stretch; background: var(--surface); }
.login-left { flex: 1; background: var(--sidebar-bg); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px; position: relative; overflow: hidden; }
.login-left::before { content: ''; position: absolute; width: 600px; height: 600px; background: radial-gradient(circle, rgba(0,71,255,.25) 0%, transparent 70%); top: 50%; left: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 20px; text-align: center; position: relative; z-index: 1; }
.login-brand-mark { width: 64px; height: 64px; border-radius: 16px; background: var(--primary-gradient); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.6rem; }
.login-brand h1 { color: #fff; font-size: 2rem; font-weight: 800; }
.login-brand h1 span { color: var(--primary-light); }
.login-tagline { color: rgba(255,255,255,.5); font-size: .95rem; max-width: 340px; line-height: 1.6; }
.login-right { width: 440px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 56px; }
.login-form-wrap { width: 100%; }
.login-form-wrap h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 6px; }
.login-form-wrap p { color: var(--text-muted); font-size: .875rem; margin-bottom: 32px; }
.login-form-wrap .btn-primary { width: 100%; justify-content: center; padding: 13px; font-size: .95rem; margin-top: 8px; }
.login-error { background: #FEF2F2; border: 1px solid #FECACA; color: var(--danger); padding: 10px 14px; border-radius: var(--radius-sm); font-size: .85rem; display: none; margin-bottom: 16px; }
.login-error.show { display: block; }

/* ── Toast ── */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }
.toast { background: var(--text); color: #fff; padding: 12px 18px; border-radius: var(--radius-sm); font-size: .85rem; font-weight: 500; box-shadow: var(--shadow-md); display: flex; align-items: center; gap: 10px; animation: slideIn .3s ease; min-width: 260px; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-sm { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; vertical-align: middle; opacity: .7; }

@media (max-width: 900px) {
  .login-left { display: none; }
  .login-right { width: 100%; }
  .sidebar { width: 72px; }
  .sidebar-logo-text, .user-info, .nav-item span.nav-label { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
}
