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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  background: #d4cebc;
  color: #1a1a1a;
  font-size: 14px;
  line-height: 1.45;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: 210px;
  min-width: 210px;
  background: #2d2822;
  color: #c8b898;
  padding: 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.brand {
  font-size: 17px;
  font-weight: 800;
  color: #e8d8b8;
  padding: 0 10px;
  margin-bottom: 14px;
  letter-spacing: 1px;
}

.menu-section { margin-bottom: 4px; }

.menu-label {
  font-size: 10px;
  font-weight: 700;
  color: #7a6848;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 10px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  color: #a89878;
  text-decoration: none;
  border-radius: 2px;
  font-size: 13px;
  transition: background 0.1s, color 0.1s;
  margin-bottom: 1px;
}

.menu-item:hover { background: #3d3428; color: #d8c898; }

.menu-item.active {
  background: #9a8a60;
  color: #fff;
  font-weight: 600;
}

.menu-item svg { flex-shrink: 0; opacity: 0.7; }
.menu-item.active svg { opacity: 1; }

/* ── Main ─────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  padding: 16px 20px;
  min-width: 0;
}

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
  background: #e8e3d8;
  border: 1px solid #b0a898;
  padding: 7px 12px;
}

h1 {
  font-size: 15px;
  font-weight: 700;
  color: #1a1a1a;
}

.subtitle {
  font-size: 12px;
  color: #6a5a40;
  margin-top: 2px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
  background: #d8d0b8;
  color: #1a1a1a;
  border: 1px solid #9a9080;
  border-radius: 2px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s;
}

.btn-primary:hover { background: #c8c0a8; }
.btn-primary:disabled { background: #e8e4d8; color: #9a9080; cursor: not-allowed; }

.btn-secondary {
  background: #e0dcd0;
  color: #3a3020;
  border: 1px solid #a0988a;
  border-radius: 2px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s;
}

.btn-secondary:hover { background: #d0c8b8; }

.btn-connect {
  background: #e0dcd0;
  color: #4a3820;
  border: 1px solid #a0988a;
  border-radius: 2px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s;
  white-space: nowrap;
}

.btn-connect:hover { background: #d0c8b8; }

.btn-connect.btn-connected {
  background: #d0e8d0;
  border-color: #7a9a7a;
  color: #2a6a2a;
}

.full-w { width: 100%; }

/* ── Banners ──────────────────────────────────────────────────────────────── */
.banner {
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 8px;
  border: 1px solid;
}

.banner-success { background: #d8eed8; color: #1a4a1a; border-color: #98c898; }
.banner-error   { background: #f0d8d8; color: #6a1a1a; border-color: #d89898; }

/* ── Compact filter row (1C style) ──────────────────────────────────────── */
.form-top-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  background: #ece8de;
  border: 1px solid #b0a898;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.form-top-item {
  display: flex;
  flex-direction: column;
  min-width: 140px;
  flex: 1;
}

.date-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.date-inputs input[type="date"] {
  width: auto;
  min-width: 118px;
  flex: 1;
}

.date-sep {
  color: #7a6848;
  font-size: 13px;
  flex-shrink: 0;
}

/* ── Filters (legacy) ─────────────────────────────────────────────────────── */
.filter-box {
  background: #ece8de;
  border: 1px solid #b0a898;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
  align-items: flex-end;
}

.filter-field { display: flex; flex-direction: column; min-width: 140px; flex: 1; }
.filter-btn   { min-width: 180px; flex: 0 0 auto; }

/* ── Labels & inputs ──────────────────────────────────────────────────────── */
label {
  font-size: 11px;
  color: #5a4830;
  font-weight: 600;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"],
input[type="password"],
input[type="date"],
select {
  border: 1px solid #a0988a;
  border-radius: 0;
  padding: 4px 7px;
  font-size: 13px;
  color: #1a1a1a;
  background: #fff;
  outline: none;
  transition: border-color 0.1s;
  width: 100%;
}

input:focus, select:focus {
  border-color: #8a7050;
  background: #fffff8;
  box-shadow: none;
}

/* ── Summary cards (legacy) ───────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.card {
  background: #f5f1e8;
  border: 1px solid #b0a898;
  padding: 10px 12px;
}

.card-label {
  font-size: 11px;
  color: #6a5a40;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.card-value {
  font-size: 17px;
  font-weight: 700;
  color: #1a1a1a;
  font-variant-numeric: tabular-nums;
}

/* ── Report boxes ─────────────────────────────────────────────────────────── */
.report-box {
  background: #f5f1e8;
  border: 1px solid #b0a898;
  margin-bottom: 8px;
  overflow: hidden;
}

.report-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 12px;
  border-bottom: 1px solid #b0a898;
  background: #e8e3d8;
}

.report-title {
  font-weight: 700;
  font-size: 13px;
  color: #1a1a1a;
}

.report-period-label {
  font-size: 12px;
  color: #6a5a40;
}

/* ── Report table ─────────────────────────────────────────────────────────── */
.report-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.report-table th:first-child,
.report-table td:first-child { width: 44%; }

.report-table .col-num { width: 18.666%; }

.report-table thead th {
  background: #ece8de;
  height: 34px;
  padding: 5px 12px;
  font-size: 12px;
  color: #4a3820;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  border-bottom: 1px solid #b0a898;
  text-align: left;
}

.report-table tbody td {
  height: 30px;
  padding: 4px 12px;
  border-bottom: 1px solid #e0dcd0;
  font-size: 13px;
  color: #1a1a1a;
  vertical-align: middle;
}

.report-table tbody tr:last-child td { border-bottom: none; }
.report-table tbody tr:hover td { background: #ede8dc; }

.col-num {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* group header row */
.group-header td {
  font-weight: 700;
  font-size: 12px;
  color: #4a3820;
  background: #e8e3d8 !important;
  padding: 5px 12px !important;
  border-top: 1px solid #b0a898;
}

/* subsection header row (Взаиморасчеты) */
.subsection-header-row td {
  font-weight: 700;
  font-size: 12px;
  color: #4a3820;
  background: #e8e3d8 !important;
  padding: 4px 12px !important;
  border-top: 1px solid #b0a898;
  border-bottom: 1px solid #c8c0b0;
}

/* indented td */
.td-indent {
  padding-left: 26px !important;
  color: #3a2a10;
}

/* indented sub-rows */
.indent-row td:first-child {
  padding-left: 26px;
  color: #4a3820;
}

/* total row */
.total-row td {
  background: #e8e3d8;
  border-top: 1px solid #b0a898 !important;
  height: 32px;
  padding-top: 4px !important;
  padding-bottom: 4px !important;
  font-size: 13px;
  color: #cc0000;
}

/* financial result */
.result-table .result-header-row td {
  background: #e8e3d8;
  font-size: 13px;
  color: #1a1a1a;
  font-weight: 700;
  padding: 6px 12px;
  border-bottom: 1px solid #b0a898;
}

.result-table .total-row td {
  font-size: 14px;
  background: #e8e3d8;
}

/* ── Colors ───────────────────────────────────────────────────────────────── */
.green { color: #006600 !important; }
.red   { color: #cc0000 !important; }
.muted { color: #9a8a70; }

.currency-badge {
  font-size: 11px;
  color: #9a8a70;
  font-weight: 400;
  margin-left: 4px;
}

/* ── Clickable rows ───────────────────────────────────────────────────────── */
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: #ddd8c8 !important; }
.clickable-row td:first-child { color: #5a3810; text-decoration: underline; text-underline-offset: 2px; }
.detail-icon {
  font-size: 10px;
  color: #8a7848;
  margin-left: 4px;
  vertical-align: middle;
  font-weight: 400;
  text-decoration: none;
  display: inline;
}

/* ── Auth modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 10, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: #f0ece0;
  border: 1px solid #b0a898;
  padding: 18px 22px;
  width: 340px;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.25);
}

.modal-title {
  font-size: 14px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 14px;
  border-bottom: 1px solid #c0b8a8;
  padding-bottom: 7px;
}

.modal-field { margin-bottom: 10px; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

.error-msg {
  background: #f0d8d8;
  color: #6a1a1a;
  border: 1px solid #d89898;
  padding: 7px 10px;
  font-size: 12px;
  margin-top: 6px;
}

/* ── Detail modal ─────────────────────────────────────────────────────────── */
.modal-wide {
  width: min(800px, 94vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  padding: 14px 18px;
}

.detail-scroll {
  overflow-y: auto;
  flex: 1;
  max-height: 55vh;
  border: 1px solid #b0a898;
}

.detail-modal-table { table-layout: auto !important; }
.detail-modal-table th:first-child,
.detail-modal-table td:first-child { width: auto !important; }
.detail-modal-table .col-num { width: 160px !important; }

.detail-total {
  margin-top: 6px;
  text-align: right;
  font-size: 13px;
  color: #1a1a1a;
  padding: 6px 12px;
  background: #e8e3d8;
  border: 1px solid #b0a898;
}

.detail-total strong { font-size: 14px; color: #cc0000; }

.detail-empty {
  text-align: center;
  color: #8a7848;
  padding: 20px 12px;
  font-size: 13px;
}

/* ── Fullscreen warehouse modal ───────────────────────────────────────────── */
.fullscreen-modal {
  position: fixed;
  inset: 0;
  background: #f5f1e8;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fullscreen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #2d2822;
  color: #d8c898;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.fullscreen-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fullscreen-title strong { font-size: 14px; font-weight: 700; color: #e8d8b8; }
.fullscreen-subtitle { font-size: 12px; color: #9a8868; }

.fullscreen-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.fullscreen-controls input[type="text"] {
  width: 240px;
  background: #3d3428;
  border-color: #5a4838;
  color: #e0d0b0;
  padding: 5px 8px;
  font-size: 12px;
}

.fullscreen-controls input[type="text"]::placeholder { color: #7a6848; }
.fullscreen-controls input[type="text"]:focus {
  background: #3d3428;
  border-color: #9a8060;
  box-shadow: none;
}

.fullscreen-count {
  font-size: 12px;
  color: #9a8868;
  white-space: nowrap;
}

.fullscreen-body { flex: 1; overflow: auto; }

/* Warehouse table */
.wh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
}

.wh-table thead { position: sticky; top: 0; z-index: 10; }

.wh-table thead th {
  background: #ece8de;
  padding: 7px 10px;
  text-align: left;
  font-size: 11px;
  color: #4a3820;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #b0a898;
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
}

.wh-table thead th:hover { background: #e0dcd0; color: #1a1a1a; }

.wh-table tbody td {
  padding: 4px 10px;
  border-bottom: 1px solid #e0dcd0;
  color: #1a1a1a;
  vertical-align: middle;
}

.wh-table tbody tr:hover td { background: #ede8dc; }

.wh-table tfoot td {
  padding: 7px 10px;
  background: #e8e3d8;
  font-weight: 700;
  font-size: 13px;
  border-top: 1px solid #b0a898;
  position: sticky;
  bottom: 0;
  color: #cc0000;
}

.wh-num   { width: 44px;  text-align: right !important; color: #8a7848 !important; font-size: 11px; }
.wh-group { width: 160px; color: #5a4830; }
.wh-name  { min-width: 200px; font-weight: 500; }
.wh-qty   { width: 100px; text-align: right !important; font-variant-numeric: tabular-nums; }
.wh-unit  { width: 48px;  color: #8a7848; font-size: 12px; }
.wh-price { width: 140px; text-align: right !important; font-variant-numeric: tabular-nums; }
.wh-sum   { width: 160px; text-align: right !important; font-variant-numeric: tabular-nums; font-weight: 600; color: #1a1a1a; }

/* ── Form bottom controls ─────────────────────────────────────────────────── */
.form-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #4a3820;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 0;
  font-weight: normal;
}

.form-check input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.form-bottom-actions { display: flex; gap: 8px; }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; padding: 10px; }
  .main { padding: 10px; }
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-box { gap: 8px; }
  .filter-field { min-width: 130px; }
  .report-box { overflow-x: auto; }
  .report-table { min-width: 600px; }
}

@media (max-width: 540px) {
  .cards-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
