/* ============================================================
   CLARA - Hoja de estilos principal
   ============================================================ */

:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --bg-panel: #ffffff;
  --bg-sidebar: #ffffff;
  --text-sidebar: #1c2330;
  --sidebar-active: #eef2fb;
  --sidebar-hover: #f5f7fb;
  --sidebar-border: #e2e5eb;
  --text: #1c2330;
  --text-muted: #6b7280;
  --border: #e2e5eb;
  --accent: #3f6fd9;
  --accent-hover: #345bb5;
  --danger: #d9463f;
  --success: #2e9e5b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-elevated: 0 12px 40px rgba(30, 35, 50, 0.14);
  --radius: 10px;
  --page-bg: #bdb9cd;
  --scrollbar-thumb: rgba(0, 0, 0, 0.22);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.38);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141a2c;
  --bg-panel: #171d31;
  --bg-sidebar: #0b0e1b;
  --text: #cdd0d8;
  --text-muted: #9aa2b1;
  --text-sidebar: #cdd3e0;
  --sidebar-active: rgba(255, 255, 255, 0.08);
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-border: #2a2f3a;
  --border: #2a2f3a;
  --accent: #5b86ea;
  --accent-hover: #7098f0;
  --danger: #e2685f;
  --success: #3fbd75;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-elevated: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 20px 60px rgba(0, 0, 0, 0.55);
  --radius: 10px;
  --page-bg: #221732;
  --scrollbar-thumb: rgba(255, 255, 255, 0.32);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.5);
}

* { box-sizing: border-box; }

/* Los controles de formulario (button, input, select, textarea) no
   heredan font-family del body por defecto en los navegadores; sin
   esto, caian en la fuente del sistema (tipicamente Arial en Windows)
   en vez de la tipografia definida abajo en body. */
button {
  font-family: inherit;
}

/* pre/code se mantienen SIEMPRE en monospace, independientemente de la
   tipografia general de la app (util para logs, ids tecnicos, etc.) */
pre, code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

/* ---------- Scrollbars finas y con estilo, coherentes con el tema ---------- */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--page-bg);
  color: var(--text);
}

/* ---------- Estructura general: envoltorio "levantado" + sidebar + contenido ---------- */

.app-shell-wrapper {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 24px;
}

.app-shell {
  display: flex;
  width: 100%;
  max-width: 1400px;
  height: calc(100vh - 48px);
  min-height: 0;
  background: var(--bg);
  border-radius: 18px;
  box-shadow: var(--shadow-elevated);
  overflow: hidden;
}

.sidebar {
  width: 240px;
  height: 100%;
  flex-shrink: 0;
  min-height: 0;
  box-sizing: border-box;
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 36px 0 20px;
}

.sidebar__brand {
  flex-shrink: 0;
  font-size: 1.3rem;
  font-weight: 700;
  padding: 0 20px 24px;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
}

.sidebar__menu {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.sidebar__item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-sidebar);
  padding: 12px 20px;
  font-size: 0.95rem;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.sidebar__item:hover {
  background: var(--sidebar-hover);
}

.sidebar__item.active {
  border-left-color: var(--accent);
  background: var(--sidebar-active);
  font-weight: 600;
}

.sidebar__separador {
  border: none;
  border-top: 1px solid var(--sidebar-border);
  margin: 8px 20px;
}

.sidebar__item--secundario {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.sidebar__footer {
  flex-shrink: 0;
  padding: 12px 20px 0;
  border-top: 1px solid var(--sidebar-border);
  font-size: 0.85rem;
}

.main {
  flex: 1;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.topbar__title {
  font-size: 1.1rem;
  font-weight: 600;
}

.content {
  flex: 1;
  min-height: 0;
  padding: 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ============================================================
   INICIO fondo decorativo del area de contenido (opcional).
   Para revertir: borrar este bloque completo (hasta "FIN").
   No afecta a tarjetas/paneles (tienen fondo opaco propio) ni a
   modales (se insertan directamente en <body>, fuera de .content).
   ============================================================ */
.content {
  position: relative;
}
.content::before {
  content: "";
  position: absolute;
  inset: -40px;
  background-image: url("../img/login-bg.svg");
  background-repeat: no-repeat;
  background-position: center top;
  background-size: cover;
  filter: blur(10px);
  opacity: 0.14;
  z-index: 0;
  pointer-events: none;
}
[data-theme="dark"] .content::before {
  opacity: 0.2;
  filter: blur(10px) brightness(1.4);
}
.content > * {
  position: relative;
  z-index: 1;
}
/* ============================================================
   FIN fondo decorativo del area de contenido
   ============================================================ */

/* ---------- Botones y controles ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  padding: 0 16px;
  box-sizing: border-box;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}

.btn:hover { border-color: var(--accent); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn--primary:hover { background: var(--accent-hover); }

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* Resaltado de coincidencias de busqueda: discreto, con el propio color
   de acento de la app (nada de amarillo chillon del <mark> por defecto
   del navegador). */
mark.resaltado-busqueda {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: inherit;
  border-radius: 4px;
  padding: 0 2px;
  font-weight: 700;
}

.spinner-amiga {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spinner-amiga-giro 0.8s linear infinite;
}

@keyframes spinner-amiga-giro {
  to {
    transform: rotate(360deg);
  }
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-radius: 6px;
  font-weight: bolder;
}

.icon-btn:hover {
  background: var(--border);
  color: var(--text);
  transform: scale(1.2);
}
.icon-btn { transition: transform 0.12s ease, background 0.12s ease, color 0.12s ease; }

input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  box-sizing: border-box;
}

input:not([type="checkbox"]), select {
  height: 42px;
}

/* Placeholder con contraste bajo (mas discreto que el texto real
   introducido), igual en modo claro y oscuro. */
input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.45;
}

/* El spinner nativo de +/- en inputs numericos ya no hace falta
   ocultarlo: con "color-scheme" definido arriba, el navegador lo pinta
   con la paleta oscura/clara correcta segun el tema, en vez del
   cuadrado blanco que desentonaba antes. */

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
}

fieldset {
  color: var(--text);
}

/* ---------- Panel de grupo (concepto reutilizable): agrupa visualmente
   un bloque de contenido relacionado, con cabecera diferenciada. Se usa
   por ejemplo en el editor de Programacion (Recogida / Entrega), y en
   cualquier otro sitio donde haga falta destacar un grupo de campos. ---------- */

.panel-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 18px;
  background: var(--bg);
}

.panel-group__header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 3px 10px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 16%, var(--bg));
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}

.panel-group__body {
  padding: 16px;
}

legend {
  color: var(--text);
  font-size: 0.95rem;
}

summary {
  list-style: none;
  user-select: none;
  cursor: pointer;
}
summary::-webkit-details-marker {
  display: none;
}
summary::before {
  content: "+";
  font-size: 1.15rem;
  font-weight: 700;
  display: inline-block;
  width: 16px;
  text-align: center;
  margin-right: 4px;
}
details[open] summary::before {
  content: "−";
}

/* ---------- Vista de login / setup ---------- */

.auth-screen {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page-bg);
  overflow: hidden;
}

.auth-screen::before {
  content: "";
  position: absolute;
  inset: -20px;
  background-image: url("../img/login-bg.svg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  filter: blur(6px);
  opacity: 0.9;
  transform: scale(1.03);
  z-index: 0;
}

/* ---------- Pagina de creditos ---------- */

.creditos-card {
  position: relative;
  overflow: hidden;
}

.creditos-card::before {
  content: "";
  position: absolute;
  inset: -20px;
  background-image: url("../img/login-bg.svg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  filter: blur(8px);
  opacity: 0.12;
  transform: scale(1.05);
  z-index: 0;
}

[data-theme="dark"] .creditos-card::before {
  opacity: 0.16;
  filter: blur(8px) brightness(1.4);
}

.creditos-card > * {
  position: relative;
  z-index: 1;
}

.logo-pill {
  width: 200px;
  height: 80px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  box-sizing: border-box;
}

.logo-pill img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.logo-pill--small {
  width: 80px;
  height: 50px;
  padding: 5px;
}

[data-theme="dark"] .auth-screen::before {
  opacity: 0.65;
  filter: blur(6px) brightness(1.3);
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 360px;
  background: var(--bg-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elevated);
  padding: 32px;
}

.auth-card h1 {
  font-size: 1.3rem;
  margin: 0 0 4px;
}

.auth-card p.subtitle {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 0.9rem;
}

.auth-card .btn--primary {
  width: 100%;
  justify-content: center;
  margin-top: 20px;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* ---------- Toolbar de modulo (listado/cuadricula, boton nuevo) ---------- */

.module-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.view-toggle {
  display: flex;
  height: 42px;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.view-toggle button {
  border: none;
  background: var(--bg-panel);
  color: var(--text-muted);
  padding: 0 14px;
  cursor: pointer;
  font-family: inherit;
}

.view-toggle button.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- Cuadricula de tarjetas (grid) ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.card:hover { border-color: var(--accent); }

.card h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.card p {
  margin: 2px 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--success);
  color: #fff;
}
.badge--off { background: var(--text-muted); }

/* ---------- Avisos (toast) ---------- */
#clara-toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 420px;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: toast-entrada 0.2s ease-out;
}
.toast--exito {
  border-left: 6px solid var(--success);
  background: color-mix(in srgb, var(--success) 18%, var(--bg-panel));
}
.toast--error {
  border-left: 6px solid #e05656;
  background: color-mix(in srgb, #e05656 18%, var(--bg-panel));
}
.toast--info {
  border-left: 6px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--bg-panel));
}
.toast--saliendo { opacity: 0; transform: translateX(12px); transition: all 0.2s ease-in; }
.toast__mensaje { flex: 1; font-size: 0.92rem; font-weight: 600; line-height: 1.4; }
.toast__cerrar {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  line-height: 1;
}
@keyframes toast-entrada {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

.badge--grande {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 12px;
}

/* ---------- Listado (filas) ---------- */

.list-view {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.list-row {
  background: var(--bg-panel);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  gap: 12px;
}

.list-row:hover { background: var(--bg); }

/* ---------- Tags de resumen de programacion (Recogida/Entrega) ---------- */

.prog-tag {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 4px;
  column-gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
  min-width: 330px;
  box-sizing: border-box;
}

.prog-tag__grupo {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.card .prog-tag {
  min-width: 0;
  width: 100%;
  border-radius: var(--radius);
}

.prog-tag__separador {
  color: var(--border);
  margin: 0 2px;
}

.prog-tag--vacio {
  opacity: 0.6;
  font-style: italic;
}

.prog-tag--inactiva {
  opacity: 0.5;
}

.prog-tag__etiqueta {
  font-weight: 600;
  color: var(--text);
}

.prog-tag__hora {
  font-weight: 700;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  padding: 1px 6px;
  border-radius: 999px;
}

.prog-tag__dias {
  color: var(--text-muted);
}

.prog-tag__excepciones {
  color: var(--danger);
  font-weight: 600;
}

/* ---------- Tag generico reutilizable (misma estetica, sin ancho fijo) ---------- */

.tag-info {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 240px;
}

.tag-info strong {
  color: var(--text);
  font-weight: 600;
  flex-shrink: 0;
}

.tag-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Oculta el input file nativo, manteniendolo accesible
   (enfocable con teclado); el label.btn asociado hace de disparador ---------- */
.input-file-oculto {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Interruptor estilo iOS (activar/desactivar llamada) ---------- */

.ios-switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 19px;
  flex-shrink: 0;
  vertical-align: middle;
  margin-bottom: 10px;
}

.ios-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.ios-switch__track {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--text) 30%, transparent);
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.ios-switch__track::before {
  content: "";
  position: absolute;
  height: 15px;
  width: 15px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.ios-switch input:checked + .ios-switch__track {
  background: var(--success);
}

.ios-switch input:checked + .ios-switch__track::before {
  transform: translateX(15px);
}

/* ---------- Panel modal de edicion ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elevated);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
}

.modal--confirm {
  max-width: 360px;
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* ---------- Responsive ---------- */

@media (max-width: 800px) {
  .app-shell-wrapper { padding: 0; }

  .app-shell {
    flex-direction: column;
    height: 100vh;
    max-width: none;
    border-radius: 0;
    box-shadow: none;
  }

  .sidebar {
    width: 100%;
    height: auto;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand footer"
      "menu menu";
    align-items: center;
    padding: 10px 0 0;
  }

  .sidebar__brand {
    grid-area: brand;
    padding: 0 8px 10px 16px;
  }

  .sidebar__footer {
    grid-area: footer;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 16px 10px 0;
    border-top: none;
    flex-shrink: 0;
  }

  .sidebar__footer #toggle-tema { height: 36px; }
  .sidebar__footer #btn-logout { padding: 0 12px; height: 36px; }

  .sidebar__menu {
    grid-area: menu;
    display: flex;
    flex: none;
    overflow-x: auto;
    overflow-y: hidden;
    border-top: 1px solid var(--sidebar-border);
  }

  .sidebar__item {
    white-space: nowrap;
    border-left: none;
    border-bottom: 3px solid transparent;
  }

  .sidebar__item.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }

  .content { padding: 16px; }

  .card-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}