:root {
  /* Paleta oficial de La Hornería */
  --negro: #1D1D1B;
  --negro-suave: #141311;
  --crema: #EEE8E3;
  --crema-osc: #E2D8CB;
  --tan: #E7BB82;
  --gris: #EAEAEA;
  --acento: #F75631;
  --acento-hover: #DC431F;
  --rojo: #c0392b;
  --rojo-bg: #fdecea;
  --verde: #1e7e34;
  --verde-bg: #e9f7ef;
  --texto: #1D1D1B;
  --borde: #E2D8CB;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--crema);
  color: var(--texto);
}

/* ---------- Login ---------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-box {
  background: #fff;
  padding: 32px 28px;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-box .login-logo {
  max-width: 220px;
  width: 100%;
  height: auto;
  margin-bottom: 4px;
}

.login-box h1 {
  color: var(--negro);
  margin-bottom: 4px;
  font-size: 22px;
}

.login-box p.subtitle {
  color: #8a7a68;
  margin-top: 0;
  margin-bottom: 20px;
  font-size: 14px;
}

.login-box input {
  width: 100%;
  margin-bottom: 12px;
}

.login-box button {
  width: 100%;
}

#login-error {
  color: var(--rojo);
  font-size: 13px;
  min-height: 18px;
  margin-top: 6px;
}

/* ---------- Layout general ---------- */
#app { display: none; min-height: 100vh; }

header.topbar {
  background: var(--negro);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

header.topbar .topbar-logo {
  height: 34px;
  width: auto;
  /* logo original es negro; lo pasamos a blanco para que se vea sobre el header oscuro */
  filter: brightness(0) invert(1);
  display: block;
}

header.topbar button {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.5);
  color: #fff;
  padding: 6px 14px;
}

header.topbar button:hover { background: rgba(255,255,255,0.15); }

nav.tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 4px;
  background: var(--negro-suave);
  padding: 0 12px;
  position: relative;
}

nav.tabs button {
  background: transparent;
  border: none;
  color: var(--tan);
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 3px solid transparent;
}

nav.tabs button.active {
  color: #fff;
  border-bottom: 3px solid var(--acento);
  font-weight: 600;
}

/* ---------- Menú agrupado con desplegables ---------- */
.tab-group {
  position: relative;
}

.tab-group-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 100%;
}

.tab-group-btn .caret {
  font-size: 10px;
  line-height: 1;
}

.tab-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: #fff;
  border-radius: 8px;
  padding: 6px;
  min-width: 190px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  z-index: 20;
}

.tab-group.open .tab-dropdown {
  display: block;
}

.tab-dropdown .tab-btn {
  display: block;
  width: 100%;
  text-align: left;
  color: var(--negro);
  padding: 9px 10px;
  border-radius: 6px;
  border-bottom: none;
}

.tab-dropdown .tab-btn:hover {
  background: var(--crema);
}

.tab-dropdown .tab-btn.active {
  background: var(--crema-osc);
  color: var(--negro);
  border-bottom: none;
  font-weight: 600;
}

main { padding: 20px; max-width: 1100px; margin: 0 auto; }

.section { display: none; }
.section.active { display: block; }

.section h2 {
  color: var(--negro);
  margin-top: 0;
}

/* ---------- Tarjetas / paneles ---------- */
.card {
  background: #fff;
  border: 1px solid var(--borde);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 20px;
}

.card h3 {
  margin-top: 0;
  font-size: 15px;
  color: var(--negro);
}

/* ---------- Formularios ---------- */
label {
  display: block;
  font-size: 13px;
  color: #6b5b48;
  margin-bottom: 4px;
  margin-top: 10px;
}

input, select, textarea {
  padding: 9px 10px;
  border: 1px solid var(--borde);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--texto);
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--acento);
}

input[type="checkbox"] {
  width: auto;
  padding: 0;
  border: none;
  accent-color: var(--acento);
}

label.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--texto);
}

.lista-seleccion-catalogo {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 10px 14px;
}

.lista-seleccion-catalogo label.checkbox-label {
  padding: 6px 0;
  border-bottom: 1px solid var(--borde);
}

.lista-seleccion-catalogo label.checkbox-label:last-child {
  border-bottom: none;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.form-row > div { flex: 1; min-width: 160px; }

button, .btn {
  background: var(--acento);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}

button:hover { background: var(--acento-hover); }

button.secondary {
  background: #fff;
  color: var(--negro);
  border: 1px solid var(--borde);
}

button.secondary:hover { background: var(--crema-osc); }

button.danger {
  background: #fff;
  color: var(--rojo);
  border: 1px solid #f3c7c2;
}

button.danger:hover { background: var(--rojo-bg); }

button.small {
  padding: 5px 10px;
  font-size: 12px;
}

/* ---------- Tablas ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--borde);
}

th { color: #6b5b48; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }

tr:last-child td { border-bottom: none; }

td.num, th.num { text-align: right; }

.saldo-debe { color: var(--rojo); font-weight: 700; background: var(--rojo-bg); padding: 3px 8px; border-radius: 6px; }
.saldo-ok { color: var(--verde); font-weight: 700; background: var(--verde-bg); padding: 3px 8px; border-radius: 6px; }

.acciones { display: flex; gap: 6px; flex-wrap: wrap; }

.muted { color: #8a7a68; font-size: 13px; }

.items-mini-table { margin: 10px 0; }
.items-mini-table td, .items-mini-table th { padding: 6px 8px; }

.total-line {
  text-align: right;
  font-size: 16px;
  font-weight: 700;
  color: var(--negro);
  margin-top: 8px;
}

.detalle-cliente {
  background: var(--crema);
  padding: 14px;
  border-radius: 10px;
  margin: 4px 0 12px;
}

.detalle-cliente h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--negro);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detalle-cliente .detalle-bloque { margin-bottom: 14px; }
.detalle-cliente .detalle-bloque:last-child { margin-bottom: 0; }

.detalle-cliente table { background: #fff; border-radius: 8px; overflow: hidden; }
.detalle-cliente th, .detalle-cliente td { padding: 7px 8px; font-size: 13px; }

.monto-pago { color: var(--verde); font-weight: 600; }

.badge-pagado, .badge-pendiente, .badge-parcial, .badge-vencido {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.badge-pagado { color: var(--verde); background: var(--verde-bg); }
.badge-pendiente { color: #8a6d1a; background: #fdf3d9; }
.badge-parcial { color: #1a5d8a; background: #e3f1fa; }
.badge-vencido { color: var(--rojo); background: var(--rojo-bg); margin-left: 6px; }

/* ---------- Inicio (dashboard) ---------- */
.stat-grid { display: flex; gap: 14px; flex-wrap: wrap; }

.stat-box {
  flex: 1;
  min-width: 170px;
  background: var(--crema);
  border-radius: 10px;
  padding: 14px 16px;
}

.stat-box .stat-label {
  font-size: 12px;
  color: #6b5b48;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
}

.stat-box .stat-valor { font-size: 22px; font-weight: 700; color: var(--negro); }

.alerta-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--borde);
  font-size: 14px;
}

.alerta-item:last-child { border-bottom: none; }

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--negro-suave);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 999;
  max-width: 90vw;
  text-align: center;
}

#toast.show { opacity: 1; }

@media (max-width: 600px) {
  main { padding: 12px; }
  nav.tabs { overflow: visible; flex-direction: column; }
  .tab-dropdown { position: static; box-shadow: none; min-width: 0; padding: 0 0 6px 12px; background: transparent; }
  .tab-dropdown .tab-btn { color: var(--tan); }
  .tab-dropdown .tab-btn:hover { background: rgba(255,255,255,0.08); }
  .tab-dropdown .tab-btn.active { background: transparent; color: #fff; border-left: 3px solid var(--acento); padding-left: 7px; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tr { border: 1px solid var(--borde); border-radius: 10px; margin-bottom: 10px; padding: 6px 10px; background: #fff; }
  td { border: none; display: flex; justify-content: space-between; gap: 10px; padding: 6px 2px; }
  td::before { content: attr(data-label); color: #8a7a68; font-size: 12px; font-weight: 600; }
  td.num { text-align: right; }
}

/* ==================== Página pública de pedidos (pedido.html) ==================== */
.pc-wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 140px; }
.pc-header { text-align: center; padding: 18px 0 10px; }
.pc-header img { max-width: 170px; width: 100%; height: auto; }
.pc-saludo { color: var(--negro); font-size: 18px; margin: 6px 0 0; }
.pc-saludo strong { color: var(--acento); }
.pc-buscador { margin: 12px 0 18px; }
.pc-buscador input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--borde);
  font-size: 15px; background: #fff;
}
.pc-producto {
  background: #fff; border-radius: 12px; padding: 14px 16px; margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.pc-producto-info h4 { margin: 0 0 3px; font-size: 15.5px; color: var(--negro); }
.pc-producto-info p { margin: 0 0 3px; font-size: 13px; color: #8a7a68; }
.pc-producto-precio { font-weight: 700; color: var(--negro); font-size: 15px; }
.pc-stepper { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.pc-stepper button {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--borde); background: #fff;
  font-size: 18px; line-height: 1; cursor: pointer; color: var(--negro);
}
.pc-stepper button:active { background: var(--crema-osc); }
.pc-stepper span { min-width: 22px; text-align: center; font-weight: 600; }
.pc-notas { margin: 18px 0; }
.pc-notas label { display: block; font-size: 14px; color: var(--negro); margin-bottom: 6px; font-weight: 600; }
.pc-notas textarea {
  width: 100%; min-height: 70px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--borde);
  font-family: inherit; font-size: 14px; resize: vertical;
}
.pc-footer {
  position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--borde);
  padding: 12px 16px; box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}
.pc-footer-inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.pc-footer-total { font-size: 15px; color: var(--negro); }
.pc-footer-total strong { font-size: 19px; display: block; }
.pc-footer button {
  background: var(--acento); color: #fff; border: none; border-radius: 10px; padding: 13px 22px;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.pc-footer button:disabled { background: #ccc; cursor: not-allowed; }
.pc-estado-vacio, .pc-error, .pc-confirmacion { text-align: center; padding: 60px 20px; color: var(--negro); }
.pc-confirmacion h2 { color: var(--acento); }
.pc-confirmacion .pc-numero { font-size: 34px; font-weight: 800; margin: 10px 0; }

/* ==================== Pantalla de Producción (produccion.html) ==================== */
.pr-wrap { max-width: 1400px; margin: 0 auto; padding: 20px; }
.pr-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.pr-header img { max-width: 140px; }
.pr-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .pr-cols { grid-template-columns: 1fr; } }
.pr-col { background: #fff; border-radius: 14px; padding: 14px; min-height: 200px; }
.pr-col h3 { margin: 0 0 12px; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
.pr-col h3 .pr-count {
  background: var(--crema-osc); border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 700;
}
.pr-card {
  background: var(--crema); border-radius: 12px; padding: 14px; margin-bottom: 12px; border-left: 5px solid var(--acento);
}
.pr-card.pr-web { border-left-color: #2d7dd2; }
.pr-card-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.pr-card-cliente { font-weight: 800; font-size: 16px; color: var(--negro); }
.pr-card-numero { font-size: 12px; color: #8a7a68; }
.pr-card-items { font-size: 14px; margin: 8px 0; color: var(--negro); }
.pr-card-items div { padding: 2px 0; }
.pr-card-notas { font-size: 13px; font-style: italic; color: #8a7a68; margin: 6px 0; }
.pr-card-hora { font-size: 12px; color: #8a7a68; margin-bottom: 8px; }
.pr-card button {
  width: 100%; padding: 9px; border-radius: 8px; border: none; background: var(--acento); color: #fff;
  font-weight: 700; cursor: pointer; font-size: 13.5px;
}
.pr-card.pr-listo { opacity: 0.6; }
.pr-card.pr-listo button { background: var(--verde); }
.pr-vacio { color: #8a7a68; font-size: 14px; text-align: center; padding: 20px 0; }
