/* Alfa Business–inspired UI for Bills */
:root {
  --font: "Alfa Interface Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, sans-serif;
  --bg: #f2f3f5;
  --bg-soft: #e9ebef;
  --surface: #ffffff;
  --ink: #0f0f12;
  --ink-2: #1e2b44;
  --muted: rgba(4, 4, 19, 0.55);
  --muted-2: rgba(4, 4, 19, 0.35);
  --line: rgba(30, 43, 68, 0.08);
  --line-strong: rgba(30, 43, 68, 0.12);
  --red: #ef3124;
  --ok: #0cc44d;
  --warn: #ff4837;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow: 0 1px 2px rgba(15, 25, 55, 0.04), 0 4px 16px rgba(15, 25, 55, 0.04);
  --sidebar-w: 260px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
[x-cloak] { display: none !important; }

/* убрать стрелочки у type="number" */
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.shell {
  min-height: 100vh;
  max-width: 1920px;
  margin: 0 auto;
  width: 100%;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(30, 43, 68, 0.08), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(239, 49, 36, 0.06), transparent 50%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-brand {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: -0.02em;
}
.login-hint {
  margin: -4px 0 4px;
  color: var(--muted);
}
.login-error {
  margin: 0;
  color: var(--warn);
  font-size: 13px;
}
body .login-submit {
  width: 100%;
  height: 48px;
  margin-top: 16px;
  font-size: 15px;
  /* border-radius: var(--radius-sm); */
}
.side-user {
  padding: 4px 12px 0;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--line); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 32px;
  min-height: 100vh;
}

.sidebar {
  padding: 20px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.25;
}
.side-link svg { color: rgba(4, 4, 19, 0.65); flex-shrink: 0; }
.side-link:hover { background: rgba(30, 43, 68, 0.06); }
.side-link.active {
  background: #e7e8eb;
  box-shadow: none;
  font-weight: 600;
}
.side-link.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}
.badge-soon {
  margin-left: auto;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.side-divider {
  height: 1px;
  background: var(--line);
  margin: 8px 8px;
}

.content {
  padding: 20px 24px 40px 0;
  width: 100%;
  max-width: none;
  min-width: 0;
}

.page-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.page-title-row h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.search-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 240px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid transparent;
  box-shadow: var(--shadow);
}
.search-pill:focus-within {
  border-color: rgba(239, 49, 36, 0.35);
}
.search-pill svg { color: var(--muted); flex-shrink: 0; }
.search-pill input {
  border: 0;
  outline: 0;
  width: 100%;
  min-width: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}
.search-pill input[type="search"]::-webkit-search-decoration,
.search-pill input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}
.search-clear {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.search-clear:hover {
  background: var(--line);
  color: var(--ink);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--surface);
  padding: 4px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.chip {
  border: 0;
  background: transparent;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.chip.active {
  background: var(--ink);
  color: #fff;
}
.filter-select {
  height: 40px;
  min-width: 180px;
  max-width: 260px;
  padding: 0 36px 0 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  background-size: 16px;
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  appearance: none;
  cursor: pointer;
}
.filter-select:focus {
  outline: 0;
  border-color: rgba(239, 49, 36, 0.35);
}
.filter-select-year {
  min-width: 92px;
  max-width: 100px;
  width: 92px;
  padding-right: 30px;
}

.ui-select {
  position: relative;
  min-width: 168px;
  max-width: 260px;
}
.ui-select-year {
  min-width: 96px;
  max-width: 110px;
  width: 96px;
}
.ui-select-trigger {
  position: relative;
  width: 100%;
  height: 40px;
  padding: 0 36px 0 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-align: left;
}
.ui-select-trigger:hover {
  border-color: var(--line-strong);
}
.ui-select.is-open .ui-select-trigger,
.ui-select-trigger:focus {
  outline: 0;
  border-color: rgba(239, 49, 36, 0.35);
}
.ui-select-value {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ui-select-caret {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  transition: transform 0.15s ease;
}
.ui-select.is-open .ui-select-caret {
  transform: translateY(-50%) rotate(180deg);
}
.ui-select-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  min-width: 100%;
  max-height: 280px;
  overflow: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(15, 25, 55, 0.12);
  scrollbar-width: thin;
  scrollbar-color: rgba(30, 43, 68, 0.28) transparent;
}
.ui-select-menu::-webkit-scrollbar {
  width: 4px;
}
.ui-select-menu::-webkit-scrollbar-track {
  background: transparent;
}
.ui-select-menu::-webkit-scrollbar-thumb {
  background: rgba(30, 43, 68, 0.28);
  border-radius: 999px;
}
.ui-select-menu::-webkit-scrollbar-thumb:hover {
  background: rgba(30, 43, 68, 0.42);
}
.ui-select-year .ui-select-menu {
  min-width: 112px;
}
.ui-select-option {
  width: 100%;
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}
.ui-select-option:hover {
  background: var(--bg);
}
.ui-select-option.active {
  background: rgba(30, 43, 68, 0.06);
  color: var(--ink-2);
}
.ui-select-option svg {
  flex: 0 0 auto;
  color: var(--ink-2);
}
.archive-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}
.archive-controls-page {
  margin-top: 16px;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.archive-year-field {
  margin: 0;
}
.archive-year-field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.archive-year-select {
  min-width: 120px;
  max-width: 140px;
  padding-right: 32px;
}
.archive-page {
  padding: 4px 2px;
}
.archive-meta {
  margin-top: 14px;
  font-size: 13px;
}
.archive-meta strong {
  color: var(--ink);
  font-weight: 600;
}
.archive-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}
.archive-card {
  padding: 20px 22px 22px;
  min-width: 0;
  max-width: none;
}
.archive-section-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stats-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 320px));
  gap: 12px;
  margin-bottom: 12px;
}
.dashboard-stats-row {
  grid-template-columns: repeat(3, minmax(0, 320px));
}
.dashboard-stat-link {
  cursor: pointer;
  transition: box-shadow 0.15s ease;
}
.dashboard-stat-link:hover {
  box-shadow: 0 2px 10px rgba(15, 25, 55, 0.08);
}
.dashboard-chart-card {
  width: 100%;
  padding: 20px 22px 12px;
  margin-bottom: 12px;
}
.dashboard-chart-card.is-collapsed {
  padding-bottom: 16px;
}
.dashboard-chart-toggle {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.dashboard-chart-toggle:hover .dashboard-chart-chevron {
  color: var(--ink);
  background: var(--bg-soft);
}
.dashboard-chart-head {
  min-width: 0;
  flex: 1;
}
.dashboard-chart-head h2,
.dashboard-section-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.dashboard-chart-head p {
  margin: 4px 0 0;
}
.dashboard-chart-chevron {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-top: 2px;
  border-radius: 8px;
  color: var(--muted);
  transition: transform 0.18s ease, background 0.15s ease, color 0.15s ease;
}
.dashboard-chart-card.is-collapsed .dashboard-chart-chevron {
  transform: rotate(-90deg);
}
.dashboard-chart-body {
  width: 100%;
}
.dashboard-section-head {
  padding: 18px 20px 0;
}
.dashboard-section-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.dashboard-chart-wrap {
  position: relative;
  height: 340px;
  margin-top: 12px;
}
.table-card .dashboard-section-head + .empty {
  padding-top: 12px;
}
.dashboard-tops {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.dashboard-top-card {
  min-width: 0;
}
.dashboard-top-card .dashboard-section-head {
  padding: 18px 20px 8px;
}
.dashboard-top-card .dashboard-section-head p {
  margin: 4px 0 0;
}
.dashboard-top-card .empty {
  padding: 8px 20px 20px;
}
.dashboard-rank {
  list-style: none;
  margin: 0;
  padding: 4px 12px 14px;
}
.dashboard-rank li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-top: 1px solid var(--line);
}
.dashboard-rank li:first-child {
  border-top: 0;
}
.dashboard-rank-n {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--bg-soft);
}
.dashboard-rank-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* font-weight: 600; */
}
.dashboard-rank-sum {
  font-weight: 600;
  white-space: nowrap;
}
.stat { padding: 18px 20px; }
.stat-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.stat-value.ok { color: #0a9f3c; }
.stat-value.warn { color: var(--warn); }
.stat-hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.table-card { overflow: visible; }
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
/* overflow-x:auto клипит absolute-меню — на время открытия снимаем обрезку */
.table-wrap:has(.row-menu-toggle.open) {
  overflow: visible;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}
.data-table th {
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: rgba(30, 43, 68, 0.025); }
.data-table tr.busy { opacity: 0.55; }
.data-table .num { text-align: right; }
.data-table.hosting-table {
  min-width: 0;
  table-layout: fixed;
}
.data-table.hosting-table th:nth-child(1),
.data-table.hosting-table td:nth-child(1) { width: 20%; }
.data-table.hosting-table th:nth-child(2),
.data-table.hosting-table td:nth-child(2) { width: 18%; }
.data-table.hosting-table th:nth-child(3),
.data-table.hosting-table td:nth-child(3) { width: 10%; }
.data-table.hosting-table th:nth-child(4),
.data-table.hosting-table td:nth-child(4),
.data-table.hosting-table th:nth-child(5),
.data-table.hosting-table td:nth-child(5),
.data-table.hosting-table th:nth-child(6),
.data-table.hosting-table td:nth-child(6) { width: 10%; }
.data-table.hosting-table th.col-info,
.data-table.hosting-table td.col-info { width: 40px; text-align: center; padding-left: 8px; padding-right: 8px; }
.data-table.hosting-table th.col-actions,
.data-table.hosting-table td.col-actions { width: 120px; }
.col-info { vertical-align: middle; }
.info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--muted);
  cursor: help;
  outline: none;
  z-index: 1;
}
.info-tip:hover,
.info-tip:focus-visible {
  color: var(--ink);
  background: var(--bg-soft);
  z-index: 50;
}
.info-tip-bubble {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 60;
  width: max-content;
  min-width: 140px;
  max-width: min(320px, 55vw);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: normal;
  text-align: left;
  box-shadow: 0 10px 30px rgba(15, 25, 55, 0.14);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.12s ease, visibility 0.12s ease;
}
.info-tip-bubble::after {
  content: '';
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: var(--surface);
  filter: drop-shadow(1px 0 0 var(--line-strong));
}
.info-tip:hover .info-tip-bubble,
.info-tip:focus-visible .info-tip-bubble {
  opacity: 1;
  visibility: visible;
}
tr:has(.info-tip:hover),
tr:has(.info-tip:focus-visible) {
  position: relative;
  z-index: 8;
}
.cell-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 0;
}
.kudir-form-row td {
  padding: 10px 12px;
  background: rgba(30, 43, 68, 0.03);
  vertical-align: middle;
}
.kudir-form-row:hover td {
  background: rgba(30, 43, 68, 0.04);
}
.kudir-note-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
}
.kudir-invoice-link {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  line-height: 1.3;
}
.kudir-invoice-link:hover {
  text-decoration: underline;
}
.table-input {
  width: 100%;
  min-width: 0;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 0 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  box-sizing: border-box;
}
.table-input:focus {
  outline: 0;
  border-color: rgba(239, 49, 36, 0.45);
  box-shadow: 0 0 0 2px rgba(239, 49, 36, 0.15);
}
select.table-input {
  appearance: none;
  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='%231e2b44' d='M1.4.6 6 5.2 10.6.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}
.table-input.num-input {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.table-input.date-input,
.table-input.flatpickr-input,
input.table-input.flatpickr-input[readonly] {
  cursor: pointer;
  background: #fff;
}
.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 28px 18px !important;
}
.empty-cell .btn {
  margin-left: 8px;
}
.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.th-sort::after {
  content: '';
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid currentColor;
  opacity: 0.28;
  transform: translateY(1px);
}
.th-sort.is-asc::after,
.th-sort.is-desc::after {
  opacity: 1;
  color: var(--ink);
}
.th-sort.is-desc::after {
  border-bottom: 0;
  border-top: 5px solid currentColor;
  transform: translateY(2px);
}
.th-sort-num {
  width: 100%;
  justify-content: flex-end;
}
.th-sort:hover {
  color: var(--ink);
}
.mono { font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.ok { color: #0a9f3c; }

.status-badge {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 0;
  background: var(--bg-soft);
  color: var(--muted);
}
.status-badge.paid {
  background: rgba(12, 196, 77, 0.12);
  color: #0a9f3c;
}
.status-badge.partial {
  background: rgba(255, 170, 0, 0.16);
  color: #b46b00;
}
.status-badge.unpaid {
  background: rgba(255, 72, 55, 0.12);
  color: var(--warn);
}

.card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
  color: var(--muted);
  font-size: 12px;
}
.card-foot-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.lazy-sentinel {
  height: 1px;
  width: 100%;
  pointer-events: none;
}

/* Buttons */
.btn {
  height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn-primary {
  background: var(--ink);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: var(--line);
  color: var(--ink);
}
.btn-ghost:hover { background: var(--line-strong); }
.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.06); }

.modal.modal-sm {
  width: min(440px, 100%);
  height: auto;
  max-height: min(640px, 100%);
}
.modal-backdrop.modal-layer-top {
  z-index: 55;
}
.modal-message {
  margin: 0;
  color: var(--ink-2);
  line-height: 1.45;
}
.usage-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
}
.usage-list-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: inherit;
}
.usage-list-item:last-child { border-bottom: 0; }
.usage-list-item:hover { background: rgba(30, 43, 68, 0.03); }
.usage-list-more {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}
.empty.error { color: var(--warn); }
.empty .btn { margin-top: 12px; }

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #eceef2 25%, #f7f8fa 50%, #eceef2 75%);
  background-size: 200% 100%;
  animation: shimmer 1.1s linear infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Settings */
.settings-card { padding: 20px; }
.settings-form { display: flex; flex-direction: column; gap: 20px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.field.span-2 { grid-column: 1 / -1; }
.field-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.field-checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent, #ef3124);
  cursor: pointer;
}
.field-input-icon {
  position: relative;
}
.field-input-icon input {
  width: 100%;
  padding-right: 42px;
}
.field-input-icon-btn {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.field-input-icon-btn:hover:not(:disabled) {
  background: rgba(30, 43, 68, 0.06);
  color: var(--ink);
}
.field-input-icon-btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.field-input-icon-btn .is-spinning {
  animation: field-icon-spin 0.8s linear infinite;
}
@keyframes field-icon-spin {
  to { transform: rotate(360deg); }
}
.field input {
  height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 0 14px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
}
.field select {
  height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  padding: 0 14px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  appearance: none;
  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='%231e2b44' d='M1.4.6 6 5.2 10.6.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.field input:focus,
.field select:focus {
  outline: 0;
  box-shadow: 0 0 0 2px rgba(239, 49, 36, 0.25);
  background-color: #fff;
}
.field select:focus {
  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='%231e2b44' d='M1.4.6 6 5.2 10.6.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.field-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.field-hint {
  margin: 4px 0 12px;
  font-size: 12px;
  color: var(--muted);
}
.facsimile { padding-top: 4px; border-top: 1px solid var(--line); }
.facsimile-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}
.facsimile-box {
  width: 180px;
  height: 110px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
}
.facsimile-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.facsimile-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.settings-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.muted { color: var(--muted); font-size: 12px; }

.cell-title { font-weight: 600; color: var(--text); }
.cell-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  max-width: 280px;
}
.col-actions { width: 1%; white-space: nowrap; text-align: right; vertical-align: middle; }
.row-actions-inline {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
}
.row-action-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
}
.row-action-icon:hover {
  background: var(--bg-soft);
  color: var(--ink);
}
.row-menu {
  position: relative;
  display: inline-flex;
  justify-content: flex-end;
  z-index: 1;
}
.row-menu:has(.row-menu-toggle.open) {
  z-index: 30;
}
tr:has(.row-menu-toggle.open) {
  position: relative;
  z-index: 6;
}
.row-menu-toggle {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--muted);
}
.row-menu-toggle:hover,
.row-menu-toggle.open {
  background: var(--bg-soft);
  color: var(--ink);
}
.row-menu-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 31;
  min-width: 168px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15, 25, 55, 0.14);
  display: grid;
  gap: 2px;
}
.row-menu-item {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.row-menu-item:hover:not(:disabled) {
  background: var(--bg);
}
.row-menu-item.danger { color: var(--red); }
.row-menu-item.danger:hover:not(:disabled) {
  background: rgba(239, 49, 36, 0.08);
}
.row-menu-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 999px;
}
.btn-danger-ghost {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--red);
}
.btn-danger-ghost:hover:not(:disabled) {
  background: rgba(239, 49, 36, 0.08);
}
.payments-table .btn {
  border-radius: 999px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 15, 16, 0.45);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}
.modal {
  width: min(640px, 100%);
  height: min(800px, 100%);
  max-height: min(800px, 100%);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  font-size: 14px;
}
.modal.modal-lg { width: min(720px, 100%); }
.modal .field { font-size: 14px; }
.modal .field-hint,
.modal .muted,
.modal .cell-sub,
.modal .invoice-preview-label,
.modal .invoice-money-meta,
.modal .payments-empty { font-size: 12px; }
.modal .status-badge { font-size: 14px; }
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: rgba(30, 43, 68, 0.03); }
.check-field .check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  font-weight: 500;
  cursor: pointer;
}
.check-field .check-row input { width: auto; margin: 0; }
.field select,
.field input[type="number"],
.field input.date-input,
.field .flatpickr-input {
  width: 100%;
}
.modal-foot-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}
.invoice-preview {
  display: grid;
  padding: 4px 0 8px;
}
.invoice-preview-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.invoice-preview-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}
.invoice-preview-comment {
  font-size: 14px;
  line-height: 1.4;
  margin: 0 4px 18px;
}
.invoice-preview-grid .strong {
  font-size: 18px;
}
.invoice-preview-amount{
  margin-top:10px;
}
.invoice-preview-amount .stat-value {
  font-size: 28px;
}
.invoice-money-meta {
  display: grid;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.payments-block {
  margin-top: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.payments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.payments-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}
.payments-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}
.payments-table th,
.payments-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
.payments-table tbody tr:last-child td {
  border-bottom: none;
}
.payments-table th:first-child,
.payments-table td:first-child {
  padding-left: 0;
}
.payments-table th:last-child,
.payments-table td:last-child {
  padding-right: 0;
}
.payments-table th {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.payments-table .num { text-align: right; }
.payments-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 0;
}
.invoice-items-block {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
}
.invoice-works-head {
  margin-bottom: 0;
}
.invoice-add-work {
  width: 100%;
}
.client-picker {
  position: relative;
  width: 100%;
}
.client-picker-selected {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 8px 10px 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
}
.client-picker-selected:hover {
  box-shadow: 0 0 0 2px rgba(239, 49, 36, 0.18);
  background: #fff;
}
.client-picker-selected-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.client-picker-clear {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.client-picker-clear:hover {
  background: rgba(30, 43, 68, 0.06);
  color: var(--ink);
}
.work-picker {
  position: relative;
  width: 100%;
}
.work-picker-input {
  width: 100%;
  height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 0 14px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
}
.work-picker-input:focus {
  outline: 0;
  box-shadow: 0 0 0 2px rgba(239, 49, 36, 0.25);
  background: #fff;
}
.work-picker-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 35;
  max-height: 260px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15, 25, 55, 0.14);
  padding: 6px;
  display: grid;
  gap: 2px;
}
.work-picker-option {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  gap: 2px;
  color: var(--ink);
  font: inherit;
}
.work-picker-option:hover {
  background: var(--bg);
}
.work-picker-empty {
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
}
.invoice-items-list {
  display: grid;
  gap: 8px;
}
.invoice-item-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.4fr) 90px 48px 110px 100px 36px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.invoice-item-main { min-width: 0; }
.invoice-item-name {
  margin: 0;
}
.invoice-item-name input {
  width: 100%;
  font-weight: 600;
}
.act-item-name {
  margin: 0 0 4px;
}
.act-item-name input {
  width: 100%;
  font-weight: 600;
}
.invoice-item-qty,
.invoice-item-price { margin: 0; }
.invoice-item-unit {
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.invoice-item-sum {
  height: 44px;
  display: grid;
  place-items: center end;
}
.invoice-items-total {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 600;
}
@media (max-width: 900px) {
  .invoice-item-row {
    grid-template-columns: 1fr 1fr;
  }
  .invoice-item-main,
  .invoice-item-sum { grid-column: 1 / -1; }
}
.modal-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.modal-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 16px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-foot {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 12px 20px 16px;
  margin-left: -20px;
  margin-right: -20px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  background: #212124;
  color: #f2f3f5;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

/* Flatpickr — под стиль Bills */
.flatpickr-calendar {
  font-family: var(--font);
  font-size: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(15, 25, 55, 0.16);
  overflow: hidden;
  padding: 0;
  width: 280px;
}
.flatpickr-calendar.open { z-index: 60; }
.flatpickr-months {
  background: var(--surface);
  padding: 8px 6px 2px;
  align-items: center;
}
.flatpickr-months .flatpickr-month {
  height: 34px;
  color: var(--ink);
  fill: var(--ink);
}
.flatpickr-current-month {
  font-size: 12px !important;
  font-weight: 700;
  padding-top: 6px;
}
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year {
  font-weight: 700;
  font-size: 12px !important;
}
.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
  fill: var(--ink-2);
  padding: 8px;
  border-radius: 8px;
}
.flatpickr-months .flatpickr-prev-month:hover,
.flatpickr-months .flatpickr-next-month:hover {
  background: var(--bg);
  color: var(--ink);
}
.flatpickr-months .flatpickr-prev-month:hover svg,
.flatpickr-months .flatpickr-next-month:hover svg {
  fill: var(--ink);
}
.flatpickr-weekdays {
  background: var(--surface);
  padding: 0 6px;
}
span.flatpickr-weekday {
  color: var(--muted);
  font-size: 11px !important;
  font-weight: 600;
}
.flatpickr-days { padding: 2px 6px 8px; width: 100%; }
.dayContainer { width: 266px; min-width: 266px; max-width: 266px; }
.flatpickr-day {
  height: 34px;
  line-height: 34px;
  max-width: 34px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 12px !important;
  font-weight: 500;
  border: 0;
}
.flatpickr-day:hover,
.flatpickr-day:focus {
  background: var(--bg);
  border-color: transparent;
}
.flatpickr-day.today {
  border: 1px solid var(--line-strong);
  background: transparent;
}
.flatpickr-day.today:hover {
  background: var(--bg);
  color: var(--ink);
}
.flatpickr-day.selected,
.flatpickr-day.selected:hover,
.flatpickr-day.selected:focus {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
  font-weight: 700;
}
.flatpickr-day.flatpickr-disabled,
.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay {
  color: var(--muted-2);
}
.flatpickr-day.inRange,
.flatpickr-day.prevMonthDay.inRange,
.flatpickr-day.nextMonthDay.inRange {
  background: rgba(239, 49, 36, 0.08);
  box-shadow: none;
  border-color: transparent;
}
.field input.flatpickr-input[readonly],
.field input.date-input {
  cursor: pointer;
  background: var(--bg);
}
.flatpickr-input[readonly]:focus {
  outline: 0;
}

/* Expense plan */
.expense-plan-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}
.expense-plan-card {
  overflow: visible;
  min-width: 0;
}
.expense-plan-card .table-wrap {
  overflow: visible;
}
.expense-plan-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 2px solid var(--line);
}
.expense-plan-day {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.expense-plan-head-right {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.expense-plan-total {
  font-size: 16px;
  white-space: nowrap;
}
.expense-plan-reset {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  color: var(--muted);
}
.expense-plan-reset:hover:not(:disabled) {
  color: var(--ink);
}
.expense-plan-reset:disabled {
  opacity: 0.35;
  cursor: default;
}
.expense-plan-table.data-table {
  min-width: 0;
  width: 100%;
  table-layout: fixed;
}
.expense-plan-table th,
.expense-plan-table td {
  padding: 10px 8px;
  white-space: normal;
}
.expense-plan-table .col-drag {
  width: 32px;
  padding-left: 6px;
  padding-right: 0;
}
.expense-plan-table th:nth-child(2),
.expense-plan-table td:nth-child(2) {
  width: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.expense-plan-table th:nth-child(3),
.expense-plan-table td:nth-child(3) {
  width: 104px;
}
.expense-plan-table th:nth-child(4),
.expense-plan-table td:nth-child(4) {
  width: 88px;
}
.expense-plan-table .col-actions {
  width: 44px;
  padding-left: 4px;
  padding-right: 6px;
}
.expense-plan-table .col-actions .icon-btn {
  width: 34px;
  height: 34px;
}
.expense-plan-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}
.expense-plan-add .table-input {
  width: 100%;
  min-width: 0;
}
.expense-plan-add-amount {
  text-align: right;
}
.expense-plan-add .btn {
  white-space: nowrap;
}
.expense-plan-drag {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--muted);
  cursor: grab;
  user-select: none;
}
.expense-plan-drag:active {
  cursor: grabbing;
}
.expense-plan-sortable {
  position: relative;
}
.expense-plan-sortable.is-empty {
  min-height: 56px;
}
.expense-plan-row.expense-plan-ghost {
  opacity: 0.45;
  background: var(--bg-soft);
}
.expense-plan-row.expense-plan-chosen {
  background: rgba(30, 43, 68, 0.04);
}
.expense-plan-table .status-badge {
  cursor: pointer;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  justify-content: center;
  box-sizing: border-box;
}
.expense-plan-table .status-badge.outline {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}
.expense-plan-table .status-badge:disabled {
  cursor: default;
  opacity: 0.7;
}
.expense-plan-table .table-input {
  width: 100%;
  min-width: 0;
}
.expense-plan-page .stats-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Debts */
.debts-total-row {
  grid-template-columns: repeat(2, minmax(0, 320px));
}
.debts-total-card,
.debts-change-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.debts-total-value-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.debts-total-value-row .stat-value {
  min-width: 0;
}
.debts-snapshot-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  margin-top: 1px;
  color: var(--warn);
}
.debts-snapshot-btn:hover:not(:disabled) {
  background: rgba(196, 92, 38, 0.12);
}
.debts-snapshot-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.debts-change-card .stat-value.is-muted {
  color: var(--muted);
}
.debts-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 320px));
  gap: 12px;
  align-items: stretch;
}
.debt-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 118px;
  padding: 18px 20px;
  border-radius: 14px;
  /* background: #212121; */
  background-color: rgba(4, 4, 19, 0.734);
  border: 1px solid #212121;
  color: #fff;
  box-shadow: none;
  cursor: pointer;
  user-select: none;
  transition: box-shadow 0.15s ease, border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}
.debt-tile:hover:not(.is-editing) {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
}
.debt-tile.is-editing {
  cursor: default;
  justify-content: flex-start;
  min-height: 198px;
  border-color: #3a3a3a;
  box-shadow: var(--shadow);
}
.debt-tile.is-excluded:not(.is-editing) .debt-tile-amount {
  /* opacity: 0.72; */
}
.debt-tile.has-color {
  color: var(--ink);
}
.debt-tile.has-color .debt-tile-title {
  color: var(--ink);
}
.debt-tile.has-color .debt-tile-amount {
  color: rgba(4, 4, 19, 0.72);
}
.debt-tile.has-color .debt-tile-excluded {
  color: rgba(4, 4, 19, 0.55);
}
.debt-tile.has-color .debt-tile-delta {
  color: var(--ink);
}
.debt-tile.has-color .debt-tile-delta.is-up {
  color: #c45c26;
}
.debt-tile.has-color .debt-tile-delta.is-down {
  color: #0a9f3c;
}
.debt-tile.has-color .debt-drag,
.debt-tile.has-color .debt-delete {
  color: var(--ink);
  background: rgba(4, 4, 19, 0.1);
}
.debt-tile.has-color .debt-exclude-check {
  color: rgba(4, 4, 19, 0.78);
}
.debt-tile.has-color .btn-ghost {
  background: rgba(4, 4, 19, 0.1);
  color: var(--ink);
}
.debt-tile.has-color .btn-ghost:hover {
  background: rgba(4, 4, 19, 0.16);
}
.debt-tile.has-color.is-editing {
  border-color: rgba(4, 4, 19, 0.16);
}
.debt-tile-view {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  justify-content: center;
}
.debt-tile-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #fff;
  line-height: 1.25;
  word-break: break-word;
}
.debt-tile-amount {
  font-size: 15px;
  font-weight: 400;
  color: rgba(255, 255, 255, 1);
  font-variant-numeric: tabular-nums;
}
.debt-tile-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  color: #fff;
}
.debt-tile-delta-icon {
  flex: 0 0 auto;
}
.debt-tile-delta.is-up {
  color: #ffb4a8;
}
.debt-tile-delta.is-down {
  color: #9be7b0;
}
.debt-tile-excluded {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.62);
  line-height: 1.2;
}
.debt-tile-excluded-icon {
  flex: 0 0 auto;
}
.debt-exclude-check {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  gap: 8px;
  align-items: flex-start;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.88);
}
.debt-exclude-check input {
  margin-top: 1px;
  flex: 0 0 auto;
}
.debt-drag {
  position: absolute;
  top: 6px;
  right: 36px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: #fff;
  cursor: grab;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease;
  background: rgba(255, 255, 255, 0.12);
}
.debt-tile:hover .debt-drag,
.debt-tile.debt-tile-chosen .debt-drag,
.debts-sortable.is-dragging .debt-drag {
  opacity: 1;
}
.debt-drag:active {
  cursor: grabbing;
}
.debt-tile.debt-tile-ghost {
  opacity: 0.4;
}
.debt-tile.debt-tile-chosen {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}
.debt-tile.debt-tile-drag-active {
  opacity: 0.95;
}
.debt-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}
.debt-tile:hover .debt-delete {
  opacity: 1;
}
.debt-tile-edit {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.debt-tile-edit .table-input {
  width: 100%;
}
.debt-color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.debt-color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: #2c2c2c;
  padding: 0;
  cursor: pointer;
  position: relative;
}
.debt-color-swatch.active {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.debt-color-swatch:first-child::after {
  content: "";
  position: absolute;
  inset: 11px 4px;
  height: 2px;
  background: rgba(255, 255, 255, 0.55);
  transform: rotate(-45deg);
}
.debt-tile-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.debt-tile .btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.debt-tile .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.2);
}
.debt-tile-add {
  display: grid;
  place-items: center;
  min-height: 118px;
  /* background: #212121; */
  background-color: rgba(4, 4, 19, 0.2);

  border: 1px dashed rgba(255, 255, 255, 0.35);
  box-shadow: none;
  color: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.debt-tile-add:hover:not(:disabled) {
  background: #2a2a2a;
  /* border-color: rgba(255, 255, 255, 0.55); */
  background-color: rgba(4, 4, 19, 0.55);

  color: #fff;
  box-shadow: none;
}
.debt-tile-add:disabled {
  opacity: 0.5;
  cursor: default;
}
.debt-tile-add-plus {
  font-size: 42px;
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.04em;
  color: #fff;
}

/* Mobile topbar / drawer — hidden on desktop */
.mobile-topbar,
.nav-backdrop {
  display: none;
}

@media (max-width: 1200px) {
  .expense-plan-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
  .layout { gap: 20px; }
  .content { padding-right: 16px; }
  .stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .archive-cards { grid-template-columns: 1fr; }
  .debts-total-row,
  .debts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: none;
  }
}

@media (max-width: 900px) {
  body {
    overflow-x: hidden;
  }
  .shell.nav-open {
    overflow: hidden;
  }
  .shell.nav-open body,
  body:has(.shell.nav-open) {
    overflow: hidden;
  }

  .mobile-topbar {
    display: grid;
    grid-template-columns: 40px 1fr 40px;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 35;
    height: 56px;
    padding: 0 12px;
    background: rgba(242, 243, 245, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
  }
  .mobile-topbar-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-align: center;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-topbar-spacer { width: 40px; height: 40px; }
  .mobile-menu-btn { color: var(--ink); }

  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(15, 15, 16, 0.4);
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 0;
    min-height: calc(100vh - 56px);
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 45;
    width: min(300px, 86vw);
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding: 16px 12px 24px;
    background: var(--surface);
    box-shadow: 8px 0 32px rgba(15, 25, 55, 0.18);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .shell.nav-open .sidebar {
    transform: translateX(0);
  }
  .side-nav {
    flex-direction: column;
    flex-wrap: nowrap;
  }
  .side-link {
    font-size: 14px;
    padding: 12px 14px;
  }

  .content {
    padding: 12px 12px 40px;
  }

  .page-title-row {
    display: none; /* title is in mobile topbar */
  }

  .expense-plan-page .page-title-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 12px;
  }
  .expense-plan-page .page-title-row h1 {
    display: none;
  }
  .expense-plan-toolbar {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }
  .expense-plan-toolbar .filter-select,
  .expense-plan-toolbar .ui-select {
    width: 100%;
    max-width: none;
  }
  .expense-plan-page .stats-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .expense-plan-page .stat {
    padding: 12px 14px;
  }
  .expense-plan-page .stat-value {
    font-size: 18px;
  }
  .expense-plan-head {
    padding: 12px 12px 8px;
  }
  .expense-plan-table th,
  .expense-plan-table td {
    padding: 8px 6px;
    font-size: 13px;
  }
  .expense-plan-table th:nth-child(3),
  .expense-plan-table td:nth-child(3) {
    width: 92px;
  }
  .expense-plan-table th:nth-child(4),
  .expense-plan-table td:nth-child(4) {
    width: 76px;
  }
  .expense-plan-table .status-badge {
    height: 26px;
    padding: 0 8px;
    font-size: 11px;
  }
  .expense-plan-add {
    grid-template-columns: minmax(0, 1fr) 80px auto;
    padding: 10px;
    gap: 6px;
  }
  .expense-plan-add .btn {
    padding-left: 10px;
    padding-right: 10px;
    font-size: 12px;
  }

  .toolbar {
    width: 100%;
  }
  .toolbar > * {
    flex: 1 1 auto;
  }
  .chips {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .chip { flex: 0 0 auto; }
  .search-pill { min-width: 0; width: 100%; }
  .filter-select,
  .ui-select { min-width: 0; width: 100%; max-width: none; }
  .ui-select-year { width: 100%; max-width: none; }

  .stats-row:not(.debts-total-row),
  .dashboard-tops,
  .form-grid {
    grid-template-columns: 1fr;
  }
  .stat-value { font-size: 22px; }
  .dashboard-chart-wrap { height: 260px; }
  .dashboard-chart-card { padding: 16px 14px 8px; }
  .dashboard-section-head { padding: 14px 14px 0; }
  .dashboard-section-head-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .data-table { min-width: 720px; }
  .data-table.hosting-table { min-width: 860px; }
  .data-table th,
  .data-table td {
    padding: 10px 12px;
    font-size: 13px;
  }
  .cell-sub { max-width: 160px; }

  .archive-controls-page {
    flex-direction: column;
    align-items: stretch;
  }
  .archive-year-select,
  .archive-controls-page .btn {
    width: 100%;
  }

  .modal-backdrop {
    padding: 0;
    align-items: stretch;
  }
  .modal,
  .modal.modal-lg,
  .modal.modal-sm {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
  .modal-head { padding: 14px 16px 10px; }
  .modal-body { padding: 12px 16px 0; }
  .modal-foot {
    padding: 12px 16px 16px;
    margin-left: -16px;
    margin-right: -16px;
  }
  .modal-foot .btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    text-align: center;
  }

  .payments-table {
    min-width: 480px;
  }
  .payments-head {
    flex-wrap: wrap;
  }
}

@media (max-width: 650px) {
  .debts-total-row,
  .debts-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .stat { padding: 14px 16px; }
  .dashboard-chart-wrap { height: 220px; }
  .side-link .badge-soon { font-size: 9px; }

  .expense-plan-page .stats-row {
    grid-template-columns: 1fr;
  }
  .expense-plan-table thead th:nth-child(3) {
    font-size: 0;
  }
  .expense-plan-table thead th:nth-child(3)::after {
    content: 'Ст.';
    font-size: 12px;
  }
  .expense-plan-table th:nth-child(3),
  .expense-plan-table td:nth-child(3) {
    width: 72px;
  }
  .expense-plan-table th:nth-child(4),
  .expense-plan-table td:nth-child(4) {
    width: 68px;
  }
  .expense-plan-table .status-badge {
    padding: 0 4px;
    min-width: 28px;
  }
  .expense-plan-table .col-drag {
    width: 28px;
  }
  .expense-plan-drag {
    width: 24px;
    height: 24px;
  }
  .expense-plan-add {
    grid-template-columns: minmax(0, 1fr) 72px;
  }
  .expense-plan-add .btn {
    grid-column: 1 / -1;
    width: 100%;
  }
}
