/*
 * 팀 수익 대시보드 — 파스텔 테마
 *
 * 색은 두 갈래로 나뉩니다.
 *  1) UI 표면·텍스트 : 텔레그램이 내려주는 테마 변수를 우선 쓰고, 없으면 자체 파스텔 값으로 떨어집니다.
 *  2) 데이터 마크    : 텔레그램 테마와 무관하게 고정. 라이트/다크 각각 별도로 검증한 5색입니다.
 *     (dataviz 검증기 통과 — 명도대역·채도·색각이상 분리 ΔE 8.2·정상시야 ΔE 22.4·대비)
 *     라이트 모드의 일부 슬롯은 대비 3:1 미만이라 "직접 라벨" 이 필수입니다.
 *     그래서 모든 카테고리 막대에 이름과 금액을 항상 글자로 함께 적습니다.
 */

:root {
  color-scheme: light;

  --bg: var(--tg-theme-bg-color, #fbfafc);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-tint: #f4f2f8;
  --ink: var(--tg-theme-text-color, #1c1b22);
  --ink-2: #55535f;
  --muted: var(--tg-theme-hint-color, #8b8896);
  --line: #e9e6f0;
  --accent: var(--tg-theme-button-color, #5b8def);
  --accent-ink: var(--tg-theme-button-text-color, #ffffff);
  --accent-wash: #e8eefd;
  --danger: var(--tg-theme-destructive-text-color, #d9705a);

  /* 데이터 마크 — 라이트 스텝 */
  --series-1: #5b8def;
  --series-2: #f2856d;
  --series-3: #2fb89b;
  --series-4: #b084e8;
  --series-5: #e8a33d;

  --radius: 18px;
  --radius-sm: 12px;
  --gap: 12px;
  --shadow: 0 1px 2px rgba(28, 27, 34, 0.04), 0 8px 24px rgba(28, 27, 34, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;

    --bg: var(--tg-theme-bg-color, #14151a);
    --surface: var(--tg-theme-secondary-bg-color, #1e1f26);
    --surface-tint: #23242c;
    --ink: var(--tg-theme-text-color, #f1f0f5);
    --ink-2: #b9b7c4;
    --muted: var(--tg-theme-hint-color, #85838f);
    --line: #2d2e37;
    --accent: var(--tg-theme-button-color, #4e86dc);
    --accent-wash: #212b3d;
    --danger: var(--tg-theme-destructive-text-color, #d9705a);

    /* 데이터 마크 — 다크 스텝 (라이트를 뒤집은 게 아니라 다크 표면 기준으로 따로 고른 값) */
    --series-1: #4e86dc;
    --series-2: #d9705a;
    --series-3: #2aa98d;
    --series-4: #9a79d4;
    --series-5: #b8842e;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --bg: var(--tg-theme-bg-color, #14151a);
  --surface: var(--tg-theme-secondary-bg-color, #1e1f26);
  --surface-tint: #23242c;
  --ink: var(--tg-theme-text-color, #f1f0f5);
  --ink-2: #b9b7c4;
  --muted: var(--tg-theme-hint-color, #85838f);
  --line: #2d2e37;
  --accent: var(--tg-theme-button-color, #4e86dc);
  --accent-wash: #212b3d;
  --danger: var(--tg-theme-destructive-text-color, #d9705a);

  --series-1: #4e86dc;
  --series-2: #d9705a;
  --series-3: #2aa98d;
  --series-4: #9a79d4;
  --series-5: #b8842e;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui,
    sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

main {
  padding: 14px 14px calc(96px + env(safe-area-inset-bottom));
  max-width: 760px;
  margin: 0 auto;
}

h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.2px;
}
h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.1px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

/* ------------------------------ 상단 ------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 14px;
}

.currency {
  appearance: none;
  background: var(--surface-tint);
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 30px 7px 13px;
  font-size: 13px;
  font-weight: 600;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 11px) 52%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 6px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ------------------------------ 히어로 ------------------------------ */

.hero {
  background: linear-gradient(150deg, var(--accent-wash), var(--surface) 72%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  margin: 4px 0 12px;
  box-shadow: var(--shadow);
}
.hero__label {
  margin: 0;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
}
.hero__value {
  margin: 6px 0 0;
  font-size: 32px;
  font-weight: 750;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.hero__sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

/* ------------------------------ 스탯 타일 ------------------------------ */

.cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
}
.card__label {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card__label::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--dot, var(--series-1));
  flex: 0 0 auto;
}
.card__value {
  font-size: 17px;
  font-weight: 700;
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
}

/* ------------------------------ 패널 ------------------------------ */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

/* ------------------------------ 차트 ------------------------------ */

.chart {
  position: relative;
}
.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  touch-action: pan-y;
}
.chart .bar {
  fill: var(--series-1);
  transition: opacity 0.12s;
}
.chart .bar--neg {
  fill: var(--danger);
}
.chart .bar.is-dim {
  opacity: 0.35;
}
.chart .hit {
  fill: transparent;
}
.chart .baseline {
  stroke: var(--line);
  stroke-width: 1;
}
.chart .tick {
  fill: var(--muted);
  font-size: 9px;
  font-weight: 500;
}
.chart .empty {
  fill: var(--muted);
  font-size: 12px;
}

.tip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--bg);
  border-radius: 9px;
  padding: 6px 9px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  transform: translate(-50%, -125%);
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 5;
  font-variant-numeric: tabular-nums;
}
.tip.is-on {
  opacity: 1;
}

/* ------------------------- 카테고리 막대 ------------------------- */
/* 라이트 모드에서 일부 색이 대비 3:1 미만이라, 이름과 금액을 항상 글자로 함께 적습니다. */

.bars {
  list-style: none;
  margin: 0;
  padding: 0;
}
.bars li + li {
  margin-top: 12px;
}
.bars .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 6px;
}
.bars .name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  min-width: 0;
}
.bars .swatch {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex: 0 0 auto;
}
.bars .val {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}
.bars .track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-tint);
  overflow: hidden;
}
.bars .fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ------------------------------ 기록 목록 ------------------------------ */

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
}
.entries li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.entries li:first-child {
  border-top: 0;
  padding-top: 2px;
}
.entry__main {
  flex: 1;
  min-width: 0;
}
.entry__title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry__meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry__amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 14px;
}
.entry__amount.is-neg {
  color: var(--danger);
}
.entry__del {
  border: 0;
  background: var(--surface-tint);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  cursor: pointer;
  flex: 0 0 auto;
}

.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-tint);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  margin-left: 5px;
  vertical-align: 1px;
}

.tag--auto {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-weight: 500;
}

.more {
  width: 100%;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--surface-tint);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ------------------------------ 입력 ------------------------------ */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 50px;
  height: 50px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(91, 141, 239, 0.4);
  cursor: pointer;
}

.sheet {
  border: 0;
  border-radius: 22px 22px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 520px;
  margin: auto auto 0;
  background: var(--bg);
  color: var(--ink);
}
.sheet::backdrop {
  background: rgba(20, 21, 26, 0.5);
  backdrop-filter: blur(2px);
}
.sheet h2 {
  font-size: 17px;
  margin-bottom: 4px;
}
.sheet label {
  display: block;
  margin-top: 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
}
.sheet input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 12px 13px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}
.sheet input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.sheet__actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}
.btn {
  flex: 1;
  border: 0;
  border-radius: 13px;
  padding: 13px;
  font-size: 15px;
  font-weight: 650;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
.btn--ghost {
  background: var(--surface-tint);
  color: var(--ink-2);
}

.status {
  text-align: center;
  color: var(--muted);
  padding: 48px 24px;
  font-size: 14px;
}
