:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-soft: #e0f2fe;
  --accent: #0f766e;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --radius: 12px;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: 3rem;
}

.hidden {
  display: none !important;
}

/* TOPBAR */
.topbar {
  background: #0f172a;
  color: #ffffff;
  border-bottom: 1px solid #1e293b;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  font-size: 1.9rem;
  background: rgba(255, 255, 255, 0.1);
  width: 46px;
  height: 46px;
  border-radius: 10px;
  display: grid;
  place-items: center;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-title span {
  color: #38bdf8;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: #94a3b8;
}

.session-bar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.session-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.role-badge {
  background: #38bdf8;
  color: #0f172a;
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
}

.role-badge.admin {
  background: #f59e0b;
  color: #0f172a;
}

.shipping-pill {
  background: rgba(255, 255, 255, 0.14);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.82rem;
  color: #e2e8f0;
}

.session-actions {
  display: flex;
  gap: 0.45rem;
}

/* MAIN LAYOUT */
.main-container {
  max-width: 1360px;
  margin: 1.25rem auto;
  padding: 0 1.25rem;
}

/* BUTTONS & INPUTS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #0f172a;
  color: #ffffff;
}

.btn-secondary:hover:not(:disabled) {
  background: #1e293b;
}

.btn-outline {
  background: transparent;
  border-color: #cbd5e1;
  color: inherit;
}

.topbar .btn-outline {
  border-color: rgba(255, 255, 255, 0.3);
  color: #ffffff;
}

.topbar .btn-ghost {
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.08);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: rgba(15, 23, 42, 0.06);
  color: var(--text);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-danger:hover {
  background: #fecaca;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 0.75rem 1.2rem;
  font-size: 0.98rem;
}

.btn-block {
  width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.field label {
  font-size: 0.84rem;
  font-weight: 600;
  color: #334155;
}

.field-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.92rem;
  background: #ffffff;
  color: var(--text);
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

/* AUTH CARD */
.auth-wrapper {
  max-width: 500px;
  margin: 2rem auto;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
}

.auth-tab {
  padding: 0.9rem;
  border: none;
  background: transparent;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.92rem;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--primary);
  border-bottom: 3px solid var(--primary);
}

.auth-form {
  padding: 1.5rem;
}

.auth-form h2 {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}

.form-help {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-bottom: 1.15rem;
}

.quick-demo-box {
  background: #f8fafc;
  border-top: 1px solid var(--border);
  padding: 1.1rem 1.5rem;
}

.quick-demo-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: #475569;
  margin-bottom: 0.6rem;
}

.quick-demo-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.btn-admin-demo {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
  justify-content: flex-start;
}

.btn-admin-demo:hover {
  background: #fde68a;
}

.btn-client-demo {
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
  justify-content: flex-start;
}

.btn-client-demo:hover {
  background: #bae6fd;
}

/* SUBNAV & TABS */
.subnav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

.subnav-tabs {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.subnav-btn {
  border: none;
  background: transparent;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.subnav-btn:hover {
  background: #f1f5f9;
  color: var(--text);
}

.subnav-btn.active {
  background: var(--primary);
  color: #ffffff;
}

.badge-counter {
  background: rgba(15, 23, 42, 0.15);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
}

.subnav-btn.active .badge-counter {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.shipping-editor {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.shipping-editor label {
  font-size: 0.84rem;
  font-weight: 700;
  color: #334155;
}

.shipping-editor input {
  width: 200px;
  padding: 0.4rem 0.65rem;
  font-size: 0.86rem;
}

/* CATALOG & CLIENT VIEW */
.catalog-layout {
  display: grid;
  grid-template-columns: 1fr 370px;
  gap: 1.25rem;
  align-items: start;
}

.catalog-header-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin-bottom: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.catalog-header-card h2 {
  font-size: 1.15rem;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.catalog-search-bar {
  min-width: 250px;
}

.type-pills {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.type-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  color: #334155;
}

.type-pill.active {
  background: #0f172a;
  color: #ffffff;
  border-color: #0f172a;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 1rem;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: var(--shadow);
}

.product-card.selected-in-cart {
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.product-img-wrap {
  position: relative;
  height: 155px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.product-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-type-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(15, 23, 42, 0.82);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
}

.stock-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 0.73rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
}

.stock-ok {
  background: var(--success-soft);
  color: #166534;
}

.stock-low {
  background: var(--warning-soft);
  color: #92400e;
}

.stock-out {
  background: var(--danger-soft);
  color: #991b1b;
}

.product-body {
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.55rem;
}

.product-title {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text);
}

.product-price-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 0.35rem;
}

.product-price {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
}

.product-unit {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.qty-selector {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  background: #f8fafc;
  padding: 0.35rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.qty-btn {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
}

.qty-btn:hover:not(:disabled) {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.qty-input {
  width: 64px !important;
  text-align: center;
  font-weight: 700;
  padding: 0.3rem !important;
}

.line-subtotal-pill {
  font-size: 0.8rem;
  font-weight: 700;
  color: #0f766e;
  background: #ccfbf1;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  text-align: center;
}

/* MISSING PRODUCT CALLOUT */
.missing-product-callout {
  margin-top: 1.25rem;
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.missing-product-callout h3 {
  font-size: 1rem;
  color: #92400e;
}

.missing-product-callout p {
  font-size: 0.85rem;
  color: #b45309;
}

/* ORDER SIDEBAR (TOTAL SIN IVA) */
.order-sidebar {
  position: sticky;
  top: 82px;
}

.order-summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  box-shadow: var(--shadow);
}

.order-summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.no-vat-tag {
  background: #dcfce7;
  color: #166534;
  font-weight: 800;
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
}

.shipping-summary-line {
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}

.cart-items-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 0.9rem;
}

.empty-cart-msg {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  padding: 1.1rem 0.5rem;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
}

.cart-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.cart-item-info strong {
  display: block;
  font-size: 0.86rem;
}

.cart-item-info small {
  color: var(--text-muted);
}

.cart-item-subtotal {
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}

.inline-custom-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.85rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.84rem;
  font-weight: 700;
  color: #92400e;
  cursor: pointer;
}

.inline-custom-fields {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px dashed #fcd34d;
}

.order-total-box {
  background: #0f172a;
  color: #ffffff;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.9rem;
}

.total-row-sub {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #94a3b8;
  margin-bottom: 0.4rem;
}

.total-row-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.total-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 800;
}

.total-sublabel {
  display: block;
  font-size: 0.72rem;
  color: #38bdf8;
}

.total-amount {
  font-size: 1.5rem;
  font-weight: 900;
  color: #38bdf8;
}

.order-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* CARDS & ADMIN LAYOUT */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.card h2 {
  font-size: 1.15rem;
  margin-bottom: 0.25rem;
}

.card h3 {
  font-size: 1.02rem;
  margin-bottom: 0.75rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.kpi-card.kpi-alert {
  border-left: 4px solid var(--warning);
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.kpi-value {
  font-size: 1.65rem;
  font-weight: 900;
  margin: 0.2rem 0;
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.warehouse-layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 1.25rem;
  align-items: start;
}

.panel-grid-2 {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 1.25rem;
  align-items: start;
}

.photo-upload-box {
  border: 1px dashed #94a3b8;
  border-radius: 10px;
  padding: 0.75rem;
  background: #f8fafc;
}

.photo-preview-wrap {
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.65rem;
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.photo-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-placeholder {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.75rem;
}

.photo-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.file-btn {
  cursor: pointer;
  width: 100%;
}

.form-buttons {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.warehouse-filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.warehouse-filters select,
.warehouse-filters input {
  width: auto;
  min-width: 170px;
}

.warehouse-items-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.warehouse-item {
  display: grid;
  grid-template-columns: 78px 1fr auto;
  gap: 0.9rem;
  align-items: center;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
}

.warehouse-item.low-stock-row {
  background: #fffbeb;
  border-color: #fde68a;
}

.warehouse-thumb {
  width: 78px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.warehouse-info h4 {
  font-size: 0.95rem;
  margin-bottom: 0.2rem;
}

.warehouse-meta {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.warehouse-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
}

.stock-quick-bar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.stock-pill-number {
  min-width: 72px;
  text-align: center;
  font-weight: 800;
  font-size: 0.92rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  background: #f1f5f9;
}

/* STACK LISTS (ORDERS, TYPES, REQUESTS) */
.stack-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.order-card,
.request-card,
.type-row-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.95rem 1.1rem;
  background: #ffffff;
}

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-bottom: 0.6rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.status-pill {
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}

.status-pendiente {
  background: #fef3c7;
  color: #92400e;
}

.status-preparando {
  background: #e0f2fe;
  color: #075985;
}

.status-entregado,
.status-disponible,
.status-añadido_al_catalogo {
  background: #dcfce7;
  color: #166534;
}

.status-cancelado,
.status-no_disponible {
  background: #fee2e2;
  color: #991b1b;
}

.order-lines-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  margin: 0.5rem 0;
}

.order-lines-table th,
.order-lines-table td {
  padding: 0.35rem 0.4rem;
  text-align: left;
  border-bottom: 1px dashed #e2e8f0;
}

.order-lines-table th:last-child,
.order-lines-table td:last-child {
  text-align: right;
}

.order-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.6rem;
  padding-top: 0.5rem;
}

.movements-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 290px;
  overflow-y: auto;
}

.movement-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  background: #f8fafc;
  font-size: 0.83rem;
}

.mov-plus {
  color: var(--success);
  font-weight: 800;
}

.mov-minus {
  color: var(--danger);
  font-weight: 800;
}

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

.client-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.95rem;
  background: #f8fafc;
}

/* TOASTS */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 0.75rem 1.1rem;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  font-size: 0.88rem;
  font-weight: 600;
  border-left: 4px solid #38bdf8;
}

.toast.error {
  border-left-color: #ef4444;
}

.toast.success {
  border-left-color: #22c55e;
}

@media (max-width: 980px) {
  .catalog-layout,
  .warehouse-layout,
  .panel-grid-2 {
    grid-template-columns: 1fr;
  }

  .order-sidebar {
    position: static;
  }

  .warehouse-item {
    grid-template-columns: 64px 1fr;
  }

  .warehouse-controls {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }
}
