:root {
  --color-primary: #9c3f95;
  --color-primary-hover: #83337d;
  --color-primary-light: #f3e6f2;
  --color-text: #1f1f1f;
  --color-text-muted: #6b6b6b;
  --color-border: #e3e3e3;
  --color-bg: #ffffff;
  --color-bg-soft: #f6f6f6;
  --color-disabled: #b9b9b9;
  --color-accent-yellow: #f4d000;
  --radius: 6px;
  --font-main: "Poppins", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-main);
  color: var(--color-text);
  background: var(--color-bg);
}

a {
  color: inherit;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- LOGIN ---------- */

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

.login-image {
  flex: 1.4;
  background-image: linear-gradient(
      rgba(25, 15, 25, 0.62),
      rgba(25, 15, 25, 0.72)
    ),
    url("../assets/login-bg.webp");
  background-size: cover;
  background-position: center;
  position: relative;
  min-height: 100vh;
}

.login-panel {
  flex: 1;
  min-width: 360px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4rem 4rem;
  zoom: 0.85;
}

.login-panel h1 {
  font-size: 2.5rem;
  font-weight: 500;
  margin: 0 0 2.5rem 0;
}

.field {
  margin-bottom: 1.5rem;
}

.field label {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  color: var(--color-text);
}

.field input {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
}

.field input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 0.6rem 1.6rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  transition: background 0.15s ease;
  white-space: nowrap;
}

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

.error-msg {
  color: #c0392b;
  font-size: 0.9rem;
  margin-top: -0.75rem;
  margin-bottom: 1rem;
  min-height: 1.2em;
}

/* ---------- CAPTCHA ---------- */

.captcha-field {
  margin-bottom: 1.25rem;
}

.captcha-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.captcha-row canvas {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.btn-captcha-refresh {
  background: var(--color-bg-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--color-text);
}

.btn-captcha-refresh:hover {
  background: var(--color-primary-light);
}

@media (max-width: 800px) {
  .login-image {
    display: none;
  }
  .login-panel {
    padding: 2rem;
    min-width: 0;
    width: 100%;
    zoom: 1;
  }
}

/* ---------- DASHBOARD ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 2.5rem;
  border-bottom: 1px solid var(--color-border);
  gap: 1.5rem;
  flex-wrap: wrap;
  position: relative;
}

.brand {
  font-size: 1.9rem;
  font-weight: 500;
  white-space: nowrap;
}

.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  padding: 0;
  flex-shrink: 0;
}

.hamburger-btn span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--color-text);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.hamburger-btn.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.hamburger-btn.open span:nth-child(2) {
  opacity: 0;
}

.hamburger-btn.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.main-nav {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  flex: 1;
}

.main-nav .nav-item {
  font-size: 1.1rem;
  color: var(--color-text);
  text-decoration: none;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid transparent;
}

.main-nav .nav-item.active {
  font-weight: 700;
  border-bottom-color: var(--color-primary);
}

.main-nav .nav-item.disabled {
  color: var(--color-disabled);
  cursor: not-allowed;
  pointer-events: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.user-badge {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.btn-logout {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  text-decoration: underline;
}

.layout {
  display: flex;
  min-height: calc(100vh - 200px);
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  padding: 2rem 1.5rem;
  border-right: 1px solid var(--color-border);
}

.sidebar h2 {
  font-size: 1.1rem;
  margin: 0 0 1.5rem 0;
}

.sidebar h3 {
  font-size: 1rem;
  margin: 0 0 0.75rem 0;
}

.sidebar h3.filter-block-spacing {
  margin-top: 1.75rem;
}

#filterListMarca,
#filterListNumero {
  max-height: 260px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.filter-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0;
  font-size: 0.95rem;
  cursor: pointer;
}

.filter-option span {
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

.filter-option input[type="radio"] {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.content {
  flex: 1;
  padding: 0 2.5rem;
  overflow-x: auto;
}

.content-full {
  flex: none;
  width: 100%;
  padding: 1.5rem 2.5rem 0 2.5rem;
}

/* ---------- BUSCADOR / BREADCRUMB (Clientes) ---------- */

.search-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--color-bg-soft);
  padding: 1.25rem 2.5rem;
  font-size: 1rem;
  color: var(--color-text-muted);
}

.search-icon {
  font-size: 1.1rem;
}

.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 1rem;
  color: var(--color-text);
  outline: none;
}

.search-bar input::placeholder {
  color: var(--color-text-muted);
}

.breadcrumb-bar {
  font-size: 0.95rem;
}

.breadcrumb-bar a {
  text-decoration: underline;
  color: var(--color-text-muted);
}

.breadcrumb-bar strong {
  color: var(--color-text);
}

.clients-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
}

.clients-count {
  font-size: 1rem;
}

.link-download {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  text-decoration: underline;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.link-download:hover {
  color: var(--color-primary);
}

table.clients-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.clients-table thead th {
  text-align: left;
  padding: 0.75rem 1.25rem;
  font-weight: 500;
  font-size: 1.05rem;
  border-bottom: 1px solid var(--color-border);
}

.clients-table tbody td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.95rem;
}

.clients-table tbody tr:hover {
  background: var(--color-bg-soft);
}

/* ---------- PERFIL DE CLIENTE ---------- */

.client-profile-header {
  display: flex;
  align-items: center;
  gap: 1.75rem;
  padding: 1.5rem 0 2rem 0;
  flex-wrap: wrap;
}

.client-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 600;
  flex-shrink: 0;
}

.client-info-name {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 0.3rem 0;
}

.client-info-line {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0.2rem 0;
}

.client-profile-actions {
  display: flex;
  gap: 0.75rem;
  margin-left: auto;
}

.btn-danger-outline {
  color: #c0392b;
  border-color: #e6b3ac;
}

.btn-danger-outline:hover {
  background: #fbebe9;
}

.notes-section {
  padding-bottom: 3rem;
}

.notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.notes-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.note-card {
  background: var(--color-bg-soft);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1rem;
}

.note-label {
  display: block;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.note-fecha,
.note-descripcion {
  font-size: 0.95rem;
  line-height: 1.4;
}

.table-scroll {
  margin-top: 1rem;
  max-height: 66vh;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

table.inventory-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

.inventory-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--color-bg-soft);
  text-align: left;
  padding: 1rem 1.25rem;
  font-weight: 500;
  font-size: 1.05rem;
  overflow-wrap: break-word;
}

.inventory-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.inventory-toolbar .hint-text {
  margin: 0;
}

.btn-download {
  background: var(--color-accent-yellow);
  color: #2b2200;
  border: none;
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-download:hover {
  filter: brightness(0.95);
}

.inventory-table tbody td {
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.95rem;
  overflow-wrap: break-word;
  word-break: break-word;
}

.inventory-table tbody tr:hover {
  background: var(--color-bg-soft);
}

.clickable-row {
  cursor: pointer;
}

.hint-text {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 1rem 0 0 0;
}

/* ---------- TABLA DE HISTORIAL ---------- */

table.history-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.history-table thead th {
  background: var(--color-bg-soft);
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 500;
  font-size: 0.95rem;
}

.history-table tbody td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}

.stock-value {
  font-weight: 600;
}

.stock-low {
  color: #c0392b;
}

.row-actions button {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  text-decoration: underline;
  margin-right: 0.75rem;
  padding: 0;
}

.row-actions button:hover {
  color: var(--color-primary);
}

.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--color-text-muted);
}

.app-footer {
  border-top: 1px solid var(--color-border);
  padding: 2rem 2.5rem;
  margin-top: 2rem;
}

.app-footer .brand {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
}

.app-footer p {
  margin: 0.2rem 0;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.app-footer a {
  color: var(--color-text-muted);
  text-decoration: underline;
}

/* ---------- MODAL ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
}

.modal h2 {
  margin-top: 0;
  font-size: 1.4rem;
  font-weight: 500;
}

.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.25rem;
}

.modal-grid .field:nth-child(1),
.modal-grid .field:nth-child(2) {
  grid-column: span 1;
}

.modal .field input,
.modal .field select,
.modal .field textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
}

.modal .field textarea {
  resize: vertical;
  min-height: 100px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}

.btn-secondary {
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 0.6rem 1.4rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.btn-secondary:hover {
  background: var(--color-bg-soft);
}

.datalist-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: -0.75rem;
  margin-bottom: 1rem;
}

/* ---------- RESPONSIVE: TABLET (iPad) ---------- */

@media (max-width: 1120px) {
  .app-header {
    padding: 1.25rem 1.75rem;
  }
  .content {
    padding: 0 1.75rem;
  }
  .content-full {
    padding: 1.5rem 1.75rem 0 1.75rem;
  }
  .search-bar {
    padding: 1.1rem 1.75rem;
  }
  .sidebar {
    width: 220px;
    padding: 1.75rem 1.25rem;
  }
  .modal {
    max-width: 560px;
  }
  .inventory-table thead th {
    padding: 0.75rem 0.6rem;
    font-size: 0.9rem;
  }
  .inventory-table tbody td {
    padding: 0.75rem 0.6rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 900px) {
  .main-nav {
    gap: 1.5rem;
  }
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    gap: 2.5rem;
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .sidebar h2 {
    width: 100%;
  }
  .sidebar h3.filter-block-spacing {
    margin-top: 0;
  }
}

/* ---------- RESPONSIVE: SMARTPHONE ---------- */

@media (max-width: 640px) {
  .app-header {
    padding: 1rem 1.25rem;
  }
  .brand {
    font-size: 1.5rem;
  }
  .hamburger-btn {
    display: flex;
    order: 1;
    margin-left: auto;
  }
  .header-actions {
    order: 2;
    width: 100%;
    justify-content: flex-end;
  }
  .main-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.08);
    padding: 0.25rem 1.25rem 0.75rem;
    z-index: 40;
  }
  .main-nav.open {
    display: flex;
  }
  .main-nav .nav-item {
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--color-border);
  }
  .main-nav .nav-item:last-child {
    border-bottom: none;
  }
  .content {
    padding: 0 1.25rem;
  }
  .app-footer {
    padding: 1.5rem 1.25rem;
  }
  .modal {
    padding: 1.5rem;
  }
  .modal-grid {
    grid-template-columns: 1fr;
  }

  /* Tabla en formato tarjeta para pantallas angostas */
  .inventory-table thead {
    display: none;
  }
  .inventory-table,
  .inventory-table tbody,
  .inventory-table tr,
  .inventory-table td {
    display: block;
    width: 100%;
  }
  .inventory-table tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    padding: 0.5rem 1rem;
  }
  .inventory-table td {
    border-bottom: none;
    padding: 0.5rem 0;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
  }
  .inventory-table td[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
  }
  .inventory-table td.row-actions {
    justify-content: flex-start;
    gap: 1rem;
  }

  .history-table thead {
    display: none;
  }
  .history-table,
  .history-table tbody,
  .history-table tr,
  .history-table td {
    display: block;
    width: 100%;
  }
  .history-table tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    padding: 0.5rem 1rem;
  }
  .history-table td {
    border-bottom: none;
    padding: 0.35rem 0;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
  }
  .history-table td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
  }

  /* ---------- Clientes / Perfil en celular ---------- */

  .content-full {
    padding: 1.25rem 1.25rem 0 1.25rem;
  }
  .search-bar {
    padding: 1rem 1.25rem;
  }
  .clients-toolbar {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .clients-table thead {
    display: none;
  }
  .clients-table,
  .clients-table tbody,
  .clients-table tr,
  .clients-table td {
    display: block;
    width: 100%;
  }
  .clients-table tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    padding: 0.5rem 1rem;
  }
  .clients-table td {
    border-bottom: none;
    padding: 0.5rem 0;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    text-align: right;
  }
  .clients-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
    text-align: left;
  }

  .client-profile-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .client-profile-actions {
    margin-left: 0;
    width: 100%;
  }
  .client-profile-actions button {
    flex: 1;
  }

  .note-card {
    grid-template-columns: 1fr;
  }
}
