* { box-sizing: border-box; }
:root {
  --bg: #f0f2f8;
  --surface: #fff;
  --text: #1a1a2e;
  --muted: #5c6370;
  --accent: #2d3a8c;
  --accent-soft: #e8ebff;
  --danger: #c0392b;
  --success: #1e7a3a;
  --danger-bg: #fdecec;
  --success-bg: #e8f8ee;
  --border: #e2e6ef;
  --radius: 10px;
  --link: #3b4a9a;
  --link-hover: #1e2a6e;
}
body { font-family: "Segoe UI", system-ui, sans-serif; margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
a {
  color: var(--link);
  text-decoration: none;
  font-weight: 500;
  transition: color .15s ease;
}
a:visited { color: var(--link); }
a:hover { color: var(--link-hover); }
a:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
  border-radius: 3px;
}
.nav { display: flex; gap: .5rem 1rem; flex-wrap: wrap; align-items: center; padding: .85rem 1rem; background: var(--text); position: sticky; top: 0; z-index: 10; }
.nav a { color: #fff; text-decoration: none; padding: .35rem .5rem; border-radius: 6px; font-size: .95rem; font-weight: 500; }
.nav a:visited { color: #fff; }
.nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-user { margin-left: auto; color: #c8d0e0; font-size: .875rem; }
.container { max-width: 1100px; margin: 0 auto; padding: 1rem; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { padding: .65rem .85rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--accent-soft); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1rem; align-items: start; }
.stats-grid:has(.stat-card-clickable) { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stats-grid-compact { margin-bottom: .5rem; }
.stats-grid-compact .stat-card { padding: .85rem 1rem; }
.stats-grid-compact .stat-value { font-size: 1.35rem; }
.stat-card { background: var(--surface); padding: 1.1rem; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.stat-card-clickable { cursor: pointer; border: 1px solid transparent; transition: border-color .15s, box-shadow .15s; min-width: 0; width: 100%; box-sizing: border-box; }
.stat-card-clickable[open] { border-color: var(--accent-soft); box-shadow: 0 2px 8px rgba(0,0,0,.08); z-index: 2; position: relative; }
.stat-card-clickable:hover { border-color: var(--accent-soft); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.stat-card-clickable summary { list-style: none; cursor: pointer; display: block; }
.stat-card-clickable summary::-webkit-details-marker { display: none; }
.stat-card-clickable summary::after { content: '▾'; float: right; color: var(--muted); font-size: .85rem; line-height: 1.65rem; margin-left: .5rem; }
.stat-card-clickable[open] summary::after { content: '▴'; }
.stat-breakdown { margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.stat-breakdown-head,
.stat-breakdown-row { display: grid; column-gap: .5rem; row-gap: 0; align-items: center; font-size: .85rem; line-height: 1.35; }
.stat-breakdown-head { grid-template-columns: minmax(0, 1fr) 2.75rem; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding-bottom: .35rem; margin-bottom: .15rem; border-bottom: 1px solid var(--border); }
.stat-breakdown-head.stat-breakdown-head--money { grid-template-columns: minmax(0, 1fr) 2.75rem 5.5rem; }
.stat-breakdown-row { grid-template-columns: minmax(0, 1fr) 2.75rem; padding: .28rem 0; }
.stat-breakdown-row--money { grid-template-columns: minmax(0, 1fr) 2.75rem 5.5rem; }
.stat-breakdown-head span:not(:first-child),
.stat-breakdown-row span:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-breakdown-row + .stat-breakdown-row { border-top: 1px solid rgba(0,0,0,.04); }
.collapsible-section { margin: 1.25rem 0; }
.collapsible-section > summary { cursor: pointer; font-weight: 600; font-size: 1.15rem; padding: .5rem 0; list-style: none; }
.collapsible-section > summary::-webkit-details-marker { display: none; }
.collapsible-section > summary::before { content: '▸ '; color: var(--muted); }
.collapsible-section[open] > summary::before { content: '▾ '; }
.stat-label { display: block; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .35rem; }
.stat-value { font-size: 1.65rem; font-weight: 700; }
.stat-positive { color: var(--success); }
.stat-negative { color: var(--danger); }
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-error { background: var(--danger-bg); color: #8b1a1a; }
.alert-success { background: var(--success-bg); color: var(--success); }
.badge-error { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 6px; background: var(--danger-bg); color: #8b1a1a; font-size: 0.82rem; }
.row-failed { background: #fff9f9; }
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.login-card { background: var(--surface); padding: 2rem; border-radius: 14px; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.08); max-width: 400px; width: 100%; }
/* Единый вид всех полей ввода */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
select,
textarea {
  width: 100%;
  padding: .55rem .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: .95rem;
  line-height: 1.4;
  color: var(--text);
  background: #fff;
  min-height: 2.5rem;
  appearance: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235c6370' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  padding-right: 2rem;
  cursor: pointer;
}
textarea { min-height: 5rem; resize: vertical; }
input[type="file"] { padding: .4rem .5rem; min-height: auto; cursor: pointer; }
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
input::placeholder, textarea::placeholder { color: #9aa3b2; }

.form label:not(.checkbox-row),
.filters label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .875rem;
  font-weight: 500;
}
.form label { margin-bottom: .85rem; }
.filters label { margin-bottom: 0; }
.checkbox-row, .checkbox-grid label {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: .6rem;
  margin-bottom: .65rem;
  font-weight: 400;
  cursor: pointer;
  width: fit-content;
  max-width: 100%;
}
.checkbox-row input[type="checkbox"],
.checkbox-grid input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 1.125rem !important;
  height: 1.125rem !important;
  min-height: 1.125rem !important;
  margin: 0;
  padding: 0;
  border: 2px solid #b8c0d0;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
}
.checkbox-row input[type="checkbox"]:checked,
.checkbox-grid input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox-row input[type="checkbox"]:checked::after,
.checkbox-grid input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.checkbox-row input[type="checkbox"]:focus-visible,
.checkbox-grid input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}
.checkbox-row span { line-height: 1.35; }
.btn, button { background: var(--accent); color: #fff; border: 0; padding: .55rem 1rem; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; }
.btn:hover, button:hover { filter: brightness(1.08); }
.btn-secondary { background: #6b7280; }
.btn-danger { background: var(--danger); }
.btn-link {
  background: transparent;
  color: var(--link);
  padding: 0;
  text-decoration: none;
  font-weight: 500;
  border: 0;
  cursor: pointer;
}
.btn-link:hover { color: var(--link-hover); filter: none; }
a.btn, a.btn:visited,
a.btn-secondary, a.btn-secondary:visited,
a.btn-danger, a.btn-danger:visited {
  color: #fff;
  font-weight: 500;
}
a.btn:hover, a.btn-secondary:hover, a.btn-danger:hover { color: #fff; }
.alert a { color: inherit; font-weight: 600; }
.alert a:hover { opacity: .85; }
.image-preview-grid a { color: inherit; font-weight: normal; }
.image-preview-grid a:hover { opacity: .92; }
table a { font-weight: 500; }
.mt-4 { margin-top: 1rem; }
.card { background: var(--surface); padding: 1.25rem; border-radius: var(--radius); margin-bottom: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; background: var(--surface); }
legend { font-weight: 600; padding: 0 .5rem; }
.checkbox-grid { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; }
.hint { font-size: .85rem; color: var(--muted); margin-top: .35rem; font-weight: 400; }
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: 1rem; padding: 1rem; background: var(--surface); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.filters label { margin: 0; flex: 1 1 160px; min-width: 140px; }
.filters button, .filters .btn { flex: 0 0 auto; align-self: flex-end; min-height: 2.5rem; }
details.collapsible { background: var(--surface); border-radius: var(--radius); margin-bottom: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
details.collapsible summary { padding: .85rem 1rem; cursor: pointer; font-weight: 600; list-style: none; }
details.collapsible summary::-webkit-details-marker { display: none; }
details.collapsible summary::before { content: "▸ "; color: var(--muted); }
details.collapsible[open] summary::before { content: "▾ "; }
details.collapsible .details-body { padding: 0 1rem 1rem; }
.image-preview-grid { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .5rem; }
.image-preview-item { display: flex; flex-direction: column; gap: .35rem; max-width: 96px; }
.image-preview-grid img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: #f8f9fc; }
.image-remove { font-size: .75rem; }
.image-remove span { color: var(--muted); }
.hint code { font-size: .82em; background: #f0f2f8; padding: .1rem .35rem; border-radius: 4px; }
.expense-rows .expense-row { display: flex; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; align-items: center; }
.expense-rows .expense-row input { flex: 1 1 160px; }
.form-rows { display: flex; flex-direction: column; gap: .75rem; margin-top: .5rem; }
.form-rows .form-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8f9fc;
}
.form-rows .form-row select,
.form-rows .form-row input { flex: 1 1 140px; min-width: 120px; }
.period-stats { padding: 1.25rem; margin-bottom: 1.5rem; }
.period-stats > .form { margin-bottom: 1rem; box-shadow: none; padding: 0; }
.period-filter-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.period-filter-row label { flex: 1 1 140px; margin: 0; }
.period-filter-row button { flex: 0 0 auto; min-height: 2.5rem; }
.period-label { font-size: .9rem; color: var(--muted); margin: 0 0 .75rem; font-weight: 500; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
.section-head h2 { margin: 0; }
.btn-sm { padding: .4rem .75rem; font-size: .85rem; min-height: auto; }
.sale-row-extra-hidden { display: none !important; }
.collapsible.mt-4 { margin-top: 1rem; }
.tabs { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .45rem .85rem; border-radius: 999px; background: var(--surface); color: var(--text); text-decoration: none; border: 1px solid var(--border); font-size: .9rem; font-weight: 500; }
.tabs a:visited { color: var(--text); }
.tabs a.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tabs a.active:visited { color: #fff; }
.tabs-buttons { margin-bottom: 0; border-bottom: 1px solid var(--border); padding-bottom: .75rem; }
.tab-btn {
  padding: .45rem .85rem; border-radius: 999px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); font-size: .9rem; font-weight: 500; cursor: pointer;
}
.tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.shelf-ops { padding: 1rem 1.25rem; margin-bottom: 1rem; }
.tab-panel { display: none; padding-top: 1rem; }
.tab-panel.active { display: block; }
@media (max-width: 640px) {
  .nav { gap: .35rem .6rem; }
  .nav-user { width: 100%; margin-left: 0; order: 10; }
  h1 { font-size: 1.35rem; }
  .stat-value { font-size: 1.35rem; }
  .filters { flex-direction: column; align-items: stretch; }
  table { min-width: 480px; }
}
