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

:root {
  --sidebar:      #0a1628;
  --accent:       #2563EB;
  --accent-hover: #1d4ed8;
  --accent-light: rgba(37,99,235,.10);
  --bg:           #f8fafc;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #0f172a;
  --text-muted:   #94a3b8;
  --danger:       #dc2626;
  --warning:      #d97706;
  --ok:           #059669;
  --excellent:    #15803d;
  --sidebar-w:    220px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }

.hidden { display: none !important; }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }
#login-screen .error { color: #fca5a5; }

/* ── Login ─────────────────────────────── */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(145deg, #0a1628 0%, #0f2d52 60%, #0a1628 100%); }
.login-card { background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.10); border-radius: 20px; padding: 44px 40px; width: 360px; box-shadow: 0 24px 60px rgba(0,0,0,.4); text-align: center; -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); }
.login-logo { margin-bottom: 20px; }
.login-logo img { width: 160px; }
.login-card h1 { display: none; }
.login-sub { color: rgba(255,255,255,.45); margin-bottom: 28px; font-size: 14px; }
.login-card input { display: block; width: 100%; padding: 13px 16px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: 10px; font-size: 14px; color: white; outline: none; margin-bottom: 10px; transition: border-color .2s, box-shadow .2s; }
.login-card input::placeholder { color: rgba(255,255,255,.35); }
.login-card input:focus { border-color: var(--accent); background: rgba(37,99,235,.12); box-shadow: 0 0 0 3px rgba(37,99,235,.25); }
.login-card button { width: 100%; padding: 14px; background: var(--accent); color: white; border: none; border-radius: 10px; font-size: 15px; font-weight: 700; cursor: pointer; box-shadow: 0 4px 16px rgba(37,99,235,.4); margin-top: 6px; transition: background .2s; letter-spacing: .3px; }
.login-card button:hover { background: var(--accent-hover); }

/* ── Layout ─────────────────────────────── */
#main-app { display: flex; min-height: 100vh; }
#sidebar { width: var(--sidebar-w); background: var(--sidebar); color: white; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; }
.sidebar-logo { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.07); }
.sidebar-logo img { width: 140px; display: block; }
.sidebar-logo-sub { font-size: 10px; letter-spacing: 1px; color: rgba(255,255,255,.35); text-transform: uppercase; margin-top: 5px; }
.nav-links { list-style: none; padding: 10px 0; flex: 1; }
.nav-links li a { display: flex; align-items: center; gap: 9px; padding: 11px 18px; color: rgba(255,255,255,.5); text-decoration: none; font-size: 13px; font-weight: 500; transition: all .15s; border-left: 3px solid transparent; }
.nav-links li a:hover, .nav-links li a.active, .nav-links li a:focus-visible { color: white; background: rgba(37,99,235,.18); border-left-color: var(--accent); outline: none; }
.nav-links li a svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.nav-links li a.active svg, .nav-links li a:hover svg { opacity: 1; }
.sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.07); }
.user-name { display: block; font-size: 12px; font-weight: 700; color: white; }
.user-rol { display: block; font-size: 11px; color: rgba(255,255,255,.4); margin-bottom: 10px; text-transform: capitalize; }
.btn-logout { background: transparent; border: 1px solid rgba(255,255,255,.15); color: rgba(255,255,255,.5); padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 12px; width: 100%; transition: all .2s; }
.btn-logout:hover { background: rgba(255,255,255,.06); color: white; }
.btn-logout:focus-visible { outline: 2px solid rgba(255,255,255,.5); outline-offset: 2px; }
#content { margin-left: var(--sidebar-w); flex: 1; padding: 32px; max-width: calc(100vw - var(--sidebar-w)); }

/* ── Componentes base ─────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-title { font-size: 20px; font-weight: 800; color: var(--text); letter-spacing: -.3px; }
.btn { padding: 9px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; transition: all .2s; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: white; box-shadow: 0 2px 8px rgba(37,99,235,.3); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: #334155; border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.card { background: var(--surface); border-radius: 12px; padding: 24px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border: 1px solid var(--border); margin-bottom: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 14px; background: var(--bg); font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-critico { background: #fee2e2; color: var(--danger); }
.badge-en_curso { background: #e0f2fe; color: #0369a1; }
.badge-finalizada { background: #dcfce7; color: var(--ok); }
.badge-excelente { background: #dcfce7; color: var(--excellent); }
.badge-bueno { background: #dbeafe; color: #1d4ed8; }
.badge-aceptable { background: #fef9c3; color: #854d0e; }
.badge-no_conforme { background: #fee2e2; color: #b91c1c; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; }
.form-group input:not([type=checkbox]):not([type=radio]), .form-group select, .form-group textarea { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; transition: border-color .2s, box-shadow .2s; background: var(--surface); }
.form-group input:not([type=checkbox]):not([type=radio]):focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Avatar ──────────────────────────────── */
.avatar { width: 32px; height: 32px; border-radius: 50%; color: white; font-weight: 800; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.name-cell { display: flex; align-items: center; gap: 10px; }

/* ── Checkbox group ─────────────────────── */
.checkbox-group { display: flex; flex-direction: column; gap: 4px; }
.form-group .checkbox-option { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text); text-transform: none; letter-spacing: 0; transition: all .15s; margin-bottom: 0; }
.form-group .checkbox-option:hover { border-color: var(--accent); background: #f8fafc; }
.form-group .checkbox-option input[type=checkbox] { width: 18px; height: 18px; flex: 0 0 auto; accent-color: var(--accent); cursor: pointer; margin: 0; }
.form-group .checkbox-option:has(input:checked) { border-color: var(--accent); background: #eff6ff; color: var(--text); font-weight: 600; }

/* ── Evaluación ─────────────────────────── */
.categoria-section { border-left: 4px solid var(--accent); padding: 16px 20px; margin-bottom: 20px; background: var(--surface); border-radius: 0 10px 10px 0; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.categoria-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.categoria-header h3 { font-size: 15px; font-weight: 700; color: var(--text); }
.cat-peso { font-size: 12px; color: var(--text-muted); background: var(--bg); padding: 2px 8px; border-radius: 10px; }
.item-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.item-row:last-child { border-bottom: none; }
.item-label { font-size: 13px; color: var(--text); margin-bottom: 10px; display: flex; align-items: flex-start; gap: 8px; line-height: 1.4; }
.item-id { font-weight: 700; color: var(--text); min-width: 32px; }
.ratings-row { display: flex; gap: 8px; flex-wrap: wrap; }
.rating-btn { position: relative; }
.rating-btn input[type=radio] { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; opacity: 0; }
.rating-btn label { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 8px; cursor: pointer; border: 2px solid var(--border); font-weight: 700; font-size: 18px; transition: all .15s; background: var(--surface); }
.rating-btn label small { font-size: 10px; font-weight: 600; text-align: center; line-height: 1.1; margin-top: 2px; }
.rating-btn input:checked + label { border-color: transparent; color: white; transform: scale(1.08); }
.rating-1 label { color: #c0392b; border-color: #f5b7b1; }
.rating-1 input:checked + label { background: #c0392b; }
.rating-2 label { color: #d35400; border-color: #f5cba7; }
.rating-2 input:checked + label { background: #d35400; }
.rating-3 label { color: #b7950b; border-color: #fdebd0; }
.rating-3 input:checked + label { background: #d4ac0d; }
.rating-4 label { color: #1e8449; border-color: #a9dfbf; }
.rating-4 input:checked + label { background: #1e8449; }
.rating-5 label { color: #145a32; border-color: #82e0aa; }
.rating-5 input:checked + label { background: #145a32; }
.descriptor-panel { margin: 8px 0; padding: 10px 14px; background: var(--bg); border-radius: 8px; font-size: 13px; color: var(--text); border-left: 3px solid var(--accent); line-height: 1.5; }
.obs-field { margin-top: 8px; }
.obs-field textarea { width: 100%; padding: 8px 10px; border: 1.5px solid #f5b7b1; border-radius: 6px; font-size: 13px; resize: vertical; background: #fdf8f8; }

/* ── KPI Cards ─────────────────────────── */
.kpi-card { background: var(--surface); border-radius: 12px; padding: 20px; text-align: center; border: 1px solid var(--border); }
.kpi-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 8px; }
.kpi-value { font-size: 28px; font-weight: 900; color: var(--text); }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.delta-positive { color: var(--ok); }
.delta-negative { color: var(--danger); }
.clasificacion-badge { display: inline-block; padding: 6px 16px; border-radius: 20px; font-weight: 700; font-size: 14px; }

/* ── Comparativa ─────────────────────────── */
.comparativa-table td.mejora { color: var(--ok); font-weight: 600; }
.comparativa-table td.retrocede { color: var(--danger); font-weight: 600; }
.comparativa-table td.sin-cambio { color: var(--text-muted); }

/* ── Modal ─────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-box { width: 480px; max-width: 96vw; max-height: 90vh; overflow-y: auto; }

/* ── Topbar móvil (oculto en desktop) ───── */
#topbar { display: none; position: fixed; top: 0; left: 0; right: 0; height: 56px; background: var(--sidebar); color: white; align-items: center; gap: 14px; padding: 0 16px; z-index: 110; }
#menu-toggle { background: transparent; border: none; color: white; font-size: 24px; line-height: 1; cursor: pointer; padding: 4px 8px; }
.topbar-logo img { height: 28px; display: block; }
#sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 99; }

@media (max-width: 768px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }

  #topbar { display: flex; }
  #sidebar { transform: translateX(-100%); transition: transform .25s ease; box-shadow: 2px 0 16px rgba(0,0,0,.2); }
  #main-app.sidebar-open #sidebar { transform: translateX(0); }
  #main-app.sidebar-open #sidebar-overlay { display: block; }

  #content { margin-left: 0; max-width: 100vw; padding: 16px; padding-top: 72px; }

  .page-header { flex-wrap: wrap; gap: 12px; }
  .page-title { font-size: 18px; }

  .card > table, .card > div > table { display: block; overflow-x: auto; white-space: nowrap; }

  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; justify-content: center; }
  .modal-box { width: 100%; }
}

@media (max-width: 420px) {
  .grid-4 { grid-template-columns: 1fr; }
}
