/* Buho v2 — tema del admin basado en el preset shadcn b1FRKMn7Q
   (estilo base-nova · base zinc · primario azul océano · Inter · radius .625rem).
   Traducción a CSS vanilla de los design tokens generados por
   `npx shadcn init --preset b1FRKMn7Q`; modo oscuro automático por
   prefers-color-scheme con los valores .dark del preset. */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.141 0.005 285.823);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.141 0.005 285.823);
  --primary: oklch(0.5 0.134 242.749);
  --primary-foreground: oklch(0.977 0.013 236.62);
  --secondary: oklch(0.967 0.001 286.375);
  --secondary-foreground: oklch(0.21 0.006 285.885);
  --muted: oklch(0.967 0.001 286.375);
  --muted-foreground: oklch(0.552 0.016 285.938);
  --accent: oklch(0.967 0.001 286.375);
  --accent-foreground: oklch(0.21 0.006 285.885);
  --destructive: oklch(0.577 0.245 27.325);
  --success: oklch(0.627 0.194 149.214);
  --warning: oklch(0.666 0.179 58.318);
  --border: oklch(0.92 0.004 286.32);
  --input: oklch(0.92 0.004 286.32);
  --ring: oklch(0.705 0.015 286.067);
  --sidebar: oklch(0.985 0 0);
  --sidebar-foreground: oklch(0.141 0.005 285.823);
  --sidebar-primary: oklch(0.588 0.158 241.966);
  --sidebar-border: oklch(0.92 0.004 286.32);
  --link: oklch(0.5 0.134 242.749); /* enlaces en texto (claro) */
  --radius: 0.625rem;
  --radius-sm: calc(var(--radius) * 0.6);
  --radius-md: calc(var(--radius) * 0.8);
  --radius-lg: var(--radius);
  --shadow-lg: 0 18px 50px oklch(0.141 0.005 285.823 / 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: oklch(0.141 0.005 285.823);
    --foreground: oklch(0.985 0 0);
    --card: oklch(0.21 0.006 285.885);
    --card-foreground: oklch(0.985 0 0);
    --primary: oklch(0.443 0.11 240.79);
    --primary-foreground: oklch(0.977 0.013 236.62);
    --secondary: oklch(0.274 0.006 286.033);
    --secondary-foreground: oklch(0.985 0 0);
    --muted: oklch(0.274 0.006 286.033);
    --muted-foreground: oklch(0.705 0.015 286.067);
    --accent: oklch(0.274 0.006 286.033);
    --accent-foreground: oklch(0.985 0 0);
    --destructive: oklch(0.704 0.191 22.216);
    --success: oklch(0.723 0.219 149.579);
    --warning: oklch(0.769 0.188 70.08);
    --border: oklch(1 0 0 / 10%);
    --input: oklch(1 0 0 / 15%);
    --ring: oklch(0.552 0.016 285.938);
    --sidebar: oklch(0.21 0.006 285.885);
    --sidebar-foreground: oklch(0.985 0 0);
    --sidebar-primary: oklch(0.685 0.169 237.323);
    --sidebar-border: oklch(1 0 0 / 10%);
    --shadow-lg: 0 18px 50px oklch(0 0 0 / 0.45);
    --link: oklch(0.72 0.15 240); /* azul más claro: contraste sobre fondo oscuro */
  }
}

/* Compatibilidad con nombres antiguos usados puntualmente */
:root { --navy: var(--primary); --ink: var(--foreground); --muted-c: var(--muted-foreground); --err: var(--destructive); --ok: var(--success); --bg: var(--background); }

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------- barra lateral */
:root { --sw-full: 15rem; --sw-rail: 3.75rem; --sw: var(--sw-full); }
body[data-sidebar="collapsed"], body[data-sidebar="hover"] { --sw: var(--sw-rail); }

.layout { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; margin-left: var(--sw); transition: margin-left .18s ease; }

.sidebar {
  position: fixed; top: 0; left: 0; height: 100vh; width: var(--sw); z-index: 50;
  display: flex; flex-direction: column; gap: .25rem;
  background: var(--sidebar); color: var(--sidebar-foreground);
  border-right: 1px solid var(--sidebar-border);
  padding: .5rem; overflow: hidden;
  transition: width .18s ease, box-shadow .18s ease;
}
/* Modo "expandir al pasar": rail que se despliega EN OVERLAY al hover (el
   contenido no se mueve). */
body[data-sidebar="hover"] .sidebar:hover { width: var(--sw-full); box-shadow: var(--shadow-lg); }

/* Marca */
.sidebar .brand {
  display: flex; align-items: center; gap: .55rem; text-decoration: none;
  color: var(--sidebar-primary); font-weight: 700; letter-spacing: -0.01em;
  padding: .4rem .5rem; white-space: nowrap;
}
.brand-logo { height: 28px; width: auto; display: block; flex-shrink: 0; }
.login-logo { height: 72px; width: auto; margin-bottom: .5rem; }
/* Logo navy en claro, blanco en oscuro (swap automático) */
.logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .logo-light { display: none; }
  .logo-dark { display: block; }
  .login-logo.logo-dark { display: inline-block; }
}

/* Icono común de la barra */
.sidebar .ic { width: 20px; height: 20px; flex-shrink: 0; }

/* Selector de edición: estilo base del <select> (compartido con el filtro del
   archivo, que también usa .edition-form) */
.edition-form { margin: 0; }
.edition-form select {
  background: var(--background); color: var(--foreground);
  border: 1px solid var(--input); border-radius: var(--radius-md);
  padding: .35rem .5rem; font-size: .85rem; font-family: inherit;
}
/* En la barra lateral: en fila con el icono, ocupando el ancho */
.sidebar-edition { padding: .25rem .1rem .5rem; }
.sidebar-edition .edition-form { display: flex; align-items: center; gap: .5rem; }
.sidebar-edition .edition-form select { flex: 1; min-width: 0; }
.edition-ic { display: inline-flex; color: var(--muted-foreground); }
.edition-fixed { display: flex; align-items: center; gap: .5rem; color: var(--muted-foreground); font-size: .85rem; padding: .2rem .1rem; }

/* Navegación */
.sidebar-nav { display: flex; flex-direction: column; gap: .15rem; flex: 1; overflow-y: auto; overflow-x: hidden; }
.nav-item {
  display: flex; align-items: center; gap: .7rem; white-space: nowrap;
  color: var(--sidebar-foreground); text-decoration: none;
  padding: .5rem .55rem; border-radius: var(--radius-md);
  font-size: .9rem; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item .ic { color: var(--muted-foreground); transition: color .15s; }
.nav-item:hover { background: var(--accent); color: var(--accent-foreground); }
.nav-item:hover .ic { color: var(--accent-foreground); }
.nav-item.active {
  background: color-mix(in oklab, var(--sidebar-primary) 12%, transparent);
  color: var(--sidebar-primary);
}
.nav-item.active .ic { color: var(--sidebar-primary); }

/* Pie: ficha de usuario + control de modo */
.sidebar-foot { display: flex; flex-direction: column; gap: .35rem; border-top: 1px solid var(--sidebar-border); padding-top: .4rem; }
.user-card { display: flex; align-items: center; gap: .55rem; padding: .3rem .4rem; border-radius: var(--radius-md); }
.user-ic { display: inline-flex; color: var(--muted-foreground); }
.user-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-name { font-size: .82rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; flex-shrink: 0; padding: 0; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-md);
  color: var(--muted-foreground); transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--accent); color: var(--foreground); }
.inline { display: inline; margin: 0; }

/* Control de modo (popover tipo Supabase) */
.sidebar-control { position: relative; }
.sidebar-control summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: .7rem;
  padding: .45rem .55rem; border-radius: var(--radius-md);
  color: var(--muted-foreground); font-size: .85rem; white-space: nowrap;
}
.sidebar-control summary::-webkit-details-marker { display: none; }
.sidebar-control summary:hover { background: var(--accent); color: var(--foreground); }
.sidebar-control-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; min-width: 190px; z-index: 60;
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: .3rem;
}
.scm-title { margin: .1rem .4rem .3rem; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-foreground); }
.sidebar-control-menu button {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: transparent; border: none; border-radius: var(--radius-sm);
  padding: .4rem .5rem; font-size: .85rem; font-family: inherit; color: var(--card-foreground);
}
.sidebar-control-menu button:hover { background: var(--accent); }
.sidebar-control-menu button[aria-current="true"] {
  background: color-mix(in oklab, var(--sidebar-primary) 12%, transparent);
  color: var(--sidebar-primary); font-weight: 600;
}

/* --- Estado CONTRAÍDO (rail): solo iconos; etiquetas ocultas + tooltip --- */
body[data-sidebar="collapsed"] .lbl,
body[data-sidebar="collapsed"] .sidebar-edition select,
body[data-sidebar="collapsed"] .user-meta,
body[data-sidebar="collapsed"] .logout-form,
body[data-sidebar="hover"] .lbl,
body[data-sidebar="hover"] .sidebar-edition select,
body[data-sidebar="hover"] .user-meta,
body[data-sidebar="hover"] .logout-form { display: none; }
body[data-sidebar="collapsed"] .sidebar,
body[data-sidebar="hover"] .sidebar { padding-left: .4rem; padding-right: .4rem; }
body[data-sidebar="collapsed"] .nav-item,
body[data-sidebar="hover"] .nav-item { justify-content: center; }
body[data-sidebar="collapsed"] .edition-form,
body[data-sidebar="hover"] .edition-form,
body[data-sidebar="collapsed"] .user-card,
body[data-sidebar="hover"] .user-card { justify-content: center; }

/* Al desplegar en hover, vuelve todo a estado "ancho" */
body[data-sidebar="hover"] .sidebar:hover .lbl { display: inline; }
body[data-sidebar="hover"] .sidebar:hover .sidebar-edition select,
body[data-sidebar="hover"] .sidebar:hover .user-meta,
body[data-sidebar="hover"] .sidebar:hover .logout-form { display: flex; }
body[data-sidebar="hover"] .sidebar:hover .nav-item,
body[data-sidebar="hover"] .sidebar:hover .edition-form,
body[data-sidebar="hover"] .sidebar:hover .user-card { justify-content: flex-start; }

/* Tooltip de la etiqueta cuando la barra está estrecha */
.sidebar:not(:hover) .nav-item { position: relative; }
body[data-sidebar="collapsed"] .nav-item:hover::after,
body[data-sidebar="hover"] .sidebar:not(:hover) .nav-item:hover::after {
  content: attr(data-label); position: absolute; left: calc(100% + 10px); top: 50%;
  transform: translateY(-50%); white-space: nowrap; z-index: 70;
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .25rem .5rem; font-size: .8rem; box-shadow: var(--shadow-lg); pointer-events: none;
}

/* --------------------------------------------------------------- contenedores */
.content { max-width: 900px; margin: 1.5rem auto; padding: 0 1rem; }
h1 { font-size: 1.45rem; font-weight: 600; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; font-weight: 600; letter-spacing: -0.01em; margin-top: 1.6rem; }
.muted { color: var(--muted-foreground); }
a { color: var(--link); }
.badge {
  background: var(--secondary); color: var(--secondary-foreground);
  border: 1px solid var(--border);
  border-radius: 999px; padding: .1rem .5rem; font-size: .75rem; font-weight: 500;
}
.flash {
  background: color-mix(in oklab, var(--primary) 8%, var(--card));
  border: 1px solid color-mix(in oklab, var(--primary) 25%, transparent);
  color: var(--card-foreground);
  padding: .6rem .8rem; border-radius: var(--radius); margin: 1rem 0; font-size: .9rem;
}
.flash.ok { background: color-mix(in oklab, var(--success) 10%, var(--card)); border-color: color-mix(in oklab, var(--success) 30%, transparent); }
.flash.err { background: color-mix(in oklab, var(--destructive) 10%, var(--card)); border-color: color-mix(in oklab, var(--destructive) 30%, transparent); }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

/* Portada del PDF en el dashboard del día (centrada en su sección) */
figure.cover { margin: 1rem 0; text-align: center; }
figure.cover img {
  max-width: 240px; width: 100%; height: auto; display: block; margin: 0 auto;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: 0 4px 14px oklch(0 0 0 / 0.10);
}

/* -------------------------------------------------------------------- botones */
.btn {
  display: inline-block;
  background: var(--primary); color: var(--primary-foreground);
  text-decoration: none; border: none; border-radius: var(--radius-md);
  padding: .5rem 1rem; font-size: .875rem; font-weight: 500; font-family: inherit;
  cursor: pointer; transition: background .15s;
}
.btn:hover { background: color-mix(in oklab, var(--primary) 90%, black); }
.btn:focus-visible, .linkbtn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
.linkbtn {
  background: transparent; border: 1px solid var(--input); color: var(--foreground);
  border-radius: var(--radius-md); padding: .3rem .65rem; font-size: .82rem;
  font-family: inherit; font-weight: 500; cursor: pointer; transition: background .15s;
}
.linkbtn:hover { background: var(--accent); }
.linkbtn.dark { border-color: color-mix(in oklab, var(--primary) 40%, transparent); color: var(--primary); background: transparent; }
.linkbtn.dark:hover { background: color-mix(in oklab, var(--primary) 10%, transparent); }
.linkbtn.danger { border-color: color-mix(in oklab, var(--destructive) 40%, transparent); color: var(--destructive); background: transparent; }
.linkbtn.danger:hover { background: color-mix(in oklab, var(--destructive) 10%, transparent); }

/* --------------------------------------------------------------------- tablas */
/* Contenedor con scroll horizontal: en móvil las tablas anchas (5-7 columnas)
   desbordarían .content y forzarían scroll lateral de toda la página. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 1rem; }
.table-wrap > table.data, .table-wrap > table.matrix { margin-top: 0; }
table.data {
  width: 100%; border-collapse: separate; border-spacing: 0; margin-top: 1rem;
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
table.data th, table.data td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--border); font-size: .875rem; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data thead th {
  background: var(--muted); color: var(--muted-foreground);
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
}
table.data tbody tr:hover { background: color-mix(in oklab, var(--muted) 55%, transparent); }

/* --------------------------------------------------------------------- cards */
.cards { list-style: none; padding: 0; display: flex; gap: 1rem; flex-wrap: wrap; margin: 1rem 0; }
.cards li, .cards .card {
  flex: 1 1 160px; background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem;
}
.cards .card h2 { margin: .2rem 0 0; font-size: 1.7rem; letter-spacing: -0.02em; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 640px) { .cols2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- formularios */
.form {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; max-width: 560px;
}
.form.wide { max-width: 760px; }
.form label { display: block; margin-bottom: .8rem; font-size: .875rem; font-weight: 500; }
.form label .muted { font-weight: 400; }
.form input[type=text], .form input[type=email], .form input[type=password],
.form input[type=number], .form input[type=time], .form input[type=date],
.form input[type=file], .form select, .form textarea {
  width: 100%; padding: .45rem .65rem;
  background: var(--background); color: var(--foreground);
  border: 1px solid var(--input); border-radius: var(--radius-md);
  margin-top: .25rem; font-size: .875rem; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none; border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 35%, transparent);
}
.form label.check { display: flex; align-items: center; gap: .5rem; }
.form label.check input { width: auto; margin-top: 0; accent-color: var(--primary); }
.form label.check code { color: var(--muted-foreground); }
.form input[type=checkbox] { accent-color: var(--primary); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 1rem 0; }
legend { padding: 0 .4rem; color: var(--muted-foreground); font-size: .8rem; }
.form-actions { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.form.inline-filter { flex-direction: row; align-items: end; gap: .8rem; flex-wrap: wrap; display: flex; max-width: none; }
.form.inline-filter label { margin-bottom: 0; }
.form.inline-filter select, .form.inline-filter input { width: auto; }
.sub-row { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; margin-bottom: .4rem; }
.form-delete { margin-top: .75rem; }

/* Suscripción por edición en el CRUD de destinatarios */
fieldset.ed-sub { padding: .6rem .9rem; margin: .5rem 0; }
fieldset.ed-sub legend { color: var(--foreground); font-weight: 500; font-size: .9rem; }
fieldset.ed-sub label { margin-bottom: .5rem; }
fieldset.ed-sub input[type=time] { width: auto; }
fieldset.ed-sub .muted { margin: .1rem 0 0; font-size: .8rem; }

/* ---------------------------------------------------------------------- login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--muted); }
.login-card {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: calc(var(--radius) * 1.4);
  padding: 2.5rem; text-align: center; box-shadow: var(--shadow-lg);
}
.login-card h1 { color: var(--card-foreground); margin-top: 0; }
.btn-google {
  display: inline-block; background: var(--primary); color: var(--primary-foreground);
  text-decoration: none; padding: .7rem 1.4rem; border-radius: var(--radius-md); font-weight: 600;
  transition: background .15s;
}
.btn-google:hover { background: color-mix(in oklab, var(--primary) 90%, black); }
.login-card .denied {
  color: var(--destructive);
  background: color-mix(in oklab, var(--destructive) 10%, var(--card));
  border: 1px solid color-mix(in oklab, var(--destructive) 30%, transparent);
  padding: .6rem; border-radius: var(--radius-md);
}

/* -------------------------------------- selector de edición de trabajo (navbar) */
.edition-form { margin: 0; }
.edition-form select, .edition-fixed {
  background: var(--background); color: var(--foreground);
  border: 1px solid var(--input); border-radius: var(--radius-md);
  padding: .3rem .5rem; font-size: .85rem; font-family: inherit;
}
.edition-fixed { display: inline-block; color: var(--muted-foreground); }

/* ------------------------------------ matriz de permisos usuario×edición×sección */
table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.matrix th, table.matrix td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: .35rem .5rem; text-align: center; font-size: .85rem; }
table.matrix tr > :last-child { border-right: none; }
table.matrix tbody tr:last-child > * { border-bottom: none; }
table.matrix th.rowh { text-align: left; background: var(--muted); color: var(--muted-foreground); white-space: nowrap; font-weight: 500; }
table.matrix thead th { background: var(--muted); color: var(--muted-foreground); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
table.matrix select {
  padding: .2rem .35rem; background: var(--background); color: var(--foreground);
  border: 1px solid var(--input); border-radius: var(--radius-sm); font-family: inherit;
}

/* ------------------------------------- estados de jobs/entregas en el dashboard */
.st { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 500; }
.st-done, .st-sent { background: color-mix(in oklab, var(--success) 14%, transparent); color: color-mix(in oklab, var(--success) 80%, var(--foreground)); }
.st-running, .st-sending { background: color-mix(in oklab, var(--primary) 14%, transparent); color: color-mix(in oklab, var(--primary) 80%, var(--foreground)); }
.st-pending { background: var(--muted); color: var(--muted-foreground); }
.st-failed { background: color-mix(in oklab, var(--destructive) 14%, transparent); color: color-mix(in oklab, var(--destructive) 80%, var(--foreground)); }
.st-skipped, .st-cancelled { background: var(--muted); color: var(--muted-foreground); }

td.log { font-size: .8rem; color: var(--muted-foreground); max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.log .err { color: var(--destructive); }
.sched { margin: .4rem 0; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 768px) {
  /* En móvil la barra se fuerza a rail de iconos (sin hamburguesa): siempre
     accesible sin comerse el ancho. Se puede desplegar al pasar/tocar. */
  body { --sw: var(--sw-rail); }
  .sidebar .lbl,
  .sidebar-edition select,
  .user-meta,
  .logout-form { display: none; }
  .sidebar { padding-left: .4rem; padding-right: .4rem; }
  .nav-item, .edition-form, .user-card { justify-content: center; }
  .sidebar:hover { width: var(--sw-full); box-shadow: var(--shadow-lg); }
  .sidebar:hover .lbl { display: inline; }
  .sidebar:hover .sidebar-edition select,
  .sidebar:hover .user-meta,
  .sidebar:hover .logout-form { display: flex; }
  .sidebar:hover .nav-item,
  .sidebar:hover .edition-form,
  .sidebar:hover .user-card { justify-content: flex-start; }
  .nav-item:hover::after {
    content: attr(data-label); position: absolute; left: calc(100% + 10px); top: 50%;
    transform: translateY(-50%); white-space: nowrap; z-index: 70;
    background: var(--card); color: var(--card-foreground);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: .25rem .5rem; font-size: .8rem; box-shadow: var(--shadow-lg); pointer-events: none;
  }
  .sidebar:hover .nav-item:hover::after { content: none; }
  td.log { max-width: 220px; }
}
