/* === Tokens ================================================================ */
:root {
  --bg:           #F5F3EE;
  --panel:        #FFFFFF;
  --ink:          #1C1F1A;
  --muted:        #6B726A;
  --accent:       #2A6924;
  --accent-hi:    #1F5119;
  --danger:       #B53232;
  --ok:           #2A6924;
  --warn-1:       #C07A10;
  --warn-2:       #C05510;
  --line:         #E4E1D8;
  --side-fg:      #B8C8B5;
  --side-active:  #2D4229;
  --side-stripe:  #5A8C52;
  --radius-sm:    10px;
  --radius-md:    16px;
  --radius-lg:    20px;
  --ease-out:     cubic-bezier(0.23, 1, 0.32, 1);
  --dur-fast:     150ms;
  --dur-base:     200ms;
  color-scheme: light dark;
}

/* === Base ================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* === Layout ================================================================ */
.layout { display: flex; min-height: 100vh; }

/* === Sidebar =============================================================== */
.sidebar {
  width: 224px;
  background: linear-gradient(165deg, rgba(28,43,25,.94), rgba(20,32,18,.96));
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  color: var(--side-fg);
  padding: 20px 12px;
  flex-shrink: 0;
  border-right: 3px solid var(--side-stripe);
  box-shadow: inset -1px 0 0 rgba(255,255,255,.06);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand-wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 20px 8px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand-wordmark .brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--side-stripe);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.brand-wordmark .brand-name { color: #FFFFFF; }
.brand-wordmark .brand-bot { color: var(--side-stripe); }
.sidebar a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--side-fg);
  padding: 9px 12px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 14px;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.nav-icon { font-size: 14px; line-height: 1; flex-shrink: 0; width: 18px; text-align: center; }
.nav-group-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #7A8A76;
  margin: 14px 12px 4px;
}
.sidebar a:hover { background: #2D4229; color: #FFFFFF; text-decoration: none; }
.sidebar a.active {
  background: var(--side-active);
  color: #FFFFFF;
  font-weight: 600;
  border-left: 3px solid var(--side-stripe);
  padding-left: 9px;
}

/* === Main ================================================================== */
.main { flex: 1; padding: 28px 32px; min-width: 0; position: relative; }

/* === Topbar ================================================================ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.topbar-heading {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

/* === Card ================================================================== */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px;
  overflow-x: auto;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(28,43,25,.05);
  transition: box-shadow var(--dur-base) var(--ease-out);
}
.card:hover { box-shadow: 0 2px 4px rgba(0,0,0,.06), 0 6px 20px rgba(28,43,25,.08); }

/* === Tables ================================================================ */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
td { font-variant-numeric: tabular-nums; }
th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: #F9F8F4;
  border-bottom: 2px solid var(--line);
}
tbody tr:hover td { background: #F0F5EE; }
tbody tr:nth-child(even) td { background: #FAFAF6; }
tbody tr:nth-child(even):hover td { background: #EDF4EB; }

/* === Buttons =============================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 16px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn:hover { background: #F0EDE6; border-color: #C8C4BA; text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #FDF0F0; }
.btn-sm { font-size: 12px; padding: 4px 10px; min-height: 30px; }
/* Acción de fila destacada: perímetro y texto en color de marca para que resalte. */
.btn-accent { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.btn-accent:hover { background: rgba(42, 105, 36, 0.10); border-color: var(--accent-hi); color: var(--accent-hi); }
/* Volver a la pantalla anterior: fondo un poco más marcado que .btn para que resalte. */
.btn-back { background: var(--line); border-color: var(--line); }
.btn-back:hover { filter: brightness(0.94); }

/* === Forms ================================================================= */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--panel);
  color: var(--ink);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42, 105, 36, 0.12);
  outline: none;
}
.field textarea { resize: vertical; min-height: 80px; }
.field .error { color: var(--danger); font-size: 12px; margin-top: 4px; }

/* === Flash ================================================================= */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-ok    { background: #E9F5E7; color: #1F5119; border-left: 3px solid var(--ok); }
.flash-error { background: #FAEAEA; color: #8B2020; border-left: 3px solid var(--danger); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }

/* === Login ================================================================= */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(340px, 100%); }
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 16px;
  background: #FFFFFF;     /* fondo claro fijo: el logo se lee también en dark mode */
  border-radius: var(--radius-md);
}
.login-brand .login-logo-tambot { max-width: 180px; height: auto; }
.login-brand .login-logo-est { max-width: 120px; height: auto; opacity: 0.9; }

/* === Toolbar =============================================================== */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-search { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-search input {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-width: min(240px, 100%);
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.toolbar-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42, 105, 36, 0.12);
  outline: none;
}
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* === Filtro por período (barra de botones) ================================= */
.filterbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }

/* === Badges ================================================================ */
.badge    { font-size: 12px; padding: 3px 8px; border-radius: 999px; font-weight: 500; }
.badge-sm { font-size: 11px; padding: 2px 6px; }
.badge-ok    { background: #E9F5E7; color: #1F5119; }
.badge-off   { background: #F2F1ED; color: var(--muted); }
.badge-error { background: #FAEAEA; color: #8B2020; }
.badge-warn  { background: #FEF3C7; color: #7C4A10; }
.badge-l2    { background: #FFEDD5; color: #7C2C10; }

/* === Row states ============================================================ */
.row-inactive td { color: var(--muted); }
.row-stock-l1 td:first-child { border-left: 3px solid var(--warn-1); }
.row-stock-l2 td:first-child { border-left: 3px solid var(--warn-2); }
.row-stock-l3 td:first-child { border-left: 3px solid var(--danger); }
.row-cumple-hoy td:first-child { border-left: 3px solid var(--warn-1); }
.row-cumple-hoy td { font-weight: 600; }

/* === Utility =============================================================== */
.muted { color: var(--muted); font-size: 13px; }
.sort-link { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.sort-link:hover { color: var(--ink); }
.sort-arrows { display: inline-flex; flex-direction: column; line-height: 0.7; font-size: 8px; }
.sort-arrows .up, .sort-arrows .down { opacity: 0.3; }
.sort-arrows .on { opacity: 1; color: var(--accent); }

/* === Form layout =========================================================== */
.form-card   { max-width: 520px; }
.form-inline { display: inline-flex; align-items: center; }
.inline-edit { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* === KPIs ================================================================== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 20px 20px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(28,43,25,.05);
  transition: box-shadow var(--dur-base) var(--ease-out);
}
.kpi:hover { box-shadow: 0 6px 20px rgba(28,43,25,.10); }
.kpi-label {
  font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.07em; margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px;
}
.kpi-value {
  font-size: 32px; font-weight: 700; letter-spacing: -0.02em;
  line-height: 1; margin-bottom: 6px; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.kpi-detail { font-size: 12px; color: var(--muted); }
.kpi-warn { border-left: 4px solid var(--danger); }
.kpi-warn .kpi-value { color: var(--danger); }

/* === Card header =========================================================== */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-header-title { font-size: 13px; font-weight: 600; color: var(--danger); }

/* === Grilla de francos (RF-26) ============================================= */
/* Columnas de día angostas: 31 días de un empleado no tienen que ocupar el ancho
   de una columna normal. El scroll horizontal lo da `.card` (ya tiene overflow-x). */
.grid-mes th:not(:first-child),
.grid-mes td:not(:first-child) {
  width: 26px;
  min-width: 26px;
  padding: 6px 2px;
  text-align: center;
}
.grid-mes td:first-child, .grid-mes th:first-child { white-space: nowrap; }

/* Un color por tipo de ausencia (RN-M1). Selector reforzado a propósito: sin la
   clase `.grid-mes` de más, el cebrado de filas pares (`tbody tr:nth-child(even)
   td`) le gana en especificidad y tapa el color de la mitad de las filas. */
.dia-FRANCO     { --dia-color: #E9F5E7; }
.dia-VACACIONES { --dia-color: #FFEDD5; }
.dia-ENFERMEDAD { --dia-color: #FEF3C7; }
.dia-AUSENCIA   { --dia-color: #FAEAEA; }
.grid-mes tbody tr td.dia { background: var(--dia-color); }
/* Medio día: mitad pintada, mitad libre, en diagonal — se distingue de un día
   entero sin agregar otro color. */
.grid-mes tbody tr td.dia.medio {
  background: linear-gradient(45deg, var(--dia-color) 50%, var(--panel) 50%);
}
/* Inicio/fin del rango: el cliente pidió poder ver "cuándo entra y cuándo sale"
   sin contar celdas. Un rango de un día lleva las dos clases. */
.grid-mes tbody tr td.dia.inicio { border-left: 3px solid var(--ink); }
.grid-mes tbody tr td.dia.fin { border-right: 3px solid var(--ink); }

.franco-legend {
  display: flex; gap: 16px; flex-wrap: wrap; align-items: center;
  margin-bottom: 16px; font-size: 13px; color: var(--muted);
}
.franco-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.franco-swatch {
  display: inline-block; width: 14px; height: 14px;
  border-radius: 3px; border: 1px solid var(--line); background: var(--dia-color);
}

/* === Confirm dialog ======================================================== */
#confirm-dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,.10);
  background: var(--panel);
  color: var(--ink);
  opacity: 0;
  transform: scale(0.95);
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out),
              display var(--dur-base) allow-discrete, overlay var(--dur-base) allow-discrete;
}
#confirm-dialog[open] {
  opacity: 1;
  transform: scale(1);

  @starting-style {
    opacity: 0;
    transform: scale(0.95);
  }
}
#confirm-dialog::backdrop { background: rgba(0,0,0,.35); }
#confirm-dialog p { margin: 0 0 20px; }
#confirm-dialog .dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* === Watermark del dashboard ============================================== */
.dash-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(60%, 520px);
  max-height: 70%;
  object-fit: contain;
  opacity: 0.05;
  z-index: 0;
  pointer-events: none;
  user-select: none;
}
/* El contenido real del main queda por encima de la filigrana. */
.main > :not(.dash-watermark) { position: relative; z-index: 1; }

/* === Responsive ============================================================ */
@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 3px solid var(--side-stripe); }
  .main { padding: 16px; }
}

/* === Dark mode ============================================================= */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0F120E;
    --panel:     #161D14;
    --ink:       #DCE5DA;
    --muted:     #8A9B87;
    --line:      #2A3628;
    --accent:    #5AAF52;
    --accent-hi: #4A9043;
    --warn-1:    #D4900A;
    --warn-2:    #C46210;
  }
  .sidebar {
    background: linear-gradient(165deg, rgba(10,16,9,.92), rgba(6,10,5,.96));
    box-shadow: inset -1px 0 0 rgba(255,255,255,.04);
  }
  th { background: #131A11; }
  tbody tr:hover td { background: #1A2518; }
  tbody tr:nth-child(even) td { background: #141B12; }
  tbody tr:nth-child(even):hover td { background: #1C2A19; }
  .btn { background: var(--panel); color: var(--ink); }
  .btn:hover { background: #1F2B1C; }
  .btn-primary { background: var(--accent); color: #fff; }
  .btn-danger { color: #E57373; border-color: #E57373; }
  .btn-danger:hover { background: #1F1212; }
  .field input, .field select, .field textarea { background: var(--panel); color: var(--ink); }
  .flash-ok    { background: #122210; color: #7DCF74; }
  .flash-error { background: #220E0E; color: #E57373; }
  .badge-ok    { background: #122210; color: #7DCF74; }
  .badge-error { background: #220E0E; color: #E57373; }
  .badge-warn  { background: #2A1800; color: #F8C060; }
  .badge-l2    { background: #2A1000; color: #FDBA74; }
  .badge-off   { background: #1F2B1C; color: var(--muted); }
  #confirm-dialog { background: var(--panel); }
  .dash-watermark { opacity: 0.08; filter: invert(1) brightness(1.6); }
}

/* === Reduced motion ======================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
