/* ============================================================
   css/style.css — Inventario de Gavetas
   Paleta: azul oscuro encabezado, blanco/gris claro fondo,
   colores por gavetero en celdas, fuente Inter + mono
   ============================================================ */

/* --- Reset & base ------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #F0F2F5;
  --surface:     #FFFFFF;
  --border:      #D1D5DB;
  --text:        #111827;
  --text-muted:  #6B7280;
  --primary:     #1D4ED8;
  --primary-dk:  #1E3A8A;
  --danger:      #DC2626;
  --shadow-sm:   0 1px 3px rgba(0,0,0,.10);
  --shadow-md:   0 4px 16px rgba(0,0,0,.14);
  --radius:      10px;
  --radius-sm:   6px;
  --font:        'Inter', system-ui, sans-serif;
  --font-mono:   'JetBrains Mono', 'Courier New', monospace;
  --top-bar-h:   56px;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* --- Google Fonts import ----------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500&display=swap');

/* --- Top bar ----------------------------------------------- */
.top-bar {
  position: sticky; top: 0; z-index: 100;
  background: var(--primary-dk);
  height: var(--top-bar-h);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.top-bar__inner {
  max-width: 1100px; margin: 0 auto;
  height: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}
.top-bar__brand {
  display: flex; align-items: center; gap: 10px;
  min-width: 0;
}
.top-bar__icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.top-bar__title {
  font-size: 1.05rem; font-weight: 700; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-bar__nav { display: flex; gap: 8px; flex-shrink: 0; }
.btn-nav {
  padding: 6px 14px; border-radius: 20px;
  font-size: .85rem; font-weight: 600;
  color: rgba(255,255,255,.80);
  border: 1.5px solid rgba(255,255,255,.25);
  transition: background .2s, color .2s;
}
.btn-nav:hover, .btn-nav.active {
  background: rgba(255,255,255,.18); color: #fff;
}
.btn-back {
  font-size: 1.4rem; color: rgba(255,255,255,.8);
  padding: 0 4px; line-height: 1;
  transition: color .15s;
}
.btn-back:hover { color: #fff; }

/* --- Main content ------------------------------------------ */
.main-content {
  max-width: 1100px; margin: 0 auto;
  padding: 24px 16px 60px;
}

/* --- Hero -------------------------------------------------- */
.hero { margin-bottom: 24px; }
.hero__title { font-size: 1.6rem; font-weight: 700; }
.hero__sub { color: var(--text-muted); margin-top: 4px; }

/* --- Gaveteros grid (index) -------------------------------- */
.gaveteros-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.gavetero-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-left: 5px solid var(--card-color, #4A90D9);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, transform .15s;
}
.gavetero-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.gavetero-card__letter {
  width: 44px; height: 44px; flex-shrink: 0;
  background: var(--card-color, #4A90D9);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 1.3rem; font-weight: 700;
  color: #fff;
}
.gavetero-card__info { flex: 1; min-width: 0; }
.gavetero-card__name {
  font-weight: 600; font-size: 1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gavetero-card__dim { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }
.gavetero-card__total {
  display: inline-block;
  background: #EEF2FF; color: #4F46E5;
  padding: 1px 7px; border-radius: 20px;
  font-size: .75rem; font-weight: 600; margin-left: 6px;
}
.gavetero-card__arrow { color: var(--text-muted); font-size: 1.4rem; }

/* --- Gavetero meta chips ----------------------------------- */
.gavetero-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.chip {
  padding: 4px 14px; border-radius: 20px;
  font-size: .82rem; font-weight: 600; color: #fff;
}
.chip--gray { background: var(--text-muted) !important; }

/* --- Drawer grid ------------------------------------------- */
.drawer-grid-wrapper {
  display: inline-grid;
  gap: 0;
  overflow-x: auto;
  max-width: 100%;
  padding-bottom: 8px;
}
.col-labels, .drawer-row {
  display: flex; align-items: center;
}
.corner-cell, .col-label, .row-label {
  width: 30px; height: 30px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 600; color: var(--text-muted);
  font-family: var(--font-mono);
}
.col-label { width: 48px; }
.drawer-cell {
  width: 48px; height: 48px; flex-shrink: 0;
  border: 1.5px solid var(--border);
  margin: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; font-weight: 700;
  transition: background .15s, transform .1s, box-shadow .15s;
  position: relative;
}
.drawer-cell:hover {
  background: #EFF6FF;
  box-shadow: 0 0 0 2px var(--current-color, var(--primary));
  transform: scale(1.08);
  z-index: 1;
}
.drawer-cell:active { transform: scale(.97); }
.drawer-cell--filled {
  background: color-mix(in srgb, var(--current-color, var(--primary)) 14%, white);
  border-color: color-mix(in srgb, var(--current-color, var(--primary)) 40%, white);
}
.drawer-cell__count {
  font-family: var(--font-mono);
  color: var(--current-color, var(--primary));
  font-size: .85rem;
}
.drawer-cell__plus {
  color: #CBD5E1;
  font-size: 1.1rem;
  font-weight: 400;
}

/* --- Legend ------------------------------------------------ */
.legend { display: flex; gap: 16px; margin-top: 16px; flex-wrap: wrap; }
.legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: .8rem; color: var(--text-muted);
}
.legend-item::before {
  content: '';
  width: 18px; height: 18px; border-radius: 4px;
  border: 1.5px solid var(--border);
}
.legend-item--filled::before {
  background: color-mix(in srgb, var(--current-color, var(--primary)) 14%, white);
  border-color: color-mix(in srgb, var(--current-color, var(--primary)) 40%, white);
}

/* --- Modal ------------------------------------------------- */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}
.modal__box {
  position: relative; z-index: 1;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  display: flex; flex-direction: column;
}
.modal__box--sm { max-width: 420px; }

@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal__box { border-radius: 16px; }
}

.modal__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 10px;
  border-bottom: 1px solid var(--border);
}
.modal__title { font-size: 1.1rem; font-weight: 700; }
.modal__close {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: var(--bg);
  font-size: .9rem; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.modal__close:hover { background: #E5E7EB; }
.modal__body { padding: 16px 20px; flex: 1; overflow-y: auto; }
.modal__footer {
  padding: 12px 20px 20px;
  border-top: 1px solid var(--border);
}

/* --- Items list in modal ----------------------------------- */
.item-list { display: flex; flex-direction: column; gap: 10px; }
.item-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex; align-items: flex-start; gap: 12px;
}
.item-card__body { flex: 1; min-width: 0; }
.item-card__name {
  font-weight: 600; font-size: .95rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-card__qty {
  display: inline-block;
  background: #DBEAFE; color: #1D4ED8;
  padding: 2px 8px; border-radius: 20px;
  font-size: .75rem; font-weight: 700;
  margin-top: 4px;
}
.item-card__notes {
  font-size: .82rem; color: var(--text-muted);
  margin-top: 4px; white-space: pre-wrap; word-break: break-word;
}
.item-card__actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-icon {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem;
  transition: background .15s;
}
.btn-icon--danger:hover { background: #FEE2E2; border-color: var(--danger); }
.btn-icon--edit:hover { background: #EFF6FF; border-color: var(--primary); }

/* --- Empty state ------------------------------------------- */
.empty-state {
  text-align: center; color: var(--text-muted);
  padding: 32px 16px; font-size: .95rem;
}
.drawer-empty {
  text-align: center; color: var(--text-muted);
  padding: 24px 0; font-size: .9rem;
}

/* --- Buttons ----------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 600;
  border: none;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: #1E40AF; }
.btn--danger  { background: var(--danger); color: #fff; }
.btn--ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn--ghost:hover { background: var(--bg); }
.btn--full { width: 100%; }

/* --- Forms ------------------------------------------------- */
.form-group { margin-bottom: 14px; position: relative; }
.form-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 5px; }
.form-input {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem; font-family: inherit;
  background: var(--bg);
  transition: border-color .15s, box-shadow .15s;
  resize: vertical;
}
.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.15);
  background: #fff;
}
.form-input--sm { max-width: 120px; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }

/* --- Autocomplete ------------------------------------------ */
.ac-list {
  position: absolute; left: 0; right: 0; top: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 300;
  max-height: 200px; overflow-y: auto;
}
.ac-item {
  padding: 10px 14px; cursor: pointer;
  font-size: .9rem;
  border-bottom: 1px solid #F3F4F6;
  transition: background .1s;
}
.ac-item:hover, .ac-item.ac-active { background: #EFF6FF; }

/* --- Search page ------------------------------------------- */
.search-form { margin-bottom: 20px; position: relative; }
.search-bar { display: flex; gap: 8px; }
.search-input {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem; font-family: inherit;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.search-input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.15);
}
.search-btn { flex-shrink: 0; }
.search-count { font-size: .9rem; color: var(--text-muted); margin-bottom: 12px; }
.results-list { display: flex; flex-direction: column; gap: 10px; }
.result-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, transform .12s;
}
.result-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.result-card__badge {
  padding: 5px 12px; border-radius: 20px;
  font-family: var(--font-mono); font-size: .82rem; font-weight: 700;
  color: #fff; flex-shrink: 0;
}
.result-card__info { flex: 1; min-width: 0; }
.result-card__comp { font-weight: 600; font-size: .95rem; }
.result-card__meta { font-size: .8rem; color: var(--text-muted); margin-top: 3px; }
.result-card__notes { font-style: italic; }
.result-card__arrow { color: var(--text-muted); font-size: 1.3rem; }

/* --- Field error ------------------------------------------- */
.field-error {
  display: block; color: var(--danger);
  font-size: .8rem; margin-top: 4px;
}

/* --- Loading ----------------------------------------------- */
.loading-spinner {
  text-align: center; color: var(--text-muted);
  padding: 30px; font-size: .9rem;
}

/* --- Responsive: phones ------------------------------------ */
@media (max-width: 480px) {
  .hero__title { font-size: 1.3rem; }
  .top-bar__title { font-size: .95rem; }
  .gaveteros-grid { grid-template-columns: 1fr; }
  .drawer-cell { width: 40px; height: 40px; }
  .col-label { width: 40px; }
  .modal__box { border-radius: 20px 20px 0 0; }
}

/* ============================================================
   Modal v4 — un overlay, un box, dos paneles
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,.48);
}
.modal-box {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 520px;
  max-height: 90vh;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 -4px 32px rgba(0,0,0,.18);
}
@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
  .modal-box { border-radius: 16px; max-height: 85vh; }
}
#panelLista, #panelForm {
  display: flex; flex-direction: column;
  max-height: 90vh; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title {
  flex: 1; font-size: 1.05rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-close {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: var(--bg); cursor: pointer;
  font-size: .9rem; color: var(--text-muted);
  flex-shrink: 0;
}
.btn-back-sm {
  border: none; background: none; cursor: pointer;
  font-size: .95rem; font-weight: 700; color: var(--primary);
  padding: 4px 6px; flex-shrink: 0;
}
.modal-body {
  flex: 1; overflow-y: auto;
  padding: 14px 18px 16px;
}
.modal-footer {
  padding: 12px 18px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
