:root {
  --bg: #f6efe2;
  --panel: rgba(255, 250, 241, 0.88);
  --line: rgba(74, 48, 28, 0.12);
  --text: #2b1d14;
  --muted: #7a6757;
  --accent: #d86a2d;
  --accent-dark: #8d3510;
  --accent-soft: #f3c9ab;
  --success: #16795d;
  --danger: #c33e35;
  --shadow: 0 18px 45px rgba(84, 52, 24, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(216, 106, 45, 0.16), transparent 28%),
    radial-gradient(circle at right, rgba(48, 115, 96, 0.14), transparent 24%),
    linear-gradient(180deg, #fbf6ee 0%, var(--bg) 100%);
}

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

.login-panel {
  width: min(560px, 100%);
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 300px;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 248, 239, 0.98), rgba(247, 237, 224, 0.94)),
    rgba(255, 251, 246, 0.8);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.page-shell {
  flex: 1;
  width: min(1260px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.brand {
  padding: 8px 8px 14px;
}

.small {
  font-size: 14px;
}

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

.nav-link {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--text);
  border: 1px solid transparent;
  font-weight: 700;
}

.nav-link.active {
  background: linear-gradient(135deg, #d86a2d, #b94f17);
  color: #fffaf3;
  box-shadow: var(--shadow);
}

.sidebar-actions {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.hero,
.panel,
.card {
  backdrop-filter: blur(14px);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero {
  border-radius: 28px;
  padding: 28px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-end;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 12px;
  color: var(--accent-dark);
}

h1,
h2 {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

.lead {
  max-width: 720px;
  color: var(--muted);
}

.hero-actions,
.cards,
.grid,
.panel-header,
.inspect-grid,
.inline {
  display: flex;
  gap: 14px;
}

.filters {
  margin-top: 16px;
  flex-wrap: wrap;
}

.hero-actions {
  flex-wrap: wrap;
}

.cards {
  margin: 22px 0;
  flex-wrap: wrap;
}

.cards-tight {
  margin: 16px 0 18px;
}

.card {
  flex: 1 1 200px;
  border-radius: 22px;
  padding: 18px;
}

.card .label {
  color: var(--muted);
  font-size: 13px;
}

.card .value {
  margin-top: 10px;
  font-size: 30px;
  font-weight: 700;
}

.grid {
  margin-top: 22px;
  flex-wrap: wrap;
}

.panel {
  flex: 1 1 390px;
  min-width: 0;
  border-radius: 24px;
  padding: 22px;
}

.panel-soft {
  margin-top: 18px;
  background: rgba(255, 252, 247, 0.72);
}

.content-section {
  display: none;
  gap: 22px;
}

.content-section.is-active {
  display: grid;
}

.panel-header {
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.button,
button {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff9f3;
  padding: 12px 18px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 700;
}

.button.secondary {
  background: #fff1e7;
  color: var(--accent-dark);
}

.button.secondary.is-selected {
  background: linear-gradient(135deg, #d86a2d, #b94f17);
  color: #fffaf3;
  box-shadow: var(--shadow);
}

.table-action {
  padding: 8px 12px;
  font-size: 13px;
}

.history-link {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.danger-action {
  background: rgba(195, 62, 53, 0.12);
  color: var(--danger);
}

.stack {
  display: grid;
  gap: 12px;
}

input,
select {
  width: 100%;
  border: 1px solid rgba(89, 57, 29, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  padding: 12px 14px;
}

.period-block {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(89, 57, 29, 0.12);
  border-radius: 18px;
  background: rgba(255, 252, 248, 0.72);
}

.period-block-compact {
  width: min(560px, 100%);
}

.period-badge {
  display: inline-flex;
  width: fit-content;
  padding: 8px 12px;
  border-radius: 999px;
  background: #fff1e7;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

.period-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.date-field {
  display: grid;
  gap: 8px;
  font-weight: 600;
}

.date-field span {
  color: var(--muted);
}

.inspect-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.preview-col-toggle {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  min-height: 88px;
  gap: 8px;
}

.preview-col-toggle span {
  display: block;
  line-height: 1.15;
}

.preview-col-toggle input {
  width: 16px;
  height: 16px;
  margin-top: auto;
}

.column-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.column-check input {
  width: auto;
  margin: 0;
}

.summary,
.warnings {
  margin-top: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  background: #fff4eb;
  margin-right: 8px;
  margin-bottom: 8px;
}

.pill.success {
  background: rgba(22, 121, 93, 0.12);
  color: var(--success);
}

.pill.danger {
  background: rgba(195, 62, 53, 0.12);
  color: var(--danger);
}

.table-wrap {
  overflow-x: auto;
  margin-top: 12px;
}

#hot-telegram-base.table-wrap {
  max-height: 70vh;
  overflow: auto;
}

#hot-telegram-duplicates.table-wrap {
  max-height: 70vh;
  overflow: auto;
}

#finance-matched-payers.table-wrap,
#finance-unmatched-payers.table-wrap {
  max-height: 70vh;
  overflow: auto;
}

.hot-referrer-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.hot-referrer-chip {
  padding: 10px 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th input[type="checkbox"],
td input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

.preview-table {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  margin-top: 12px;
}

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

canvas {
  width: 100%;
  background: linear-gradient(180deg, rgba(255, 248, 240, 0.8), rgba(255, 252, 247, 0.95));
  border-radius: 18px;
  border: 1px solid var(--line);
  padding: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 19, 12, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  width: min(1080px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border-radius: 24px;
  padding: 22px;
  background: rgba(255, 251, 245, 0.98);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.modal-choice-row {
  margin-top: 6px;
}

.modal-actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 12px;
}

#user-edit-form .inspect-grid {
  align-items: end;
}

.conflict-list {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}

.conflict-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 249, 0.9);
  padding: 16px;
}

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

.conflict-col {
  border: 1px solid rgba(89, 57, 29, 0.1);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.conflict-col.current {
  background: rgba(255, 244, 235, 0.7);
}

.conflict-col.incoming {
  background: rgba(235, 250, 243, 0.7);
}

.conflict-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.conflict-field {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.conflict-field.changed {
  border-left: 4px solid var(--accent);
  padding-left: 8px;
}

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

@media (max-width: 860px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .page-shell {
    width: min(100vw - 20px, 1260px);
    padding-top: 12px;
  }

  .hero {
    flex-direction: column;
    align-items: stretch;
  }

  .panel {
    flex-basis: 100%;
  }

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

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

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