:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #fafafa;
  --ink: #111111;
  --muted: #6b7280;
  --line: #dedede;
  --line-strong: #c9c9c9;
  --direct-yellow: #ffd21e;
  --direct-yellow-soft: #fff6c7;
  --direct-black: #0e0e0e;
  --blue: #2563eb;
  --danger: #e23d28;
  --danger-soft: #fff1ee;
  --ok: #16833a;
  --ok-soft: #eef9f1;
  --shadow: 0 12px 30px rgba(17, 17, 17, .07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, #fff8d9 0, #f4f5f7 210px),
    var(--bg);
}

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

.access-denied[hidden] {
  display: none;
}

.access-denied > div {
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.access-denied strong {
  display: block;
  margin-bottom: 8px;
  font-size: 24px;
}

.access-denied p {
  margin: 0;
  color: var(--muted);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, .86);
  border: 1px solid rgba(222, 222, 222, .82);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.topbar > div {
  position: relative;
  padding-left: 54px;
}

.topbar > div::before {
  content: "Д";
  position: absolute;
  left: 0;
  top: 50%;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  transform: translateY(-50%);
  border-radius: 8px;
  color: var(--direct-black);
  background: var(--direct-yellow);
  font-weight: 800;
  font-size: 23px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

h1, h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1;
}

h2 { font-size: 18px; }

.icon-button,
.compact-button,
.primary-button,
.tab,
.dialog-actions button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  min-height: 40px;
}

.icon-button {
  width: 44px;
  display: grid;
  place-items: center;
}

.icon-button:hover,
.compact-button:hover,
.tab:hover,
.dialog-actions button:hover {
  border-color: var(--line-strong);
  background: var(--surface-alt);
}

.icon-button svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.compact-button,
.primary-button {
  padding: 0 14px;
  font-weight: 600;
}

.primary-button {
  background: var(--direct-yellow);
  border-color: var(--direct-yellow);
  color: var(--direct-black);
}

.primary-button:hover {
  background: #ffe15f;
  border-color: #ffe15f;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.metric-panel,
.content-panel,
.sidebar,
.stats-grid article,
.account-card,
.rule-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric-panel {
  position: relative;
  overflow: hidden;
  padding: 16px;
}

.metric-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--direct-yellow);
}

.metric-panel span,
.stats-grid span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.metric-panel strong {
  display: block;
  margin: 10px 0 4px;
  font-size: 30px;
  line-height: 1.05;
}

.metric-panel small { color: var(--muted); }

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.sidebar,
.content-panel {
  padding: 12px;
}

.sidebar {
  position: sticky;
  top: 10px;
}

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

.accounts-list,
.cards-grid,
.rules-list {
  display: grid;
  gap: 8px;
}

.account-card {
  width: 100%;
  padding: 12px;
  text-align: left;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}

.account-error {
  grid-column: 1 / -1;
  margin: 2px 0 0;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.35;
}

.account-card:hover {
  border-color: var(--line-strong);
  background: var(--surface-alt);
}

.account-card.is-active {
  border-color: var(--direct-black);
  box-shadow: inset 4px 0 0 var(--direct-yellow);
}

.account-card strong,
.balance-card strong {
  display: block;
  margin-bottom: 4px;
}

.account-main {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

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

.account-meta {
  display: grid;
  justify-items: end;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.account-delete {
  width: 30px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--danger);
  background: #fff;
  font-size: 18px;
  line-height: 1;
}

.account-delete:hover {
  border-color: rgba(226, 61, 40, .45);
  background: var(--danger-soft);
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  margin-bottom: 14px;
  background: #f0f1f3;
  border-radius: 8px;
}

.tab {
  flex: 1;
  padding: 0 10px;
  border-color: transparent;
  background: transparent;
  font-weight: 600;
}

.tab.is-active {
  color: var(--direct-black);
  background: var(--surface);
  border-color: var(--surface);
  box-shadow: 0 1px 4px rgba(17, 17, 17, .08);
}

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

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

.balance-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.balance-card.is-low {
  border-color: rgba(226, 61, 40, .45);
  background: var(--danger-soft);
}

.balance-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid #eeeeee;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 8px;
  background: var(--ok-soft);
  color: var(--ok);
  font-size: 13px;
  font-weight: 700;
}

.pill.danger {
  color: var(--danger);
  background: #ffe1dc;
}

.filters {
  display: grid;
  grid-template-columns: minmax(170px, 1.4fr) repeat(2, minmax(130px, 1fr)) auto;
  gap: 8px;
  align-items: end;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
}

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

input, select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid rgba(255, 210, 30, .72);
  outline-offset: 2px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stats-grid article {
  padding: 12px;
  background: var(--surface-alt);
}

.stats-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th, td {
  padding: 11px 12px;
  border-bottom: 1px solid #ededed;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: #f7f7f8;
  font-size: 13px;
  font-weight: 700;
}

tbody tr:hover { background: #fff9db; }
tr:last-child td { border-bottom: 0; }

.rule-card {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.rule-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.rule-actions button {
  width: 40px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.rule-actions button:hover {
  background: var(--direct-yellow-soft);
  border-color: #f0cc38;
}

dialog {
  width: min(430px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(17, 17, 17, .42); }

dialog form {
  padding: 18px;
  display: grid;
  gap: 12px;
}

.checkbox {
  grid-template-columns: 20px 1fr;
  align-items: center;
}

.checkbox input { min-height: auto; }

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

.dialog-actions button { padding: 0 14px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(120%);
  max-width: min(460px, calc(100% - 24px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--direct-black);
  box-shadow: var(--shadow);
  transition: transform .22s ease;
  z-index: 10;
}

#toast.is-visible {
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  .summary-grid,
  .workspace,
  .cards-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

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

  .filters .primary-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 10px;
  }

  .summary-grid,
  .stats-grid,
  .filters {
    grid-template-columns: 1fr;
  }

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

  .topbar {
    align-items: flex-start;
  }

  .topbar > div {
    padding-left: 48px;
  }

  .topbar > div::before {
    width: 38px;
    height: 38px;
  }

  .metric-panel strong {
    font-size: 26px;
  }

  .rule-card {
    grid-template-columns: 1fr;
  }
}
