/* Агент Финансы — тёмная тема админки (раздел 10.5 плана).
   Адаптив под телефон, аккуратная типографика, без анимационных излишеств. */

:root {
  --bg:      #0f1115;
  --surface: #1a1d23;
  --surface2:#22262e;
  --border:  #2a2f3a;
  --text:    #e7e9ee;
  --muted:   #98a0ad;
  --accent:  #4c8dff;
  --green:   #4caf50;
  --red:     #ef5350;
  --radius:  14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 16px 60px;
}

/* --- Шапка --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.topbar h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 650;
}
.topbar .sub { color: var(--muted); font-size: 13px; }

.btn {
  display: inline-block;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: #ffb4b4; }

/* --- Панель фильтров --- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 18px;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  padding: 7px 14px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  border-right: 1px solid var(--border);
}
.seg label:last-of-type { border-right: none; }
.seg input:checked + label { background: var(--accent); color: #fff; }
.filters .custom { display: flex; gap: 6px; }
.filters input[type=date], .filters select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 14px;
}
.filters .spacer { flex: 1; }
.filters .who { color: var(--muted); font-size: 13px; margin-right: 2px; }

/* --- Карточки-итоги --- */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.card .value { font-size: 22px; font-weight: 650; white-space: nowrap; }
.card .value.green { color: var(--green); }
.card .value.red { color: var(--red); }

/* --- Блоки графиков --- */
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.panel.full { grid-column: 1 / -1; }
.panel h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; color: var(--text); }
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 320px; }

/* --- Легенда пончика --- */
.donut-wrap { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.donut-canvas { position: relative; width: 240px; height: 240px; flex: 0 0 auto; }
.legend { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 6px; }
.legend .row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.legend .dot { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.legend .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .am { color: var(--muted); white-space: nowrap; }
.legend .pc { color: var(--muted); width: 46px; text-align: right; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* --- Таблица последних операций --- */
.tx { width: 100%; border-collapse: collapse; font-size: 14px; }
.tx th {
  text-align: left; color: var(--muted); font-weight: 500;
  padding: 8px 8px; border-bottom: 1px solid var(--border); font-size: 12px;
  text-transform: uppercase; letter-spacing: .03em;
}
.tx td { padding: 9px 8px; border-bottom: 1px solid var(--border); }
.tx tr:last-child td { border-bottom: none; }
.tx .amt { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx .amt.income { color: var(--green); }
.tx .amt.expense { color: var(--red); }
.tx .cmt { color: var(--muted); }
.tx .date { color: var(--muted); white-space: nowrap; }

/* --- Логин --- */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px 24px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%; background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 15px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.login-card .btn-primary { width: 100%; padding: 11px; font-size: 15px; }
.error {
  background: rgba(239,83,80,.12); border: 1px solid rgba(239,83,80,.4);
  color: #ffb4b4; border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px;
}

/* --- Навигация в шапке --- */
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.nav { display: inline-flex; gap: 4px; }
.nav a {
  padding: 7px 12px; border-radius: 10px; font-size: 14px;
  color: var(--muted); border: 1px solid transparent;
}
.nav a:hover { background: var(--surface2); color: var(--text); }
.nav a.active { background: var(--surface2); color: var(--text); border-color: var(--border); }

/* --- Флеш-сообщения --- */
.flash {
  border-radius: 10px; padding: 10px 14px; font-size: 14px; margin-bottom: 14px;
}
.flash.ok { background: rgba(76,175,80,.12); border: 1px solid rgba(76,175,80,.4); color: #b9e6bb; }
.flash.err { background: rgba(239,83,80,.12); border: 1px solid rgba(239,83,80,.4); color: #ffb4b4; }

/* --- Доп. поля фильтров/форм --- */
.filters .mini { color: var(--muted); font-size: 13px; }
.filters .search {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 10px; font-size: 14px; min-width: 190px; flex: 1;
}
.filters input[type=color] {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; width: 42px; height: 36px; padding: 3px; cursor: pointer;
}
.filters .emoji-in { width: 90px; }
.addcat .search { flex: 2; }

/* --- Кнопки-иконки в таблице --- */
.tx .act { white-space: nowrap; text-align: right; }
.icon {
  background: none; border: none; cursor: pointer; font-size: 17px;
  padding: 3px 6px; border-radius: 8px; line-height: 1;
}
.icon:hover { background: var(--surface2); }
.btn.disabled { opacity: .4; pointer-events: none; }

/* --- Таблица категорий --- */
.tx.cats .ord { width: 70px; color: var(--muted); text-align: center; }
.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 6px;
  border: 1px solid var(--border); vertical-align: middle; }
tr.archived { opacity: .5; }
.tag {
  font-size: 11px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 6px; padding: 1px 6px; margin-left: 4px; text-transform: uppercase;
}

/* --- Палитра эмодзи (выбор мышкой) --- */
.emoji-palette { display: flex; flex-wrap: wrap; gap: 5px; align-items: center;
  margin: 0 0 18px; }
.emoji-palette .pal-label { color: var(--muted); font-size: 13px; margin-right: 4px; }
.emoji-palette button {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  font-size: 18px; line-height: 1; padding: 5px 7px; cursor: pointer;
}
.emoji-palette button:hover { border-color: var(--accent); }
.modal .emoji-palette { margin: 8px 0 0; }

/* --- Пагинация --- */
.pager { display: flex; align-items: center; gap: 12px; justify-content: center;
  margin-top: 16px; }
.pager .pageinfo { color: var(--muted); font-size: 14px; }

/* --- Модальные окна --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal-overlay.open { display: flex; }
.modal {
  width: 100%; max-width: 440px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 22px 20px;
}
.modal h2 { font-size: 18px; margin: 0 0 16px; }
.modal .field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.modal .field .hint { font-size: 12px; opacity: .8; }
.modal .field input, .modal .field select {
  width: 100%; background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 15px;
}
.modal .field input[type=color] { height: 42px; padding: 4px; cursor: pointer; }
.modal .field input:focus, .modal .field select:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.field .hint { color: var(--muted); }

/* --- Адаптив под телефон --- */
@media (max-width: 860px) {
  .panels { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .card .value { font-size: 19px; }
  .topbar h1 { font-size: 18px; }
  .donut-canvas { margin: 0 auto; }
  .filters { gap: 8px; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .nav { flex-wrap: wrap; }
}
