/* Day / night palettes — high contrast, teal brand (no purple wash) */
:root,
html[data-resolved-theme="light"] {
  --ink: #10221f;
  --ink-soft: #3a514c;
  --paper: #f7f4ec;
  --surface: #ffffff;
  --surface-2: #eef3f0;
  --brand: #0a4f49;
  --brand-2: #12756c;
  --accent: #c45a1a;
  --accent-soft: rgba(196, 90, 26, 0.14);
  --line: rgba(16, 34, 31, 0.14);
  --hero-fg: #10221f;
  --hero-muted: #3a514c;
  --shadow: 0 14px 34px rgba(10, 79, 73, 0.12);
  --chart-1: #0a4f49;
  --chart-2: #c45a1a;
  --chart-3: #1f7a55;
  --chart-4: #b08900;
  --chart-5: #2f5d8c;
  --chart-6: #8a3d5b;
  --chart-7: #5b6b3a;
  --chart-8: #4a6670;
  --radius: 20px;
  --font: "Vazirmatn", system-ui, sans-serif;
  color-scheme: light;
}

html[data-resolved-theme="dark"] {
  --ink: #eef5f2;
  --ink-soft: #b7c7c2;
  --paper: #0c1a18;
  --surface: #142826;
  --surface-2: #1b3330;
  --brand: #4fd1c5;
  --brand-2: #2aa89d;
  --accent: #ff9a4d;
  --accent-soft: rgba(255, 154, 77, 0.18);
  --line: rgba(238, 245, 242, 0.14);
  --hero-fg: #eef5f2;
  --hero-muted: #b7c7c2;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  --chart-1: #4fd1c5;
  --chart-2: #ff9a4d;
  --chart-3: #6ee7b7;
  --chart-4: #f5d76e;
  --chart-5: #7db4e8;
  --chart-6: #e08ab0;
  --chart-7: #b5d07a;
  --chart-8: #9bb7bf;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 420px at 0% 0%, color-mix(in srgb, var(--brand) 18%, transparent), transparent 55%),
    radial-gradient(700px 380px at 100% 8%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 50%),
    var(--paper);
}
.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cpath d='M0 60h120M60 0v120' stroke='%2310221f' stroke-width='1'/%3E%3C/svg%3E");
  pointer-events: none;
}
html[data-resolved-theme="dark"] .bg::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cpath d='M0 60h120M60 0v120' stroke='%23eef5f2' stroke-width='1'/%3E%3C/svg%3E");
}

.shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.hero {
  padding: 14px 2px 6px;
  color: var(--hero-fg);
  animation: rise 420ms ease both;
}
.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--hero-fg);
}
.headline {
  margin: 10px 0 0;
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--hero-fg);
}
.lede {
  margin: 6px 0 0;
  font-size: 0.92rem;
  color: var(--hero-muted);
  max-width: 34ch;
}

.view-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 14px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.view-tabs button {
  border: 0;
  border-radius: 999px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--ink-soft);
  background: transparent;
  cursor: pointer;
}
.view-tabs button[aria-selected="true"] {
  background: var(--brand);
  color: #fff;
}
html[data-resolved-theme="dark"] .view-tabs button[aria-selected="true"] {
  color: #0c1a18;
}

.edit-block {
  margin-top: 14px;
  animation: rise 480ms ease both;
}
.edit-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.edit-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.edit-item-body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}
.edit-item-body strong {
  font-size: 0.95rem;
}
.edit-item .amt {
  font-weight: 800;
  color: var(--brand);
}
.edit-item .meta {
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.btn-edit {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}
.btn-edit:hover {
  background: color-mix(in srgb, var(--brand) 12%, var(--surface-2));
}
.edit-form {
  margin-top: 16px;
  padding: 16px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}
.field {
  display: grid;
  gap: 6px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.field input,
.field select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-inline-end: 32px;
}
html[dir="rtl"] .field select {
  background-position: 18px calc(50% - 3px), 12px calc(50% - 3px);
  padding-inline-end: 12px;
  padding-inline-start: 32px;
}
.field input:focus,
.field select:focus {
  border-color: var(--brand);
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.edit-total {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--brand);
}
.edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.btn-primary,
.btn-ghost,
.btn-danger {
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
}
.btn-primary {
  flex: 1;
  background: var(--brand);
  color: #fff;
}
html[data-resolved-theme="dark"] .btn-primary {
  color: #0c1a18;
}
.btn-ghost {
  flex: 1;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-danger {
  width: 100%;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  margin-top: 2px;
}

.theme-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.theme-switch button {
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: transparent;
  cursor: pointer;
}
.theme-switch button[aria-pressed="true"] {
  background: var(--brand);
  color: #fff;
}
html[data-resolved-theme="dark"] .theme-switch button[aria-pressed="true"] {
  color: #0c1a18;
}

.controls { margin-top: 14px; animation: rise 520ms ease both; }
.period-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 5px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.period-tabs button {
  border: 0;
  border-radius: 999px;
  padding: 10px 0;
  font: inherit;
  font-weight: 700;
  font-size: 0.84rem;
  color: var(--ink-soft);
  background: transparent;
  cursor: pointer;
}
.period-tabs button[aria-selected="true"] {
  background: var(--brand);
  color: #fff;
}
html[data-resolved-theme="dark"] .period-tabs button[aria-selected="true"] {
  color: #0c1a18;
}

.nav-row {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.nav-btn, .window-label, .cal-nav, .cal-today, .cal-close, .cat-picker-btn {
  font: inherit;
}
.nav-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--brand);
  font-size: 1.35rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.window-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  text-align: center;
  font-weight: 800;
  color: var(--ink);
  background: var(--surface);
  border-radius: 16px;
  padding: 12px 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.cal-ico { opacity: 0.9; }

.cal-sheet, .cat-sheet {
  margin-top: 10px;
  padding: 14px 12px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: rise 240ms ease both;
}
.cal-sheet[hidden], .cat-sheet[hidden] { display: none !important; }
.cal-head {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.cal-title {
  text-align: center;
  font-weight: 800;
  color: var(--ink);
}
.cal-nav {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 1.2rem;
  cursor: pointer;
}
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--ink-soft);
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-day {
  aspect-ratio: 1;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}
.cal-day:hover { background: var(--surface-2); }
.cal-day.muted { opacity: 0.25; cursor: default; }
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--brand); }
.cal-day.selected {
  background: var(--accent);
  color: #fff;
}
.cal-actions { display: flex; gap: 8px; margin-top: 12px; }
.cal-today, .cal-close {
  flex: 1;
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 800;
  cursor: pointer;
}
.cal-today { background: var(--brand); color: #fff; }
html[data-resolved-theme="dark"] .cal-today { color: #0c1a18; }
.cal-close {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
}

.total-block {
  margin-top: 14px;
  padding: 20px 16px 16px;
  border-radius: var(--radius);
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: var(--shadow);
  animation: rise 620ms ease both;
}
html[data-resolved-theme="dark"] .total-block {
  color: #0c1a18;
}
.total-kicker { margin: 0; font-size: 0.84rem; opacity: 0.85; font-weight: 600; }
.total-value {
  margin: 6px 0 0;
  font-size: clamp(1.7rem, 6.5vw, 2.35rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.total-meta { margin: 8px 0 0; font-size: 0.88rem; opacity: 0.88; font-weight: 600; }

.filter-row { margin-top: 12px; }
.cat-picker-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: right;
}
.cat-picker-kicker {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.cat-picker-value {
  font-size: 1rem;
  font-weight: 800;
  color: var(--ink);
}
.cat-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  margin-bottom: 8px;
  outline: none;
}
.cat-search:focus { border-color: var(--brand); }
.cat-list {
  max-height: 240px;
  overflow: auto;
  display: grid;
  gap: 4px;
}
.cat-option {
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  text-align: right;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}
.cat-option:hover { background: var(--surface-2); }
.cat-option[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  color: var(--ink);
  box-shadow: inset 3px 0 0 var(--accent);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 0 10px;
  flex-wrap: wrap;
}
.section-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--ink);
}
.lines-block .section-title { margin: 20px 2px 10px; }

.chart-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.chart-tabs button {
  border: 0;
  border-radius: 999px;
  padding: 7px 11px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--ink-soft);
  background: transparent;
  cursor: pointer;
}
.chart-tabs button[aria-selected="true"] {
  background: var(--brand);
  color: #fff;
}
html[data-resolved-theme="dark"] .chart-tabs button[aria-selected="true"] {
  color: #0c1a18;
}

.chart-wrap {
  position: relative;
}
.chart-stage {
  min-height: 180px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 16px 14px;
  overflow: hidden;
  color: var(--ink);
  /* keep SVG geometry LTR; Persian labels still render fine */
  direction: ltr;
  unicode-bidi: isolate;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.chart-stage [data-tip] {
  cursor: pointer;
}
.chart-tip {
  position: absolute;
  z-index: 5;
  display: flex;
  min-width: 168px;
  max-width: min(280px, 84vw);
  overflow: hidden;
  border-radius: 14px;
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 14px 36px rgba(8, 28, 24, 0.28);
  direction: rtl;
  pointer-events: none;
  transform: translate(-50%, -112%);
  animation: rise 160ms ease both;
}
html[data-resolved-theme="dark"] .chart-tip {
  background: #eef5f2;
  color: #0c1a18;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
}
.chart-tip-accent {
  width: 6px;
  flex: 0 0 auto;
}
.chart-tip-body {
  padding: 12px 14px 12px 12px;
  min-width: 0;
}
.chart-tip-cat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.25;
}
.chart-tip-swatch {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}
.chart-tip-amt {
  margin-top: 8px;
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.chart-tip-meta {
  margin-top: 4px;
  font-size: 0.76rem;
  font-weight: 650;
  opacity: 0.78;
  line-height: 1.35;
}
.chart-stage svg {
  width: 100%;
  max-width: 100%;
  max-height: 260px;
  height: auto;
  display: block;
  margin: 0 auto;
  overflow: visible;
}
.chart-stage .empty {
  direction: rtl;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.bars { display: grid; gap: 10px; }
.bar-row {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 10px;
  align-items: center;
}
.bar-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  transition: width 650ms cubic-bezier(.2,.8,.2,1);
}
.bar-amt {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  min-width: 4.5rem;
  text-align: left;
}

.lines {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.line-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.line-item strong { font-size: 0.95rem; color: var(--ink); }
.line-item .meta {
  grid-column: 1 / -1;
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-weight: 600;
}
.line-item .amt {
  font-weight: 800;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
}

.status {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
}
.empty {
  padding: 22px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--ink-soft);
  text-align: center;
  font-weight: 700;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 420px) {
  .period-tabs button { font-size: 0.74rem; padding: 9px 0; }
  .bar-row { grid-template-columns: 70px 1fr auto; }
  .theme-switch button { padding: 7px 8px; font-size: 0.7rem; }
}
