:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-muted: #f2f4f7;
  --border: #d9dee7;
  --primary: #3062d4;
  --primary-dark: #254bb2;
  --text: #1b2333;
  --text-muted: #5b6576;
  --success: #2e9d57;
  --danger: #d64545;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

html {
  font-size: 70%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.panel__filters[hidden] {
  display: none !important;
}

.order-bar[hidden] {
  display: none !important;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app--hidden {
  display: none;
}

.app__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app__header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand {
  font-size: 1.5rem;
  font-weight: 700;
}

.user-info {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.app__content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.5rem 2rem 6rem;
}


.panel {
  background: var(--surface);
  border-radius: 1rem;
  border: 1px solid var(--border);
  padding: 1.5rem;
}

.panel__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.panel__heading {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.panel__title {
  margin: 0;
  font-size: 1.1rem;
}

.panel__caption {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.panel__body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel__body--filters {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.panel__filters {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  padding-block: 0.75rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 12px 24px -20px rgba(15, 23, 42, 0.25);
}

.panel__filters-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  width: 100%;
}

.panel__filters-row .field {
  flex: 0 1 220px;
  transition: flex-basis 0.25s ease, flex-grow 0.25s ease;
}

.panel__filters-row .field--search {
  flex: 1 1 auto;
  min-width: 0;
}



.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 160px;
}

.field__label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.field__input {
  font: inherit;
  padding: 0.65rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  min-width: 0;
}

.field__input:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-color: var(--primary);
}

.field--search {
  flex: 1;
  min-width: 180px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.toggle input {
  width: 1.2rem;
  height: 1.2rem;
}

.product-grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.product-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.product-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.product-section__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  background: var(--surface-muted);
}

.product-section__grid {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.product-section--virtual-placeholder .product-section__grid::after {
  content: "Загрузка...";
  display: block;
  padding: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.product-card {
  display: grid;
  gap: 0.35rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  padding: 0.5rem;
  background: var(--surface);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.product-card:hover {
  border-color: color-mix(in srgb, var(--primary) 20%, white);
  box-shadow: 0 12px 26px -24px rgba(15, 23, 42, 0.3);
}

.product-card--selected {
  border-color: color-mix(in srgb, var(--primary) 40%, white);
  box-shadow: 0 10px 22px -18px rgba(48, 98, 212, 0.35);
}

.product-card__title {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.35;
  font-weight: 500;
}

.product-card__meta {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.product-card__price {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.product-card__code {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
}


.counter {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  border-radius: 999px;
  border: 1px solid var(--border);
  overflow: hidden;
  width: 100%;
  min-height: 1.85rem;
}

.counter__btn {
  background: transparent;
  border: none;
  padding: 0.25rem 0.45rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
  min-width: 1.85rem;
  display: grid;
  place-items: center;
}

.counter__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.counter__value {
  flex: 1;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: text;
  outline: none;
}

.counter__value:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.counter__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  text-align: center;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text);
  padding: 0;
  margin: 0;
  outline: none;
}

.counter__input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.summary {
  display: grid;
  gap: 1rem;
}

.summary__empty {
  margin: 0;
  text-align: center;
  color: var(--text-muted);
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.summary-item__info {
  display: grid;
  gap: 0.25rem;
}

.summary-item__title {
  margin: 0;
  font-size: 1rem;
}

.summary-item__meta {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.summary__total {
  display: flex;
  justify-content: space-between;
  font-size: 1.1rem;
  font-weight: 600;
}

.btn {
  border: none;
  border-radius: 0.9rem;
  padding: 0.75rem 1.25rem;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--primary);
  color: white;
  font-weight: 600;
}

.btn--primary:hover {
  background: var(--primary-dark);
}

.btn--secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}

.btn--secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn--success {
  background: var(--success);
  color: #ffffff;
  font-weight: 600;
}

.btn--success:hover {
  background: color-mix(in srgb, var(--success) 85%, #ffffff 15%);
}

.btn--danger {
  background: var(--danger);
  color: #ffffff;
  font-weight: 600;
}

.btn--danger:hover {
  background: color-mix(in srgb, var(--danger) 85%, #ffffff 15%);
}

.btn--wide {
  width: 100%;
}

.btn--small {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

#drawerSave.btn--secondary {
  background: #fbbf24 !important;
  color: #1a202c !important;
  font-weight: 600;
  border: none !important;
}

#drawerSave.btn--secondary:hover {
  background: #f59e0b !important;
  border-color: #f59e0b !important;
  color: #1a202c !important;
}

#drawerSave.btn--secondary:disabled {
  background: #fbbf24 !important;
  opacity: 0.6;
  border: none !important;
}

.order-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  border-radius: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 -12px 32px -24px rgba(15, 23, 42, 0.3);
  z-index: 50;
  transition: box-shadow 0.2s ease, opacity 0.2s ease;
}

.order-bar__summary {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  border: none;
  background: transparent;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.order-bar__summary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.order-bar__label {
  font-weight: 600;
}

.order-bar__info {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.order-bar__actions {
  display: flex;
  gap: 0.5rem;
}

.order-bar__actions .btn {
  min-width: 80px;
}

.order-bar--inactive {
  opacity: 0.75;
  box-shadow: none;
}

.order-drawer {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: end center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 100;
}

.order-drawer__overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.order-drawer__panel {
  position: relative;
  width: min(100%, 520px);
  background: var(--surface);
  border-radius: 1.5rem 1.5rem 0 0;
  padding: 1.5rem;
  box-shadow: 0 -24px 48px -32px rgba(15, 23, 42, 0.5);
  transform: translateY(32px);
  transition: transform 0.3s ease;
  display: grid;
  gap: 1.5rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
}

.order-drawer__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.order-drawer__title {
  margin: 0;
  font-size: 1.2rem;
}

.order-drawer__body {
  display: grid;
  gap: 1rem;
}

.order-drawer__footer {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
}

.order-drawer--open {
  pointer-events: auto;
  opacity: 1;
}

.order-drawer--open .order-drawer__overlay {
  opacity: 1;
}

.order-drawer--open .order-drawer__panel {
  transform: translateY(0);
}

.order-drawer__footer .btn {
  width: 100%;
}

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

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 1.5rem;
  transition: opacity 0.3s ease;
}

.modal[aria-hidden="true"] {
  opacity: 0;
  pointer-events: none;
}

.modal__content {
  background: var(--surface);
  border-radius: 1.25rem;
  padding: 2rem;
  max-width: 420px;
  width: min(100%, 420px);
  display: grid;
  gap: 1.25rem;
  box-shadow: 0 32px 48px -32px rgba(15, 23, 42, 0.4);
}

.modal__content--store {
  max-width: 560px;
  width: min(100%, 560px);
  min-height: 540px;
  max-height: min(90vh, 640px);
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  align-content: stretch;
  padding: 1.5rem;
  font-size: 0.95rem;
  row-gap: 1rem;
}

.modal__title {
  margin: 0;
  font-size: 1.5rem;
}

.modal__subtitle {
  margin: 0;
  color: var(--text-muted);
}

.modal__search {
  width: 100%;
  margin-bottom: 0.25rem;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.store-list {
  display: grid;
  gap: 0.5rem;
  height: 100%;
  overflow-y: auto;
  padding-right: 0.25rem;
  min-height: 0;
  grid-template-columns: repeat(auto-fit, minmax(220px, 320px));
  justify-content: center;
  align-content: start;
}

.store-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  transition:
    box-shadow 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease;
}

.store-option:hover {
  box-shadow: 0 12px 28px -22px rgba(15, 23, 42, 0.35);
  border-color: color-mix(in srgb, var(--primary) 40%, transparent);
  transform: translateY(-1px);
}

.store-option:focus-within {
  box-shadow: 0 14px 30px -20px rgba(48, 98, 212, 0.45);
  border-color: var(--primary);
}

.store-option__info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.store-option__name {
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.01em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.store-option__address {
  font-size: 0.65rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.store-option__select {
  flex-shrink: 0;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
  background: var(--surface-muted);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.store-option__select:hover,
.store-option__select:focus-visible {
  outline: none;
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}

.store-option__icon {
  font-size: 1rem;
  line-height: 1;
}

.store-option--active {
  border-color: var(--primary);
  box-shadow: 0 14px 30px -20px rgba(48, 98, 212, 0.45);
}

.store-option--active .store-option__select {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.drafts-list {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

.draft-card {
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: auto;
}

.draft-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(48, 98, 212, 0.15);
}

.draft-card--empty {
  opacity: 0.9;
}

.draft-card--empty:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(48, 98, 212, 0.15);
  opacity: 1;
}

.draft-card__info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 0.25rem;
}

.draft-card__supplier-label,
.draft-card__order-label {
  font-size: 0.85rem;
  color: #2d3748;
  font-weight: 500;
}

.draft-card__supplier {
  font-weight: 600;
  font-size: 1rem;
  color: #1a202c;
  margin-bottom: 0.25rem;
}

.draft-card__meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
}

.draft-card__items {
  color: #2d3748;
  font-weight: 500;
  font-size: 0.85rem;
}

.draft-card__amount {
  font-weight: 600;
  color: var(--primary);
  font-size: 0.9rem;
}

.draft-card__empty-text {
  color: #4a5568;
  font-style: italic;
  font-size: 0.85rem;
  font-weight: 500;
}

.auth-form {
  display: grid;
  gap: 1rem;
}

.auth-form__hint {
  margin: 0;
  font-size: 0.85rem;
  text-align: center;
  color: var(--text-muted);
}

.auth-form__error {
  margin: 0;
  font-size: 0.8rem;
  text-align: center;
  color: var(--danger);
  min-height: 1.2em;
}

body.modal-open {
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 1200px) {
  .app__content {
    padding: 1.5rem 1.75rem 6rem;
  }
}

@media (max-width: 768px) {
  .app__header {
    padding: 1rem 1.5rem;
  }

  .app__content {
    padding: 1.25rem 1.5rem 5.5rem;
    gap: 1.25rem;
  }

  .panel__body--filters {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .panel__filters-row {
    display: flex;
    gap: 0.5rem;
  }

  .panel__filters-row .field,
  .panel__filters-row .field--search {
    flex: 1 1 50%;
    width: auto;
    min-width: 0;
  }

  .panel__filters--search-active .panel__filters-row .field:first-child {
    flex: 1 1 35%;
  }

  .panel__filters--search-active .panel__filters-row .field--search {
    flex: 1 1 65%;
  }

  .product-section__grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
  }

  .product-card {
    padding: 0.55rem;
    gap: 0.4rem;
  }

  .product-card__title {
    font-size: 0.85rem;
  }

  .product-card__price {
    font-size: 0.95rem;
  }

  .counter {
    min-height: 2rem;
  }

  .order-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 1rem;
  }

  .order-bar__summary {
    width: 100%;
  }

  .order-bar__actions {
    width: 100%;
    justify-content: space-between;
  }

  .order-bar__actions .btn {
    flex: 1;
    min-width: auto;
  }

  .order-drawer__panel {
    width: 100%;
    border-radius: 1.25rem 1.25rem 0 0;
  }
}

/* Loading animations */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }
  100% {
    background-position: 1000px 0;
  }
}

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(48, 98, 212, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.loading-overlay__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.loading-spinner--large {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

.loading-text {
  color: var(--text-muted);
  font-size: 1.4rem;
  font-weight: 500;
}

.skeleton {
  background: linear-gradient(
    90deg,
    #f0f0f0 25%,
    #e0e0e0 50%,
    #f0f0f0 75%
  );
  background-size: 1000px 100%;
  animation: shimmer 2s infinite;
  border-radius: 4px;
}

.skeleton--text {
  height: 1em;
  width: 80%;
}

.skeleton--button {
  height: 40px;
  width: 120px;
  border-radius: 0.75rem;
}

.product-card--loading {
  opacity: 0.6;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
