/* ─── Garlic ERP — custom styles ─── */

/* Прячет элементы с x-show до инициализации Alpine — иначе поле успевает
   мигнуть на экране до того, как условие его скроет. */
[x-cloak] {
  display: none !important;
}

:root {
  --sidebar-width: 250px;
  --sidebar-bg: #1e4620;
  --sidebar-hover: #2d6a31;
  --sidebar-active: #3a8540;
  --sidebar-text: #d4edda;
  --sidebar-muted: #8fbc94;
  --sidebar-border: #2d6a31;
  --topbar-height: 56px;
}

/* ─── Layout ─── */
body {
  background-color: #f4f6f9;
  overflow-x: hidden;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  overflow-y: auto;
  /* Hardware acceleration — фикс моргания в Safari на iPad */
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  will-change: transform;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  text-decoration: none;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.sidebar-brand:hover {
  color: #fff;
}

.sidebar-user {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-user .username {
  font-size: 0.875rem;
  color: var(--sidebar-text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user .badge-role {
  font-size: 0.7rem;
  background: var(--sidebar-active);
  color: #fff;
  padding: 0.2em 0.5em;
  border-radius: 4px;
  margin-top: 0.15rem;
  display: inline-block;
}

/* ─── Nav menu ─── */
.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0;
  list-style: none;
  margin: 0;
}

.sidebar-nav .nav-section {
  padding: 0.6rem 1rem 0.2rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-muted);
}

.sidebar-nav .nav-item a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.sidebar-nav .nav-item a:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-nav .nav-item a.active {
  background: var(--sidebar-active);
  border-left-color: #8bc34a;
  color: #fff;
  font-weight: 600;
}

.sidebar-nav .nav-item a .nav-icon {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

/* ─── Main content ─── */
.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #dee2e6;
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: #343a40;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Переключатель языка ─── */
.topbar-lang {
  margin-left: auto;
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.topbar-lang .btn-lang {
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
  color: #6c757d;
  background: transparent;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.topbar-lang .btn-lang:hover:not(:disabled) {
  background: #e9ecef;
  color: #343a40;
}

.topbar-lang .btn-lang.active {
  background: #2c3e50;
  border-color: #2c3e50;
  color: #fff;
  cursor: default;
}

/* ─── Logout — top right corner ─── */
.topbar-logout {
  margin-left: 0;
  padding-left: 0.75rem;
  flex-shrink: 0;
}

.topbar-logout .btn-logout {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  font-size: 0.875rem;
  color: #6c757d;
  background: transparent;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.topbar-logout .btn-logout:hover {
  background: #c0392b;
  border-color: #c0392b;
  color: #fff;
}

.main-content {
  flex: 1;
  padding: 1.5rem 1.25rem;
}

/* ─── Mobile overlay ─── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1035;
}

/* ─── Mobile burger ─── */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  padding: 0.25rem 0.5rem;
  margin-right: 0.75rem;
  cursor: pointer;
  color: #495057;
}

/* ─── Responsive ─── */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
    transition: transform 0.3s ease;
  }

  .sidebar.show {
    transform: translateX(0);
  }

  .sidebar-overlay.show {
    display: block;
  }

  .main-wrapper {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
  }
}

@media (max-width: 575.98px) {
  /* Icon-only logout on narrow screens */
  .topbar-logout .btn-logout-text {
    display: none;
  }

  .topbar-logout .btn-logout {
    padding: 0.35rem 0.5rem;
  }
}

/* ─── Cards / tables ─── */
.card {
  border: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.table th {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6c757d;
  border-bottom-width: 1px;
}

.table td {
  vertical-align: middle;
}

/* ─── Badges for status ─── */
.badge-status-pending    { background: #ffc107; color: #000; }
.badge-status-confirmed  { background: #198754; color: #fff; }
.badge-status-finished   { background: #6c757d; color: #fff; }
.badge-status-cancelled  { background: #dc3545; color: #fff; }
.badge-status-active     { background: #0dcaf0; color: #000; }
.badge-status-overdue    { background: #dc3545; color: #fff; }
.badge-status-completed  { background: #198754; color: #fff; }

/* ─── HTMX loading indicator ─── */
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator  { opacity: 1; }

/* ─── Toast stack ─── */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2000;
}

/* ─── Hoverable card link ─── */
.card-hover {
  transition: box-shadow 0.15s, transform 0.15s;
  color: inherit;
}

.card-hover:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  transform: translateY(-2px);
  color: inherit;
}

/* ─── Border dashed (placeholder card) ─── */
.border-dashed {
  border: 2px dashed #dee2e6 !important;
}

/* ─── Empty state ─── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #adb5bd;
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

/* ─── Login page ─── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e4620 0%, #2d6a31 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.login-logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e4620;
}

/* ─── Склады: плитки остатков + панель подробностей ─── */
.wh-tiles {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
}

.wh-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 96px;
  padding: 0.75rem 0.5rem;
  background: #fff;
  border: 1.5px solid #6c757d;
  border-radius: 10px;
  color: #6c757d;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.wh-tile:hover {
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.wh-tile.active {
  border-color: #198754;
  color: #198754;
  background: #f3faf6;
}

.wh-tile:focus-visible {
  outline: 3px solid rgba(25,135,84,0.35);
  outline-offset: 2px;
}

.wh-tile-label {
  font-size: 1.15rem;
  line-height: 1.2;
}

.wh-tile-weight {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.wh-panel {
  border-radius: 10px;
  overflow: hidden;
}

.wh-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #eef0f2;
}

.wh-panel-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}

.wh-sell {
  font-weight: 600;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
  white-space: nowrap;
}

.wh-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  padding: 0.85rem 1.25rem;
  background: #fafbfc;
  border-bottom: 1px solid #eef0f2;
}

.wh-stats > div {
  display: flex;
  flex-direction: column;
}

.wh-stats span {
  font-size: 0.75rem;
  color: #6c757d;
}

.wh-stats b {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.wh-evap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid #eef0f2;
}

.wh-evap-item {
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  border: 1px solid #eef0f2;
  border-radius: 8px;
}

.wh-evap-item span { font-size: 0.75rem; color: #6c757d; }
.wh-evap-item b { font-size: 1.3rem; }
.wh-evap-item small { font-size: 0.72rem; color: #6c757d; }

.wh-evap-note {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.75rem;
  color: #6c757d;
}

.wh-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.wh-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid #f1f3f5;
}

.wh-list-main {
  min-width: 0;
  overflow-wrap: anywhere;
}

.wh-list-sub {
  font-size: 0.8rem;
  color: #6c757d;
  margin-top: 0.1rem;
}

.wh-list-weight {
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.wh-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
}

@media (max-width: 991.98px) {
  .wh-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 575.98px) {
  /* Сырьё — во всю ширину, сорта парами: 1 / 2+2 / 2+2 */
  .wh-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
  .wh-tile--raw { grid-column: 1 / -1; }
  .wh-tile { min-height: 80px; }
  .wh-tile-label { font-size: 1rem; }
  .wh-tile-weight { font-size: 0.95rem; }

  .wh-panel-head { flex-wrap: wrap; padding: 0.85rem 1rem; }
  .wh-sell { width: 100%; padding-top: 0.6rem; padding-bottom: 0.6rem; }
  .wh-stats, .wh-evap, .wh-links { padding-left: 1rem; padding-right: 1rem; }
  .wh-stats { gap: 0.5rem 1.25rem; }
  .wh-evap { grid-template-columns: 1fr; }
  .wh-list li { padding: 0.65rem 1rem; }
  .wh-links .btn { flex: 1 1 auto; }
}

/* ─── Мобильные устройства: общие правки ─── */
@media (max-width: 991.98px) {
  /* Пункты меню — под палец (≥ 44px) */
  .sidebar-nav .nav-item a { padding-top: 0.7rem; padding-bottom: 0.7rem; }
  .sidebar { height: 100dvh; overscroll-behavior: contain; }
}

@media (max-width: 575.98px) {
  .topbar { padding: 0 0.75rem; }
  .sidebar-toggle { margin-right: 0.4rem; }
  .main-content { padding: 1rem 0.75rem; }

  /* iOS увеличивает страницу при фокусе на поле со шрифтом < 16px */
  .form-control, .form-select, input, select, textarea { font-size: 16px; }

  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }

  .card-header, .card-body { padding-left: 0.85rem; padding-right: 0.85rem; }
  /* Широкие таблицы без .table-responsive не должны раздвигать страницу */
  .card-body.p-0 { padding: 0 !important; overflow-x: auto; }

  .table { font-size: 0.85rem; }
  .table th { font-size: 0.7rem; }
  .table > :not(caption) > * > * { padding: 0.5rem 0.5rem; }

  .modal-dialog { margin: 0.5rem; }

  .toast-container { left: 0.75rem; right: 0.75rem; top: 0.75rem; }
  .toast-container .toast { width: 100%; }

  /* Группа кнопок-фильтров не влезает в экран — листается пальцем */
  .btn-group-scroll {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .btn-group-scroll::-webkit-scrollbar { display: none; }
  .btn-group-scroll > .btn { flex: 0 0 auto; white-space: nowrap; }

  .btn-row-edit { min-width: 36px; }

  /* Вкладки делят ширину поровну и не переносятся */
  .nav-tabs-mobile { flex-wrap: nowrap; }
  .nav-tabs-mobile .nav-item { flex: 1 1 0; min-width: 0; }
  .nav-tabs-mobile .nav-link {
    padding: 0.5rem 0.35rem;
    font-size: 0.85rem;
    text-align: center;
    white-space: nowrap;
  }

  /* Главная кнопка формы — во всю ширину, под большой палец */
  .btn-submit-mobile { width: 100%; }
  .form-actions-mobile { flex-direction: column; }
  .form-actions-mobile > .btn { width: 100%; }
}

/* Компактная кнопка «исправить» в строке таблицы */
.btn-row-edit { padding: 0 0.3rem; }

/* ─── Реализации: бейдж типа чеснока в общей истории ─── */
.sale-type {
  font-weight: 600;
  font-size: 0.72rem;
}
.sale-type--raw     { background: #f1e7d8; color: #6b4f1d; }
.sale-type--grade1  { background: #d9f0e2; color: #146c43; }
.sale-type--grade2  { background: #e2e8f0; color: #41536b; }
.sale-type--cloves1 { background: #e3f1d3; color: #3d6b12; }
.sale-type--cloves2 { background: #ece6f5; color: #59428a; }

.sale-rows li { align-items: flex-start; }

/* ─── Мобильные строки отчётов: подпись + значение сеткой ─── */
.m-kv {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem 0.75rem;
  margin-top: 0.45rem;
}
.m-kv--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.m-kv > div { display: flex; flex-direction: column; min-width: 0; }
.m-kv span { font-size: 0.72rem; color: #6c757d; line-height: 1.2; }
.m-kv b { font-weight: 600; font-variant-numeric: tabular-nums; }

@media (max-width: 575.98px) {
  .sale-rows li { flex-wrap: wrap; }
  .sale-rows li > .text-end { width: 100%; display: flex; justify-content: space-between; align-items: center; }
  .sale-rows li > .text-end .btn { margin-top: 0 !important; }
}
