:root {
  --color-primary: #2f6bff;
  --color-accent: #5b7cff;
  --color-bg: #0b1220;
  --color-card: #111827;
  --color-text: #f9fafb;
  --color-muted: #98a2b3;
  --color-success: #31d879;
  --ink: var(--color-text);
  --muted: var(--color-muted);
  --paper: var(--color-bg);
  --panel: #111827;
  --line: rgba(234, 236, 240, 0.13);
  --accent: var(--color-accent);
  --accent-ink: #ffffff;
  --green: #47d18c;
  --red: #ff8a8a;
  --blue: var(--color-primary);
  --warning: #f7c56b;
  --surface-soft: #111827;
  --surface-strong: #172033;
  --surface-input: #0f172a;
  --surface-hover: rgba(91, 124, 255, 0.12);
  --dropdown-bg: #111827;
  --row-bg: #0f172a;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.2);
  --body-bg: #0b1220;
  --primary-action: #2f6bff;
  --primary-action-hover: #2555d6;
  --primary-action-text: #ffffff;
  --radius-card: 18px;
  --radius-row: 12px;
  --app-safe-top: 0px;
  --top-chrome-gap: 10px;
  color-scheme: dark;
}

html[data-theme="light"] {
  --color-bg: #f7f8fa;
  --color-card: #ffffff;
  --color-text: #101828;
  --color-muted: #667085;
  --ink: var(--color-text);
  --muted: var(--color-muted);
  --paper: var(--color-bg);
  --panel: #ffffff;
  --line: #e4e7ec;
  --accent-ink: #ffffff;
  --green: #027a48;
  --red: #b42318;
  --warning: #b54708;
  --surface-soft: #ffffff;
  --surface-strong: #ffffff;
  --surface-input: #fcfcfd;
  --surface-hover: #eef3ff;
  --dropdown-bg: #ffffff;
  --row-bg: #fcfcfd;
  --shadow: 0 4px 18px rgba(16, 24, 40, 0.06);
  --body-bg: #f7f8fa;
  --primary-action: #111827;
  --primary-action-hover: #1f2937;
  --primary-action-text: #ffffff;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  background: var(--body-bg);
  transition: background 0.24s ease, color 0.24s ease;
}

button {
  font: inherit;
}

.shell {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: calc(18px + var(--top-chrome-gap) + env(safe-area-inset-top, 0px)) 14px 28px;
  padding: calc(
      18px + var(--top-chrome-gap) + max(
        env(safe-area-inset-top, 0px),
        var(--tg-safe-area-inset-top, 0px),
        var(--tg-content-safe-area-inset-top, 0px),
        var(--app-safe-top, 0px)
      )
    )
    14px 28px;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 9px;
  padding: 16px 4px 12px;
}

.hero-actions {
  align-self: flex-end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-screen {
  min-height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: minmax(0, 420px);
  align-content: center;
  justify-content: center;
  justify-items: center;
  gap: 14px;
  padding: 26px;
  text-align: center;
}

.auth-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  border: 1px solid rgba(255, 111, 134, 0.24);
  border-radius: 18px;
  background: rgba(255, 111, 134, 0.12);
  color: var(--red);
  font-size: 34px;
  font-weight: 900;
}

.auth-screen h1 {
  width: 100%;
  max-width: 360px;
  font-size: 28px;
  text-align: center;
}

.auth-screen p {
  width: 100%;
  max-width: 420px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.subtitle {
  max-width: 680px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.35;
  text-align: center;
}

.role-pill {
  flex: 0 0 auto;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-input);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.theme-toggle {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-input);
  color: var(--ink);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.theme-toggle:hover {
  border-color: rgba(47, 107, 255, 0.32);
  background: var(--surface-hover);
  transform: translateY(-1px);
}

.theme-icon {
  width: 20px;
  height: 20px;
  fill: none;
  grid-area: 1 / 1;
  opacity: 1;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  transform: scale(1) rotate(0deg);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.theme-icon-moon {
  opacity: 0;
  transform: scale(0.72) rotate(-18deg);
}

html[data-theme="light"] .theme-icon-sun {
  opacity: 0;
  transform: scale(0.72) rotate(18deg);
}

html[data-theme="light"] .theme-icon-moon {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.actions {
  display: grid;
  gap: 8px;
  margin: 8px 0;
}

.actions {
  grid-template-columns: 1fr auto;
  margin-bottom: 14px;
}

.period-tools {
  margin: 8px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface-soft);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.period-tools summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 900;
  list-style: none;
}

.period-tools summary::-webkit-details-marker {
  display: none;
}

.period-tools summary::after {
  content: "↓";
  color: var(--muted);
  font-weight: 900;
}

.period-tools[open] summary::after {
  content: "↑";
}

.range-panel {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.range-group {
  display: grid;
  gap: 8px;
  align-items: end;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-row);
  background: var(--row-bg);
}

.shift-range {
  grid-template-columns: 1fr;
}

.custom-range {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.all-period-btn {
  grid-column: 1 / -1;
  justify-self: start;
  min-width: 156px;
  border-color: var(--line);
  background: var(--surface-input);
}

.all-period-btn:hover {
  background: var(--surface-hover);
}

.range-group label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.range-group input {
  min-height: 42px;
  min-width: 0;
  max-width: 100%;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-row);
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface-input);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 0 10px;
}

.filter-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  margin: 8px 0 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface-soft);
  box-shadow: var(--shadow);
}

.filter-control {
  position: relative;
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.dropdown-button {
  min-height: 42px;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-row);
  background: var(--surface-input);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  overflow: hidden;
  padding: 0 36px 0 10px;
  position: relative;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-button::after {
  position: absolute;
  right: 12px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-bottom: 2px solid var(--muted);
  border-right: 2px solid var(--muted);
  content: "";
  transform: translateY(-65%) rotate(45deg);
  transition: transform 0.18s ease;
}

.dropdown-button[aria-expanded="true"] {
  border-color: rgba(47, 107, 255, 0.36);
  background: var(--surface-strong);
}

.dropdown-button[aria-expanded="true"]::after {
  transform: translateY(-30%) rotate(225deg);
}

.dropdown-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: grid;
  max-height: 236px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-row);
  background: var(--dropdown-bg);
  box-shadow: var(--shadow);
}

.dropdown-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 0 9px;
  text-align: left;
}

.dropdown-option span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-option:hover,
.dropdown-option[aria-selected="true"] {
  background: var(--surface-hover);
}

.dropdown-check {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(49, 216, 121, 0.14);
  color: var(--green);
}

.dropdown-check::before {
  width: 8px;
  height: 4px;
  border-bottom: 2px solid currentColor;
  border-left: 2px solid currentColor;
  content: "";
  transform: translateY(-1px) rotate(-45deg);
}

.reset-filters-btn {
  min-width: 104px;
}

.export-btn,
.ghost-btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-row);
  background: var(--surface-input);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.export-btn {
  border: 0;
  background: var(--primary-action);
  background-clip: border-box;
  color: var(--primary-action-text);
  box-shadow: var(--shadow);
}

.export-btn:not(:disabled):hover {
  background: var(--primary-action-hover);
  box-shadow: 0 8px 22px rgba(16, 24, 40, 0.12);
}

.export-btn:disabled,
.ghost-btn:disabled,
.copy-btn:disabled {
  cursor: wait;
  opacity: 0.72;
}

.ghost-btn {
  min-width: 118px;
}

.action-note {
  grid-column: 1 / -1;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
}

.action-note[data-mode="error"] {
  color: var(--red);
}

.role-pill,
.period-tools,
.range-group,
.range-group input,
.filter-tools,
.dropdown-button,
.dropdown-menu,
.dropdown-option,
.export-btn,
.ghost-btn,
.metric,
.panel,
.empty,
.status-row,
.list-row,
.payment-row,
.payment-card,
.show-more-btn,
.payment-toggle,
.payment-details,
.detail-row strong,
.copy-btn,
.badge {
  transition:
    background 0.22s ease,
    background-color 0.22s ease,
    border-color 0.22s ease,
    box-shadow 0.22s ease,
    color 0.22s ease;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

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

.metric {
  min-height: 112px;
  padding: 14px;
}

.metric .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.metric .value {
  margin-top: 14px;
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
}

.metric .hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.panel,
.empty {
  margin-top: 10px;
  padding: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.list,
.payments {
  display: grid;
  gap: 8px;
}

.status-bars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  justify-content: start;
  gap: 8px;
}

.status-bars[data-status-count="0"],
.status-bars[data-status-count="1"] {
  grid-template-columns: minmax(168px, 190px);
}

.status-bars[data-status-count="2"] {
  grid-template-columns: repeat(2, minmax(168px, 190px));
}

.status-bars[data-status-count="3"] {
  grid-template-columns: repeat(3, minmax(168px, 190px));
}

.status-bars[data-status-count="4"] {
  grid-template-columns: repeat(4, minmax(168px, 190px));
}

.payments {
  align-items: start;
}

@media (min-width: 900px) {
  .payments {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.status-row,
.list-row,
.payment-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-row);
  background: var(--row-bg);
}

.status-row {
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 7px;
  min-height: 72px;
  padding: 9px 10px;
}

.status-row .amount {
  overflow: hidden;
  font-size: 15px;
  line-height: 1.1;
  text-overflow: ellipsis;
}

.payment-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-row);
  background: var(--row-bg);
  overflow: hidden;
}

.payment-card .payment-row {
  width: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.show-more-btn {
  width: 100%;
  min-height: 42px;
  margin-top: 10px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-row);
  background: var(--surface-input);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 900;
}

.show-more-btn:hover {
  background: var(--surface-hover);
}

.payment-toggle {
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.payment-toggle[aria-expanded="true"] {
  background: var(--surface-hover);
}

.status-meta,
.row-meta,
.payment-meta {
  min-width: 0;
}

.status-title,
.row-title,
.payment-title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-title.paid {
  color: var(--green);
}

.status-title.active {
  color: var(--warning);
}

.status-title.bad,
.status-title.stopped {
  color: var(--red);
}

.status-title.neutral {
  color: var(--muted);
}

.status-sub,
.row-sub,
.payment-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.amount {
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
}

.payment-side {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.payment-details {
  display: grid;
  gap: 7px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.detail-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.detail-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 13px;
}

.copy-btn {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-input);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  padding: 0 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-width: 76px;
  justify-content: center;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.badge.paid {
  border-color: rgba(49, 216, 121, 0.24);
  background: rgba(49, 216, 121, 0.16);
  color: var(--green);
}

.badge.active {
  border-color: rgba(255, 209, 102, 0.22);
  background: rgba(255, 209, 102, 0.16);
  color: var(--warning);
}

.badge.bad {
  border-color: rgba(255, 111, 134, 0.24);
  background: rgba(255, 111, 134, 0.16);
  color: var(--red);
}

.badge.stopped {
  border-color: rgba(255, 111, 134, 0.2);
  background: rgba(255, 111, 134, 0.12);
  color: var(--red);
}

.badge.neutral {
  background: var(--surface-input);
  color: var(--muted);
}

.skeleton {
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(110deg, transparent 10%, rgba(24, 215, 255, 0.16), transparent 70%);
  animation: shimmer 1.2s infinite;
}

.hidden {
  display: none;
}

.empty {
  color: var(--red);
  font-weight: 800;
}

@keyframes shimmer {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .role-pill,
  .period-tools,
  .range-group,
  .range-group input,
  .filter-tools,
  .dropdown-button,
  .dropdown-menu,
  .dropdown-option,
  .export-btn,
  .ghost-btn,
  .metric,
  .panel,
  .empty,
  .status-row,
  .list-row,
  .payment-row,
  .payment-card,
  .show-more-btn,
  .payment-toggle,
  .payment-details,
  .detail-row strong,
  .copy-btn,
  .badge,
  .theme-toggle,
  .theme-icon {
    transition: none;
  }

  .skeleton::after {
    animation: none;
  }
}

@media (max-width: 760px) {
  .shell {
    padding: calc(14px + var(--top-chrome-gap) + env(safe-area-inset-top, 0px)) 10px 24px;
    padding: calc(
        14px + var(--top-chrome-gap) + max(
          env(safe-area-inset-top, 0px),
          var(--tg-safe-area-inset-top, 0px),
          var(--tg-content-safe-area-inset-top, 0px),
          var(--app-safe-top, 0px)
        )
      )
      10px 24px;
  }

  .hero {
    gap: 10px;
  }

  .hero-actions {
    align-self: stretch;
    width: 100%;
    justify-content: space-between;
  }

  h1 {
    font-size: 30px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .status-bars,
  .status-bars[data-status-count] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .range-panel {
    grid-template-columns: 1fr;
  }

  .shift-range,
  .custom-range {
    grid-template-columns: 1fr;
    padding: 9px;
  }

  .range-group .ghost-btn {
    grid-column: 1 / -1;
    width: 100%;
  }

  .all-period-btn {
    width: 100%;
  }

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

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

  .reset-filters-btn {
    width: 100%;
  }

  .metric {
    min-height: 96px;
  }

  .detail-row {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .copy-btn {
    grid-column: 2;
    justify-self: start;
  }
}
