/* ==========================================================================
   Portal B2B de Grandes Clientes — RAÚL ASENCIO PASTELERÍAS
   Design System Luna / Gestigest Calidad (Manrope · Warm Tones · Deep Wine)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #fff8f6;
  --bg-gradient: radial-gradient(circle at 30% 40%, rgba(178, 31, 31, 0.06), transparent 50%),
                 radial-gradient(circle at top right, rgba(178, 31, 31, 0.08), transparent 24%),
                 linear-gradient(180deg, #fffaf8 0%, #fff3ee 100%);
  --panel: #ffffff;
  --panel-soft: #fffaf8;
  --panel-hover: #fff3ee;
  --text: #2d1717;
  --text-secondary: #5c3b3b;
  --muted: #816565;
  --line: rgba(129, 50, 50, 0.14);
  --line-strong: rgba(129, 50, 50, 0.28);
  
  --primary: #b21f1f;
  --primary-strong: #8f1313;
  --primary-hover: #9e1b1b;
  --primary-soft: linear-gradient(135deg, #fce8e4 0%, #fff6f4 100%);
  --primary-soft-flat: #fce8e4;
  --primary-gradient: linear-gradient(135deg, #cf3d2f 0%, #8f1313 100%);

  --warning: #cf7b00;
  --warning-bg: rgba(207, 123, 0, 0.12);
  --success: #18794e;
  --success-bg: rgba(24, 121, 78, 0.12);
  --danger: #b42318;
  --danger-bg: rgba(180, 35, 24, 0.12);
  --info: #1d4ed8;
  --info-bg: rgba(29, 78, 216, 0.1);

  --shadow: 0 18px 50px rgba(123, 39, 39, 0.12);
  --shadow-sm: 0 4px 14px rgba(123, 39, 39, 0.06);
  --shadow-md: 0 8px 24px rgba(123, 39, 39, 0.1);
  --shadow-lg: 0 24px 60px rgba(123, 39, 39, 0.16);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-full: 999px;

  --tr-fast: 140ms ease;
  --tr-normal: 220ms ease;
}

/* ── REGLA MAESTRA DE VISIBILIDAD SPA (CRÍTICA) ────────────────────────── */
.hidden {
  display: none !important;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

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

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(129, 50, 50, 0.22);
  border-radius: var(--r-full);
}
::-webkit-scrollbar-thumb:hover { background: rgba(129, 50, 50, 0.4); }

/* ── Pantalla de Autenticación (Login & Reset) ─────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 30%, rgba(178, 31, 31, 0.12), transparent 60%),
              radial-gradient(circle at top right, rgba(143, 19, 19, 0.15), transparent 40%),
              linear-gradient(135deg, #440d0d 0%, #2b0808 50%, #170404 100%);
  position: relative;
}
.auth-wrapper.hidden {
  display: none !important;
}

.auth-wrapper::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(circle at bottom center, rgba(207, 61, 47, 0.15), transparent 70%);
  pointer-events: none;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border-radius: var(--r-xl);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.12);
  padding: 36px 32px;
  position: relative;
  z-index: 1;
}

.auth-header {
  text-align: center;
  margin-bottom: 24px;
}

.auth-logo-img {
  max-width: 170px;
  max-height: 64px;
  object-fit: contain;
  margin: 0 auto 12px auto;
  display: block;
}

.auth-eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 2px;
}

.auth-header h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}

.auth-header p {
  font-size: 13px;
  color: var(--muted);
}

.auth-body {
  display: block;
}
.auth-body.hidden {
  display: none !important;
}

.form-group {
  margin-bottom: 18px;
  position: relative;
}

.form-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  font-size: 13.5px;
  background: var(--panel-soft);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  color: var(--text);
  outline: none;
  transition: border-color var(--tr-fast), box-shadow var(--tr-fast), background-color var(--tr-fast);
}

.form-control:focus {
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(178, 31, 31, 0.14);
}

.input-password-wrapper, .password-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-password-wrapper .form-control, .password-input-wrapper .form-control {
  padding-right: 44px;
}

.btn-toggle-password, .btn-toggle-pwd {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  font-size: 16px;
  color: var(--muted);
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--tr-fast), transform var(--tr-fast);
}
.btn-toggle-password:hover, .btn-toggle-pwd:hover {
  color: var(--primary);
  transform: scale(1.1);
}

.auth-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  margin-bottom: 18px;
  color: var(--muted);
}

.link-btn {
  background: transparent;
  border: none;
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  transition: color var(--tr-fast);
}
.link-btn:hover {
  color: var(--primary-strong);
}

.notice-locked {
  background: var(--primary-soft);
  border: 1px solid rgba(178, 31, 31, 0.18);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-top: 18px;
}

/* ── Botones ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  font-size: 13.5px;
  padding: 10px 18px;
  border-radius: var(--r-md);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all var(--tr-fast);
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary-gradient);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(178, 31, 31, 0.32);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #b21f1f 0%, #750f0f 100%);
  box-shadow: 0 6px 18px rgba(178, 31, 31, 0.42);
  transform: translateY(-1px);
}
.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--panel-hover);
  border-color: var(--line-strong);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: rgba(178, 31, 31, 0.3);
}
.btn-outline:hover:not(:disabled) {
  background: var(--primary-soft-flat);
  border-color: var(--primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #991b1b;
}

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  background: #15803d;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12.5px;
  border-radius: var(--r-sm);
}

.btn-lg {
  padding: 13px 24px;
  font-size: 15px;
  border-radius: var(--r-lg);
}

/* ── Estructura de la Aplicación (App Shell) ───────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
  position: relative;
}
.app-shell.hidden {
  display: none !important;
}

/* Sidebar */
.sidebar {
  width: 275px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}

.sidebar-brand {
  padding: 22px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo-img {
  max-width: 140px;
  max-height: 46px;
  object-fit: contain;
}

.brand-eyebrow {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--primary);
}

.sidebar-brand-text h2 {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.client-card-mini {
  margin: 16px;
  padding: 14px;
  background: var(--primary-soft);
  border: 1px solid rgba(178, 31, 31, 0.16);
  border-radius: var(--r-md);
}

.client-card-mini__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.client-card-mini__top strong {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.role-pill {
  font-size: 9.5px;
  font-weight: 800;
  text-transform: uppercase;
  background: var(--primary);
  color: #fff;
  padding: 2px 7px;
  border-radius: var(--r-full);
}

.client-card-mini__nif {
  font-size: 11px;
  color: var(--muted);
}

.client-card-mini__user {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-menu {
  list-style: none;
  flex: 1;
  padding: 10px 14px;
  overflow-y: auto;
  margin: 0;
}

.nav-menu li {
  margin-bottom: 5px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: var(--r-md);
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all var(--tr-fast);
  text-align: left;
}

.nav-item:hover {
  background: var(--panel-hover);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary-gradient);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(178, 31, 31, 0.28);
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--panel-soft);
}

.btn-change-pwd {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  width: 100% !important;
  padding: 9px 12px !important;
  background-color: #ffffff !important;
  color: #4A1C1D !important;
  border: 1.5px solid #D5C2B4 !important;
  border-radius: 6px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06) !important;
  transition: all 0.2s ease !important;
}

.btn-change-pwd:hover {
  background-color: #FBF4EE !important;
  border-color: #8A2424 !important;
  color: #8A2424 !important;
}

.btn-change-pwd span {
  color: #4A1C1D !important;
}

/* Área Principal */
.main-area {
  flex: 1;
  margin-left: 275px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-title h1 {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
}

.topbar-title p {
  font-size: 12.5px;
  color: var(--muted);
}

.view-container {
  padding: 24px 28px;
  flex: 1;
}

/* ── Secciones Individuales (Solo se muestra la que NO tiene .hidden) ──── */
.view-section {
  display: block;
  animation: fadeInView 180ms ease forwards;
}
.view-section.hidden {
  display: none !important;
}

@keyframes fadeInView {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Tarjetas y Contenedores ──────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  margin-bottom: 22px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.card-header h3 {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

/* Grid del Creador de Pedidos (Catálogo + Carrito) */
.order-builder-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
  align-items: start;
}

/* Catálogo de Productos */
.catalog-tabs {
  display: flex;
  gap: 8px;
}

.catalog-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

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

.product-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all var(--tr-fast);
  box-shadow: var(--shadow-sm);
}

.product-card:hover {
  border-color: rgba(178, 31, 31, 0.35);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.product-card .fam {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.product-card .title {
  font-size: 14.5px;
  font-weight: 800;
  color: var(--text);
  margin: 6px 0 10px 0;
  line-height: 1.35;
}

.product-card .price-box {
  background: var(--primary-soft);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.product-card .price {
  font-size: 17px;
  font-weight: 800;
  color: var(--primary-strong);
}

.product-card .qty-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.qty-input {
  width: 72px;
  text-align: center;
  font-weight: 700;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
}

/* Carrito Flotante Lateral */
.cart-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: 20px;
  position: sticky;
  top: 92px;
}

.cart-items {
  max-height: 380px;
  overflow-y: auto;
  margin: 14px 0;
}

.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.cart-item-title {
  font-weight: 700;
  color: var(--text);
}
.cart-item-sub {
  font-size: 11px;
  color: var(--muted);
}

.cart-totals {
  background: var(--panel-soft);
  border-radius: var(--r-md);
  padding: 14px;
  margin-top: 14px;
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.cart-total-row.final {
  font-size: 17px;
  font-weight: 800;
  color: var(--primary-strong);
  padding-top: 8px;
  border-top: 1.5px dashed var(--line);
  margin-top: 8px;
  margin-bottom: 0;
}

/* ── Tablas de Documentos (Albaranes, Facturas, Pedidos) ───────────────── */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
  background: var(--panel);
}

.data-table th {
  background: var(--panel-soft);
  padding: 12px 16px;
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  border-bottom: 1.5px solid var(--line);
}

.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

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

.data-table tr:hover td {
  background: var(--panel-hover);
}

/* ── Badges y Semáforos ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: var(--r-full);
  line-height: 1.2;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger);  }
.badge-info    { background: var(--info-bg);    color: var(--info);    }
.badge-custom  { background: var(--primary-soft-flat); color: var(--primary-strong); }

/* ── Modales ───────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(45, 23, 23, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-backdrop.hidden {
  display: none !important;
}

.modal-dialog {
  background: var(--panel);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideInModal 180ms ease forwards;
}

@keyframes slideInModal {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-soft);
}

.modal-header h3 {
  font-size: 16.5px;
  font-weight: 800;
  color: var(--text);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--panel-soft);
}

/* ── Toast Notifications ───────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: #2d1717;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInToast 200ms ease forwards;
}

.toast.success { background: #134e2f; border-left: 4px solid #22c55e; }
.toast.error   { background: #5c1414; border-left: 4px solid #ef4444; }
.toast.warning { background: #54320b; border-left: 4px solid #f59e0b; }

@keyframes slideInToast {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .order-builder-grid {
    grid-template-columns: 1fr;
  }
  .cart-panel {
    position: static;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--tr-normal);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .main-area {
    margin-left: 0;
  }
  .topbar {
    padding: 14px 18px;
  }
  .view-container {
    padding: 16px;
  }
}
