:root {
  --color-bg: #f1f2f5;
  --color-surface: #ffffff;
  --color-text: #22252a;
  --color-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-primary: #7a1f2b;
  --color-primary-dark: #5c1620;
  --color-primary-light: #fbeaec;
  --color-success: #15803d;
  --color-success-bg: #dcfce7;
  --color-warning: #b45309;
  --color-warning-bg: #fef3c7;
  --color-danger: #b91c1c;
  --color-danger-bg: #fee2e2;
  --color-info: #1d4ed8;
  --color-info-bg: #dbeafe;
  --color-neutral: #4b5563;
  --color-neutral-bg: #e5e7eb;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 10px rgba(16, 24, 40, 0.10);
  --sidebar-w: 230px;
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; color: var(--color-text); }
h3 { font-size: 0.95rem; margin: 1rem 0 0.4rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.03em; }

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

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--color-primary-dark), var(--color-primary));
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .marca {
  padding: 1.25rem 1.25rem 1rem;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.sidebar nav {
  flex: 1;
  padding: 0.75rem 0.5rem;
  overflow-y: auto;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: rgba(255,255,255,0.88);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.15rem;
  font-size: 0.92rem;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.12); text-decoration: none; }
.sidebar nav a.activo { background: rgba(255,255,255,0.2); color: white; font-weight: 600; }
.sidebar nav svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar nav .nav-seccion {
  margin: 0.9rem 0.75rem 0.3rem;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
}

.sidebar .usuario {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 0.85rem;
}
.sidebar .usuario a { color: rgba(255,255,255,0.75); }
.rol-chip { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; background: rgba(255,255,255,0.18); padding: 0.1rem 0.4rem; border-radius: 999px; }
.sidebar .usuario svg { width: 15px; height: 15px; vertical-align: -3px; margin-right: 0.25rem; }

main.contenido {
  flex: 1;
  padding: 2rem 2.5rem;
  max-width: 1100px;
}

/* --- tarjetas --- */
.tarjeta {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
  overflow-x: auto;   /* una tabla ancha se desplaza dentro de su tarjeta en vez de romper la página */
}

/* --- formularios --- */
label { display: block; font-size: 0.85rem; color: var(--color-muted); margin-top: 0.75rem; margin-bottom: 0.25rem; }
input, select, textarea {
  display: block;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: white;
  color: var(--color-text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
input[type=checkbox] { width: auto; display: inline-block; }

button, .boton {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background .15s, transform .05s;
}
button:hover { background: var(--color-primary-dark); }
button:active { transform: scale(0.98); }
button:disabled { background: var(--color-neutral-bg); color: var(--color-muted); cursor: default; }
button.secundario { background: var(--color-neutral-bg); color: var(--color-text); }
button.secundario:hover { background: #d1d5db; }
button.peligro { background: var(--color-danger-bg); color: var(--color-danger); }
button.peligro:hover { background: #fecaca; }

/* --- contabilidad --- */
.pestanas { display: flex; gap: 0.25rem; border-bottom: 2px solid var(--color-border); margin-bottom: 1.25rem; }
.pestanas a {
  padding: 0.6rem 1rem; color: var(--color-muted); font-weight: 600; font-size: 0.92rem;
  border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.pestanas a:hover { color: var(--color-text); text-decoration: none; }
.pestanas a.activa { color: var(--color-primary); border-bottom-color: var(--color-primary); }
th.num, td.num, input.num { text-align: right; font-variant-numeric: tabular-nums; }
.error-form {
  background: var(--color-danger-bg); color: var(--color-danger);
  padding: 0.65rem 0.9rem; border-radius: var(--radius-sm); margin: 0 0 1rem; font-weight: 600;
}
.total-fila td { border-top: 2px solid var(--color-border); background: #fafafa; }
.fila-grupo td { font-weight: 600; background: #fafafa; }
.cuenta-inactiva td { opacity: 0.55; }
.check-inline { display: inline-flex; align-items: center; gap: 0.3rem; margin: 0; white-space: nowrap; }
.edicion-en-linea { display: flex; gap: 0.5rem; align-items: center; }
.edicion-en-linea input[type=text] { flex: 1; margin: 0; min-width: 12rem; }
.edicion-en-linea button { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.tabla-cuentas td:first-child { white-space: nowrap; }
.tabla-cuentas td { padding: 0.4rem 0.5rem; }

/* --- calendario de eventos --- */
.calendario { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--color-border); border: 1px solid var(--color-border); }
.cal-cabecera { background: #f3f4f6; padding: 0.4rem; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--color-muted); text-align: center; }
.cal-dia { background: white; min-height: 5.5rem; padding: 0.25rem; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.cal-otro { background: #fafafa; color: var(--color-muted); }
.cal-hoy { box-shadow: inset 0 0 0 2px var(--color-primary); }
.cal-numero { font-size: 0.75rem; font-weight: 700; }
.cal-evento { display: block; font-size: 0.72rem; line-height: 1.2; padding: 2px 4px; border-radius: 4px; background: var(--color-info-bg); color: var(--color-info); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-evento:hover { text-decoration: none; filter: brightness(0.95); }
.cal-en_preparacion { background: var(--color-warning-bg); color: var(--color-warning); }
.cal-completado { background: var(--color-success-bg); color: var(--color-success); }

/* --- tablas --- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-muted); padding: 0.6rem 0.5rem; border-bottom: 2px solid var(--color-border); }
td { padding: 0.65rem 0.5rem; border-bottom: 1px solid var(--color-border); }
tbody tr:hover { background: #fafafa; }

/* --- badges de estado --- */
.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge-exito { background: var(--color-success-bg); color: var(--color-success); }
.badge-alerta { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-peligro { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-info { background: var(--color-info-bg); color: var(--color-info); }
.badge-neutral { background: var(--color-neutral-bg); color: var(--color-neutral); }

/* --- kpis / numero grande --- */
.kpis { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.kpi { flex: 1 1 200px; min-width: 0; }
.kpi .numero { font-size: 1.6rem; font-weight: 700; color: var(--color-primary); display: block; white-space: nowrap; }
.kpi .etiqueta { color: var(--color-muted); font-size: 0.85rem; }

/* --- kanban --- */
.kanban { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 0.5rem; }
.kanban-col { flex: 1; min-width: 220px; background: #f7f7f8; border-radius: var(--radius); padding: 0.75rem; }
.kanban-col h3 { margin-top: 0; }
.kanban-card {
  background: white;
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.6rem;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
}
.kanban-card .cliente { font-weight: 600; display: block; margin-bottom: 0.15rem; }
.kanban-card .detalle { color: var(--color-muted); }

/* --- alertas de trabajo pendiente --- */
.aviso-fila { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid var(--color-border); }
.aviso-fila:last-child { border-bottom: none; }

/* --- toasts --- */
#toasts { position: fixed; top: 1rem; right: 1rem; z-index: 1000; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  background: var(--color-text);
  color: white;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 0.88rem;
  min-width: 220px;
  animation: entrar 0.2s ease-out;
}
.toast.error { background: var(--color-danger); }
@keyframes entrar { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

.vacio { color: var(--color-muted); font-style: italic; }
.ayuda { color: var(--color-muted); font-size: 0.85rem; margin-top: 0.25rem; }

/* Aviso de la actualización en vivo (otra persona guardó, o se perdió la conexión con el servidor). */
.vivo-aviso { position: fixed; right: 1rem; bottom: 1rem; z-index: 50; max-width: 22rem; padding: .6rem .9rem;
  border-radius: 8px; background: #1f2937; color: #fff; font-size: .9rem; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.vivo-aviso.sin-conexion { background: #b91c1c; }
.vivo-aviso button { margin-left: .4rem; padding: .2rem .5rem; font-size: .8rem; }
