/* ОДДС — оформление в духе Apple: много воздуха, тонкие линии, спокойный цвет.
   Акцент несёт только смысл: зелёный — приход, красный — расход, синий — действие. */

:root {
  --ink:            #1d1d1f;
  --ink-2:          #424245;
  --muted:          #6e6e73;
  --muted-2:        #86868b;
  --hairline:       #d2d2d7;
  --hairline-soft:  #ebebf0;
  --surface:        #ffffff;
  --surface-2:      #f5f5f7;
  --surface-3:      #fafafc;
  --accent:         #0071e3;
  --accent-soft:    #e8f1fd;
  --green:          #1d7a3d;
  --green-soft:     #e6f4ea;
  --red:            #b3261e;
  --red-soft:       #fdeceb;
  --amber:          #8a6100;
  --amber-soft:     #fdf3dd;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.04), 0 1px 6px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);

  --ease: cubic-bezier(.4, 0, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Segoe UI", Inter, system-ui, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink:            #f5f5f7;
    --ink-2:          #d6d6db;
    --muted:          #a1a1a6;
    --muted-2:        #86868b;
    --hairline:       #3a3a3c;
    --hairline-soft:  #2c2c2e;
    --surface:        #1c1c1e;
    --surface-2:      #000000;
    --surface-3:      #232325;
    --accent:         #2997ff;
    --accent-soft:    #10304d;
    --green:          #56d364;
    --green-soft:     #12301b;
    --red:            #ff6b60;
    --red-soft:       #3a1614;
    --amber:          #f0c674;
    --amber-soft:     #3a2f14;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
    --shadow-md: 0 4px 16px rgba(0,0,0,.5);
    --shadow-lg: 0 12px 40px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface-2);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "tnum" 1;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 24px 96px; }

/* ───────────── Вход ───────────── */

.auth {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 40px 20px;
  background: var(--surface-2);
}

.auth__card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: 44px 40px 36px;
  box-shadow: var(--shadow-md);
  text-align: center;
  animation: rise .5s var(--ease-out) both;
}

.auth__mark {
  width: 56px; height: 56px;
  margin: 0 auto 18px;
  border-radius: 16px;
  display: grid; place-items: center;
  font-size: 28px; font-weight: 600;
  color: #fff;
  background: linear-gradient(145deg, #0a84ff, #0055c9);
  box-shadow: 0 6px 18px rgba(0,113,227,.28);
}

.auth__title {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -.022em;
}

.auth__lede {
  margin: 8px 0 26px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.auth__form { text-align: left; display: grid; gap: 14px; }

.auth__hint { margin: -4px 0 0; font-size: 12px; color: var(--muted-2); }

.auth__foot { margin: 0; font-size: 12px; color: var(--muted-2); }

/* ───────────── Поля и кнопки ───────────── */

.field { display: block; }

.field__label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: -.01em;
}

.field__input,
.control__input {
  width: 100%;
  padding: 11px 14px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface-3);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background .18s var(--ease);
}

.field__input::placeholder { color: var(--muted-2); }

.field__input:focus,
.control__input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}

.button {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 18px;
  border-radius: 980px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: transform .12s var(--ease), background .18s var(--ease),
              border-color .18s var(--ease), opacity .18s var(--ease);
}

.button:hover { background: var(--surface-3); }
.button:active { transform: scale(.97); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.button--primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.button--primary:hover { background: color-mix(in srgb, var(--accent) 86%, #000); }

.button--wide { width: 100%; padding: 12px; font-size: 15px; margin-top: 4px; }

.button--quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
}
.button--quiet:hover { background: var(--surface-2); color: var(--ink); }

.button--danger { color: var(--red); border-color: transparent; background: transparent; }
.button--danger:hover { background: var(--red-soft); }

/* Сегментированный переключатель */

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border-radius: 11px;
  width: 100%;
}

.segmented__item {
  flex: 1;
  appearance: none;
  border: 0;
  background: transparent;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s var(--ease), color .2s var(--ease), box-shadow .2s var(--ease);
}

.segmented__item.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.segmented--sm .segmented__item { padding: 7px 10px; font-size: 12.5px; }

.alert {
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: 13px;
  line-height: 1.4;
}
.alert--error { background: var(--red-soft); color: var(--red); }
.alert--info  { background: var(--accent-soft); color: var(--accent); margin-bottom: 16px; }

/* ───────────── Шапка ───────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline-soft);
}

.topbar__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.topbar__mark {
  width: 22px; height: 22px;
  border-radius: 6px;
  display: grid; place-items: center;
  font-size: 13px;
  color: #fff;
  background: linear-gradient(145deg, #0a84ff, #0055c9);
}

.topbar__nav { display: flex; gap: 4px; margin-left: 8px; }

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab.is-active { color: var(--ink); font-weight: 500; background: var(--surface-2); }

.tab__badge {
  min-width: 19px;
  padding: 0 6px;
  border-radius: 980px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 19px;
  text-align: center;
}

.topbar__user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar__email { font-size: 13px; color: var(--muted); }

/* ───────────── Заголовки страниц ───────────── */

.page-head { padding: 40px 0 26px; }
.page-head--row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.page-head__title {
  margin: 0;
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -.024em;
  line-height: 1.15;
}

.page-head__lede {
  margin: 10px 0 0;
  max-width: 62ch;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.5;
}

.page-head__actions { display: flex; gap: 8px; }

/* ───────────── Загрузка файлов ───────────── */

.dropzone {
  border: 1.5px dashed var(--hairline);
  border-radius: var(--r-xl);
  background: var(--surface);
  padding: 52px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease);
}

.dropzone:hover, .dropzone:focus-visible {
  border-color: var(--accent);
  background: var(--surface-3);
  outline: none;
}

.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.006);
}

.dropzone__icon { color: var(--muted-2); margin-bottom: 12px; }
.dropzone.is-over .dropzone__icon { color: var(--accent); }

.dropzone__title { margin: 0; font-size: 17px; font-weight: 500; }
.dropzone__hint { margin: 5px 0 0; font-size: 13.5px; color: var(--muted); }

.progress { margin-top: 20px; }

.progress__bar {
  height: 4px;
  border-radius: 999px;
  background: var(--hairline-soft);
  overflow: hidden;
}

.progress__fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width .35s var(--ease);
}

.progress__label { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

/* ───────────── Панели ───────────── */

.panel {
  margin-top: 28px;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--hairline-soft);
  flex-wrap: wrap;
}

.panel__title { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.panel__meta { font-size: 13px; color: var(--muted); }

.panel--empty { padding: 56px 24px; text-align: center; }
.empty__title { margin: 0; font-size: 17px; font-weight: 500; }
.empty__text { margin: 6px 0 18px; color: var(--muted); font-size: 14px; }

/* Список загрузок */

.uploads { display: flex; flex-direction: column; }

.upload {
  display: grid;
  grid-template-columns: 30px 1fr auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--hairline-soft);
}
.upload:last-child { border-bottom: 0; }

.upload__status {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  color: #fff;
}
.upload__status--ok        { background: var(--green); }
.upload__status--duplicate { background: var(--muted-2); }
.upload__status--failed    { background: var(--red); }
.upload__status--pending   { background: var(--amber); }

.upload__name {
  font-size: 14px;
  font-weight: 500;
  word-break: break-word;
}
.upload__meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; line-height: 1.45; }
.upload__rows { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ───────────── Фильтры ───────────── */

.filters {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px 22px;
}

.filters__row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  align-items: end;
}

.control { display: block; min-width: 0; }
.control--grow { grid-column: span 2; }

.control__label {
  display: block;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: none;
  letter-spacing: -.005em;
}

.control__input { padding: 9px 12px; font-size: 14px; }

.filters__note {
  margin: 14px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  padding-top: 12px;
  border-top: 1px solid var(--hairline-soft);
}

/* ───────────── Плитки итогов ───────────── */

.tiles {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.tile {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  animation: rise .4s var(--ease-out) both;
}

.tile__label { font-size: 12.5px; color: var(--muted); font-weight: 500; }

.tile__value {
  margin-top: 6px;
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.tile__value--in  { color: var(--green); }
.tile__value--out { color: var(--red); }
.tile__value--neg { color: var(--red); }

.tile__sub { margin-top: 4px; font-size: 12.5px; color: var(--muted-2); }

/* ───────────── График ───────────── */

.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }

.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.dot--in  { background: var(--green); }
.dot--out { background: var(--red); }
.dot--net { background: var(--accent); }

.chart { padding: 20px 24px 24px; overflow-x: auto; }
.chart svg { display: block; min-width: 100%; }

.chart__grid { stroke: var(--hairline-soft); stroke-width: 1; }
.chart__axis { fill: var(--muted-2); font-size: 10px; font-family: var(--font); }
.chart__bar-in  { fill: var(--green); }
.chart__bar-out { fill: var(--red); }
.chart__net     { stroke: var(--accent); stroke-width: 2; fill: none; stroke-linejoin: round; }
.chart__net-dot { fill: var(--accent); }
.chart__hit:hover ~ .chart__label, .chart__hit:focus ~ .chart__label { opacity: 1; }

/* ───────────── Дерево ОДДС ───────────── */

.section { margin-top: 28px; }

.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 0 4px 12px;
  flex-wrap: wrap;
}

.section__title { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -.018em; }
.section__total { font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.018em; }
.section__total--in  { color: var(--green); }
.section__total--out { color: var(--red); }

.tree { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden; }

.node { border-bottom: 1px solid var(--hairline-soft); }
.node:last-child { border-bottom: 0; }

.node__row {
  display: grid;
  grid-template-columns: 18px 1fr 88px 132px 64px;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 22px;
  background: transparent;
  border: 0;
  text-align: left;
  cursor: pointer;
  transition: background .16s var(--ease);
}

.node__row:hover { background: var(--surface-3); }

.node--l1 > .node__row { padding-left: 22px; }
.node--l2 > .node__row { padding-left: 46px; background: var(--surface-3); }
.node--l2 > .node__row:hover { background: var(--surface-2); }
.node--l3 > .node__row { padding-left: 70px; }

.node__chevron {
  width: 16px; height: 16px;
  color: var(--muted-2);
  transition: transform .22s var(--ease);
  flex: none;
}
.node.is-open > .node__row .node__chevron { transform: rotate(90deg); }

.node__name {
  font-size: 14.5px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.node--l1 .node__name { font-weight: 500; font-size: 15px; }
.node--l3 .node__name { color: var(--ink-2); font-size: 14px; }

.node__tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 500;
  background: var(--amber-soft);
  color: var(--amber);
  vertical-align: 1px;
}

.node__bar {
  height: 5px;
  border-radius: 999px;
  background: var(--hairline-soft);
  overflow: hidden;
}
.node__bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width .5s var(--ease-out);
}
.node__bar--in span  { background: var(--green); }
.node__bar--out span { background: var(--red); }

.node__value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
}
.node--l1 .node__value { font-size: 15px; font-weight: 600; }
.node__value--neg { color: var(--red); }

.node__count {
  text-align: right;
  font-size: 12px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.node__body { display: none; }
.node.is-open > .node__body { display: block; animation: fade .28s var(--ease-out) both; }

/* Таблица деталей */

.details { padding: 4px 22px 20px 70px; background: var(--surface-3); }

.details__table { width: 100%; border-collapse: collapse; font-size: 12.5px; }

.details__table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
  font-size: 11.5px;
}

.details__table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--hairline-soft);
  vertical-align: top;
  color: var(--ink-2);
}

.details__table tr:last-child td { border-bottom: 0; }
.details__table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.details__table .strong { color: var(--ink); font-weight: 500; }

.details__scroll { overflow-x: auto; }

.pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 500;
  white-space: nowrap;
}
.pill--cash { background: var(--green-soft); color: var(--green); }
.pill--accr { background: var(--surface-2); color: var(--muted); }

.details__more { margin-top: 12px; display: flex; justify-content: center; }
.details__empty { padding: 16px 0; color: var(--muted); font-size: 13px; }

/* ───────────── Модальное окно ───────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0,0,0,.28);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade .2s var(--ease-out) both;
}

.modal__card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  animation: rise .3s var(--ease-out) both;
}

.modal__title { margin: 0 0 8px; font-size: 20px; font-weight: 600; letter-spacing: -.018em; }
.modal__text { margin: 0 0 20px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.modal__row { display: grid; grid-template-columns: 1fr 120px; gap: 12px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

/* ───────────── Уведомления и загрузка ───────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(520px, calc(100vw - 40px));
  padding: 12px 20px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--surface);
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: var(--shadow-lg);
  animation: toast-in .3s var(--ease-out) both;
}

.toast--error { background: var(--red); color: #fff; }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 56px 0;
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--hairline);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ───────────── Адаптив ───────────── */

@media (max-width: 900px) {
  .control--grow { grid-column: span 1; }
  .node__row { grid-template-columns: 16px 1fr 110px; }
  .node__bar, .node__count { display: none; }
  .details { padding-left: 22px; }
}

@media (max-width: 620px) {
  .wrap { padding: 0 16px 72px; }
  .topbar__inner { padding: 0 16px; gap: 12px; }
  .topbar__email { display: none; }
  .page-head__title { font-size: 27px; }
  .tile__value { font-size: 23px; }
  .upload { grid-template-columns: 24px 1fr; }
  .upload__rows { grid-column: 2; }
  .node--l2 > .node__row { padding-left: 34px; }
  .node--l3 > .node__row { padding-left: 46px; }
}
