:root {
  --bg: #f4efe7;
  --bg-deep: #e9dfd2;
  --surface: rgba(255, 252, 248, 0.88);
  --surface-strong: #fffaf4;
  --ink: #1f2a24;
  --ink-soft: #59655d;
  --line: rgba(31, 42, 36, 0.12);
  --accent: #a64b2a;
  --accent-deep: #76341d;
  --mint: #3f6d56;
  --danger: #9f3e35;
  --shadow: 0 18px 42px rgba(66, 46, 18, 0.08);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --alphabet-sticky-top: 6px;
  --entry-row-sticky-top: 0px;
  --alphabet-scroll-offset: 0px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    var(--surface);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  overflow: hidden;
}

body.loading-active {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.page-shell {
  width: min(100%, 90vw);
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 1rem 0 1rem;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  background: rgba(244, 239, 231, 0.58);
  backdrop-filter: blur(2px);
}

.loading-overlay-card {
  min-width: min(18rem, calc(100vw - 2.4rem));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  padding: 1rem 1.2rem;
  border: 1px solid rgba(31, 42, 36, 0.12);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.96);
  box-shadow: var(--shadow);
  color: var(--accent-deep);
  font-weight: 600;
}

.scroll-to-top-button {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 1200;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.9rem;
  min-width: 2.9rem;
  min-height: 2.9rem;
  padding: 0;
  border: 1px solid rgba(31, 42, 36, 0.12);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.95);
  box-shadow: 0 14px 30px rgba(66, 46, 18, 0.12);
  color: var(--accent-deep);
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.scroll-to-top-button svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: currentColor;
}

.scroll-to-top-button:hover {
  transform: translateY(-1px);
  border-color: rgba(166, 75, 42, 0.24);
}

.loading-spinner {
  width: 1.35rem;
  height: 1.35rem;
  border: 2px solid rgba(166, 75, 42, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.owner-field {
  min-width: min(22rem, 100%);
}

.owner-field .custom-dropdown {
  width: 100%;
}

.owner-inline-status {
  text-align: left;
}

.owner-status-error {
  color: var(--danger);
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.main-grid {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
}

.panel {
  background: var(--surface);
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.4rem;
  min-height: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field {
  display: grid;
  gap: 0.4rem;
}

.rivenditore-picker,
.category-picker {
  display: grid;
  gap: 0.7rem;
}

.custom-dropdown {
  position: relative;
}

.custom-dropdown-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 250, 244, 0.95);
  padding: 0.4rem 0.4rem;
  color: var(--ink);
  cursor: pointer;
}

.custom-dropdown-trigger svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: currentColor;
  flex: 0 0 auto;
}

.custom-dropdown-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  display: grid;
  gap: 0.55rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  width: max-content;

}

.custom-dropdown-panel input {
  min-height: 2.7rem;
}

.custom-dropdown-options {
  display: grid;
  gap: 0.35rem;
  max-height: 15rem;
  overflow: auto;
}

.custom-dropdown-option {
  text-align: left;
  width: 100%;
  min-height: 2.6rem;
  display: flex;
  align-items: center;
  padding: 0.65rem 0.8rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: rgba(255, 250, 244, 0.92);
  color: var(--ink);
  cursor: pointer;
}

.custom-dropdown-option-active {
  border-color: rgba(166, 75, 42, 0.25);
  background: rgba(166, 75, 42, 0.12);
  color: var(--accent-deep);
}

.custom-dropdown-empty {
  padding: 0.65rem 0.2rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.field-help {
  margin: 0;
  font-size: 0.84rem;
  color: var(--ink-soft);
}

.field span {
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

input,
select {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.95);
  padding: 0.4rem 0.4rem;
  color: var(--ink);
}

.primary-button,
.secondary-button,
.pill {
  border-radius: 999px;
}

.primary-button,
.secondary-button {
  min-width: 4.5rem;
  padding: 0.4rem 0.4rem;
  border: none;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fff9f2;
}

.secondary-button {
  background: rgba(255, 250, 244, 0.9);
  border: 1px solid var(--line);
  color: var(--ink);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--accent-deep);
  font-size: 0.82rem;
  width: max-content;

}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.alphabet-index-wrap {
  position: sticky;
  top: var(--alphabet-sticky-top);
  z-index: 14;
}

.alphabet-index {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
}

.alphabet-index-button {
  width: 1.5rem;
  min-width: 1.5rem;
  min-height: 1.5rem;
  padding: 0;
  border: 1px solid rgba(166, 75, 42, 0.14);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.94);
  color: var(--accent-deep);
  cursor: pointer;
}

.alphabet-index-button-disabled {
  border-color: var(--line);
  color: rgba(89, 101, 93, 0.45);
  background: rgba(255, 250, 244, 0.6);
  cursor: default;
}

.alphabet-index-button:not(:disabled):hover {
  transform: translateY(-1px);
  border-color: rgba(166, 75, 42, 0.28);
  background: rgba(166, 75, 42, 0.1);
}

.panel-title-row {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.panel-title-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  min-width: 0;
}

.panel-owner-inline {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  min-width: 0;
}

.panel-owner-inline .eyebrow {
  margin: 0;
}

.panel-owner-inline .owner-field {
  min-width: 0;
}

.panel-owner-inline .owner-field .custom-dropdown {
  width: auto;
}

.feedback {
  padding: 0.8rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.92);
}

.feedback-inline {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 0.85rem);
  left: 50%;
  z-index: 1800;
  width: min(32rem, calc(100vw - 1rem));
  margin: 0;
  display: flex;
  align-items: center;
  min-height: 3rem;
  padding: 0.8rem 0.95rem;
  transform: translateX(-50%);
  box-shadow: 0 14px 32px rgba(66, 46, 18, 0.14);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.feedback-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  width: 100%;
}

.feedback-message {
  min-width: 0;
}

.feedback-timer {
  --feedback-progress: 0%;
  position: relative;
  flex: 0 0 auto;
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 50%;
  background: conic-gradient(var(--mint) var(--feedback-progress), rgba(63, 109, 86, 0.14) 0);
}

.feedback-timer::after {
  content: "";
  position: absolute;
  inset: 0.23rem;
  border-radius: 50%;
  background: rgba(255, 250, 244, 0.96);
}

.feedback-success {
  border-left: 4px solid var(--mint);
}

.feedback-error {
  border-left: 4px solid var(--danger);
}

.selection-panel {
  display: grid;
  gap: 0.2rem;
  transition: max-height 0.3s ease;
}

.selection-panel.reduced {
  max-height: 12rem;
}

.selected-row-item {
  cursor: pointer;
  transition: opacity 0.2s, text-decoration 0.2s;
}

.selected-row-item.crossed-out {
  text-decoration: line-through;
  opacity: 0.4;
}

.selection-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.selection-box-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.selection-box-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.selection-box-title .icon-button:disabled,
.selection-box-actions .secondary-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.selection-box-title .icon-button {
  width: 2.35rem;
  min-width: 2.35rem;
  min-height: 2.35rem;
}

.selection-box-title .icon-button:disabled {
  pointer-events: none;
}

.selection-plain-list {
  margin: 0;
  max-height: 17rem;
  padding: 0.8rem 0.9rem;
  overflow: auto;
  border: 1px solid rgba(166, 75, 42, 0.14);
  border-radius: var(--radius-sm);
  background: rgba(166, 75, 42, 0.06);
  color: var(--ink);
  font-family: "SFMono-Regular", "Cascadia Code", "Fira Code", "Courier New", monospace;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.hidden {
  display: none !important;
}

.table-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: var(--radius-sm);
  background: rgba(255, 250, 244, 0.72);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.5rem 0.3rem;
  text-align: left;
  border-bottom: 1px solid rgba(31, 42, 36, 0.08);
  vertical-align: top;
}

tbody tr:not(.alphabet-divider-row) td {
  vertical-align: middle;
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  background: rgba(244, 239, 231, 0.95);
  position: sticky;
  top: 0;
  z-index: 5;
  vertical-align: middle
}

.sort-head {
  white-space: nowrap;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.38rem;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.sort-button:hover {
  color: var(--accent-deep);
}

.sort-button:focus-visible {
  outline: 2px solid rgba(166, 75, 42, 0.25);
  outline-offset: 3px;
  border-radius: 0.35rem;
}

.sort-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0.9rem;
  color: rgba(89, 101, 93, 0.55);
  font-size: 0.8rem;
  line-height: 1;
}

.sort-button-active .sort-indicator {
  color: var(--accent);
}

.selection-head,
.selection-cell,
.entry-selection-cell {
  text-align: center;
  vertical-align: middle;
}

th[data-sort-column="prezzo"],
td[data-label="Prezzo"] {
  text-align: right;
}

.product-cell {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.product-name {
  min-width: 0;
}

.quantity-control {
  display: inline-flex;
  align-items: stretch;
  flex: 0 0 auto;
  min-width: 3.9rem;
  border: 1px solid rgba(31, 42, 36, 0.12);
  border-radius: 0.75rem;
  background: rgba(255, 250, 244, 0.98);
  overflow: hidden;
}

.quantity-input {
  width: 2.45rem;
  min-width: 2.45rem;
  padding: 0.3rem 0.2rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  appearance: textfield;
  -moz-appearance: textfield;
}

.quantity-input::-webkit-outer-spin-button,
.quantity-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.quantity-stepper {
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(31, 42, 36, 0.08);
}

.quantity-step-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  min-width: 1.25rem;
  height: 0.95rem;
  padding: 0;
  border: 0;
  background: rgba(244, 239, 231, 0.85);
  color: var(--ink-soft);
  font-size: 0.58rem;
  line-height: 1;
  cursor: pointer;
}

.quantity-step-button + .quantity-step-button {
  border-top: 1px solid rgba(31, 42, 36, 0.08);
}

.quantity-step-button:hover {
  background: rgba(166, 75, 42, 0.1);
  color: var(--accent-deep);
}

th:last-child,
td.entry-actions-cell {
  width: max-content;
  min-width: max-content;
  white-space: nowrap;
}

.entry-selection-placeholder {
  display: inline-block;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 0.35rem;
  background: var(--surface-strong);
  opacity: 1;
}

.row-selection-checkbox {
  width: 1.25rem;
  min-height: 1.25rem;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.row-actions {
  display: flex;
  gap: 0.55rem;
  align-items: center;
}

.entry-row td {
  position: sticky;
  top: var(--entry-row-sticky-top);
  z-index: 4;
  background: var(--surface-strong);
  vertical-align: middle;
  box-shadow: inset 0 -1px 0 rgba(31, 42, 36, 0.08);
}


.entry-actions-cell {
  min-width: 9.5rem;
}

.entry-actions {
  display: grid;
  flex-wrap: nowrap !important;
  gap: 0.55rem;
}

.entry-button-row {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.compact-button {
  padding: 0.4rem 0.4rem;
}

.entry-row-editing td {
  background: rgba(166, 75, 42, 0.1);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  min-width: 2rem;
  min-height: 2rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.95);
  color: var(--ink);
  cursor: pointer;
}

.icon-button svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
}

.icon-button:hover {
  border-color: rgba(31, 42, 36, 0.2);
  transform: translateY(-1px);
}

.icon-button-danger {
  color: var(--danger);
}

.alphabet-divider-row td {
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid rgba(166, 75, 42, 0.14);
  background: rgba(166, 75, 42, 0.08);
  color: var(--accent-deep);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.alphabet-jump-target td {
  background: rgba(166, 75, 42, 0.12);
}

#listino-panel {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;

}
