:root {
  --shell-nav-bg: #eef2ff;
  --shell-nav-border: #c7d2fe;
  --shell-nav-text: #1e293b;
  --shell-nav-muted: #64748b;
  --shell-nav-active-bg: rgba(37, 99, 235, 0.14);
  --shell-nav-active-text: #1d4ed8;
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  margin: 0;
  background: #f1f5f9;
  color: #1e293b;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

a {
  text-decoration: none;
  color: inherit;
}

/* —— Barra superior —— */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--shell-nav-bg);
  color: var(--shell-nav-text);
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.12);
  border-bottom: 1px solid var(--shell-nav-border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--shell-nav-text);
  letter-spacing: -0.02em;
  min-width: 0;
  flex: 1;
}

.brand-text {
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-logo-mobile {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  object-fit: contain;
  background: transparent;
}

/* Login móvil — mismo aspecto que el resto de la app */
.auth-page {
  min-height: 100vh;
  background: #f1f5f9;
}

.auth-card {
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
}

.mobile-auth-logo-wrap {
  display: flex;
  justify-content: center;
  margin: 0 0 16px;
}

.mobile-auth-logo {
  width: 72px;
  height: 72px;
  max-width: 72px;
  max-height: 72px;
  object-fit: contain;
  background: transparent;
  display: block;
  flex-shrink: 0;
}

.nav-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid var(--shell-nav-border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.nav-toggle-bar {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--shell-nav-text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

.topbar.nav-open .nav-toggle-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.topbar.nav-open .nav-toggle-bar:nth-child(2) {
  opacity: 0;
}

.topbar.nav-open .nav-toggle-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.nav-menu {
  display: none;
  flex-direction: column;
  padding: 8px 12px 16px;
  border-top: 1px solid var(--shell-nav-border);
  background: var(--shell-nav-bg);
  max-height: calc(100vh - 68px);
  overflow-y: auto;
}

.nav-menu.open {
  display: flex;
}

.nav-menu a {
  display: block;
  padding: 14px 16px;
  margin-bottom: 4px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--shell-nav-text);
  transition: background 0.15s;
}

.nav-menu a:active,
.nav-menu a:hover,
.nav-menu a.active {
  background: var(--shell-nav-active-bg);
  color: var(--shell-nav-active-text);
}

.nav-menu .nav-logout {
  margin-top: 8px;
  color: #b91c1c;
  border-top: 1px solid var(--shell-nav-border);
  border-radius: 10px 10px 0 0;
  padding-top: 18px;
}

/* —— Contenido —— */
.container {
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  margin: 0 0 14px;
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-back:active {
  background: #dbeafe;
}

h1 {
  font-size: 1.35rem;
  margin: 0 0 12px;
}

.card--from-fabrica,
.list .card.card--from-fabrica {
  position: relative;
}

.card--facturado,
.list .card.card--facturado {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  box-shadow: 0 1px 3px rgba(16, 185, 129, 0.12);
}

.quote-card-date {
  margin: 0 0 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
}

.quote-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.quote-card-head h3 {
  margin: 0;
}

.badge-facturado {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: #d1fae5;
  color: #047857;
}

.from-fabrica-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  background: #eff6ff;
  border: 1px solid #93c5fd;
  border-radius: 10px;
  cursor: help;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.15);
}

.from-fabrica-badge::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  padding: 0.4rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  background: #1e3a5f;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
  pointer-events: none;
}

.from-fabrica-badge:hover::after,
.from-fabrica-badge:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.card {
  background: #fff;
  padding: 16px;
  border-radius: 12px;
  margin: 12px 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

label {
  display: flex;
  flex-direction: column;
  font-size: 14px;
  margin: 10px 0;
  gap: 6px;
  font-weight: 500;
  color: #475569;
}

input,
select,
textarea,
button {
  font-size: 16px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-family: inherit;
}

textarea {
  resize: vertical;
}

.btn {
  background: #0ea5e9;
  color: #fff;
  border: none;
  display: inline-block;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.btn.secondary {
  background: #64748b;
}

.btn.danger {
  background: #ef4444;
}

.btn.whatsapp {
  background: #16a34a;
}

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

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.tile {
  display: block;
  padding: 18px 16px;
  border-radius: 12px;
  background: #fff;
  color: #0f172a;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: box-shadow 0.15s;
}

.tile:active {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.list .card {
  margin-bottom: 12px;
}

.card-compact {
  padding: 12px 14px;
  margin: 8px 0;
}

.card-compact p {
  margin: 4px 0;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  margin-bottom: 10px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  color: #0f172a;
  transition: box-shadow 0.15s;
}

.list-row:active {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.list-row-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.list-row-main strong {
  font-size: 1rem;
  line-height: 1.3;
}

.list-row-meta {
  font-size: 0.85rem;
  color: #64748b;
}

.list-row-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  font-weight: 600;
  color: #0ea5e9;
}

.list-row-chevron {
  font-size: 1.4rem;
  line-height: 1;
  color: #94a3b8;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.actions.large .btn {
  font-size: 1rem;
  padding: 14px 18px;
  flex: 1 1 auto;
  min-width: 140px;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid #e2e8f0;
}

.quote-totals p {
  margin: 0.35rem 0;
  font-size: 0.95rem;
}

.quote-totals strong {
  color: #0f172a;
}

.flash {
  padding: 12px 14px;
  border-radius: 10px;
  margin: 10px 0;
  font-size: 0.95rem;
}

.flash.success {
  background: #dcfce7;
  color: #166534;
}

.flash.danger {
  background: #fee2e2;
  color: #991b1b;
}

.flash.warning,
.flash.info {
  background: #fef3c7;
  color: #92400e;
}

.hint {
  font-size: 13px;
  color: #64748b;
  line-height: 1.4;
}

/* —— Filtros de listados —— */
.filter-bar {
  margin: 6px 0 8px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
  overflow: hidden;
}

.filter-bar-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  font-size: 0.9rem;
  color: #0f172a;
  -webkit-tap-highlight-color: transparent;
}

.filter-bar-summary::-webkit-details-marker {
  display: none;
}

.filter-bar-summary::before {
  content: "▾";
  font-size: 0.75rem;
  color: #64748b;
  transition: transform 0.2s;
}

.filter-bar:not([open]) .filter-bar-summary::before {
  transform: rotate(-90deg);
}

.filter-bar-title {
  flex: 1;
}

.filter-bar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #2563eb;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
}

.filter-form {
  padding: 6px 10px 8px;
}

.filter-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.filter-grid {
  display: flex;
  flex: 1 1 100%;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-width: 0;
}

.filter-field {
  flex: 1 1 140px;
  min-width: 0;
}

.filter-field--grow {
  flex: 2 1 200px;
}

.filter-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.filter-input {
  width: 100%;
  box-sizing: border-box;
  font-size: 16px;
  padding: 6px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  font-family: inherit;
  line-height: 1.2;
}

.filter-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.filter-input--date {
  color-scheme: light;
}

.filter-input--select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.filter-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.filter-preset {
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.2;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.filter-preset:hover,
.filter-preset:focus-visible {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
}

.filter-bar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
}

.filter-results {
  font-size: 0.78rem;
  color: #94a3b8;
  white-space: nowrap;
}

.filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  line-height: 1.2;
}

.filter-btn--apply {
  background: #2563eb;
  color: #fff;
}

.filter-btn--clear {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

/* —— Escritorio —— */
@media (min-width: 768px) {
  .topbar-inner {
    max-width: 900px;
    margin: 0 auto;
    padding: 14px 20px;
  }

  .nav-toggle {
    display: none;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 932px;
    margin: 0 auto;
    padding: 0 16px;
  }

  .topbar-inner {
    flex: 0 0 auto;
    padding: 14px 0;
  }

  .nav-menu {
    display: flex !important;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 14px 0;
    border-top: none;
    max-height: none;
    overflow: visible;
    background: transparent;
  }

  .nav-menu a {
    padding: 8px 12px;
    margin: 0;
    font-size: 0.9rem;
    white-space: nowrap;
  }

  .nav-menu .nav-logout {
    margin-top: 0;
    margin-left: 8px;
    padding: 8px 12px;
    border-top: none;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
  }

  .grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .item-row {
    grid-template-columns: 2fr 1fr 1fr 1fr;
  }

  .actions.large .btn {
    flex: 0 1 auto;
    min-width: auto;
  }

  .filter-grid {
    flex: 1 1 auto;
  }

  .filter-field {
    flex: 1 1 calc(50% - 8px);
  }

  .filter-field--grow {
    flex: 1 1 100%;
  }
}
