:root {
  --cream: #faf6f0;
  --cream-2: #f2ebe0;
  --ink: #2b2521;
  --ink-soft: #6b615a;
  --line: #e7ddcf;
  --accent: #b5794a;
  --accent-dark: #96602f;
  --accent-soft: #f1e2d0;
  --rose: #b8697a;
  --green: #4f7a5b;
  --green-bg: #e7f1e7;
  --amber: #a3742a;
  --amber-bg: #faf0da;
  --red: #a44b42;
  --red-bg: #f7e6e2;
  --white: #ffffff;
  --shadow-sm: 0 1px 3px rgba(43, 37, 33, 0.08);
  --shadow-md: 0 8px 24px rgba(43, 37, 33, 0.10);
  --shadow-lg: 0 20px 48px rgba(43, 37, 33, 0.18);
  --radius: 16px;
  --radius-sm: 10px;
  --font-head: 'Playfair Display', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

h1, h2, h3 { font-family: var(--font-head); margin: 0; font-weight: 700; }

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

input, select, textarea {
  font-family: inherit;
  font-size: 15px;
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 15%, #fff 0%, var(--cream) 45%, var(--cream-2) 100%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 36px 28px;
  text-align: center;
}
.login-mark {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  display: flex; align-items: center; justify-content: center;
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-sub { color: var(--ink-soft); font-size: 13.5px; margin: 0 0 24px; }
.login-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-error {
  background: var(--red-bg); color: var(--red);
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px; margin: 0;
}

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(250, 246, 240, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--font-head); font-weight: 700; font-size: 17px;
  color: var(--accent-dark);
  min-width: 0;
}
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 6px; flex-shrink: 0; }

.icon-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  transition: background 0.15s, transform 0.15s;
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn:active { transform: scale(0.94); }

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 16px 60px;
}

/* ---------- Summary cards ---------- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}
.summary-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.summary-card .label {
  font-size: 12px; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 6px;
  display: block;
}
.summary-card .value {
  font-family: var(--font-head);
  font-size: 21px; font-weight: 700;
  color: var(--ink);
  word-break: break-word;
}
.summary-card.warn .value { color: var(--amber); }
.summary-card.danger .value { color: var(--red); }
.summary-card.money .value { color: var(--accent-dark); }

/* ---------- Toolbar / filters ---------- */
.toolbar { margin-bottom: 20px; }
.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.search-box {
  flex: 1 1 220px;
  min-width: 0;
  display: flex; align-items: center; gap: 8px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  color: var(--ink-soft);
}
.search-box input {
  border: none; padding: 0; flex: 1; min-width: 0; background: transparent;
}
.search-box input:focus { box-shadow: none; }

.filters-panel {
  display: none;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 4px;
}
.filters-panel.open { display: grid; }
.filters-panel-inline { margin-bottom: 14px; }
.field-sm { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-soft); min-width: 0; }
.field-sm input, .field-sm select { padding: 8px 10px; font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 0.12s, box-shadow 0.12s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-outline { background: var(--white); border-color: var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { color: var(--ink); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-sm { padding: 7px 13px; font-size: 13px; }
.btn-block { width: 100%; display: block; text-align: center; }

/* ---------- Prenda cards ---------- */
.prendas-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.prenda-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, transform 0.15s;
}
.prenda-card:hover { box-shadow: var(--shadow-md); }
.prenda-card.archived { opacity: 0.6; }

.prenda-photo-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--cream-2);
  overflow: hidden;
}
.prenda-photo-wrap img { width: 100%; height: 100%; object-fit: cover; }
.prenda-photo-wrap .no-photo {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft); opacity: 0.5;
}
.estado-badge {
  position: absolute; top: 10px; left: 10px;
  font-size: 11.5px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  backdrop-filter: blur(4px);
}
.estado-disponible { background: rgba(79,122,91,0.14); color: var(--green); }
.estado-poco { background: rgba(163,116,42,0.16); color: var(--amber); }
.estado-agotado { background: rgba(164,75,66,0.16); color: var(--red); }

.prenda-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 0; }
.prenda-title { font-family: var(--font-head); font-size: 18px; font-weight: 700; word-break: break-word; }
.prenda-sub { font-size: 13px; color: var(--ink-soft); word-break: break-word; }

.prenda-precios {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 13px;
  padding: 10px 0; border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line);
}
.prenda-precios .pd { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.prenda-precios .pd .k { color: var(--ink-soft); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
.prenda-precios .pd .v { font-weight: 600; }
.prenda-precios .pd .v.ganancia { color: var(--green); }

.tallas-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.talla-chip {
  font-size: 12.5px; font-weight: 600;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--cream);
  white-space: nowrap;
}
.talla-chip.estado-disponible { background: var(--green-bg); border-color: transparent; color: var(--green); }
.talla-chip.estado-poco { background: var(--amber-bg); border-color: transparent; color: var(--amber); }
.talla-chip.estado-agotado { background: var(--red-bg); border-color: transparent; color: var(--red); }

.prenda-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 4px; }
.prenda-actions .btn { flex: 1 1 auto; }

.empty-state { text-align: center; color: var(--ink-soft); padding: 40px 10px; }

/* ---------- Modals ---------- */
.modal {
  display: none;
  position: fixed; inset: 0;
  z-index: 100;
  background: rgba(43, 37, 33, 0.45);
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal.open { display: flex; }
.modal-panel {
  background: var(--white);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  max-height: 90dvh; /* dvh real en móvil — la barra de direcciones no lo deja más alto que la pantalla visible */
  border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-panel-sm { max-width: 420px; }
.modal-panel-lg { max-width: 760px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 19px; }
/* flex:1 + min-height:0 es lo que de verdad activa el scroll — sin
   min-height:0 un hijo flex nunca se encoge por debajo de su contenido (el
   default es min-height:auto), así que "creció" más allá del modal en vez de
   respetar el límite del padre y dejar que overflow-y hiciera scroll. Bug
   clásico de flexbox, confirmado en vivo: el modal no bajaba nada.
   Segunda vuelta del MISMO bug, un nivel más adentro: .modal-body es TAMBIÉN
   un contenedor flex (column) para su propio contenido — sus hijos son flex
   items con flex-shrink:1 por default, así que en vez de desbordar se
   ACHICABAN para caber (confirmado forzando un div de 1500px que terminó
   midiendo 95px). flex-shrink:0 en los hijos directos evita que se aplasten. */
.modal-body { padding: 16px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 14px; min-width: 0; flex: 1 1 auto; min-height: 0; }
.modal-body > * { flex-shrink: 0; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--line); flex-shrink: 0;
}

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field span { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.form-error { background: var(--red-bg); color: var(--red); padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13.5px; }
.hint { font-size: 13px; color: var(--ink-soft); font-style: italic; }
.ganancia-preview {
  background: var(--green-bg); color: var(--green);
  padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
}

.foto-picker { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.foto-preview {
  width: 84px; height: 84px; border-radius: 14px;
  background: var(--cream-2); color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
}
.foto-preview img { width: 100%; height: 100%; object-fit: cover; }
.foto-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-title-row span { font-size: 13.5px; font-weight: 700; color: var(--ink); }

.tallas-builder { display: flex; flex-direction: column; gap: 8px; }
.talla-row { display: flex; gap: 8px; align-items: center; }
.talla-row input:first-child { flex: 1.2; min-width: 0; }
.talla-row input:last-of-type { flex: 1; min-width: 0; }
.talla-row .remove-talla {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--white); color: var(--red);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}

/* ---------- Detalle modal ---------- */
/* object-fit:contain (no aspect-ratio fijo) — con cover una foto de producto
   en vertical (la orientación normal al fotografiar una prenda con el
   celular) quedaba recortada a una rebanada casi inútil del centro. Aquí se
   ve la foto completa, con franjas si hace falta, nunca recortada. */
.detalle-photo { width: 100%; max-height: 380px; border-radius: var(--radius); overflow: hidden; background: var(--cream-2); margin-bottom: 4px; display: flex; align-items: center; justify-content: center; }
.detalle-photo img { width: 100%; height: 100%; max-height: 380px; object-fit: contain; }
.detalle-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; font-size: 14px; }
.detalle-info-grid .k { color: var(--ink-soft); font-size: 11.5px; text-transform: uppercase; }
.detalle-info-grid .v { font-weight: 600; word-break: break-word; }
.detalle-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.detalle-actions .btn { flex: 1 1 auto; }

details.acc { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
details.acc[open] { background: var(--cream); }
details.acc summary {
  padding: 12px 14px; font-weight: 700; font-size: 14px; cursor: pointer;
  list-style: none; display: flex; align-items: center; justify-content: space-between;
}
details.acc summary::-webkit-details-marker { display: none; }
details.acc summary::after { content: '+'; font-size: 18px; color: var(--ink-soft); }
details.acc[open] summary::after { content: '−'; }
.acc-body { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 10px; }

.talla-manage-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.talla-manage-row .name { font-weight: 700; flex: 1 1 60px; }
.talla-manage-row .qty { font-size: 13px; color: var(--ink-soft); flex-shrink: 0; }
.talla-manage-row .actions { display: flex; gap: 6px; flex-wrap: wrap; }

.mov-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.list-card {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px;
}
.list-card .row1 { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; flex-wrap: wrap; }
.list-card .row2 { display: flex; justify-content: space-between; gap: 10px; color: var(--ink-soft); flex-wrap: wrap; }
.list-card .tag { padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.list-card .tag.entrada { background: var(--green-bg); color: var(--green); }
.list-card .tag.salida { background: var(--red-bg); color: var(--red); }
.list-card .tag.cancelada { background: var(--amber-bg); color: var(--amber); }

.segmented { display: flex; background: var(--cream-2); border-radius: 999px; padding: 4px; gap: 4px; }
.segmented-btn { flex: 1; border: none; background: transparent; padding: 8px 10px; border-radius: 999px; font-weight: 600; font-size: 13.5px; color: var(--ink-soft); }
.segmented-btn.active { background: var(--white); color: var(--ink); box-shadow: var(--shadow-sm); }

.historial-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--white);
  padding: 12px 20px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  z-index: 200; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); }

/* ---------- Tablet ---------- */
@media (min-width: 700px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .prendas-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .modal { align-items: center; }
  .modal-panel { border-radius: 20px; max-height: 88vh; }
}

/* ---------- Desktop ---------- */
@media (min-width: 1100px) {
  .summary-grid { grid-template-columns: repeat(4, 1fr); }
  .prendas-grid { grid-template-columns: repeat(3, 1fr); }
  .container { padding: 26px 24px 70px; }
}

@media (min-width: 1400px) {
  .prendas-grid { grid-template-columns: repeat(4, 1fr); }
}
