:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #dde1e6;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #e2001a;
  --primary-dark: #111111;
  --danger: #7a1220;
  --ok: #15803d;
  --warn-bg: #fff7ed;
  --warn-border: #fdba74;
}

* { box-sizing: border-box; }

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

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

.sidebar {
  width: 220px;
  background: var(--primary-dark);
  color: white;
  display: flex;
  flex-direction: column;
  padding: 16px 0;
}

.brand {
  padding: 4px 16px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  margin-bottom: 8px;
}
.brand-logo { display: block; width: 100%; max-width: 168px; height: auto; }
.brand-subtitulo { display: block; margin-top: 6px; font-size: 11px; color: rgba(255,255,255,0.55); letter-spacing: 0.03em; }

.nav-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.85);
  text-align: left;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
}
.nav-btn:hover { background: rgba(255,255,255,0.08); }
.nav-btn.active { background: var(--primary); color: white; font-weight: 600; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  border-top: 1px solid rgba(255,255,255,0.15);
}

.content { flex: 1; padding: 28px 36px; overflow-y: auto; }
.view.hidden { display: none; }

h1 { font-size: 20px; margin-bottom: 16px; }
h3 { margin-top: 24px; }

.cards { display: flex; gap: 16px; flex-wrap: wrap; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  min-width: 160px;
}
.card .label { font-size: 12px; color: var(--muted); }
.card .value { font-size: 24px; font-weight: 700; margin-top: 4px; }

.warning, .ayuda.aviso {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 16px;
  font-size: 13px;
}
.warning.hidden { display: none; }

.ayuda { color: var(--muted); font-size: 13px; margin-bottom: 12px; }

form.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
label.full { grid-column: 1 / -1; }
input, select {
  font-size: 14px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: white;
}

.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.checkbox-label input { width: auto; }

button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
button:hover { background: var(--primary-dark); }
button.secondary, #btn-cancelar-cliente, #btn-cancelar-producto {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}

.msg { font-size: 13px; color: var(--ok); }
.msg.error { color: var(--danger); }

table.tabla {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 14px;
}
table.tabla th, table.tabla td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
table.tabla th { background: #f0f2f5; font-weight: 600; color: var(--muted); }
table.tabla.small td, table.tabla.small th { font-size: 12px; padding: 6px 10px; }
.mono { font-family: "SF Mono", Menlo, monospace; font-size: 11px; }

dialog {
  border: none;
  border-radius: 10px;
  padding: 0;
  width: 480px;
}
dialog::backdrop { background: rgba(0,0,0,0.35); }
dialog form { padding: 20px; }

.totales {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-top: 16px;
  max-width: 360px;
  margin-left: auto;
  font-size: 13px;
}
.totales div { display: flex; justify-content: space-between; padding: 3px 0; }
.totales .total-final { font-weight: 700; font-size: 15px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }

.botonera { display: flex; gap: 12px; margin-top: 8px; }

.estado-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.estado-emitida { background: #dcfce7; color: var(--ok); }
.estado-anulada { background: #fee2e2; color: var(--danger); }
.estado-borrador { background: #e5e7eb; color: var(--muted); }

.badge-prueba {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
  vertical-align: middle;
}

.badge-pruebas-sidebar {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #fcd34d;
}

.modo-pruebas-check {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.4;
}

.separador {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

button.danger {
  background: var(--danger);
}
button.danger:hover { background: #7f1313; }
button.danger:disabled {
  background: #e5e7eb;
  color: var(--muted);
  cursor: not-allowed;
}

.hidden { display: none; }

.logo-empresa {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.logo-empresa-titulo { font-size: 12px; color: var(--muted); display: block; margin-bottom: 8px; }
.logo-preview-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-preview {
  max-width: 160px;
  max-height: 70px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  padding: 4px;
}

.pantalla-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-dark);
}
.pantalla-login.hidden { display: none; }
.login-box {
  background: var(--panel);
  border-radius: 12px;
  padding: 32px 36px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.login-logo { display: block; width: 100%; max-width: 220px; height: auto; margin: 0 auto 4px auto; }
.login-subtitulo { text-align: center; margin: 0 0 4px 0; color: var(--muted); font-size: 12px; letter-spacing: 0.03em; }
.login-box .form-actions { justify-content: center; flex-direction: column; align-items: stretch; }
.login-box button[type="submit"] { width: 100%; }

.sidebar-footer { display: flex; flex-direction: column; gap: 8px; }
.sidebar-logout {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.2);
  font-size: 12px;
  padding: 6px 10px;
}
.sidebar-logout:hover { background: rgba(255,255,255,0.16); }

/* ---------------------------------------------------------------------------
 * Responsive: uso desde el móvil o la tablet.
 * Por debajo de 760px el menú lateral pasa a ser una barra horizontal
 * desplazable arriba del todo (en vez de una columna fija a la izquierda),
 * y los formularios de dos columnas pasan a una sola para que se lea bien
 * sin hacer zoom.
 * --------------------------------------------------------------------- */
@media (max-width: 760px) {
  .layout { flex-direction: column; min-height: auto; }

  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 8px;
    gap: 2px;
    -webkit-overflow-scrolling: touch;
  }
  .brand { display: none; }
  .nav-btn {
    white-space: nowrap;
    padding: 8px 12px;
    border-radius: 6px;
  }
  .sidebar-footer {
    margin-top: 0;
    margin-left: auto;
    flex-direction: row;
    align-items: center;
    padding: 6px 8px;
    border-top: none;
    border-left: 1px solid rgba(255,255,255,0.15);
    white-space: nowrap;
  }
  #modo-badge { display: none; }

  .content { padding: 16px; }

  form.form-grid { grid-template-columns: 1fr; }

  table.tabla { display: block; overflow-x: auto; white-space: nowrap; }

  .login-box { width: 90vw; max-width: 340px; padding: 24px; }

  dialog { width: 92vw; }

  .totales { max-width: 100%; }
}
