:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1b1e27;
  --text-muted: #6b7280;
  --primary: #2f5233;
  --primary-hover: #24401f;
  --accent: #b8860b;
  --danger: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.topbar__brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  flex: none;
}

/* Название — ссылка на главную, но выглядеть должно как заголовок */
a.topbar__brand:hover { color: var(--primary); text-decoration: none; }

.topbar__nav {
  display: flex;
  gap: 4px;
  align-items: center;
}

.topbar__nav a {
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
}

.topbar__nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.topbar__nav a.active { background: var(--primary); color: #fff; }

.topbar__user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 4px;
}

.page-subtitle {
  color: var(--text-muted);
  margin: 0 0 28px;
  font-size: 0.95rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.card h2 {
  font-size: 1.05rem;
  margin: 0 0 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

tbody tr:hover { background: #fafbfc; }

.table-scroll { overflow-x: auto; }

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

.total-cell { font-weight: 700; }

form .field {
  margin-bottom: 16px;
}

form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

form input[type="text"],
form input[type="number"],
form input[type="date"],
form input[type="password"],
form select,
form textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  background: var(--surface);
  color: var(--text);
}

form input:focus, form select:focus, form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 82, 51, 0.15);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px 20px;
}

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn--secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn--secondary:hover { background: var(--bg); }
.btn--sm { padding: 5px 12px; font-size: 0.82rem; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}
.badge--ok { background: #e6f4ea; color: #1e7b34; }
.badge--warn { background: #fdf0e0; color: #a5580e; }

.messages { list-style: none; padding: 0; margin: 0 0 20px; }
.messages li {
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.9rem;
  background: #e6f4ea;
  color: #1e7b34;
  border: 1px solid #bfe3c9;
}
.messages li.error { background: #fbe9e7; color: var(--danger); border-color: #f3c6c1; }
.messages li.warning { background: #fdf0e0; color: #a5580e; border-color: #f2d5ac; }

.month-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}
.month-nav strong { font-size: 1.05rem; }

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.home-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.home-card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.home-card p { margin: 0 0 16px; color: var(--text-muted); font-size: 0.9rem; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px;
  width: 100%;
  max-width: 360px;
}

.login-card h1 { font-size: 1.2rem; margin: 0 0 24px; text-align: center; }

.delete-checkbox { display: none; }

.field-error {
  color: var(--danger);
  font-size: 0.76rem;
  margin-top: 4px;
  white-space: normal;
}

tr.entry-row--error { background: #fbe9e7; }

#entry-table select,
#entry-table input[type="number"],
#entry-table input[type="text"] {
  min-width: 90px;
  padding: 6px 8px;
}

#entry-table select[name$="-model"] { min-width: 220px; }
#entry-table select[name$="-operation"] { min-width: 240px; }
#entry-table select[name$="-size"] { min-width: 110px; }

.empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 24px 0;
  text-align: center;
}

/* Справочник сотрудников */
/* 1% + nowrap — таблица отдаёт колонке ровно ширину кнопок, а не делит поровну.
   Кнопки — inline-block, а не flex: flex на самой ячейке ломает раскладку таблицы. */
td.row-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

td.row-actions > * {
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
}

td.row-actions form { margin: 0; }

.btn--danger { color: var(--danger); border-color: #f3c6c1; }
.btn--danger:hover { background: #fbe9e7; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.field-hint {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}


/* Скрытые ячейки таблицы ввода: колонки брака и размер у аксессуаров */
#entry-table [hidden] { display: none; }

/* Обычная строка при видимых колонках брака — прочерк вместо полей */
td.cell--empty::after { content: '—'; color: var(--text-muted); }

/* Доплата за месяц: узкое поле суммы + широкий комментарий рядом */
.extra-pay { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.extra-pay .field { margin-bottom: 0; }
.extra-pay__amount { flex: 0 0 160px; }
.extra-pay__comment { flex: 1 1 320px; }

/* Прайс-лист: компактная таблица ставок */
.rate-block-title { font-size: 0.9rem; margin: 20px 0 8px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.rate-table input.rate-input { width: 100px; text-align: right; padding: 6px 9px; }
.rate-table td, .rate-table th { padding: 8px 12px; }

/* Список чекбоксов в формах (группы полноты) */
.checkbox-list > div { display: flex; gap: 18px; flex-wrap: wrap; }
.checkbox-list label { display: flex; align-items: center; gap: 7px; font-weight: 400; margin: 0; cursor: pointer; }
.checkbox-list input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }

/* Таблица ввода выработки: не даём выпадающим спискам сжиматься так,
   что подписи обрезаются — вместо этого таблица прокручивается вбок. */
#entry-table select,
#entry-table input[type="number"],
#entry-table input[type="text"] { min-width: 72px; }
#entry-table select[name$="-model"] { min-width: 165px; }
#entry-table select[name$="-operation"] { min-width: 180px; }
#entry-table select[name$="-production_type"] { min-width: 165px; }
#entry-table input[name$="-comment"] { min-width: 140px; }

/* Прайс-лист: карточка модели сворачивается через <details> — без JS */
.card--collapsible { padding-top: 0; padding-bottom: 0; }

.model-rates > summary { list-style: none; cursor: pointer; }
.model-rates > summary::-webkit-details-marker { display: none; }

.model-rates__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 0;
  user-select: none;
}

.model-rates__head:hover .model-rates__title { color: var(--primary); }

.model-rates__chevron {
  flex: none;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 6px;
  position: relative;
}

/* Галочка из двух линий: вниз у свёрнутой карточки, вверх у раскрытой.
   Вращаем саму галочку, а не рамку, иначе она уезжает из центра. */
.model-rates__chevron::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.15s ease;
}

.model-rates[open] > summary .model-rates__chevron::after {
  transform: translateY(2px) rotate(225deg);
}

.model-rates__head:hover .model-rates__chevron { border-color: var(--primary); }

.model-rates__title { font-size: 1.05rem; font-weight: 700; }

.model-rates__hint { margin-left: auto; font-size: 0.82rem; color: var(--text-muted); }
.model-rates__edit { flex: none; }

.model-rates[open] > summary { border-bottom: 1px solid var(--border); }

.model-rates > form { padding-bottom: 20px; }

/* Вкладки внутри раздела «Себестоимость» */
.subtabs {
  display: flex;
  gap: 6px;
  margin: -8px 0 24px;
  border-bottom: 1px solid var(--border);
}

.subtabs a {
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.subtabs a:hover { color: var(--text); text-decoration: none; }
.subtabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Конструктор состава изделия */
.costing-block { padding: 4px 0 20px; border-bottom: 1px solid var(--border); }
.costing-block:last-of-type { border-bottom: none; }

.usage-table select.usage-material { min-width: 260px; }
.usage-table input.usage-qty { width: 110px; text-align: right; }
.usage-table td, .usage-table th { padding: 8px 12px; }
.usage-table tr[hidden] { display: none; }

.costing-summary { max-width: 640px; }
.costing-summary td { padding: 7px 12px; }
.costing-summary__total td { border-top: 1px solid var(--border); font-size: 1rem; }

.costing-add-size { padding: 18px 0 20px; border-top: 1px solid var(--border); }

.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; }
.inline-form label { margin: 0; }
.inline-form select { width: auto; min-width: 160px; }

.costing-remove-size { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.costing-remove-size form { margin: 0; }

.costing-form { padding-bottom: 4px; }

/* Прайс-лист: заголовок блока и наценка на процент в одну строку */
.rate-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 20px 0 8px;
}

.rate-block-head .rate-block-title { margin: 0; }

.rate-raise {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.rate-raise label {
  margin: 0;
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Селектор из двух классов — иначе общее правило для input перебивает ширину */
.rate-raise .rate-raise__input {
  width: 76px;
  flex: none;
  text-align: right;
  padding: 5px 8px;
}

/* Фонд зарплаты: несколько крупных цифр в ряд */
.fund { display: flex; flex-wrap: wrap; gap: 12px 32px; margin-top: 12px; }
.fund__item { display: flex; flex-direction: column; gap: 4px; }
.fund__label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.fund__value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.fund__item--total .fund__value { color: var(--primary); font-size: 1.5rem; }

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

/* ---------- Телефон и планшет ---------- */

.topbar__burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 42px;
  height: 38px;
  padding: 0 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.topbar__burger span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

@media (max-width: 860px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 16px;
    gap: 10px;
  }

  .topbar__brand { font-size: 0.95rem; margin-right: auto; }
  .topbar__burger { display: flex; }

  /* Пока меню закрыто — его и блока пользователя просто нет в потоке */
  .topbar__nav,
  .topbar__user { display: none; }

  .topbar--open .topbar__nav,
  .topbar--open .topbar__user {
    display: flex;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }

  .topbar--open .topbar__nav a { padding: 11px 12px; }

  .topbar--open .topbar__user {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .container { padding: 20px 16px; }
  .page-title { font-size: 1.3rem; }

  /* Формы в две колонки складываются в одну */
  .form-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }

  /* Крупные цифры фонда — по две в ряд, а не в одну строку */
  .fund { gap: 12px 24px; }
  .fund__value { font-size: 1.1rem; }
  .fund__item--total .fund__value { font-size: 1.3rem; }

  /* Кнопки в строках таблиц перестают жаться */
  td.row-actions { white-space: normal; }
  td.row-actions > * { margin: 2px 0 2px 6px; }

  .month-nav { flex-wrap: wrap; }
  .subtabs { overflow-x: auto; }
  .rate-block-head { gap: 8px; }
}

@media (max-width: 560px) {
  .home-grid { grid-template-columns: 1fr; }
  .btn { padding: 10px 14px; }
  .rate-raise { width: 100%; justify-content: flex-start; }

  /* Переключатель месяца должен остаться одной строкой, а не тремя */
  .month-nav { flex-wrap: nowrap; justify-content: space-between; gap: 8px; }
  .month-nav .btn { padding: 8px 10px; font-size: 0.78rem; white-space: nowrap; }
  .month-nav strong { font-size: 0.95rem; text-align: center; }

  /* Подсказка: широкую таблицу можно листать вбок */
  .table-scroll { position: relative; }
  .table-scroll::-webkit-scrollbar { height: 8px; }
  .table-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
}

/* Таблица ввода выработки на телефоне: строка превращается в карточку,
   заголовки колонок становятся подписями слева от каждого поля. */
@media (max-width: 860px) {
  #entry-table thead { display: none; }

  #entry-table,
  #entry-table tbody,
  #entry-table tr.entry-row { display: block; width: 100%; }

  #entry-table tr.entry-row {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: var(--surface);
  }

  #entry-table tr.entry-row:hover { background: var(--surface); }

  #entry-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 6px 0;
    border: none;
    text-align: left;
  }

  #entry-table td[data-label]::before {
    content: attr(data-label);
    flex: none;
    font-size: 0.8rem;
    color: var(--text-muted);
  }

  #entry-table td select,
  #entry-table td input {
    width: auto;
    flex: 1 1 auto;
    max-width: 62%;
    min-width: 0;
  }

  /* Прочерк вместо поля выравниваем по правому краю, как само поле */
  #entry-table td.cell--empty { justify-content: space-between; }

  /* Кнопка «Убрать» — на всю ширину внизу карточки */
  #entry-table td:last-child { justify-content: flex-end; padding-top: 10px; }

  .table-scroll:has(#entry-table) { overflow-x: visible; }
}

/* Отключённая учётная запись — приглушённая строка */
tr.row--muted td { color: var(--text-muted); }

/* Прайс-лист: сохранение слева, удаление отдельно справа — чтобы не путать */
.model-rates__footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* Поле пароля с кнопкой-глазком справа */
.password-field { position: relative; display: block; }

/* Отступ справа — чтобы текст не заезжал под кнопку */
.password-field input { padding-right: 42px; }

.password-field__eye {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}

.password-field__eye:hover { color: var(--text); }

.password-field__eye:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  border-radius: 8px;
}
