/* ─── FONTS ──────────────────────────────────────────────────────────── */
@import url('https://fonts.cdnfonts.com/css/bitcrusher');

/* ─── RESET & BASE ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #efefea;
  --white:     #ffffff;
  --surface:   #f7f7f4;
  --border:    #e0e0d8;
  --purple:    #a78bfa;
  --purple-d:  #8b6ef5;
  --purple-l:  #c4b5fd;
  --lime:      #bef264;
  --lime-d:    #a3e635;
  --ink:       #1e1b2e;
  --ink2:      #2d2a40;
  --muted:     #8e8e9e;
  --red:       #ef4444;
  --green:     #16a34a;
  --radius:    22px;
  --radius-sm: 14px;
  --gap:       10px;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%; /* запрет авто-увеличения шрифта на iOS */
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent; /* убрать синий оверлей при тапе */
}

a { text-decoration: none; color: inherit; }

/* ─── HOME LAYOUT ────────────────────────────────────────────────────── */
.home-wrap {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: var(--gap);
  gap: var(--gap);
}

/* Top bar */
.top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  flex-shrink: 0;
}

.brand {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--ink);
}

.top-bar .spacer { flex: 1; }

/* ─── BENTO GRID ─────────────────────────────────────────────────────── */
.bento {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: var(--gap);
  flex: 1;
  min-height: 0;
}

/* Card base */
.bc {
  border-radius: var(--radius);
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  min-width: 0;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
  text-decoration: none;
}

@media (hover: hover) {
  .bc:hover {
    transform: scale(1.015);
    box-shadow: 0 16px 48px rgba(0,0,0,.13);
    z-index: 2;
  }
}
.bc:active { transform: scale(.98); opacity: .9; }

/* Themes */
.bc-purple {
  background: var(--purple);
  color: #fff;
  grid-row: span 3;
}

.bc-lime {
  background: var(--lime);
  color: var(--ink);
}

.bc-white {
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--border);
}

.bc-ink {
  background: #1e1b2e;
  color: #fff;
}

.bc-ink2 {
  background: #2d2a40;
  color: #fff;
}

.bc-soft {
  background: #ede9fe;
  color: var(--ink);
  border: 1px solid #c4b5fd;
}

.bc-clients {
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--border);
}

.bc-wide {
  grid-column: span 2;
}

/* ── Card anatomy ────────────────────────────────────────────────────── */
.bc-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.bc-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  opacity: .55;
  color: inherit;
}

.bc-arrow {
  font-size: 18px;
  opacity: .4;
  color: inherit;
}

/* Middle — stat number */
.bc-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.bc-hero {
  font-size: clamp(28px, 3.5vw, 52px);
  font-weight: 900;
  letter-spacing: -2px;
  line-height: 1;
  color: var(--lime);
  font-variant-numeric: tabular-nums;
}

.bc-sub {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .8px;
  opacity: .4;
  margin-top: 5px;
  color: inherit;
}

/* Bottom — big title + count */
.bc-foot {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bc-big-title {
  font-family: 'Bitcrusher', sans-serif;
  font-size: clamp(28px, 3.2vw, 52px);
  font-weight: 400; /* Bitcrusher уже жирный по умолчанию */
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
  color: rgba(255,255,255,.9);
  display: block;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: none;
}

.bc-count {
  font-size: 12px;
  opacity: .4;
  font-weight: 500;
  color: inherit;
  margin-top: 6px;
}

/* Cards where title fills vertically */
.bc-fill {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 0; /* позволяет flex-child сужаться */
}

.bc-fill .bc-big-title {
  font-size: clamp(28px, 3.8vw, 64px);
  word-break: break-word;
}

/* Decorative circle */
.bc-deco-circle {
  position: absolute;
  width: 180px; height: 180px;
  border-radius: 50%;
  background: rgba(255,255,255,.07);
  bottom: -50px; right: -50px;
  pointer-events: none;
}
.bc-deco-circle2 {
  position: absolute;
  width: 100px; height: 100px;
  border-radius: 50%;
  background: rgba(255,255,255,.05);
  top: -20px; right: 60px;
  pointer-events: none;
}

/* ─── INNER PAGES ─────────────────────────────────────────────────────── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 20px 28px 0;
  padding: 8px 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}
.back-btn:hover { color: var(--ink); border-color: var(--purple-l); }

.page-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 28px 48px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.8px;
  color: var(--ink);
}

/* ─── FILTER BAR ─────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.filter-select {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--ink);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color .2s;
}
.filter-select:focus { border-color: var(--purple-l); }

/* ─── BREAKDOWN ───────────────────────────────────────────────────────── */
.breakdown-section {
  margin-top: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--white);
}

.breakdown-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  font-family: inherit;
  transition: background .15s;
}
.breakdown-toggle:hover { background: var(--surface); }

.breakdown-table-wrap {
  border-top: 1px solid var(--border);
}

.breakdown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.breakdown-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  background: var(--surface);
}
.breakdown-table td {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.breakdown-table tbody tr:hover { background: var(--surface); }

/* ─── PANEL / FORM ────────────────────────────────────────────────────── */
.panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
}

.panel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 16px;
}

.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 120px;
}

.form-group label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.form-group input, .form-group select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--ink);
  font-size: 14px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  width: 100%;
}
.form-group input:focus, .form-group select:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(108,58,237,.1);
}

/* ─── BUTTONS ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--purple); color: #fff; }
.btn-lime    { background: var(--lime); color: var(--ink); }
.btn-ghost   { background: var(--white); border: 1px solid var(--border); color: var(--muted); }
.btn-danger  { background: transparent; border: 1px solid #fee2e2; color: var(--red); padding: 6px 12px; font-size: 12px; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm      { padding: 7px 14px; font-size: 13px; }

/* ─── TABLE ──────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--white);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  background: var(--surface);
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #faf9ff; }

td { padding: 13px 16px; color: var(--ink); }

.td-muted  { color: var(--muted); }
.td-num    { font-variant-numeric: tabular-nums; font-weight: 600; }
.td-green  { color: var(--green); font-weight: 700; }
.td-red    { color: var(--red); }

/* ─── BADGES ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-green  { background: #dcfce7; color: var(--green); }
.badge-red    { background: #fee2e2; color: var(--red); }
.badge-purple { background: #ede9fe; color: var(--purple); }
.badge-lime   { background: #ecfccb; color: #365314; }

/* ─── INVENTORY ──────────────────────────────────────────────────────── */
.inv-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.inv-stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.inv-stat-card.inv-stat-dark {
  background: #1e1b2e;
}

.inv-stat-card.inv-stat-lime {
  background: var(--lime);
}

.inv-stat-val {
  font-size: clamp(22px, 2.5vw, 32px);
  font-weight: 900;
  letter-spacing: -1px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.inv-stat-dark .inv-stat-val { color: var(--lime); }
.inv-stat-lime .inv-stat-val { color: var(--ink); }

.inv-stat-lbl {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}

.inv-stat-dark .inv-stat-lbl { color: rgba(255,255,255,.4); }
.inv-stat-lime .inv-stat-lbl { color: rgba(0,0,0,.45); }

/* Кол-во в таблице */
.qty-num {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}

/* Цвет с точкой */
.color-dot-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink2);
}

/* Статус наличия */
.inv-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
}
.inv-status-ok  { background: #dcfce7; color: #15803d; }
.inv-status-low { background: #fef3c7; color: #92400e; }
.inv-status-out { background: #fee2e2; color: #b91c1c; }

@media (max-width: 760px) {
  .inv-stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 440px) {
  .inv-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .inv-stat-card { padding: 14px 16px; }
  .inv-stat-val { font-size: 20px; }
}

/* ─── CLIENTS ────────────────────────────────────────────────────────── */
.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.client-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: box-shadow .2s, transform .15s;
}
.client-card:hover {
  box-shadow: 0 6px 20px rgba(0,0,0,.07);
  transform: translateY(-2px);
}

.client-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--purple);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: -.5px;
}

.client-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.client-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-phone {
  font-size: 13px;
  font-weight: 600;
  color: var(--purple);
  text-decoration: none;
  letter-spacing: .2px;
}
.client-phone:hover { text-decoration: underline; }

.client-no-phone {
  font-size: 12px;
  color: var(--muted);
}

.client-comment {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

@media (max-width: 560px) {
  .clients-grid { grid-template-columns: 1fr; }
}

/* ─── PRICELIST CARDS ─────────────────────────────────────────────────── */
.price-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}

.price-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: box-shadow .2s, transform .2s;
}
.price-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,.08); transform: translateY(-2px); }

.price-card .product-name { font-size: 16px; font-weight: 700; margin-bottom: 14px; color: var(--ink); }

.price-card .price-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.price-card .price-row:last-child { border-bottom: none; }
.price-card .price-lbl { color: var(--muted); }
.price-card .price-val { font-weight: 700; font-variant-numeric: tabular-nums; }

.price-card .markup-big {
  font-size: 30px;
  font-weight: 900;
  color: var(--purple);
  letter-spacing: -1px;
}

/* ─── EMPTY & LOADING ─────────────────────────────────────────────────── */
.empty { text-align: center; padding: 60px 24px; color: var(--muted); }
.empty .empty-icon { font-size: 48px; margin-bottom: 12px; }

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row td { text-align: center; padding: 40px; color: var(--muted); }

/* ─── TOAST ──────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  z-index: 999;
  transform: translateY(60px);
  opacity: 0;
  transition: transform .25s, opacity .25s;
}
#toast.show  { transform: translateY(0); opacity: 1; }
#toast.success { background: var(--green); }
#toast.error   { background: var(--red); }

/* ─── RESPONSIVE ──────────────────────────────────────────────────────── */

/* Планшет */
@media (max-width: 960px) {
  .bento {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
    height: auto;
  }
  .bc-purple { grid-row: span 1; grid-column: span 2; }
  .home-wrap { height: auto; min-height: 100vh; }
  .bc { min-height: 200px; }
  .bc-big-title { font-size: clamp(36px, 8vw, 64px); }
  .bc-fill .bc-big-title { font-size: clamp(40px, 9vw, 72px); }
  .bc-hero { font-size: clamp(32px, 6vw, 52px); }
}

/* Мобильный */
@media (max-width: 560px) {
  :root { --gap: 8px; --radius: 18px; }

  .home-wrap { padding: var(--gap); gap: var(--gap); }

  .top-bar { padding: 4px 4px; }
  .brand   { font-size: 14px; }

  .bento {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
  }

  /* Закупки — полная ширина */
  .bc-purple { grid-column: span 2; min-height: 200px; }
  /* Продажи — полная ширина */
  .bc-lime { grid-column: span 2; min-height: 160px; }
  /* Прайс — полная ширина */
  .bc-ink.bc-wide  { grid-column: span 2; min-height: 130px; }

  /* Остальные — по полуширины */
  .bc { min-height: 140px; padding: 16px; }

  .bc-big-title      { font-size: clamp(28px, 10vw, 52px); }
  .bc-fill .bc-big-title { font-size: clamp(30px, 11vw, 56px); }
  .bc-hero           { font-size: clamp(26px, 9vw, 44px); }
  .bc-label          { font-size: 10px; }
  .bc-sub, .bc-count { font-size: 11px; }

  /* Внутренние страницы */
  .back-btn    { margin: 14px 14px 0; }
  .page-content { padding: 14px 14px 40px; }
  .page-title  { font-size: 22px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .panel       { padding: 14px; }
  .panel-title { font-size: 11px; margin-bottom: 12px; }

  /* Формы */
  .form-row    { flex-direction: column; gap: 8px; }
  .form-group  { min-width: unset !important; width: 100% !important; max-width: none !important; flex: unset !important; }
  .form-group input,
  .form-group select { font-size: 16px; /* предотвращает zoom на iOS */ height: 46px; width: 100%; }

  /* Фильтры */
  .filter-bar  { flex-direction: column; align-items: stretch; gap: 8px; }
  .filter-select { width: 100%; height: 44px; font-size: 16px; }
  .filter-bar .btn { width: 100%; justify-content: center; }

  /* Кнопка добавить */
  .page-header .btn { width: 100%; justify-content: center; }

  table { font-size: 12px; }
  thead th { padding: 10px 10px; font-size: 10px; }
  td { padding: 10px 10px; }

  .btn-sm { padding: 6px 12px; font-size: 12px; }
  .btn    { padding: 11px 16px; font-size: 14px; }

  /* Breakdown */
  .breakdown-section { border-radius: var(--radius-sm); }
  .breakdown-toggle  { padding: 12px 14px; font-size: 13px; }

  #toast { bottom: 16px; right: 16px; left: 16px; font-size: 13px; }
}

/* Маленький мобильный */
@media (max-width: 380px) {
  .bc-big-title { font-size: clamp(22px, 9vw, 38px); }
  .bc { min-height: 120px; padding: 14px; }
}
