/* ===== AutoFinance — стили (неоморфизм, тёмная/светлая темы) ===== */

:root {
  --radius-card: 16px;
  --radius-btn: 12px;
  --radius-input: 8px;
  --t: 200ms ease;
}

/* ТЁМНАЯ ТЕМА */
[data-theme="dark"] {
  --bg: #0d0d0d;
  --surface-1: #1a1a1a;
  --surface-2: #242424;
  --accent: #ffffff;
  --accent-contrast: #0d0d0d;
  --text: #e0e0e0;
  --text-dim: #888888;
  --border: rgba(255, 255, 255, 0.08);
  --shadow-dark: rgba(0, 0, 0, 0.5);
  --shadow-light: rgba(255, 255, 255, 0.03);
  --income: #4ade80;
  --expense: #f87171;
  --warn: #fbbf24;
}

/* СВЕТЛАЯ ТЕМА (тёплая, мягкая) */
[data-theme="light"] {
  --bg: #f0eeec;
  --surface-1: #f7f6f4;
  --surface-2: #ffffff;
  --accent: #1a1a1a;
  --accent-contrast: #ffffff;
  --text: #1a1a1a;
  --text-dim: #666666;
  --border: rgba(0, 0, 0, 0.07);
  --shadow-dark: rgba(170, 160, 150, 0.45);
  --shadow-light: rgba(255, 255, 255, 0.9);
  --income: #16a34a;
  --expense: #dc2626;
  --warn: #d97706;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

.tabular { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.income-text { color: var(--income); }
.expense-text { color: var(--expense); }

/* ===== SPLASH ===== */
.splash {
  position: fixed; inset: 0; z-index: 1000;
  background: #0d0d0d;
  display: flex; align-items: center; justify-content: center;
}
#splashCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.splash-center { position: relative; text-align: center; z-index: 2; pointer-events: none; }
.splash-logo {
  font-size: 64px; font-weight: 700; letter-spacing: -2px; color: #fff;
  opacity: 0;
}
.splash-logo span { color: #888; }
.splash-hint { margin-top: 18px; color: #555; font-size: 14px; opacity: 0; }

/* ===== Общие компоненты ===== */
.root { height: 100vh; display: flex; flex-direction: column; }

.neu-card {
  background: var(--surface-1);
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  box-shadow: 6px 6px 16px var(--shadow-dark), -6px -6px 16px var(--shadow-light);
}

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 11px 18px;
  font-size: 14px; font-weight: 500;
  transition: all var(--t);
  box-shadow: 4px 4px 10px var(--shadow-dark), -4px -4px 10px var(--shadow-light);
}
.btn:hover { transform: translateY(-1px); }
.btn:active {
  box-shadow: inset 3px 3px 8px var(--shadow-dark), inset -3px -3px 8px var(--shadow-light);
  transform: translateY(0);
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); border-color: transparent; }
.btn-danger { color: var(--expense); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.input, .select, .textarea {
  width: 100%;
  background: var(--surface-1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 11px 14px;
  font-size: 14px;
  transition: all var(--t);
  box-shadow: inset 3px 3px 7px var(--shadow-dark), inset -3px -3px 7px var(--shadow-light);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--text-dim);
}
.textarea { resize: vertical; min-height: 70px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }

.icon-btn {
  width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-btn);
  color: var(--text); transition: all var(--t);
  box-shadow: 3px 3px 8px var(--shadow-dark), -3px -3px 8px var(--shadow-light);
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn:active { box-shadow: inset 3px 3px 8px var(--shadow-dark), inset -3px -3px 8px var(--shadow-light); }

/* ===== Экран настройки (сервер/клиент) ===== */
.setup-screen, .login-screen {
  flex: 1; display: flex; padding: 20px; overflow-y: auto;
}
/* margin:auto центрирует во flex и при этом позволяет скроллить, когда
   контент выше окна (в отличие от align/justify center — там верх обрезается). */
.setup-box, .login-box { margin: auto; }
.setup-box { width: 460px; max-width: 100%; padding: 40px; text-align: center; }
.setup-box h2 { font-size: 26px; margin-bottom: 8px; }
.setup-box p { color: var(--text-dim); margin-bottom: 28px; font-size: 14px; }
.setup-choices { display: flex; gap: 16px; }
.setup-choice {
  flex: 1; padding: 28px 16px; border-radius: var(--radius-card);
  background: var(--surface-2); border: 1px solid var(--border); transition: all var(--t);
  box-shadow: 5px 5px 14px var(--shadow-dark), -5px -5px 14px var(--shadow-light);
}
.setup-choice:hover { transform: translateY(-3px); border-color: var(--text-dim); }
.setup-choice .big { font-size: 32px; margin-bottom: 10px; }
.setup-choice .title { font-weight: 600; font-size: 16px; }
.setup-choice .sub { color: var(--text-dim); font-size: 12px; margin-top: 4px; }

/* ===== Логин ===== */
.login-box { width: 400px; max-width: 100%; padding: 40px; }
.login-box h2 { font-size: 28px; margin-bottom: 6px; text-align: center; }
.login-box .subtitle { text-align: center; color: var(--text-dim); margin-bottom: 28px; font-size: 14px; }
.pwd-wrap { position: relative; }
.pwd-wrap .eye {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-dim); padding: 6px;
}
.login-links { display: flex; justify-content: center; margin-top: 16px; }
.link-btn { background: none; border: none; color: var(--text-dim); font-size: 13px; text-decoration: underline; }
.lock-msg { text-align: center; color: var(--warn); margin-top: 14px; font-size: 14px; font-weight: 500; }

/* ===== Экран входа OAuth ===== */
.auth-card { width: 380px; text-align: center; }
.auth-logo { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 18px; }
.auth-logo span { color: var(--text-dim); }
.auth-title { font-size: 26px; margin-bottom: 6px; }
.oauth-list { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.oauth-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; padding: 13px 18px; border-radius: var(--radius-btn);
  font-size: 15px; font-weight: 600; border: 1px solid var(--border);
  transition: all var(--t);
  box-shadow: 4px 4px 10px var(--shadow-dark), -4px -4px 10px var(--shadow-light);
}
.oauth-btn:hover:not(:disabled) { transform: translateY(-1px); }
.oauth-btn:active:not(:disabled) { transform: translateY(0); box-shadow: inset 3px 3px 8px var(--shadow-dark); }
.oauth-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.oauth-btn svg { flex-shrink: 0; }
.oauth-btn.yandex { background: #FC3F1D; color: #ffffff; border-color: transparent; }
.oauth-warn {
  margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-input); font-size: 12.5px;
  line-height: 1.5; color: var(--warn); background: rgba(251,191,36,0.1);
  border: 1px solid rgba(251,191,36,0.25); text-align: left;
}
.oauth-status {
  margin-top: 18px; display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 14px; color: var(--text-dim);
}
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--text);
  animation: af-spin 0.7s linear infinite; display: inline-block;
}
@keyframes af-spin { to { transform: rotate(360deg); } }
.auth-sep { display: flex; align-items: center; gap: 12px; margin: 22px 0 16px; color: var(--text-dim); font-size: 12px; }
.auth-sep::before, .auth-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.local-toggle { display: inline-block; }
.local-form { margin-top: 18px; text-align: left; }

/* ===== Вкладки настроек ===== */
.tabs { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.tab {
  padding: 10px 18px; border-radius: var(--radius-btn); font-size: 14px; font-weight: 500;
  background: var(--surface-1); border: 1px solid var(--border); color: var(--text-dim);
  transition: all var(--t);
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--surface-2); color: var(--text);
  box-shadow: inset 2px 2px 6px var(--shadow-dark), inset -2px -2px 6px var(--shadow-light);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.hint-box {
  margin-top: 14px; padding: 14px 16px; border-radius: var(--radius-input); font-size: 13px;
  line-height: 1.6; color: var(--text-dim); background: var(--surface-2); border: 1px solid var(--border);
}
.hint-box a, .link-inline { color: var(--income); cursor: pointer; text-decoration: underline; }
.hint-box code { background: rgba(127,127,127,0.18); padding: 2px 6px; border-radius: 5px; font-size: 12px; }
.pin-dots { letter-spacing: 6px; font-size: 18px; }
.copy-field { display: flex; gap: 8px; align-items: center; }
.copy-field .input { font-family: monospace; font-size: 12.5px; }

/* ===== Шапка ===== */
.topbar {
  height: 64px; display: flex; align-items: center; padding: 0 20px; gap: 14px;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.topbar .logo { font-weight: 700; font-size: 20px; letter-spacing: -0.5px; }
.topbar .logo span { color: var(--text-dim); }
.topbar .spacer { flex: 1; }
.topbar .user-chip { font-size: 13px; color: var(--text-dim); }

/* ===== Навигация ===== */
.shell { flex: 1; display: flex; overflow: hidden; }
.sidebar {
  width: 230px; background: var(--surface-1); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto; flex-shrink: 0;
}
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-radius: var(--radius-btn); color: var(--text-dim); background: transparent;
  border: 1px solid transparent; transition: all var(--t); font-size: 14px; font-weight: 500;
  text-align: left;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active {
  color: var(--text); background: var(--surface-2); border-color: var(--border);
  box-shadow: inset 2px 2px 6px var(--shadow-dark), inset -2px -2px 6px var(--shadow-light);
}
.nav-item .ico { width: 18px; text-align: center; }

.content { flex: 1; overflow-y: auto; padding: 26px 30px; }
.page-title { font-size: 24px; font-weight: 700; margin-bottom: 22px; }

/* ===== Дашборд ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; margin-bottom: 26px; }
.stat-card { padding: 22px; }
.stat-card .label { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; }
.stat-card .value { font-size: 30px; font-weight: 700; }

/* ===== Таблицы ===== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td {
  padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px;
}
table.data th { color: var(--text-dim); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; cursor: pointer; user-select: none; }
table.data th.num, table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr { transition: background var(--t); }
table.data tbody tr:hover { background: var(--surface-2); }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 500;
}
.badge.income { background: rgba(74, 222, 128, 0.15); color: var(--income); }
.badge.expense { background: rgba(248, 113, 113, 0.15); color: var(--expense); }
.badge.offline { background: rgba(251, 191, 36, 0.15); color: var(--warn); }

.section-head { display: flex; align-items: center; margin-bottom: 16px; gap: 12px; }
.section-head h3 { font-size: 17px; font-weight: 600; }
.section-head .spacer { flex: 1; }

.empty { text-align: center; padding: 40px; color: var(--text-dim); }

/* ===== Модальные окна ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal {
  width: 560px; max-width: 100%; max-height: 90vh; overflow-y: auto; padding: 26px;
}
.modal h3 { font-size: 20px; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 22px; }

/* Toggle Доход/Расход */
.type-toggle { display: flex; background: var(--surface-2); border-radius: var(--radius-btn); padding: 5px; gap: 5px; box-shadow: inset 3px 3px 7px var(--shadow-dark), inset -3px -3px 7px var(--shadow-light); }
.type-toggle button {
  flex: 1; padding: 13px; border: none; border-radius: 9px; background: transparent;
  color: var(--text-dim); font-weight: 600; font-size: 15px; transition: all var(--t);
}
.type-toggle button.active.income { background: var(--income); color: #fff; }
.type-toggle button.active.expense { background: var(--expense); color: #fff; }

/* Автодополнение */
.autocomplete { position: relative; }
.ac-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 10; margin-top: 4px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-input);
  max-height: 220px; overflow-y: auto; box-shadow: 0 8px 20px var(--shadow-dark);
}
.ac-item { padding: 10px 14px; font-size: 14px; cursor: pointer; }
.ac-item:hover, .ac-item.active { background: var(--surface-1); }

.file-preview { margin-top: 10px; }
.file-preview img { max-height: 120px; border-radius: 8px; border: 1px solid var(--border); }
.file-preview .fname { font-size: 13px; color: var(--text-dim); }

/* ===== Toast ===== */
.toast-root { position: fixed; right: 20px; bottom: 46px; z-index: 900; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 260px; max-width: 360px; padding: 14px 18px; border-radius: var(--radius-btn);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 14px;
  box-shadow: 6px 6px 16px var(--shadow-dark), -6px -6px 16px var(--shadow-light);
}
.toast.success { border-left: 3px solid var(--income); }
.toast.error { border-left: 3px solid var(--expense); }
.toast.info { border-left: 3px solid var(--warn); }

/* ===== Статус-бар ===== */
.statusbar {
  height: 30px; display: flex; align-items: center; padding: 0 16px; gap: 8px;
  font-size: 12px; background: var(--surface-1); border-top: 1px solid var(--border); color: var(--text-dim);
}
.statusbar .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--income); }
.statusbar.offline { background: var(--warn); color: #1a1a1a; }
.statusbar.offline .dot { background: #1a1a1a; }

/* ===== Отчёты ===== */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 22px; }
.filters .field { margin-bottom: 0; }
.report-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.chart-wrap { padding: 20px; margin-bottom: 24px; }
#reportChart { width: 100%; height: 280px; display: block; }
.cat-bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 13px; }
.cat-bar-row .name { width: 220px; flex-shrink: 0; }
.cat-bar-track { flex: 1; height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 6px; }
.cat-bar-row .pct { width: 56px; text-align: right; color: var(--text-dim); }

/* Скроллбары */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

.row { display: flex; gap: 14px; }
.row > * { flex: 1; }
.muted { color: var(--text-dim); }
.mt-16 { margin-top: 16px; }

/* ===== Справочники, работники, архив ===== */
.badge.archived { background: rgba(127, 127, 127, 0.18); color: var(--text-dim); }

/* Галочка с подписью в одну строку (например «показывать архивных») */
.check-inline {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--text-dim); cursor: pointer; user-select: none;
}
.check-inline input { cursor: pointer; }

/* Строка справочника: название + счётчик использований + кнопки */
.dict-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.dict-row:last-child { border-bottom: none; }
.dict-row.archived-row { opacity: 0.6; }
.dict-name { flex: 1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dict-used { font-size: 12px; }
.dict-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Заголовок группы и «ничего не найдено» в выпадающем списке выбора */
.ac-group {
  padding: 8px 14px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-dim);
}
.ac-empty { padding: 12px 14px; font-size: 13px; color: var(--text-dim); }

/* ===== Исполнители работы и живой расчёт ===== */
.share-mode { margin-bottom: 12px; }
.share-mode button { font-size: 13px; }
.share-mode button.active { background: var(--accent); color: var(--accent-contrast); }
.share-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.share-row .select { flex: 1; }
.share-row .input { width: 120px; flex-shrink: 0; }
.share-calc {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-input);
  background: var(--surface-2); font-size: 14px;
}
.share-base { margin-bottom: 8px; font-size: 13px; }
.share-line { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.share-service { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 7px; }
.share-error { color: var(--expense); font-size: 13px; }

/* ===== Долги, выплаты, смена ===== */
.badge.overdue { background: rgba(248, 113, 113, 0.18); color: var(--expense); }
.overdue-row { background: rgba(248, 113, 113, 0.07); }
.card-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.card-stats > div {
  padding: 12px 14px; border-radius: var(--radius-input); background: var(--surface-2);
  display: flex; flex-direction: column; gap: 5px;
}
.card-stats span { font-size: 12px; }
.card-stats b { font-size: 17px; font-variant-numeric: tabular-nums; }
.debt-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-input);
  border: 1px solid var(--border); margin-bottom: 8px; font-size: 14px;
}
.debt-main { flex: 1; }
.shift-debts { max-height: 260px; overflow-y: auto; }

/* Плашка про долг при выплате: мимо неё пройти нельзя */
.debt-banner {
  margin: 4px 0 18px; padding: 14px 16px; border-radius: var(--radius-input);
  background: rgba(251, 191, 36, 0.12); border: 1px solid var(--warn);
}
.debt-banner-title { font-weight: 600; font-size: 15px; color: var(--warn); }
.debt-banner-sub { font-size: 12px; color: var(--expense); margin-top: 3px; }
.debt-banner-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.debt-banner-state { font-size: 12px; margin-top: 8px; }
