:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #18202f;
  --muted: #667085;
  --line: #d9e0ea;
  --brand: #146c5c;
  --brand-strong: #0f4f45;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #027a48;
  --shadow: 0 10px 30px rgba(18, 32, 47, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

a {
  color: var(--brand);
  text-decoration: none;
  overflow-wrap: anywhere;
}

a:hover {
  color: var(--brand-strong);
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
  width: 100%;
  min-width: 0;
}

.sidebar {
  background: #102820;
  color: #eef8f4;
  padding: 20px 16px;
}

.brand {
  display: block;
  color: #ffffff;
  font-weight: 800;
  font-size: 20px;
  margin-bottom: 22px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a,
.logout-button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  color: #d7eee7;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.nav a:hover,
.nav a.active,
.logout-button:hover {
  background: rgba(255, 255, 255, 0.11);
  color: #ffffff;
}

.sidebar-footer {
  margin-top: 28px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  padding-top: 16px;
}

.main {
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
}

.muted {
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.grid > * {
  min-width: 0;
}

.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.two-col {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}

.metric,
.panel,
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 16px;
  min-width: 0;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.panel {
  padding: 18px;
  min-width: 0;
  max-width: 100%;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  min-width: 0;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.filter-actions {
  align-self: end;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row-actions {
  justify-content: flex-end;
}

.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: center;
}

.button.primary,
button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}

.button.danger,
button.danger {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.filters,
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

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

.span-4 {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow: auto;
  max-width: 100%;
  min-width: 0;
}

table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
}

tr:target {
  outline: 2px solid rgba(20, 108, 92, 0.35);
  outline-offset: -2px;
  background: #f0fdfa;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  max-width: 100%;
}

td strong,
td div,
td span {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef2f6;
  color: #344054;
  font-size: 12px;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.positive {
  color: var(--ok);
}

.negative {
  color: var(--danger);
}

.flash {
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  background: #fff7ed;
  color: #7c2d12;
}

.flash.success {
  background: #ecfdf3;
  color: #05603a;
}

.error-box {
  border-radius: 6px;
  padding: 10px 12px;
  margin: 12px 0;
  background: #fef3f2;
  color: var(--danger);
}

.bars {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 180px) 1fr auto;
  gap: 10px;
  align-items: center;
}

.bar-track {
  height: 10px;
  background: #edf1f7;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  background: var(--brand);
}

.audit {
  display: grid;
  gap: 8px;
}

.audit-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.sidebar-top {
  display: block;
}

.mobile-user {
  display: none;
}

.dashboard-charts {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  align-items: stretch;
}

.dashboard-charts .chart-panel-wide {
  grid-row: span 2;
}

.analytics-charts {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chart-panel {
  min-width: 0;
}

.chart-panel h2 {
  margin-bottom: 6px;
}

.money-chart {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 280px;
}

.analytics-charts .money-chart {
  height: 320px;
}

.summary-table td:last-child {
  text-align: right;
  font-weight: 700;
}

.panel .table-wrap {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px 14px;
  }

  .sidebar-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 10px;
  }

  .brand {
    margin-bottom: 0;
    white-space: nowrap;
  }

  .mobile-user {
    display: grid;
    gap: 1px;
    min-width: 0;
    text-align: right;
    font-size: 12px;
  }

  .mobile-user strong,
  .mobile-user span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-user span {
    color: #aacfc3;
  }

  .nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    overflow-x: hidden;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .nav a,
  .logout-button {
    flex: 0 1 auto;
    white-space: nowrap;
  }

  .sidebar-footer {
    display: none;
  }

  .main {
    padding: 16px;
  }

  .metrics,
  .two-col,
  .dashboard-charts,
  .analytics-charts,
  .filters,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-charts .chart-panel-wide {
    grid-row: auto;
  }

  .span-2,
  .span-4 {
    grid-column: auto;
  }

  .topbar,
  .toolbar {
    display: grid;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .actions {
    width: 100%;
  }

  .actions .button,
  .actions button {
    flex: 1 1 auto;
    text-align: center;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 14px;
  }

  .main {
    padding: 12px;
  }

  .metrics {
    gap: 10px;
  }

  .metric,
  .panel {
    padding: 14px;
  }

  .metric strong {
    font-size: 19px;
  }

  .money-chart,
  .analytics-charts .money-chart {
    height: 260px;
  }

  .responsive-cards {
    overflow: hidden;
    max-width: 100%;
  }

  .responsive-cards table,
  .responsive-cards thead,
  .responsive-cards tbody,
  .responsive-cards th,
  .responsive-cards td,
  .responsive-cards tr {
    display: block;
    max-width: 100%;
  }

  .responsive-cards thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .responsive-cards tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    width: 100%;
    max-width: 100%;
    padding: 0;
    margin-bottom: 10px;
    overflow: hidden;
  }

  .responsive-cards td {
    display: grid;
    grid-template-columns: minmax(86px, 28%) minmax(0, 1fr);
    align-items: start;
    gap: 12px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border-bottom: 1px solid #edf1f7;
    padding: 8px 10px;
    text-align: left;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
  }

  .responsive-cards td:last-child {
    border-bottom: 0;
  }

  .responsive-cards td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
    font-size: 13px;
    text-align: left;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .responsive-cards td > * {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .responsive-cards td[colspan] {
    display: block;
    text-align: left;
  }

  .responsive-cards td[colspan]::before {
    content: '';
  }

  .transaction-cards tr {
    box-shadow: 0 5px 18px rgba(18, 32, 47, 0.05);
  }

  .transaction-cards td:first-child {
    align-items: center;
    background: #f8fafc;
    padding-top: 9px;
    padding-bottom: 9px;
  }

  .transaction-cards td[data-label="Тип"] .tag,
  .transaction-cards td[data-label="Категория"] .tag {
    justify-self: start;
    width: auto;
    max-width: 100%;
  }

  .transaction-cards td[data-label="Описание"] strong {
    display: block;
    margin-bottom: 2px;
  }

  .transaction-cards td[data-label="Описание"] .muted,
  .transaction-cards td[data-label="Деньги"] .muted {
    font-size: 13px;
    line-height: 1.35;
  }

  .compact-cards tr {
    padding: 6px;
  }

  .compact-cards td {
    padding: 5px 4px;
  }

  .responsive-cards .actions,
  .responsive-cards .row-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .responsive-cards .actions .button,
  .responsive-cards .actions button,
  .responsive-cards .actions form {
    width: 100%;
  }

  .responsive-cards .row-actions form {
    grid-column: 1 / -1;
  }

  .responsive-cards td[data-label="Действия"] {
    display: block;
    padding-top: 10px;
    background: #fbfcfe;
  }

  .responsive-cards td[data-label="Действия"]::before {
    content: none;
  }

  .responsive-cards td[data-label="Действия"] .button,
  .responsive-cards td[data-label="Действия"] button {
    min-height: 40px;
  }
}

@media (max-width: 520px) {
  .sidebar {
    padding: 10px;
  }

  .brand {
    font-size: 18px;
  }

  .nav a {
    padding: 8px 10px;
  }

  .button,
  button,
  input,
  select,
  textarea {
    min-height: 40px;
  }

  .toolbar .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .filter-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .filter-actions .button,
  .filter-actions button {
    width: 100%;
  }

  .summary-table td {
    display: block;
    width: 100%;
    text-align: left;
  }

  .summary-table td:last-child {
    text-align: left;
    padding-top: 0;
  }

  .money-chart,
  .analytics-charts .money-chart {
    height: 240px;
  }
}

@media (max-width: 380px) {
  .main {
    padding: 8px;
  }

  .metric,
  .panel {
    padding: 12px;
  }

  .responsive-cards td {
    grid-template-columns: minmax(68px, 30%) minmax(0, 1fr);
    gap: 8px;
  }
}
