/* AV-CRM - светлая тема в стиле маркетплейса: белые блоки, серые поля, крупная типографика,
   скругленные кнопки. Все цвета - токены на :root. */
:root {
  color-scheme: light;
  --bg: #f5f4f2;
  --surface: #ffffff;
  --field: #f2f1f0;
  --field-hover: #e9e8e6;
  --line: #ecebe9;
  --text: #000000;
  --text-2: #757575;
  --text-3: #a3a3a3;

  --blue: #00aaff;
  --blue-hover: #0099e6;
  --blue-ink: #0080c7;
  --blue-soft: #e5f6ff;
  --green: #02d15c;
  --green-hover: #00bd52;
  --green-ink: #008a3c;
  --green-soft: #e3f9ec;
  --red: #ff4053;
  --red-ink: #e0001b;
  --red-soft: #ffe9eb;
  --orange-ink: #c25e00;
  --orange-soft: #fff1e0;
  --purple: #965eeb;

  /* графики */
  --series-1: #00aaff;
  --series-2: #965eeb;
  --good: #02d15c;
  --bad: #ff4053;
  --grid: #efeeec;
  --border: #ecebe9;

  --radius-s: 8px;
  --radius: 12px;
  --radius-l: 20px;
  --shadow: 0 2px 8px rgba(0, 0, 0, .04);
  --shadow-pop: 0 8px 28px rgba(0, 0, 0, .14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased;
}
a { color: var(--blue-ink); text-decoration: none; }
a:hover { color: var(--red-ink); }
h1 { font-size: 30px; line-height: 1.2; margin: 0; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 20px; line-height: 1.3; margin: 0 0 14px; font-weight: 700; letter-spacing: -.01em; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--green-ink); }
.neg { color: var(--red-ink); }

/* ---------- Шапка ---------- */
.container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 24px; }
.topbar { background: var(--surface); position: sticky; top: 0; z-index: 20; box-shadow: 0 1px 0 var(--line); }
.topbar-inner { display: flex; align-items: center; gap: 20px; height: 64px; }
.logo { display: flex; align-items: center; gap: 8px; color: var(--text); flex: none; }
.logo:hover { color: var(--text); }
.logo-mark { width: 32px; height: 32px; }
.logo-mark rect { fill: var(--blue); }
.logo-mark path { stroke: #fff; stroke-width: 3; stroke-linecap: round; fill: none; }
.logo-text { font-size: 22px; font-weight: 800; letter-spacing: -.03em; }
.logo-text b { color: var(--blue); font-weight: 800; }
.topnav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topnav a {
  padding: 8px 14px; border-radius: var(--radius); color: var(--text); font-weight: 500; white-space: nowrap;
}
.topnav a:hover { background: var(--field); color: var(--text); }
.topnav a.active { background: var(--field); font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex: none; }

.user-menu { position: relative; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--purple); color: #fff; font-weight: 700; font-size: 17px; cursor: pointer;
}
.user-dropdown {
  position: absolute; right: 0; top: 50px; width: 220px; padding: 16px; background: var(--surface);
  border-radius: var(--radius-l); box-shadow: var(--shadow-pop);
}
.user-name { font-weight: 700; margin-bottom: 12px; }

.main { padding-top: 28px; padding-bottom: 56px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin-bottom: 24px;
}

/* ---------- Блоки ---------- */
.card {
  background: var(--surface); border-radius: var(--radius-l); padding: 24px;
  box-shadow: var(--shadow); min-width: 0;
}
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.wide-left { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }

.kpi .label { color: var(--text-2); font-size: 15px; }
.kpi .value { font-size: 32px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 4px; line-height: 1.15; }
.kpi .sub { font-size: 13px; color: var(--text-2); }
.kpi.hero { background: var(--blue-soft); box-shadow: none; }
.card .kpi { padding: 16px; background: var(--field); border-radius: var(--radius); }

.progress { height: 8px; background: var(--field); border-radius: 99px; overflow: hidden; margin: 12px 0 8px; }
.progress > span { display: block; height: 100%; background: var(--blue); border-radius: 99px; }
.progress.done > span { background: var(--green); }

.breakdown { list-style: none; margin: 0; padding: 0; }
.breakdown li { display: flex; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.breakdown li:last-child { border-bottom: 0; }
.breakdown li.total { font-weight: 700; font-size: 17px; }

.chart { width: 100%; height: 300px; }
.chart.pie { height: 240px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.outcome-list { display: grid; grid-template-columns: 1fr auto auto; gap: 8px 14px; font-size: 15px; margin-top: 12px; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 20px; border-radius: var(--radius); border: 0;
  background: var(--field); color: var(--text); font: inherit; font-size: 15px; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: background-color .15s, transform .05s;
}
.btn:hover { background: var(--field-hover); color: var(--text); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-hover); color: #fff; }
.btn.success { background: var(--green); color: #fff; }
.btn.success:hover { background: var(--green-hover); }
.btn.secondary { background: var(--field); }
.btn.danger { color: var(--red-ink); }
.btn.small { height: 32px; padding: 0 12px; font-size: 14px; border-radius: var(--radius-s); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--field); }
.btn.block { width: 100%; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 2px;
}

/* ---------- Формы ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text-2); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--field); border: 1.5px solid transparent;
  border-radius: var(--radius); padding: 0 14px; height: 44px; min-width: 0; width: 100%;
  transition: border-color .15s, background-color .15s;
}
textarea { min-height: 88px; padding: 11px 14px; height: auto; resize: vertical; }
select {
  appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23757575' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 12px;
}
input:hover, select:hover, textarea:hover { background-color: var(--field-hover); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); background-color: var(--surface); }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input[type="checkbox"] {
  appearance: none; width: 22px; height: 22px; padding: 0; flex: none; border-radius: 6px;
  background: var(--field); border: 1.5px solid #d6d5d3; cursor: pointer; display: inline-grid; place-content: center;
}
input[type="checkbox"]:checked { background: var(--blue); border-color: var(--blue); }
input[type="checkbox"]:checked::after {
  content: ""; width: 10px; height: 6px; border: 2px solid #fff; border-top: 0; border-right: 0;
  transform: rotate(-45deg) translate(1px, -1px);
}
.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 15px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; align-items: center; }
.form-actions form { margin: 0; }
.inline-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.inline-form label { flex: 1 1 150px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.filters > * { flex: 1 1 160px; width: auto; }
.filters input[type="search"] { flex: 2 1 260px; }
.filters .check { flex: 0 0 auto; }
.parts { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 8px; }
.parts .check { background: var(--field); padding: 10px 14px; border-radius: var(--radius); }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; margin: 0 -24px; padding: 0 24px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 13px; font-weight: 400; color: var(--text-2); white-space: nowrap; padding-top: 6px; }
td.r, th.r { text-align: right; }
tbody tr { transition: background-color .1s; }
tbody tr:hover { background: #fafaf9; }
tbody tr:last-child td { border-bottom: 0; }
.row-link { color: var(--text); font-weight: 600; }
.row-link:hover { color: var(--red-ink); }
td .faint { margin-top: 2px; }

/* ---------- Плашки ---------- */
.badge {
  display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 13px; font-weight: 500;
  white-space: nowrap; background: var(--field); color: var(--text-2); vertical-align: middle;
}
.badge.in_stock { background: var(--blue-soft); color: var(--blue-ink); }
.badge.partially_sold { background: var(--orange-soft); color: var(--orange-ink); }
.badge.sold { background: var(--green-soft); color: var(--green-ink); }
.badge.written_off { background: var(--red-soft); color: var(--red-ink); }
.badge.review { background: var(--orange-soft); color: var(--orange-ink); font-weight: 700; }
.badge.high { background: var(--red-soft); color: var(--red-ink); }
.badge.low { background: var(--field); color: var(--text-2); }

/* ---------- Уведомления ---------- */
.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.flash { padding: 14px 18px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); font-weight: 500; }
.flash.success { background: var(--green-soft); }
.flash.error { background: var(--red-soft); color: var(--red-ink); }
.note { white-space: pre-line; padding: 14px 16px; border-radius: var(--radius); background: var(--orange-soft); font-size: 14px; }

/* ---------- Переключатель месяца ---------- */
.month-switch { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: var(--radius); padding: 4px; box-shadow: var(--shadow); }
.month-switch .btn.small { width: 36px; padding: 0; background: transparent; font-size: 18px; }
.month-switch .btn.small:hover { background: var(--field); }
.month-switch .current { font-weight: 700; min-width: 140px; text-align: center; }

/* ---------- Задачи ---------- */
.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
.column { background: var(--field); box-shadow: none; padding: 16px; }
.column h2 { display: flex; justify-content: space-between; align-items: center; font-size: 18px; padding: 4px 4px 0; }
.column h2 .faint { background: var(--surface); border-radius: 99px; padding: 2px 10px; font-size: 14px; color: var(--text-2); }
.task { border-radius: var(--radius); padding: 14px 16px; background: var(--surface); margin-bottom: 10px; box-shadow: var(--shadow); }
.task.done .task-title { text-decoration: line-through; color: var(--text-3); }
.task-title { font-weight: 600; font-size: 16px; }
.task-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--text-2); }
.task-meta .overdue { color: var(--red-ink); font-weight: 600; }
.task-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.task-actions form { margin: 0; }
.column .empty { background: transparent; }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 14px; }
details.card > summary { margin: 0; }
details.card[open] > summary { margin-bottom: 18px; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 16px; }

/* ---------- Вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login .card { width: 100%; max-width: 420px; padding: 36px 32px; border-radius: 24px; }
.login h1 { margin-bottom: 6px; }
.login form { display: flex; flex-direction: column; gap: 16px; margin-top: 24px; }
.login .btn { height: 48px; font-size: 16px; font-weight: 600; }

.error-text { color: var(--red-ink); font-size: 14px; }
.empty { text-align: center; color: var(--text-2); padding: 32px 8px; }

/* ---------- Нижняя панель (мобильная) ---------- */
.tabbar { display: none; }

@media (max-width: 960px) {
  .topnav { display: none; }
  .topbar-inner { justify-content: space-between; height: 56px; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); box-shadow: 0 -1px 0 var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 6px;
    font-size: 11px; color: var(--text-3); font-weight: 500; min-width: 56px;
  }
  .tabbar a.active { color: var(--blue); }
  .tabbar svg { width: 24px; height: 24px; }
  .main { padding-bottom: 96px; }
}
@media (max-width: 760px) {
  .container { padding: 0 16px; }
  .main { padding-top: 18px; }
  h1 { font-size: 26px; }
  .card { padding: 18px; border-radius: 16px; }
  .two, .wide-left, .board { grid-template-columns: 1fr; }
  .kpi .value { font-size: 26px; }
  .hide-sm { display: none; }
  .table-wrap { margin: 0 -18px; padding: 0 18px; }
  .topbar-actions .btn.primary { width: 40px; height: 40px; padding: 0; font-size: 22px; border-radius: 50%; }
}

/* ---------- Вспомогательное ---------- */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* ---------- Кастомный выпадающий список ---------- */
.cselect { position: relative; width: 100%; min-width: 0; }
.filters .cselect { flex: 1 1 160px; width: auto; }
.cselect-btn {
  display: flex; align-items: center; width: 100%; height: 44px; padding: 0 40px 0 14px;
  background: var(--field); border: 1.5px solid transparent; border-radius: var(--radius);
  font: inherit; color: var(--text); text-align: left; cursor: pointer; position: relative;
  transition: border-color .15s, background-color .15s;
}
.cselect-btn:hover { background: var(--field-hover); }
.cselect-btn::after {
  content: ""; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px;
  border-right: 2px solid var(--text-2); border-bottom: 2px solid var(--text-2);
  transform: translateY(-70%) rotate(45deg); transition: transform .15s;
}
.cselect.open .cselect-btn { border-color: var(--blue); background: var(--surface); }
.cselect.open .cselect-btn::after { transform: translateY(-30%) rotate(-135deg); }
.cselect.placeholder .cselect-value { color: var(--text-2); }
.cselect-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cselect-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 30; margin: 0;
  padding: 6px; list-style: none; background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-pop); max-height: 300px; overflow-y: auto; min-width: 180px;
}
.cselect.up .cselect-list { top: auto; bottom: calc(100% + 6px); }
.cselect-list li {
  padding: 10px 12px; border-radius: 10px; cursor: pointer; color: var(--text);
  font-size: 15px; line-height: 1.3;
}
.cselect-list li.active { background: var(--field); }
.cselect-list li[aria-selected="true"] { font-weight: 700; }
.cselect-list li[aria-selected="true"]::after { content: " ✓"; color: var(--blue); }
.cselect-list li[aria-disabled="true"] { color: var(--text-3); cursor: default; }
label > .cselect { flex: none; }

/* ---------- Иконки-кнопки в строках ---------- */
td.actions { white-space: nowrap; width: 1%; }
td.actions form { display: inline; margin: 0; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer; vertical-align: middle;
}
.icon-btn:hover { background: var(--field); color: var(--text); }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red-ink); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
tr.edit-row td { background: #fafaf9; padding: 16px 10px; }
tr.edit-row:hover { background: transparent; }

/* ---------- Задачи: форма редактирования ---------- */
.task-edit { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.task-edit .form-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.task-edit .form-actions { margin-top: 4px; gap: 12px; }

/* ---------- Категории расходов ---------- */
.category-list { list-style: none; margin: 0; padding: 0; }
.category-list li { border-bottom: 1px solid var(--line); padding: 6px 0; }
.category-list li:last-child { border-bottom: 0; }
.category-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.category-list form { margin: 8px 0 10px; }

/* ---------- Импорт ---------- */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; min-height: 160px; padding: 24px; border: 2px dashed #d6d5d3; border-radius: var(--radius-l);
  background: var(--field); text-align: center; cursor: pointer; color: var(--text);
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--blue); background: var(--blue-soft); }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; height: 100%; }
.dropzone-title { font-weight: 700; font-size: 17px; }
.hint-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; color: var(--text-2); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.user-dropdown a.btn { margin-bottom: 8px; }
