/* ============ Tokens (light, VirtCardPay-style) ============ */
:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #eef0f4;
  --bg-2: #e7eaf1;
  --card: #ffffff;
  --card-soft: #f6f8fb;
  --border: #e5e8ef;
  --border-strong: #d7dce6;

  /* Text */
  --text: #0b1020;
  --text-2: #1e2540;
  --muted: #8a90a2;
  --muted-2: #b0b6c6;

  /* Accent / brand */
  --accent: #3b82f6;
  --accent-2: #6366f1;

  /* Semantic (slightly desaturated for light theme) */
  --green: #10b981;
  --green-bg: #d1fae5;
  --green-soft: #ecfdf5;
  --red: #f43f5e;
  --red-bg: #ffe4e6;
  --red-soft: #fff1f2;
  --yellow: #d97706;
  --yellow-bg: #fef3c7;
  --yellow-soft: #fffbeb;
  --orange: #f97316;
  --orange-bg: #ffedd5;
  --orange-soft: #fff7ed;
  --violet: #8b5cf6;
  --violet-bg: #ede9fe;
  --violet-soft: #f5f3ff;
  --blue: #3b82f6;
  --blue-bg: #dbeafe;
  --blue-soft: #eff6ff;
  --teal: #14b8a6;
  --teal-bg: #ccfbf1;
  --teal-soft: #f0fdfa;

  --radius-sm: 12px;
  --radius: 16px;
  --radius-lg: 20px;
  --radius-xl: 24px;

  --shadow-xs: 0 1px 2px rgba(16,24,40,.04);
  --shadow-sm: 0 2px 8px rgba(16,24,40,.06);
  --shadow: 0 6px 24px rgba(16,24,40,.08);
  --shadow-lg: 0 14px 40px rgba(16,24,40,.1);

  --ease: cubic-bezier(.22,.61,.36,1);
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100dvh;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-feature-settings: "ss01", "cv11";
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 15px;
  line-height: 1.45;
}

::selection { background: #c7d7ff; color: var(--text); }

/* ============ Layout ============ */
.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 16px calc(40px + env(safe-area-inset-bottom));
}

/* ============ Topbar ============ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-badge {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f67ff 0%, #3b82f6 100%);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px;
  box-shadow: 0 6px 16px rgba(59,130,246,.35);
  flex: 0 0 auto;
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.topbar .sub {
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  font-family: inherit;
  box-shadow: var(--shadow-xs);
  transition: all .15s var(--ease);
}
.pill-btn:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.pill-btn:active { transform: scale(.97); }
.pill-ico { color: var(--accent); font-size: 14px; line-height: 1; }

/* ============ Hero (balance + period net) ============ */
.hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
@media (max-width: 420px) {
  .hero { grid-template-columns: 1fr; }
}
.hero-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease);
}
.hero-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.hero-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 6px;
}
.hero-value {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--text);
}
.hero-value.neg { color: var(--red); }
.hero-value.pos { color: var(--green); }
.hero-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
.hero-primary .hero-value { color: var(--accent); }

/* ============ Tiles (quick actions) ============ */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: all .15s var(--ease);
  font-family: inherit;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.tile:active { transform: translateY(0) scale(.97); }
.tile-ico {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}
.tile-ico svg { display: block; }
.tile-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.tile-green  .tile-ico { background: var(--green-bg);  color: var(--green); }
.tile-red    .tile-ico { background: var(--red-bg);    color: var(--red); }
.tile-orange .tile-ico { background: var(--orange-bg); color: var(--orange); }
.tile-blue   .tile-ico { background: var(--blue-bg);   color: var(--blue); }
.tile-purple .tile-ico { background: var(--violet-bg); color: var(--violet); }
.tile-teal   .tile-ico { background: var(--teal-bg);   color: var(--teal); }

/* ============ Filters (segmented pill) ============ */
.filters {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 14px;
}
.segmented {
  display: inline-flex;
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  box-shadow: var(--shadow-xs);
  width: 100%;
}
.seg {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all .2s var(--ease);
  white-space: nowrap;
  min-width: 0;
}
.seg:hover:not(.active) { color: var(--text); }
.seg.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: 0 6px 14px rgba(59,130,246,.28);
}
.seg:active { transform: scale(.97); }
.seg-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: currentColor;
  color: #fff;
  font-size: 10px; font-weight: 900; line-height: 1;
}
.seg.active .seg-ico { background: rgba(255,255,255,.9); color: var(--accent); }
.type-switch { margin-bottom: 14px; }

.period-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.period-nav button {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  box-shadow: var(--shadow-xs);
  transition: all .15s var(--ease);
}
.period-nav button:hover { background: var(--card-soft); border-color: var(--border-strong); }
.period-nav button:active { transform: scale(.97); }
.period-nav .now { color: var(--muted); font-size: 13px; padding: 8px 4px; }

/* ============ Summary cards ============ */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.sum-card {
  position: relative;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  transition: all .18s var(--ease);
}
.sum-card:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.sum-card .k {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
  display: flex; align-items: center; gap: 6px;
}
.sum-card .k::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: currentColor; opacity: .55;
}
.sum-card .v {
  margin-top: 6px;
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: var(--text);
}
.sum-card.pos { color: var(--green); }
.sum-card.pos .v { color: var(--green); }
.sum-card.neg { color: var(--red); }
.sum-card.neg .v { color: var(--red); }
.sum-card.net {
  background: linear-gradient(135deg, #eff6ff 0%, #ede9fe 100%);
  border-color: #dbe3ff;
  color: var(--accent);
}
.sum-card.net .v { color: var(--text); font-size: 19px; }

/* ============ Tabs ============ */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 14px;
  overflow-x: auto;
  box-shadow: var(--shadow-xs);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1;
  min-width: max-content;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 9px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  transition: all .15s var(--ease);
}
.tab:hover:not(.active) { color: var(--text); background: var(--card-soft); }
.tab.active {
  color: var(--text);
  background: var(--card-soft);
  box-shadow: inset 0 0 0 1px var(--border);
}
.tab:active { transform: scale(.97); }

/* ============ Panes & cards ============ */
.pane { display: none; animation: fadeSlide .25s var(--ease); }
.pane.active { display: block; }
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

/* ============ Forms ============ */
.row {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 12px;
}
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }
.row > label:only-child { grid-column: 1 / -1; }

label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

input[type=text],
input[type=number],
input[type=date] {
  background: var(--card-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  outline: none;
  width: 100%;
  transition: border-color .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
}
input::placeholder { color: var(--muted-2); font-weight: 400; }
input:hover { border-color: var(--border-strong); }
input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(59,130,246,.15);
}
input[type=date]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .6; }

.hint {
  color: var(--text-2);
  font-size: 13px;
  background: var(--blue-soft);
  border: 1px solid #dbe8ff;
  padding: 10px 12px;
  border-radius: 12px;
  margin: 6px 0 14px;
  line-height: 1.5;
}
.hint b { color: var(--text); font-weight: 700; }
.hint:empty { display: none; }

/* ============ Buttons ============ */
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 12px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: all .15s var(--ease);
  box-shadow: var(--shadow-xs);
  user-select: none;
}
.btn:hover { background: var(--card-soft); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn:active { transform: scale(.98); }

.btn.primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 20px rgba(59,130,246,.32);
}
.btn.primary:hover {
  background: linear-gradient(135deg, #4b8cf7 0%, #7078ff 100%);
  box-shadow: 0 10px 24px rgba(59,130,246,.4);
}

.btn.danger {
  background: var(--red-soft);
  color: var(--red);
  border-color: #fecdd3;
}
.btn.danger:hover { background: #ffe4e6; border-color: #fda4af; }

.hidden { display: none !important; }

/* ============ Quick chips ============ */
.quick {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  margin: 0 -2px 4px;
  scrollbar-width: none;
}
.quick::-webkit-scrollbar { display: none; }
.quick:empty { display: none; }
.chip {
  flex: 0 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  transition: all .15s var(--ease);
  box-shadow: var(--shadow-xs);
}
.chip:hover { background: var(--card-soft); border-color: var(--border-strong); }
.chip:active { transform: scale(.97); }
.chip.income  { color: var(--green); }
.chip.expense { color: var(--red); }
.chip.salary  { color: var(--orange); }
.chip.income::before  { content: "＋"; margin-right: 2px; font-weight: 800; }
.chip.expense::before { content: "−";  margin-right: 2px; font-weight: 800; }
.chip.salary::before  { content: "₽";  margin-right: 2px; font-weight: 800; }

/* ============ List ============ */
.list-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px; padding: 0 4px;
}
.list-title { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; color: var(--text); }
.list-sub { color: var(--muted); font-size: 13px; }

.txn-list { display: flex; flex-direction: column; gap: 8px; }
.txn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 12px;
  align-items: center;
  box-shadow: var(--shadow-xs);
  transition: all .15s var(--ease);
}
.txn:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.txn.child {
  margin-left: 16px;
  background: var(--card-soft);
  border-style: dashed;
}

.tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}
.tag.income     { color: var(--green);  background: var(--green-bg); }
.tag.expense    { color: var(--red);    background: var(--red-bg); }
.tag.salary     { color: var(--orange); background: var(--orange-bg); }
.tag.tax        { color: var(--yellow); background: var(--yellow-bg); }
.tag.commission { color: var(--violet); background: var(--violet-bg); }

.txn .desc { font-weight: 600; font-size: 14px; color: var(--text); }
.txn .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.txn .amt {
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.txn .amt.pos { color: var(--green); }
.txn .amt.neg { color: var(--red); }

.txn .del {
  background: transparent;
  border: 0;
  color: var(--muted-2);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  font-family: inherit;
  transition: all .15s var(--ease);
}
.txn .del:hover { color: var(--red); background: var(--red-soft); }

/* ============ Templates list ============ */
.tpl-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-xs);
  transition: all .15s var(--ease);
}
.tpl-item:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.tpl-apply {
  flex: 1;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text-2);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 0;
}
.tpl-apply b { color: var(--text); font-weight: 700; }
.icon-btn {
  background: transparent; border: 0;
  color: var(--muted-2);
  font-size: 22px; line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  font-family: inherit;
  transition: all .15s var(--ease);
}
.icon-btn:hover { color: var(--red); background: var(--red-soft); }

/* ============ Report ============ */
#report h2 {
  margin: 0 0 12px;
  font-size: 20px;
  letter-spacing: -0.02em;
  font-weight: 800;
  color: var(--text);
}
.report-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
  box-shadow: var(--shadow-xs);
}
.report-table th, .report-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.report-table th {
  background: var(--card-soft);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 700;
}
.report-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.report-table tr:last-child td { border-bottom: 0; }
.report-table tr.total td {
  background: var(--card-soft);
  font-weight: 800;
  font-size: 15px;
  color: var(--text);
}

/* ============ Misc ============ */
.empty {
  padding: 32px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--card-soft);
  font-size: 14px;
}
.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 24px;
  padding: 8px;
}

/* ============ Sync indicator ============ */
.sync-pill { padding-left: 10px; }
.sync-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted-2);
  transition: background .2s var(--ease), box-shadow .2s var(--ease);
}
.sync-pill[data-status="ok"]      .sync-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,.18); }
.sync-pill[data-status="pending"] .sync-dot { background: var(--yellow); box-shadow: 0 0 0 3px rgba(217,119,6,.18); animation: pulse 1s infinite; }
.sync-pill[data-status="offline"] .sync-dot { background: var(--red); box-shadow: 0 0 0 3px rgba(244,63,94,.18); }
.sync-pill[data-status="auth"]    .sync-dot { background: var(--orange); box-shadow: 0 0 0 3px rgba(249,115,22,.18); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

/* ============ Auth modal ============ */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(11,16,32,.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 50;
  padding: 20px;
  animation: fadeIn .2s var(--ease);
}
.modal[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: 24px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: popIn .25s var(--ease);
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-head {
  display: flex; gap: 12px; align-items: flex-start;
  margin-bottom: 18px;
}
.modal-head h2 { margin: 0 0 2px; font-size: 18px; font-weight: 700; }
.muted-text { color: var(--muted); font-size: 13px; line-height: 1.45; }
.auth-error {
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid #fecdd3;
  border-radius: 10px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 13px;
}

/* ============ Print ============ */
@media print {
  body { background: white; }
  .topbar, .hero, .tiles, .filters, .tabs, .summary-grid, .no-print, .foot { display: none !important; }
  .pane { display: block !important; animation: none; }
  .report-table { box-shadow: none; }
}
