:root {
  --yellow: #f6c928;
  --yellow-deep: #dfa617;
  --yellow-pale: #fff8df;
  --black: #1a1a1a;
  --black-soft: #2b2b2b;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #ea580c;
  --gray-border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: #f3f4f6;
  color: var(--text);
}

.topbar {
  background: var(--black);
  color: var(--yellow);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--yellow);
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar .user { font-size: 13px; opacity: 0.9; display: flex; align-items: center; gap: 12px; color: #fff; }
.topbar .user form { display: inline; }
.topbar .user button { background: none; border: 1px solid rgba(255,255,255,0.5); color: #fff; padding: 4px 10px; border-radius: 4px; cursor: pointer; }

.nav {
  background: linear-gradient(180deg, var(--yellow), var(--yellow-deep));
  display: flex;
  gap: 4px;
  padding: 0 20px;
  overflow-x: auto;
}
.nav a {
  color: #3a2c00;
  text-decoration: none;
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.nav a.active {
  color: var(--black);
  border-bottom-color: var(--black);
  font-weight: 700;
}

.container { padding: 24px; max-width: 1400px; margin: 0 auto; }

.card {
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* только у таблиц своя горизонтальная прокрутка — overflow на самой .card обрезал бы
   всплывающие списки (поиск, автоподбор товара), т.к. auto по одной оси задаёт auto и по другой */
.table-scroll { overflow-x: auto; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.card-header h2 { margin: 0; color: var(--black); font-size: 20px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--gray-border); }
th { background: #f9fafb; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: var(--yellow-pale); }

.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 5px;
  font-size: 13px;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-purple { background: var(--black); color: var(--yellow); }
.btn-outline { background: #fff; color: var(--black); border: 1px solid var(--black); }
.btn-danger { background: none; color: var(--red); }
.btn-orange { background: #fff; color: var(--orange); border: 1px solid var(--orange); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

select, input[type=text], input[type=number], input[type=date], input[type=password], textarea {
  padding: 7px 10px;
  border: 1px solid var(--gray-border);
  border-radius: 5px;
  font-size: 14px;
  font-family: inherit;
}

.status-pill { display: inline-block; white-space: nowrap; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.product-thumb { width: 76px; height: 76px; object-fit: contain; background: #f9fafb; border-radius: 6px; border: 1px solid var(--gray-border); display: block; }
.product-thumb-empty { width: 76px; height: 76px; border-radius: 6px; border: 1px dashed var(--gray-border); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; text-align: center; }
.product-thumb-large { max-width: 320px; max-height: 320px; object-fit: contain; border-radius: 8px; border: 1px solid var(--gray-border); display: block; }
.product-thumb-large-empty { width: 200px; height: 200px; border-radius: 8px; border: 1px dashed var(--gray-border); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.status-ok { background: #dcfce7; color: #166534; }
.status-low { background: #fee2e2; color: #991b1b; }

.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }

.login-wrap {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--black), #4a3600, var(--yellow-deep));
}
.login-box {
  background: #fff;
  padding: 36px;
  border-radius: 10px;
  width: 320px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.35);
  border-top: 5px solid var(--yellow);
}
.login-box h1 { color: var(--black); font-size: 22px; margin-top: 0; }
.login-box label { display: block; font-size: 13px; margin: 12px 0 4px; color: var(--muted); }
.login-box input { width: 100%; }
.login-box button { width: 100%; margin-top: 18px; padding: 10px; }
.error-msg { color: var(--red); font-size: 13px; margin-top: 10px; }

.order-items-table input[type=number] { width: 70px; }
.order-items-table td { vertical-align: middle; }

.product-picker { position: relative; }
.product-picker input { width: 100%; }
.product-results {
  position: absolute;
  z-index: 20;
  background: #fff;
  border: 1px solid var(--gray-border);
  border-radius: 6px;
  max-height: 260px;
  overflow-y: auto;
  width: 420px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  display: none;
}
.product-results div {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f3f4f6;
}
.product-results div:hover { background: var(--yellow-pale); }

.totals { text-align: right; margin-top: 16px; font-size: 15px; }
.totals .grand { font-size: 20px; font-weight: 700; color: var(--black); }

.badge-role { background: rgba(255,255,255,0.15); padding: 2px 8px; border-radius: 10px; font-size: 11px; color: var(--yellow); }

form.inline { display: inline; }

.status-select { padding: 6px 10px; border-radius: 5px; font-weight: 600; font-size: 13px; cursor: pointer; }
.status-select.st-new { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.status-select.st-progress { background: #fef9c3; color: #854d0e; border: 1px solid #fde68a; }
.status-select.st-done { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.status-select.st-cancelled { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

.items-toggle { color: var(--black); text-decoration: none; font-weight: 500; }
.items-toggle:hover { text-decoration: underline; }
.items-detail td { background: #fafafa; padding: 12px 12px 12px 32px; }
.mini-table { width: auto; min-width: 400px; font-size: 13px; }
.mini-table th, .mini-table td { padding: 5px 10px; border-bottom: 1px solid #eee; }
.mini-table th { background: none; }

/* ===== Аналитика ===== */
.period-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.period-tab {
  background: #fff; color: var(--black); text-decoration: none;
  padding: 9px 16px; border-radius: 6px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--gray-border);
}
.period-tab.active { background: var(--black); color: var(--yellow); border-color: var(--black); }
.period-tab-form input[type=month] {
  padding: 8px 10px; border-radius: 6px; border: 1px solid var(--gray-border); font-size: 13px;
}

.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: #fff; border-radius: 8px; padding: 18px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.stat-num { font-size: 26px; font-weight: 700; color: var(--green); }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

.revenue-banner {
  background: linear-gradient(135deg, var(--black), var(--black-soft));
  border: 2px solid var(--yellow);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  margin-bottom: 20px;
}
.revenue-num { font-size: 34px; font-weight: 800; color: var(--yellow); }
.revenue-label { font-size: 13px; color: #fff; opacity: 0.85; margin-top: 6px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.status-bars { display: flex; flex-direction: column; gap: 14px; }
.status-bar-row { display: grid; grid-template-columns: 90px 1fr 70px; align-items: center; gap: 10px; }
.status-bar-name { font-size: 13px; color: var(--muted); }
.status-bar-track { background: #f3f4f6; border-radius: 6px; height: 14px; overflow: hidden; }
.status-bar-fill { height: 100%; border-radius: 6px; }
.status-bar-fill.st-new { background: #d1d5db; }
.status-bar-fill.st-progress { background: #facc15; }
.status-bar-fill.st-done { background: var(--green); }
.status-bar-fill.st-cancelled { background: var(--red); }
.status-bar-value { font-size: 13px; text-align: right; color: var(--text); }

.totals-row td { background: var(--yellow-pale); font-weight: 700; color: var(--black); border-bottom: 2px solid var(--yellow-deep); }

.wide-search { position: relative; }
.wide-search input {
  width: 100%; font-size: 16px; padding: 14px 16px;
  border: 2px solid var(--gray-border); border-radius: 8px;
}
.wide-search input:focus { border-color: var(--yellow-deep); outline: none; }

.search-results-grid {
  display: none;
  position: absolute;
  z-index: 30;
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  max-height: 82vh;
  overflow-y: auto;
  padding: 16px;
  margin-top: 6px;
}
.search-columns { columns: 4 240px; column-gap: 24px; }
.search-cat-block { break-inside: avoid; margin-bottom: 16px; }
.search-cat-title {
  font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--black); background: var(--yellow-pale);
  border-radius: 4px; padding: 4px 8px; margin-bottom: 6px;
}
.no-results { color: var(--muted); padding: 10px; }

.search-item-table { width: 100%; border-collapse: collapse; font-size: 12.5px; table-layout: fixed; }
.search-item-table td {
  border: 1px solid var(--gray-border);
  padding: 6px 8px;
  cursor: pointer;
  line-height: 1.3;
  overflow-wrap: break-word;
}
.search-item-table tr:hover td { background: var(--yellow-pale); }
.search-item-qty { text-align: right; white-space: nowrap; width: 52px; color: var(--muted); }

.highlight-row { animation: highlightFade 2.2s ease-out; }
@keyframes highlightFade {
  from { background: var(--yellow); }
  to { background: transparent; }
}

.alert-error {
  background: #fee2e2; color: #991b1b; border: 1px solid #fecaca;
  border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; font-size: 14px; font-weight: 500;
}

/* ===== Мобильная адаптация ===== */
@media (max-width: 768px) {
  .container { padding: 12px; }

  .topbar { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .topbar h1 { font-size: 16px; }
  .topbar .user { font-size: 12px; gap: 8px; flex-wrap: wrap; }

  .nav { padding: 0 10px; -webkit-overflow-scrolling: touch; }
  .nav a { padding: 10px 12px; font-size: 13px; }

  .card { padding: 14px; border-radius: 6px; }
  .card-header { margin-bottom: 12px; }
  .card-header h2 { font-size: 17px; }

  /* таблицы не сжимаются — вместо этого их обёртка .table-scroll скроллится по горизонтали */
  .table-scroll table { width: max-content; min-width: 100%; }
  th, td { padding: 8px 10px; font-size: 13px; }

  .filters { flex-direction: column; align-items: stretch; }
  .filters select, .filters input, .filters button { width: 100%; }

  .login-wrap { padding: 16px; }
  .login-box { width: min(320px, 100%); padding: 24px; }

  .product-results { width: min(420px, 85vw); }

  .order-items-table .product-picker input { min-width: 160px; }

  .totals { text-align: left; }
}
