/* === Базовые сбросы и переменные === */
* { box-sizing: border-box; }

:root {
  --green: #4F6228;
  --green-dark: #3a4a1e;
  --green-light: #eef3e6;
  --green-soft: #f5f8ef;
  --red: #b00020;
  --grey: #6b6b6b;
  --grey-light: #9a9a9a;
  --border: #d4d4d4;
  --bg: #f3f5ee;
  --white: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.10);
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  color: #1f1f1f;
  background: var(--bg);
}

/* === Шапка === */
header {
  background: var(--green);
  color: #fff;
  padding: 14px 16px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.header-user {
  font-size: 14px;
  opacity: 0.92;
}

nav {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

nav a {
  color: #fff;
  text-decoration: none;
  font-size: 15px;
  padding: 6px 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  transition: background 0.15s;
}

nav a:hover { background: rgba(255, 255, 255, 0.25); }
nav a.active { background: rgba(255, 255, 255, 0.32); font-weight: 600; }
nav a.logout { margin-left: auto; background: rgba(0, 0, 0, 0.18); }

/* === Контент === */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* === Карточка-секция === */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card.invalid {
  border: 2px solid var(--red);
  animation: shake 0.3s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.card-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--green);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--green-light);
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.card-hint {
  font-size: 13px;
  font-weight: 400;
  color: var(--grey-light);
}

/* === Сетка полей === */
.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
}

label {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 6px;
  color: #2a2a2a;
}

.req { color: var(--red); }

input[type="text"], input[type="date"], input[type="password"], textarea {
  width: 100%;
  padding: 12px;
  font-size: 17px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-family: inherit;
  color: #1f1f1f;
  -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="date"] { min-height: 46px; }

input:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-light);
}

::placeholder { color: #a8a8a8; }

/* === Списки повторяющихся строк === */
.repeat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.repeat-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.repeat-row input[type="text"] {
  flex: 1;
}

/* === Строка рабочего с КТУ === */
.crew-row input[type="text"] { flex: 1; }

.ktu-select {
  flex: 0 0 auto;
  width: 100px;
  padding: 12px 8px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f5f8ef;
  color: var(--green-dark);
  font-family: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%234F6228' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}

.ktu-select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-light);
}

.pair-row .pair-what { flex: 2; }
.pair-row .pair-qty { flex: 1; max-width: 140px; }

.btn-del {
  flex: 0 0 auto;
  width: 44px;
  background: #fde8e8;
  color: var(--red);
  border: 1px solid #f5c2c2;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-del:hover { background: #f8d0d0; }

.btn-add {
  display: block;
  width: 100%;
  padding: 10px;
  background: var(--green-soft);
  color: var(--green);
  border: 1px dashed var(--green);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-add:hover { background: var(--green-light); }

/* === Кнопка отправки === */
.btn-submit {
  width: 100%;
  margin-top: 8px;
  padding: 16px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  background: var(--green);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.15s, transform 0.05s;
}

.btn-submit:hover { background: var(--green-dark); }
.btn-submit:active { transform: translateY(1px); }

.hint {
  margin: 14px 0 4px;
  font-size: 13px;
  color: var(--grey);
  text-align: center;
}

/* === Алерты === */
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 15px;
}

.alert-error {
  background: #fde8e8;
  border: 1px solid #f5c2c2;
  color: var(--red);
}

.alert-success {
  background: #e8f6e8;
  border: 1px solid #bfe3bf;
  color: #1f5a1f;
}

/* === Экран подтверждения === */
.summary {
  margin-top: 14px;
  background: var(--white);
  padding: 16px;
  border-radius: var(--radius);
  font-size: 16px;
  box-shadow: var(--shadow);
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.btn {
  flex: 1;
  display: block;
  text-align: center;
  padding: 14px;
  background: var(--green);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
  transition: background 0.15s;
}

.btn:hover { background: var(--green-dark); }
.btn:active { background: var(--green-dark); }

.btn-ghost {
  background: var(--white);
  color: var(--green);
  border: 2px solid var(--green);
}

.btn-ghost:hover { background: var(--green-light); }

/* === Логин === */
.login-page main {
  min-height: calc(100vh - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 40px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--white);
  border-radius: 14px;
  padding: 32px 24px;
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  color: var(--green);
  text-align: center;
}

.login-card .subtitle {
  margin: 0 0 18px;
  text-align: center;
  color: var(--grey);
  font-size: 14px;
}

.login-card form { box-shadow: none; padding: 0; }
.login-card label { margin-top: 16px; }

/* === Страница 403 === */
.error-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}

.error-card h1 {
  margin: 0 0 12px;
  color: var(--red);
  font-size: 22px;
}

.error-card p { margin: 8px 0; color: #333; }

/* === Таблица истории === */
.table-wrap {
  overflow-x: auto;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
  min-width: 900px;
}

th, td {
  border: 1px solid #e5e5e5;
  padding: 8px;
  text-align: left;
  vertical-align: top;
  word-wrap: break-word;
}

th {
  background: var(--green);
  color: #fff;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Закреплённые колонки в истории отчётов:
   № (слева) и Действия/✏️ (справа) видны при горизонтальном скролле. */
th.col-num, td.col-num {
  position: sticky;
  left: 0;
  z-index: 1;
}
th.col-actions, td.col-actions {
  position: sticky;
  right: 0;
  z-index: 1;
}
th.col-num, th.col-actions { z-index: 3; }   /* угол: поверх sticky-строки */
/* Фоны чтобы под скроллящейся строкой не просвечивал соседний текст */
td.col-num { background: #fff; }
td.col-actions { background: #fff; }
tr:nth-child(even) td.col-num,
tr:nth-child(even) td.col-actions { background: #fafafa; }

tr:nth-child(even) td { background: #fafafa; }

.empty {
  background: var(--white);
  padding: 24px;
  border-radius: var(--radius);
  text-align: center;
  font-size: 16px;
  box-shadow: var(--shadow);
}

/* === Бейджи для истории входов === */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-in {
  background: #e3f2fd;
  color: #1565c0;
}

.badge-out {
  background: #fce4ec;
  color: #c62828;
}

code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
}

/* === Адаптив: на узких экранах парные поля растягиваются === */
@media (max-width: 480px) {
  .pair-row { flex-wrap: wrap; }
  .pair-row .pair-what,
  .pair-row .pair-qty { max-width: none; flex: 1 1 100%; }
  .pair-row .btn-del { width: 100%; }
}

/* === Справочник === */
.dir-add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.dir-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dir-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: #fafafa;
  border-radius: 6px;
  border: 1px solid #eee;
}

.dir-value {
  font-size: 15px;
  word-break: break-word;
}

.dir-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 8px;
}

.dir-edit-btn,
.dir-del-btn {
  width: 34px;
  height: 34px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.dir-edit-btn:hover { background: #e8f0fe; }
.dir-del-btn:hover { background: #fde8e8; }

.dir-edit-input {
  flex: 1;
  padding: 6px 10px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* === user-line в success === */
.user-line {
  font-size: 14px;
  opacity: 0.92;
  margin-top: 4px;
}

/* === Успех === */
.success {
  font-size: 18px;
  font-weight: 600;
  color: var(--green);
  margin-bottom: 8px;
}

/* === Фотографии === */
.photo-upload-area {
  margin-top: 4px;
}

.photo-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.photo-existing {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.photo-thumb {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #e0e0e0;
  background: #f5f5f5;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-thumb .photo-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 10px;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.photo-del-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(200, 0, 0, 0.85);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.photo-del-btn:hover {
  background: rgba(180, 0, 0, 0.95);
}

/* === Комбобокс: видимый выпадающий список подсказок === */
.combo-dropdown {
  position: absolute;
  z-index: 1000;
  display: none;
  max-height: 280px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: 16px;
  -webkit-overflow-scrolling: touch;
}

.combo-dropdown.open {
  display: block;
}

.combo-option {
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  line-height: 1.3;
  word-break: break-word;
}

.combo-option:last-child {
  border-bottom: none;
}

.combo-option:hover,
.combo-option.active {
  background: var(--green-light);
  color: var(--green-dark);
}

.combo-empty {
  padding: 12px 14px;
  color: var(--grey);
  font-style: italic;
  font-size: 15px;
}

/* Большая зона тапа на телефоне */
@media (max-width: 600px) {
  .combo-dropdown {
    font-size: 17px;
    max-height: 240px;
  }
  .combo-option {
    padding: 14px 16px;
  }
}

/* Индикатор выпадающего списка на полях */
input[list] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%239a9a9a' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
