/* ============================================================
   INVENTARIO BARRA
   ============================================================ */

* {
  box-sizing: border-box;
}


:root {
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;

  color: #222;

  background: #f5f5f5;

  -webkit-text-size-adjust: 100%;
}


html {
  min-height: 100%;
}


body {
  min-height: 100dvh;

  margin: 0;

  background: #f5f5f5;
}


body.modal-open {
  overflow: hidden;
}

body.item-drawer-open {
  overflow: hidden;
}


button,
input,
textarea,
select {
  font: inherit;
}


button {
  cursor: pointer;

  touch-action: manipulation;

  -webkit-tap-highlight-color:
    transparent;
}


button:disabled {
  cursor: not-allowed;

  opacity: 0.45;
}


/* ============================================================
   APP
   ============================================================ */

.app {
  width:
    min(
      calc(100% - 20px),
      680px
    );

  margin: 0 auto;

  padding:
    calc(14px + env(safe-area-inset-top))
    0
    calc(28px + env(safe-area-inset-bottom));
}


/* ============================================================
   HEADER
   ============================================================ */

.app-header {
  margin-bottom: 17px;

  text-align: center;
}


.app-title-row {
  position: relative;

  display: flex;

  align-items: center;

  justify-content: center;

  min-height: 44px;
}


.app-header h1 {
  margin: 0;

  font-size:
    clamp(
      1.25rem,
      4.5vw,
      1.5rem
    );

  line-height: 1.2;
}


#progress-text {
  margin: 7px 0 0;

  color: #666;

  font-size: 0.82rem;

  text-align: right;
}


.header-back-button {
  position: absolute;

  top: 50%;

  left: 0;

  display: flex;

  align-items: center;

  gap: 4px;

  max-width: 33%;

  min-height: 44px;

  padding: 6px 0;

  transform:
    translateY(-50%);

  border: 0;

  background: transparent;

  color: #555;

  font-size: 0.76rem;

  font-weight: 650;

  text-align: left;

  white-space: nowrap;
}


.header-back-button[hidden] {
  display: none;
}


/* ============================================================
   PROGRESO
   ============================================================ */

.progress-bar-container {
  position: relative;

  width: 100%;

  height: 7px;

  margin: 12px 0 5px;

  overflow: hidden;

  background: #ddd;

  border-radius: 999px;
}


.progress-bar {
  position: absolute;

  top: 0;

  left: 0;

  width: 0;

  height: 100%;

  background: #218c4a;

  border-radius: inherit;

  transition:
    left 0.25s ease,
    width 0.25s ease;
}


.progress-bar-partial {
  background: #e5b52b;

  transition:
    left 0.25s ease,
    width 0.25s ease;
}


/* ============================================================
   CATEGORÍAS
   ============================================================ */

.categories-view {
  display: grid;

  gap: 14px;
}


.categories-heading h2 {
  margin: 0;

  font-size:
    clamp(
      1.2rem,
      4.8vw,
      1.4rem
    );
}


.categories-heading p {
  margin: 4px 0 0;

  color: #666;

  font-size: 0.84rem;
}


.category-grid {
  display: grid;

  grid-template-columns:
    repeat(
      2,
      minmax(0, 1fr)
    );

  gap: 10px;
}


.category-card {
  display: flex;

  flex-direction: column;

  min-width: 0;

  min-height: 128px;

  padding: 14px;

  border:
    1px solid #ddd;

  border-radius: 14px;

  background: #fff;

  color: #222;

  text-align: left;

  box-shadow: 0 1px 2px rgb(0 0 0 / 4%);

  transition:
    transform 0.08s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}


.scope-card {
  min-height: 88px;
  justify-content: center;
  text-decoration: none;
}

.scope-card:focus-visible {
  outline: 3px solid #777;
  outline-offset: 2px;
}

.category-card-title {
  overflow-wrap: anywhere;

  font-size: 0.98rem;

  font-weight: 700;

  line-height: 1.2;
}


.category-card-progress {
  align-self: end;

  margin-top: auto;

  color: #555;

  font-size: 0.76rem;

  line-height: 1.35;
}


.category-progress-bar {
  position: relative;

  display: block;

  width: 100%;

  height: 6px;

  margin-top: 9px;

  overflow: hidden;

  border-radius: 999px;

  background: #e5e5e5;
}


.category-progress-value {
  position: absolute;

  top: 0;

  left: 0;

  display: block;

  height: 100%;

  border-radius: inherit;

  background: #1d6b2f;

  transition:
    width 0.25s ease;
}


.category-progress-partial {
  position: absolute;

  top: 0;

  display: block;

  height: 100%;

  background: #e5b52b;

  transition:
    left 0.25s ease,
    width 0.25s ease;
}


.back-button {
  width: fit-content;

  min-height: 38px;

  padding: 7px 0;

  border: 0;

  background: transparent;

  color: #555;

  font-size: 0.84rem;

  font-weight: 650;

  text-align: left;
}


.back-arrow {
  flex-shrink: 0;

  font-size: 1.2rem;

  padding-left: 0.75rem;
}


.category-card:focus-visible,
.back-button:focus-visible,
.header-back-button:focus-visible {
  outline:
    3px solid
    rgb(0 0 0 / 18%);

  outline-offset: 2px;
}


/* ============================================================
   CONTEO
   ============================================================ */

.count-view {
  display: grid;

  gap: 16px;
}


.item-navigation-top {
  display: block;
}


.item-drawer-trigger {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 10px 15px;
  border: 1px solid rgb(0 0 0 / 13%);
  border-radius: 15px;
  background: #fff;
  color: #222;
  text-align: left;
  box-shadow: 0 1px 2px rgb(0 0 0 / 4%);
}

.item-drawer-trigger-icon {
  display: grid;
  gap: 4px;
  flex: 0 0 auto;
  width: 23px;
}

.item-drawer-trigger-icon span {
  display: block;
  height: 2px;
  border-radius: 2px;
  background: #555;
}

.item-drawer-trigger-icon span:nth-child(2) {
  width: 17px;
}

.item-drawer-trigger-label {
  flex: 1;
  font-weight: 700;
}

.item-drawer {
  position: fixed;
  z-index: 100;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear 0.34s;
}

.item-drawer.is-open {
  visibility: visible;
  pointer-events: auto;
  transition: none;
}

.item-drawer-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: transparent;
}

.item-drawer-panel {
  position: absolute;
  inset: 10px auto 10px 10px;
  display: flex;
  flex-direction: column;
  width: min(420px, calc(100vw - 32px));
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(12px + env(safe-area-inset-bottom));
  border: 1px solid rgb(255 255 255 / 42%);
  border-radius: 22px;
  background: rgb(184 184 184 / 52%);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  box-shadow: 0 6px 18px rgb(0 0 0 / 10%), inset 0 1px rgb(255 255 255 / 42%);
  transform: translateX(-105%);
  transition: transform 0.34s cubic-bezier(.22, 1, .36, 1);
  outline: none;
}

.item-drawer.is-open .item-drawer-panel {
  transform: translateX(0);
}

.item-drawer-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.item-drawer-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: #444;
  font-size: 1.8rem;
  line-height: 1;
}

.item-drawer-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.item-drawer-search {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 10px 13px;
  border: 1px solid #c6c6c6;
  border-radius: 12px;
  background: rgb(255 255 255 / 32%);
  color: #222;
  outline: none;
}

.item-drawer-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 3px 12px 0;
}

.item-drawer-group + .item-drawer-group {
  margin-top: 19px;
}

.item-drawer-group-toggle {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  margin: 0 0 4px;
  padding: 6px 5px;
  color: #666;
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
  background: var(--ui-drawer);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.item-drawer-group-toggle::-webkit-details-marker {
  display: none;
}

.item-drawer-group-toggle::after {
  content: "›";
  margin-left: 10px;
  color: #555;
  font-size: 1.4rem;
  font-weight: 400;
  line-height: 1;
}

.item-drawer-group[open] > .item-drawer-group-toggle::after {
  content: "⌄";
}

.item-drawer-group-toggle:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 1px;
  border-radius: 6px;
}

.item-drawer-link {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 54px;
  margin-bottom: 6px;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgb(255 255 255 / 16%);
  color: #222;
  text-align: left;
}

.item-drawer-link.is-current {
  border-color: transparent;
  background: var(--ui-nav-active, rgb(230 230 230 / 52%));
}

.item-drawer-link.is-current {
  box-shadow: inset 3px 0 #777;
}

.item-drawer-name {
  min-width: 0;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.item-drawer-state {
  color: #666;
  font-size: 0.67rem;
  white-space: nowrap;
}

.item-drawer-status {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.status-dot-pending { background: #cb514c; }
.status-dot-partial { background: #dda637; }
.status-dot-counted { background: #45a573; }

.item-drawer-empty {
  padding: 24px 6px;
  color: #666;
  text-align: center;
  font-size: 0.84rem;
}

.item-drawer [hidden] {
  display: none !important;
}


.item-card {
  min-width: 0;

  padding:
    clamp(
      17px,
      3.5vw,
      21px
    );

  background: #fff;

  border-radius: 14px;

  border: 1px solid #e7e7e7;
  box-shadow: 0 1px 2px rgb(0 0 0 / 4%);
}


.item-header {
  display: flex;

  align-items: flex-start;

  justify-content: space-between;

  gap: 14px;
}


.item-heading {
  min-width: 0;
}


.item-category {
  display: block;

  margin-bottom: 7px;

  color: #777;

  font-size: 0.72rem;

  text-transform: lowercase;

  letter-spacing: 0.04em;
}


.item-card h2 {
  margin: 0;

  font-size:
    clamp(
      1.1rem,
      4.5vw,
      1.3rem
    );

  line-height: 1.2;

  overflow-wrap: anywhere;
}


.item-area {
  margin: 7px 0 0;

  color: #666;

  font-size: 0.86rem;
}


/* ============================================================
   ESTADOS
   ============================================================ */

.status-badge {
  flex-shrink: 0;

  padding:
    5px 8px;

  border-radius: 999px;

  font-size: 0.7rem;

  font-weight: 650;

  white-space: nowrap;
}


.status-pending {
  background: #fce8e8;

  color: #a61b1b;
}


.status-partial {
  background: #fff1d6;

  color: #8a5b00;
}


.status-counted {
  background: #e5f4e8;

  color: #1d6b2f;
}


/* ============================================================
   FORMULARIOS
   ============================================================ */

.field {
  display: grid;

  gap: 8px;

  margin-top: 18px;
}


.field label {
  font-size: 0.88rem;

  font-weight: 650;
}


.field input,
.field textarea {
  width: 100%;

  border:
    1px solid #ccc;

  border-radius: 10px;

  background: #fff;

  color: #222;

  outline: none;

  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}


.field input {
  min-height: 50px;

  padding:
    10px 12px;

  font-size: 1.1rem;
}


.field textarea {
  min-height: 76px;

  padding:
    10px 12px;

  resize: vertical;
}


.field input:focus,
.field textarea:focus,
.item-drawer-trigger:focus-visible,
.item-drawer-close:focus-visible,
.item-drawer-link:focus-visible,
.item-drawer-search:focus {
  border-color: #222;

  box-shadow:
    0 0 0 3px
    rgb(0 0 0 / 7%);
}

@media (prefers-reduced-motion: reduce) {
  .item-drawer,
  .item-drawer-backdrop,
  .item-drawer-panel {
    transition: none;
  }
}


.field small {
  color: #777;

  font-size: 0.76rem;
}


/* ============================================================
   ACCIONES
   ============================================================ */

.count-actions {
  display: grid;

  grid-template-columns:
    1fr 1fr;

  gap: 10px;
}


.button {
  width: 100%;

  min-height: 46px;

  padding:
    10px 13px;

  border-radius: 11px;

  font-size: 0.9rem;

  font-weight: 650;

  transition:
    transform 0.08s ease,
    opacity 0.2s ease;
}



.button-primary {
  border: 0;

  background: #222;

  color: #fff;
}


.button-secondary {
  border:
    1px solid #ccc;

  background: #fff;

  color: #222;
}


.button-ghost {
  border:
    1px solid transparent;

  background: transparent;

  color: #555;
}


.button-danger {
  border: 0;

  background: #b42318;

  color: #fff;
}


/* ============================================================
   FEEDBACK
   ============================================================ */

.feedback {
  min-height: 18px;

  margin: 0;

  text-align: center;

  font-size: 0.82rem;
}


.feedback-success {
  color: #1d6b2f;
}


.feedback-error {
  color: #a61b1b;
}


/* ============================================================
   RESUMEN
   ============================================================ */

.summary-view {
  display: grid;

  gap: 13px;
}


.summary-header {
  padding-bottom: 2px;
}


.summary-header h2 {
  margin: 0;

  font-size:
    clamp(
      1.2rem,
      4.8vw,
      1.4rem
    );
}


.summary-header p {
  margin: 4px 0 0;

  color: #666;

  font-size: 0.84rem;
}


/* ============================================================
   ESTADÍSTICAS
   ============================================================ */

.stats-grid {
  display: grid;

  grid-template-columns:
    repeat(
      3,
      minmax(0, 1fr)
    );

  gap: 7px;
}


.stat-card {
  min-width: 0;

  padding:
    11px 8px;

  border: 0;

  background: #fff;

  border-radius: 10px;

  color: inherit;

  font: inherit;

  text-align: center;
}


.stat-card:focus-visible {
  outline:
    2px solid #397b4b;

  outline-offset: 2px;
}


.stat-card strong {
  display: block;

  font-size: 1.25rem;

  line-height: 1.1;
}


.stat-card span {
  display: block;

  margin-top: 3px;

  font-size: 0.72rem;

  white-space: nowrap;
}


.stat-pending span {
  color: #a61b1b;
}


.stat-partial span {
  color: #8a5b00;
}


.stat-counted span {
  color: #1d6b2f;
}


/* ============================================================
   ACORDEONES
   ============================================================ */

.accordion-list {
  display: grid;

  gap: 7px;
}


.accordion {
  overflow: hidden;

  background: #fff;

  border-radius: 11px;
}


.accordion summary {
  display: flex;

  align-items: center;

  justify-content: space-between;

  gap: 8px;

  min-height: 46px;

  padding:
    11px 13px;

  cursor: pointer;

  list-style: none;

  font-size: 0.86rem;

  font-weight: 650;

  -webkit-tap-highlight-color:
    transparent;
}


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


.accordion summary::after {
  content: "▸";

  color: #888;

  transition:
    transform 0.15s ease;
}


.accordion[open]
  summary::after {
  transform:
    rotate(90deg);
}


.section-count {
  margin-left: auto;

  color: #777;

  font-size: 0.76rem;

  font-weight: 500;
}


.accordion-content {
  display: grid;

  border-top:
    1px solid #eee;
}


/* ============================================================
   ITEMS DEL RESUMEN
   ============================================================ */

.summary-item-button {
  display: flex;

  align-items: center;

  justify-content: space-between;

  gap: 10px;

  width: 100%;

  min-height: 50px;

  padding:
    9px 13px;

  border: 0;

  border-bottom:
    1px solid #eee;

  background: #fff;

  color: #222;

  text-align: left;
}


.summary-item-button:last-child {
  border-bottom: 0;
}



.summary-item-main {
  min-width: 0;
}


.summary-item-main strong {
  display: block;

  overflow-wrap: anywhere;

  font-size: 0.84rem;
}


.summary-item-main small {
  display: block;

  margin-top: 2px;

  color: #777;

  font-size: 0.7rem;
}


.summary-item-value {
  display: flex;

  align-items: center;

  gap: 5px;

  flex-shrink: 0;

  max-width: 42%;

  color: #555;

  font-size: 0.75rem;

  text-align: right;
}


.summary-arrow {
  color: #999;

  font-size: 0.85rem;
}


.summary-empty {
  margin: 0;

  padding:
    11px 13px;

  color: #888;

  font-size: 0.75rem;
}


/* ============================================================
   RESPONSABLE
   ============================================================ */

.responsible-section {
  padding:
    13px;

  background: #fff;

  border-radius: 11px;
}


.section-heading h3 {
  margin: 0;

  font-size: 0.9rem;
}


.section-heading p {
  margin: 3px 0 0;

  color: #666;

  font-size: 0.75rem;
}


/* ============================================================
   ACCIONES DEL RESUMEN
   ============================================================ */

.summary-actions {
  display: grid;

  grid-template-columns:
    1fr 1fr;

  gap: 8px;
}


/* ============================================================
   EMPTY
   ============================================================ */

.empty-state {
  padding:
    25px 18px;

  background: #fff;

  border-radius: 14px;

  text-align: center;
}


.empty-state h2 {
  margin-top: 0;

  font-size: 1.1rem;
}


.empty-state p {
  color: #666;

  font-size: 0.85rem;
}


/* ============================================================
   MODAL
   ============================================================ */

.modal-backdrop {
  position: fixed;

  inset: 0;

  z-index: 1000;

  display: grid;

  place-items: center;

  padding:
    calc(
      14px +
      env(safe-area-inset-top)
    )
    14px
    calc(
      14px +
      env(safe-area-inset-bottom)
    );

  background:
    rgb(0 0 0 / 45%);
}


.modal-backdrop[hidden] {
  display: none;
}


.modal {
  width:
    min(
      100%,
      420px
    );

  padding:
    20px;

  background: #fff;

  border-radius: 16px;

  box-shadow: 0 8px 28px rgb(0 0 0 / 14%);
}


.modal-icon {
  display: grid;

  place-items: center;

  width: 42px;

  height: 42px;

  margin:
    0 auto 10px;

  border-radius: 50%;

  background: #fff1d6;

  color: #8a5b00;

  font-size: 1.2rem;

  font-weight: 800;
}


.modal h2 {
  margin: 0;

  font-size: 1.15rem;
}


.modal p {
  margin:
    9px 0 0;

  color: #555;

  font-size: 0.85rem;

  line-height: 1.45;
}


.modal-actions {
  display: grid;

  gap: 8px;

  margin-top: 18px;
}


/* ============================================================
   PANTALLAS PEQUEÑAS
   ============================================================ */

@media (max-width: 600px) {
  .app {
    width: calc(100% - 24px);
  }

  .app-header {
    margin-bottom: 14px;
  }

  .app-header h1 {
    font-size: 1.14rem;
    overflow-wrap: anywhere;
  }

  .category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .category-card {
    min-height: 120px;
    padding: 11px;
    box-shadow: none;
  }

  .category-card-title {
    font-size: 0.84rem;
  }

  .category-card-progress {
    font-size: 0.68rem;
  }

  .scope-card {
    min-height: 76px;
  }

  .count-view {
    gap: 12px;
  }

  .item-card {
    padding: 16px;
    box-shadow: none;
  }

  .item-header {
    flex-direction: column;
    gap: 9px;
  }

  .status-badge {
    align-self: flex-start;
  }

}

@media (max-width: 380px) {
  .count-actions {
    grid-template-columns:
      1fr;
  }


  .summary-item-value {
    max-width: 38%;
  }

}


/* ============================================================
   PANTALLAS GRANDES
   ============================================================ */

@media (min-width: 700px) {

  .app {
    padding-top: 24px;
  }


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

}
