:root {
  --bg: #eef2fb;
  --bg-grad-1: #e7ecfaff;
  --bg-grad-2: #f4f7fe;
  --surface: #ffffff;
  --surface-2: #f5f7fc;
  --surface-3: #eef1f8;
  --border: #e3e8f2;
  --border-strong: #d4dbe9;
  --text: #1a2236;
  --text-soft: #475069;
  --muted: #8590a8;
  --accent: #4f46e5;
  --accent-soft: #eef0fe;
  --accent-2: #0ea5e9;
  --green: #10b981;
  --green-soft: #e7f8f1;
  --amber: #f59e0b;
  --amber-soft: #fef4e2;
  --red: #ef4444;
  --red-soft: #fdeaea;
  --pink: #ec4899;
  --pink-soft: #fdebf5;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 30, 60, .04), 0 1px 3px rgba(20, 30, 60, .06);
  --shadow: 0 4px 14px rgba(30, 41, 80, .07);
  --shadow-lg: 0 12px 36px rgba(30, 41, 80, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background:
    radial-gradient(900px 500px at 88% -8%, #dfe6fb 0%, transparent 60%),
    radial-gradient(700px 500px at 0% 100%, #e6f6fb 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-grad-2), var(--bg));
  background-attachment: fixed;
  color: var(--text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* SIDEBAR */
.sidebar {
  width: 256px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 24px; }
.logo {
  width: 44px; height: 44px; border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-weight: 800; font-size: 16px; color: #fff;
  box-shadow: 0 6px 16px rgba(79, 70, 229, .35);
}
.brand-name { font-weight: 800; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  background: transparent; border: none; color: var(--text-soft);
  font: inherit; font-size: 14px; font-weight: 500;
  padding: 11px 13px; border-radius: 11px; cursor: pointer;
  text-align: left; transition: all .15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .7; transition: opacity .15s; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item:hover svg { opacity: 1; }
.nav-item.active {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff; font-weight: 600;
  box-shadow: 0 6px 16px rgba(79, 70, 229, .3);
}
.nav-item.active svg { opacity: 1; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 14px; }
.cache-info { font-size: 11px; color: var(--muted); margin-bottom: 8px; padding: 0 4px; }
.btn-refresh {
  width: 100%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border: none;
  padding: 11px; border-radius: 11px; font: inherit; font-weight: 600;
  cursor: pointer; transition: all .15s; box-shadow: 0 6px 16px rgba(79, 70, 229, .28);
}
.btn-refresh:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(79, 70, 229, .34); }
.btn-refresh:disabled { opacity: .6; cursor: default; transform: none; }

/* MAIN */
.main { flex: 1; margin-left: 256px; padding: 28px 34px 64px; max-width: 1560px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; gap: 20px; }
.topbar h1 { font-size: 25px; font-weight: 800; letter-spacing: -.02em; }
.topbar p { font-size: 13px; margin-top: 3px; color: var(--muted); }
.search {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 11px 15px; border-radius: 11px; font: inherit; font-size: 13px; min-width: 260px;
  box-shadow: var(--shadow-sm);
}
.search::placeholder { color: var(--muted); }
.search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* LOADER / ERROR */
.loader { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 80px; color: var(--muted); }
.spinner {
  width: 42px; height: 42px; border: 4px solid var(--surface-3);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: var(--red-soft); border: 1px solid var(--red); color: #b91c1c; padding: 16px; border-radius: 12px; }

/* TABS — separación vertical uniforme entre paneles */
.tab { display: flex; flex-direction: column; gap: 20px; }
.tab > * { margin-bottom: 0 !important; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); gap: 16px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 19px 20px; position: relative; overflow: hidden; box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); border-radius: 4px; }
.kpi.green::before { background: var(--green); }
.kpi.amber::before { background: var(--amber); }
.kpi.cyan::before { background: var(--accent-2); }
.kpi.pink::before { background: var(--pink); }
.kpi-label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 27px; font-weight: 800; margin-top: 9px; letter-spacing: -.02em; color: var(--text); }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 5px; }
.kpi.green .kpi-value { color: var(--green); }
.kpi.amber .kpi-value { color: var(--amber); }
.kpi.cyan .kpi-value { color: var(--accent-2); }
.kpi.pink .kpi-value { color: var(--pink); }

/* CARDS / GRID */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card h3 { font-size: 14px; font-weight: 700; margin-bottom: 16px; color: var(--text); letter-spacing: -.01em; }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card canvas { max-height: 300px; }

/* FILTERS */
.filters { display: flex; gap: 11px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filters select, .filters input {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: 11px; font: inherit; font-size: 13px; cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.filters select:focus, .filters input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* TABLES */
.table-wrap { overflow-x: auto; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 12px 13px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; background: var(--surface-2); }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--text-soft); border: 1px solid var(--border); }
.pill.green { color: #047857; background: var(--green-soft); border-color: transparent; }
.pill.amber { color: #b45309; background: var(--amber-soft); border-color: transparent; }
.pill.red { color: #b91c1c; background: var(--red-soft); border-color: transparent; }
.rank { font-weight: 800; color: var(--accent); }
.bar-cell { min-width: 120px; }
.bar { height: 7px; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* PAGINACIÓN */
.pager { display: flex; align-items: center; gap: 6px; padding: 16px 4px 2px; flex-wrap: wrap; }
.pager .pginfo { color: var(--muted); font-size: 12px; margin-right: auto; }
.pager button {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-soft);
  min-width: 34px; height: 33px; padding: 0 11px; border-radius: 9px;
  font: inherit; font-size: 13px; cursor: pointer; transition: all .12s; box-shadow: var(--shadow-sm);
}
.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pager button:disabled { opacity: .45; cursor: default; }
.pager button.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pager .pgsize { background: var(--surface); border: 1px solid var(--border); color: var(--text); height: 33px; border-radius: 9px; padding: 0 8px; font: inherit; font-size: 12px; cursor: pointer; }
.pager .ellipsis { color: var(--muted); padding: 0 2px; }

/* DATE RANGE */
.daterange { margin-bottom: 16px; display: flex; flex-direction: column; gap: 12px; }
.dr-presets { display: flex; gap: 7px; flex-wrap: wrap; }
.dr-presets button { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-soft); padding: 7px 14px; border-radius: 999px; font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; transition: all .12s; }
.dr-presets button:hover { color: var(--accent); border-color: var(--accent); }
.dr-presets button.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; font-weight: 600; box-shadow: 0 4px 12px rgba(79, 70, 229, .25); }
.dr-custom { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.dr-custom label, .dr-inline { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; }
.dr-custom input[type=date], .dr-custom select, .dr-inline input[type=date] {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 8px 11px; border-radius: 9px; font: inherit; font-size: 13px;
}
.dr-custom input:focus, .dr-custom select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* PAYROLL TOOLBAR + BOTONES */
.payroll-toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.btn-ghost { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 10px 15px; border-radius: 11px; font: inherit; font-weight: 500; cursor: pointer; transition: all .12s; box-shadow: var(--shadow-sm); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.row-actions button { background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); width: 31px; height: 29px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.row-actions button:hover { color: var(--accent); border-color: var(--accent); }
.row-actions button.ok:hover { color: var(--green); border-color: var(--green); }
.row-actions button.no:hover { color: var(--red); border-color: var(--red); }

/* SEMANA NAV (payroll) */
.week-nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.week-label { font-size: 14px; color: var(--text); font-weight: 700; }
.week-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.dr-inline input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(26, 34, 54, .35); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 50; padding: 24px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; width: min(820px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 22px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-soft); font-weight: 500; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  padding: 9px 11px; border-radius: 9px; font: inherit; font-size: 13px;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-section { grid-column: 1 / -1; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-top: 4px; }
.form-calc { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: flex; gap: 22px; flex-wrap: wrap; font-size: 13px; color: var(--text-soft); }
.form-calc b { color: var(--green); font-size: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr 1fr; } }

/* LOGIN */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 34px; width: min(400px, 100%); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-title { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.login-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-soft); font-weight: 500; margin-bottom: 14px; }
.login-field input { background: var(--surface); border: 1px solid var(--border-strong); color: var(--text); padding: 11px 13px; border-radius: 10px; font: inherit; font-size: 14px; }
.login-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* USUARIO / LOGOUT (sidebar) */
.user-box { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; margin-bottom: 10px; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.user-info { min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--muted); }
.btn-logout { background: var(--surface); border: 1px solid var(--border); color: var(--text-soft); padding: 9px; border-radius: 10px; font: inherit; font-size: 13px; cursor: pointer; width: 100%; transition: all .12s; }
.btn-logout:hover { border-color: var(--red); color: var(--red); }

/* READYMODE STATUS */
.rm-status { padding: 12px 16px; border-radius: 12px; font-size: 13px; margin-bottom: 14px; border: 1px solid var(--border); background: var(--surface); }
.rm-status.warn { background: var(--amber-soft); border-color: transparent; color: #92600a; }
.rm-status.ok { background: var(--green-soft); border-color: transparent; color: #047857; }

/* DROPZONE (carga de reportes) */
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); padding: 26px; text-align: center; margin-bottom: 14px; transition: all .15s; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 30px; }
.dz-link { background: none; border: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; padding: 0; }
#prodUploadMsg { margin-top: 4px; }
#prodUploadMsg.ok { color: var(--green); }
#prodUploadMsg.err { color: var(--red); }

/* VIDEOS DE ENTRENAMIENTO */
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.video-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.video-frame { position: relative; aspect-ratio: 16/9; background: #000; }
.video-frame iframe, .video-frame video { width: 100%; height: 100%; border: 0; display: block; }
.video-link { display: grid; place-items: center; aspect-ratio: 16/9; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 34px; text-decoration: none; }
.video-body { padding: 14px 16px; }
.video-body h4 { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.video-body p { font-size: 12px; color: var(--muted); line-height: 1.45; }
.video-del { margin-top: 10px; }

/* PROMEDIOS (agente) */
.avg-grid { display: flex; flex-direction: column; gap: 8px; }
.avg-head, .avg-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 8px; align-items: center; }
.avg-head { order: -1; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.avg-head span:first-child { visibility: hidden; }
.avg-row span { font-size: 13px; color: var(--text-soft); }
.avg-row b { text-align: center; font-variant-numeric: tabular-nums; font-size: 15px; }

/* PLACEHOLDER (agente, próximas fases) */
.card.placeholder { text-align: center; padding: 48px 24px; }
.card.placeholder h3 { font-size: 17px; margin-bottom: 12px; }
.card.placeholder p { max-width: 640px; margin: 0 auto; line-height: 1.55; }
