/* Obliga al navegador a ocultar elementos con la propiedad hidden */
[hidden] {
    display: none !important;
}

:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-text: #1f2430;
  --color-muted: #6b7280;
  --color-border: #e2e5ea;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;

  --estado-creado: #dd223d;
  --estado-facturado: #fd7b03;
  --estado-despachado: #f8d602;
  --estado-entregado: #95c241;
  --estado-reasignado: #0688f8;

  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.container {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

/* Barra superior */
.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__brand { font-weight: 700; margin-right: auto; }

.topbar__nav { display: flex; gap: 16px; flex-wrap: wrap; }
.topbar__nav a { color: var(--color-text); font-weight: 500; }
.topbar__nav a:hover { color: var(--color-primary); }

.topbar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--color-muted);
  width: 100%;
  justify-content: space-between;
}

@media (min-width: 640px) {
  .topbar__user { width: auto; }
}

/* Botones */
.btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn:hover { background: var(--color-primary-dark); }
.btn--ghost {
  background: transparent;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
}

/* Tarjetas / paneles */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* Formularios */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; }
.form-group input, .form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--color-surface);
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 1.3rem; margin-bottom: 20px; text-align: center; }
.error-msg {
  background: #fdecea;
  color: var(--estado-creado);
  border: 1px solid #f6c8ce;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

/* Badges de estado (para usarse en etapas de pedidos/calendario) */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; color: #fff; }
.badge--creado { background: var(--estado-creado); }
.badge--facturado { background: var(--estado-facturado); color: #1f2430; }
.badge--despachado { background: var(--estado-despachado); color: #1f2430; }
.badge--entregado { background: var(--estado-entregado); color: #1f2430; }
.badge--reasignado { background: var(--estado-reasignado); }

/* Encabezado de módulo (título + acción principal) */
.clientes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.text-muted { color: var(--color-muted); }

/* Tabla de clientes */
.tabla-clientes {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 0.95rem;
}
.tabla-clientes th, .tabla-clientes td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--color-border);
}
.tabla-clientes th { color: var(--color-muted); font-weight: 600; }

/* Modal genérico (clientes, y luego pedidos) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 25, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-box {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-box h2 { margin-top: 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* Autocompletar cliente (modal de pedidos) */
.autocomplete-list {
  position: relative;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-top: 6px;
  max-height: 180px;
  overflow-y: auto;
  background: var(--color-surface);
}
.autocomplete-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--color-bg); }

/* ---------- Calendario ---------- */
.cal-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}
.cal-tabs { display: flex; gap: 4px; background: var(--color-bg); padding: 4px; border-radius: var(--radius); }
.cal-tab {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--color-muted);
}
.cal-tab.is-active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow); font-weight: 600; }
.cal-nav { display: flex; gap: 6px; }
.cal-actions { display: flex; gap: 8px; margin-left: auto; }

.cal-titulo { margin: 16px 0 8px; font-size: 1.1rem; text-transform: capitalize; }

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.82rem;
  color: var(--color-muted);
  margin-bottom: 16px;
}
.cal-legend .dot, .dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* Vista día */
.cal-dia { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 640px) { .cal-dia { grid-template-columns: 1fr 1fr; } }
.cal-dia__col h3 { margin-top: 0; font-size: 0.95rem; color: var(--color-muted); }
.pedido-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.pedido-card__cliente { font-weight: 600; }

/* Vista semana */
.cal-semana {
  display: grid;
  grid-template-columns: repeat(7, minmax(90px, 1fr));
  gap: 8px;
  overflow-x: auto;
}
.cal-semana__col {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 8px;
  min-height: 120px;
  cursor: pointer;
}
.cal-semana__col:hover { background: var(--color-bg); }
.cal-semana__header { font-size: 0.8rem; color: var(--color-muted); margin-bottom: 6px; text-transform: capitalize; }
.cal-chip {
  color: #1f2430;
  font-size: 0.75rem;
  padding: 3px 6px;
  border-radius: 6px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Vista mes */
.cal-mes {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-mes__dow {
  font-size: 0.75rem;
  color: var(--color-muted);
  text-align: center;
  padding-bottom: 4px;
}
.cal-mes__celda {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  min-height: 64px;
  padding: 4px;
  cursor: pointer;
  font-size: 0.75rem;
}
.cal-mes__celda:hover { background: var(--color-bg); }
.cal-mes__celda.is-otro-mes { opacity: 0.4; }
.cal-mes__num { font-size: 0.8rem; font-weight: 600; margin-bottom: 3px; }

/* ---------- Dashboard ---------- */
.dash-titulo { font-size: 1.3rem; margin: 4px 0 16px; }
.dash-card { margin-bottom: 16px; }
.dash-card h2 { font-size: 1rem; margin: 0 0 12px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
}
.stat-tile {
  border: 1px solid var(--color-border);
  border-left-width: 5px;
  border-radius: var(--radius);
  padding: 10px 12px;
}
.stat-tile__num { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-tile__label { font-size: 0.8rem; color: var(--color-muted); }
.stat-tile--creado { border-left-color: var(--estado-creado); }
.stat-tile--facturado { border-left-color: var(--estado-facturado); }
.stat-tile--despachado { border-left-color: var(--estado-despachado); }
.stat-tile--entregado { border-left-color: var(--estado-entregado); }
.stat-tile--reasignado { border-left-color: var(--estado-reasignado); }

.dash-lista { list-style: none; margin: 0; padding: 0; }
.dash-lista li { border-bottom: 1px solid var(--color-border); }
.dash-lista li:last-child { border-bottom: none; }
.dash-lista a, .dash-lista__fila {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  color: inherit;
}
.dash-lista a:hover { background: var(--color-bg); }
.dash-lista__main { display: flex; flex-direction: column; gap: 2px; font-size: 0.92rem; }
.dash-lista__main .text-muted { font-size: 0.8rem; }

/* Footer */
.site-footer {
  text-align: center;
  padding: 16px;
  font-size: 0.85rem;
  color: var(--color-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}
