:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e38;
  --text: #e6e8eb;
  --muted: #9aa1ac;
  --accent: #4f8cff;
  --positive: #3ecf8e;
  --negative: #ff6b6b;
}
* { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
}
.nav {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 0.8rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}
.nav a { color: var(--text); text-decoration: none; flex-shrink: 0; }
.nav .brand { font-weight: 700; margin-right: auto; flex-shrink: 0; }
.quien { color: var(--muted); font-size: 0.8rem; margin-left: auto; flex-shrink: 0; }
.nav .logout { margin-left: 0; flex-shrink: 0; }
.nav button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0.4rem 0; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 1rem; }
.table-scroll table { margin-top: 0; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; color: var(--muted); margin-top: 2rem; }
.cards { display: flex; gap: 1rem; flex-wrap: wrap; margin: 1rem 0; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  min-width: 180px;
  flex: 1;
}
.card-label { color: var(--muted); font-size: 0.8rem; }
.card-value { font-size: 1.6rem; font-weight: 700; margin: 0.2rem 0; }
.card-sub { color: var(--muted); font-size: 0.75rem; }
.card.positive .card-value { color: var(--positive); }
.card.negative .card-value { color: var(--negative); }
table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; }
.btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.85rem;
  border: none;
  cursor: pointer;
}
.form { display: flex; flex-direction: column; gap: 0.8rem; max-width: 420px; margin-top: 1rem; }
.form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
input, select, textarea, button {
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
}
textarea { min-height: 60px; }
.error { color: var(--negative); }
.notas { color: var(--muted); font-style: italic; }
.login-box { max-width: 320px; margin: 4rem auto; text-align: center; }
.login-box form { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1rem; }
.filters { display: flex; gap: 0.6rem; margin-top: 0.8rem; }
.actions { display: flex; flex-direction: column; gap: 0.3rem; }
.inline-form { display: flex; gap: 0.3rem; }
.inline-form input { padding: 0.3rem; }
.inline-form button { padding: 0.3rem 0.5rem; font-size: 0.75rem; }
.badge { padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; }
.badge-inventario { background: #2a2e38; color: var(--muted); }
.badge-publicada { background: #26456b; color: #9cc4ff; }
.badge-vendida { background: #17422f; color: var(--positive); }
.badge-retirada { background: #4a2020; color: var(--negative); }
.badge-dac7-ok { background: #17422f; color: var(--positive); }
.badge-dac7-aviso { background: #4a3a12; color: #f0b942; }
.badge-dac7-superado { background: #4a2020; color: var(--negative); }
.aviso-parada {
  background: #4a3a12;
  color: #f0b942;
  border: 1px solid #6b5420;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  margin: 1rem 0;
  font-size: 0.85rem;
}
.aviso-parada a { color: #f0b942; }
.photo-grid { display: flex; gap: 0.8rem; flex-wrap: wrap; margin: 0.8rem 0; }
.photo-item { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }
.photo-item img { width: 140px; height: 140px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: repeating-conic-gradient(#20232b 0% 25%, #171a21 0% 50%) 50% / 16px 16px; }
.photo-item button { font-size: 0.75rem; padding: 0.3rem 0.5rem; }
.zona-badge { background: #26456b; color: #9cc4ff; font-weight: 700; }
.aviso-zona-inline { color: #f0b942; font-size: 0.75rem; margin-left: 0.3rem; }

/* ---- Móvil ---- */
@media (max-width: 640px) {
  .container { padding: 1rem 0.8rem; }
  .nav { padding: 0.6rem 0.8rem; gap: 0.9rem; }
  h1 { font-size: 1.2rem; }
  .cards { gap: 0.6rem; }
  .card { min-width: 0; flex: 1 1 calc(50% - 0.6rem); padding: 0.8rem; }
  .card-value { font-size: 1.3rem; }
  .form { max-width: 100%; }
  .filters { flex-wrap: wrap; }
  .filters select { flex: 1 1 auto; min-width: 140px; }
  th, td { padding: 0.5rem 0.5rem; font-size: 0.85rem; }
  .actions, .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input, .inline-form button { width: 100%; }
  /* objetivo tactil >=44px (Apple HIG / Material) en botones y campos */
  input, select, textarea, button, .btn { min-height: 44px; font-size: 1rem; }
  .inline-form input, .inline-form button, .photo-item button { min-height: 38px; font-size: 0.85rem; }
  .photo-item img { width: 100px; height: 100px; }

  /* tablas largas/complejas (piezas, lotes): en vez de scroll horizontal
     incomodo, cada fila se convierte en una tarjeta apilada. data-label en
     cada <td> se pinta como etiqueta via ::before (sin JS). */
  .table-stack { overflow-x: visible; }
  .table-stack table, .table-stack thead, .table-stack tbody, .table-stack th, .table-stack tr {
    display: block;
  }
  .table-stack thead { display: none; }
  .table-stack tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 0.8rem;
    padding: 0.7rem 0.8rem;
    background: var(--panel);
  }
  .table-stack td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    padding: 0.35rem 0;
    border-bottom: 1px dashed var(--border);
    text-align: right;
  }
  .table-stack td:last-child { border-bottom: none; }
  .table-stack td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-align: left;
    flex-shrink: 0;
  }
  .table-stack td.stack-actions { flex-direction: column; align-items: stretch; }
  .table-stack td.stack-actions::before { margin-bottom: 0.3rem; }
}
