*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  /* Цвета */
  --c-bg:          #141414;
  --c-surface:     #0A0A0A;
  --c-accent:      #FFD300;
  --c-accent-hi:   #FFE04D;                  /* hover основной кнопки */
  --c-accent-soft: rgba(255, 211, 0, 0.08);  /* фон hover / активного пункта */
  --c-border:      rgba(255, 211, 0, 0.4);   /* рамки второстепенных элементов */
  --c-line:        rgba(255, 211, 0, 0.14);  /* разделители */
  --c-muted:       #A8943C;  /* подписи, пояснения — приглушённый жёлтый, контраст ~5.8:1 */
  --c-focus:       #FF8C00;
  --c-error:       #FF6B61;                  /* метка и полоса ошибки */
  --c-error-text:  #FFC1BC;                  /* текст ошибки, контраст ~11:1 */
  --c-error-soft:  rgba(255, 107, 97, 0.08);
  --c-error-line:  rgba(255, 107, 97, 0.3);

  /* Шкала размеров текста */
  --fs-xs:   0.75rem;    /* 12px — мелкие пометки */
  --fs-sm:   0.875rem;   /* 14px — подписи, пояснения, контент textarea */
  --fs-base: 0.9375rem;  /* 15px — основной текст, кнопки, поля */
  --fs-lg:   1.125rem;   /* 18px — название в боковом меню */
  --fs-xl:   1.5rem;     /* 24px — заголовки секций */

  --lh-tight: 1.2;
  --lh-body:  1.5;

  --control-h: 38px;
  --radius:    6px;
  --sidebar-w: 240px;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  background: var(--c-bg);
  color: var(--c-accent);
}

/* Поля ввода и кнопки в браузере не наследуют шрифт — задаём явно */
button, input, select, textarea {
  font: inherit;
  color: inherit;
}

h1, h2 {
  line-height: var(--lh-tight);
  font-weight: 700;
}

h2 { font-size: var(--fs-xl); }

/* — Раскладка: боковое меню + контент — */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 16px;
  background: var(--c-surface);
  border-right: 1px solid var(--c-line);
}

.brand {
  padding: 0 12px;
  margin-bottom: 28px;
  font-size: var(--fs-lg);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: flex-start;  /* длинный пункт переносится — маркер остаётся у первой строки */
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--c-muted);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 120ms, color 120ms;
}

/* Терминальный маркер «>» у активного пункта; место под него зарезервировано всегда */
.nav-link::before {
  content: '>';
  width: 2ch;
  flex-shrink: 0;
  visibility: hidden;
}

.nav-link:hover {
  color: var(--c-accent);
  background: var(--c-accent-soft);
}

.nav-link.is-active {
  color: var(--c-accent);
  background: var(--c-accent-soft);
}

.nav-link.is-active::before {
  visibility: visible;
}

.nav-link:focus-visible {
  outline: 2px solid var(--c-focus);
  outline-offset: 2px;
}

main {
  width: 100%;
  max-width: 1040px;
  padding: 40px 40px 80px;
}

section {
  scroll-margin-top: 24px;
}

section + section {
  margin-top: 40px;
}

section + section::before {
  content: '';
  display: block;
  height: 1px;
  background: var(--c-line);
  margin-bottom: 40px;
}

.section-desc {
  margin: 8px 0 24px;
  font-size: var(--fs-sm);
  color: var(--c-muted);
}

/* — Формы — */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 32px;
  margin-bottom: 20px;
}

.control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--c-muted);
}

.field {
  margin-bottom: 20px;
}

.field-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 16px;
  margin-bottom: 6px;
}

.field-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Переключатель вариантов (RU / EN) */
.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}

.segmented-btn {
  height: 22px;
  padding: 0 10px;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  background: transparent;
  color: var(--c-muted);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 120ms, color 120ms;
}

.segmented-btn:hover {
  color: var(--c-accent);
}

.segmented-btn[aria-pressed="true"] {
  background: var(--c-accent);
  color: var(--c-surface);
}

.segmented-btn:focus-visible {
  outline: 2px solid var(--c-focus);
  outline-offset: 2px;
}

.field-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

select {
  height: var(--control-h);
  padding: 0 36px 0 12px;
  font-size: var(--fs-base);
  background: var(--c-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23FFD300' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--c-accent);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  cursor: pointer;
  appearance: none;
  transition: border-color 120ms;
}

select:hover {
  border-color: var(--c-accent);
}

select option {
  background: var(--c-surface);
  color: var(--c-accent);
}

select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--c-focus);
  box-shadow: 0 0 0 3px rgba(255, 140, 0, 0.25);
}

#file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-sm);
  color: var(--c-muted);
}

/* — Кнопки — */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--control-h);
  padding: 0 20px;
  font-size: var(--fs-base);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  transition: background-color 120ms, border-color 120ms, color 120ms, box-shadow 120ms, transform 60ms;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--c-focus);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Основное действие секции — заливка */
.btn-primary {
  background: var(--c-accent);
  color: var(--c-surface);
  font-weight: 700;
}

.btn-primary:hover:not(:disabled) {
  background: var(--c-accent-hi);
  box-shadow: 0 0 0 4px rgba(255, 211, 0, 0.15);
}

/* Второстепенное действие — контур */
.btn-secondary {
  background: transparent;
  color: var(--c-accent);
  border-color: var(--c-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--c-accent-soft);
  border-color: var(--c-accent);
}

/* Инструменты у поля (копировать, сохранить) — без рамки */
.btn-ghost {
  background: transparent;
  color: var(--c-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--c-accent-soft);
  color: var(--c-accent);
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: var(--fs-sm);
}

/* — Текстовые поля — */

textarea {
  display: block;
  width: 100%;
  height: 33vh;
  resize: vertical;
  overflow-y: auto;
  padding: 12px 14px;
  font-size: var(--fs-sm);
  line-height: var(--lh-body);
  background: var(--c-accent);
  color: var(--c-surface);
  border: 1px solid transparent;
  border-radius: var(--radius);
}

textarea::placeholder {
  color: var(--c-surface);
  opacity: 0.55;
}

textarea::-webkit-scrollbar { width: 12px; }
textarea::-webkit-scrollbar-corner { background: #FFD300; }
textarea::-webkit-resizer { background: #FFD300 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12'%3E%3Cline x1='11' y1='3' x2='3' y2='11' stroke='%230A0A0A' stroke-width='1.5'/%3E%3Cline x1='11' y1='7' x2='7' y2='11' stroke='%230A0A0A' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center; }
textarea::-webkit-scrollbar-track { background: #FFD300; }
textarea::-webkit-scrollbar-thumb { background: #0A0A0A; }
textarea::-webkit-scrollbar-button { background: #FFD300; border: 1px solid #0A0A0A; height: 12px; }
textarea::-webkit-scrollbar-button:vertical:decrement { border-bottom: 6px solid #0A0A0A; border-left: 5px solid transparent; border-right: 5px solid transparent; }
textarea::-webkit-scrollbar-button:vertical:increment { border-top: 6px solid #0A0A0A; border-left: 5px solid transparent; border-right: 5px solid transparent; }

/* — Загрузка — */

#loader,
#report-loader {
  margin-bottom: 16px;
  font-size: var(--fs-sm);
}

/* Спиннер того же размера, что и текст рядом — моноширинная ширина не прыгает */
#spinner-char,
#report-spinner-char {
  display: inline-block;
  width: 1ch;
  font-weight: 700;
  color: var(--c-accent);
}

/* Пояснение внутри подписи поля */
.label-hint {
  font-weight: 400;
  opacity: 0.8;
}

/* Короткое поле для данных — не на треть экрана, как у диалога и промпта */
textarea.textarea-short {
  height: 140px;
}

/* — Ошибки — */

/* Текст ошибки JS кладёт через textContent, поэтому метка «ERROR» — псевдоэлемент */
.alert-error {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 14px;
  font-size: var(--fs-sm);
  line-height: var(--lh-body);
  color: var(--c-error-text);
  background: var(--c-error-soft);
  border: 1px solid var(--c-error-line);
  border-left: 3px solid var(--c-error);
  border-radius: var(--radius);
  white-space: pre-wrap;      /* многострочные сообщения сервера */
  overflow-wrap: anywhere;    /* длинные пути и URL не ломают раскладку */
  animation: alert-in 160ms ease-out;
}

.alert-error::before {
  content: 'ERROR';
  flex-shrink: 0;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: calc(var(--fs-sm) * 1.5);  /* метка на одной линии с первой строкой текста */
  color: var(--c-error);
}

@keyframes alert-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .alert-error { animation: none; }
}

/* — Страница расходов — */

a.btn { text-decoration: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  padding: 14px 16px;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
}

.stat-label {
  font-size: var(--fs-xs);
  color: var(--c-muted);
}

.stat-value {
  margin-top: 4px;
  font-size: var(--fs-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.table-title {
  margin: 28px 0 10px;
  font-size: var(--fs-base);
  font-weight: 700;
}

/* Широкая таблица на узком экране прокручивается внутри себя, а не всей страницей */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
}

/* Полоса прокрутки — как у textarea: жёлтая дорожка, чёрный ползунок, кнопки-стрелки */
.table-wrap::-webkit-scrollbar { height: 12px; }
.table-wrap::-webkit-scrollbar-track { background: #FFD300; }
.table-wrap::-webkit-scrollbar-thumb { background: #0A0A0A; }
.table-wrap::-webkit-scrollbar-button { background: #FFD300; border: 1px solid #0A0A0A; width: 12px; }
.table-wrap::-webkit-scrollbar-button:horizontal:decrement { border-right: 6px solid #0A0A0A; border-top: 5px solid transparent; border-bottom: 5px solid transparent; }
.table-wrap::-webkit-scrollbar-button:horizontal:increment { border-left: 6px solid #0A0A0A; border-top: 5px solid transparent; border-bottom: 5px solid transparent; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.data-table th,
.data-table td {
  padding: 8px 12px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--c-line);
}

.data-table th {
  font-weight: 500;
  color: var(--c-muted);
  background: var(--c-surface);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--c-accent-soft); }

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table .total { font-weight: 700; }

.data-table .empty {
  color: var(--c-muted);
  text-align: center;
}

/* — История — */

.history-list {
  list-style: none;
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.history-list:empty { display: none; }

.history-item + .history-item {
  border-top: 1px solid var(--c-line);
}

.history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 8px;
}

/* Вся строка — кнопка раскрытия; кнопка удаления стоит справа отдельно */
.history-toggle {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  min-width: 0;
  padding: 10px 12px;
  text-align: left;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color 120ms;
}

.history-toggle::before {
  content: '>';
  width: 1ch;
  color: var(--c-muted);
  transition: transform 120ms;
}

.history-toggle[aria-expanded="true"]::before {
  transform: rotate(90deg);
}

.history-toggle:hover { background: var(--c-accent-soft); }

.history-toggle:focus-visible {
  outline: 2px solid var(--c-focus);
  outline-offset: -2px;
}

.history-kind {
  padding: 1px 8px;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid var(--c-border);
  border-radius: 4px;
}

.history-kind-report {
  background: var(--c-accent);
  color: var(--c-surface);
  border-color: var(--c-accent);
}

.history-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.history-when {
  margin-left: auto;
  font-size: var(--fs-xs);
  color: var(--c-muted);
  white-space: nowrap;
}

.history-delete.is-armed {
  color: var(--c-error-text);
  background: var(--c-error-soft);
  box-shadow: inset 0 0 0 1px var(--c-error-line);
}

.history-delete.is-armed:hover:not(:disabled) {
  color: var(--c-error-text);
  background: var(--c-error-soft);
}

.history-body {
  padding: 4px 12px 12px calc(12px + 1ch + 12px);
}

.history-meta {
  margin-bottom: 12px;
  font-size: var(--fs-sm);
  color: var(--c-muted);
}

.history-text {
  height: 24vh;
}

.history-empty {
  margin-bottom: 12px;
  font-size: var(--fs-sm);
  color: var(--c-muted);
}

/* — Узкие экраны: меню уходит наверх полосой — */

@media (max-width: 760px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    height: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--c-line);
  }

  .brand {
    margin-bottom: 0;
    padding: 0;
  }

  .nav {
    flex-direction: row;
  }

  main {
    padding: 24px 16px 64px;
  }
}

@media (max-width: 760px) {
  .history-body { padding-left: 12px; }
  .history-when { margin-left: 0; }
}

/* — Пользователь внизу бокового меню — */

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

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding: 12px 0 0 12px;
  border-top: 1px solid var(--c-line);
}

.sidebar-user-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-sm);
  color: var(--c-muted);
}

@media (max-width: 760px) {
  .sidebar { flex-direction: row; }

  .sidebar-user {
    margin: 0 0 0 auto;
    padding: 0;
    border-top: none;
  }
}

/* — Страница входа — */

/* Терминал: чёрный экран, строки текста, ввод прямо в строке после приглашения */
main.terminal {
  max-width: none;
  min-height: 100vh;
  padding: 0;
  background: #000;
  cursor: text;
}

.terminal-screen {
  max-width: 760px;
  padding: 32px 24px;
  font-size: var(--fs-base);
  line-height: var(--lh-body);
}

.term-line {
  min-height: calc(var(--fs-base) * 1.5);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.term-muted { color: var(--c-muted); }
.term-error { color: var(--c-error); }

.term-hint {
  margin-top: 24px;
  font-size: var(--fs-xs);
  color: var(--c-muted);
  opacity: 0.7;
}

.term-input-line {
  display: flex;
  gap: 1ch;
}

/* Подпись-приглашение выглядит как обычный текст терминала, а не как label формы */
.term-prompt {
  flex-shrink: 0;
  font-size: inherit;
  font-weight: 400;
  color: var(--c-accent);
}

.term-input {
  flex: 1;
  min-width: 0;
  padding: 0;
  background: transparent;
  color: var(--c-accent);
  border: none;
  outline: none;
  caret-color: var(--c-accent);
  caret-shape: block;
}

/* Пароль не отображается: текст прозрачный, а узкое поле держит курсор на месте */
.term-input-secret {
  flex: 0 0 2ch;
  color: transparent;
}

/* Автозаполнение браузера не должно красить строку в белый/жёлтый фон */
.term-input:-webkit-autofill {
  -webkit-text-fill-color: var(--c-accent);
  transition: background-color 600000s;
}

.term-input-secret:-webkit-autofill {
  -webkit-text-fill-color: transparent;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
