:root {
  --bg: #f4f6f5;
  --card: #fff;
  --text: #1a2420;
  --muted: #5c6b66;
  --accent: #1a5f4a;
  --accent-light: #e8f3ef;
  --success: #2d8a5e;
  --danger: #c0392b;
  --border: #d8e0dc;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--accent);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.15rem;
}

.nav a {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  margin-left: 14px;
  font-size: .95rem;
}

.nav a.active, .nav a:hover { color: #fff; font-weight: 600; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.hero h1 { margin: 0 0 8px; font-size: 1.5rem; }
.muted { color: var(--muted); }
.hint { font-size: .85rem; color: var(--muted); }

.cards {
  display: grid;
  gap: 12px;
  margin: 20px 0;
}

@media (min-width: 600px) {
  .cards { grid-template-columns: 1fr 1fr; }
}

.card {
  display: block;
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-accent { border-color: var(--accent); background: var(--accent-light); }
.card h2 { margin: 8px 0 4px; font-size: 1.2rem; }
.card-icon { font-size: 2rem; }

.brigade-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.brigade-list li {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.badge {
  background: var(--accent-light);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: .85rem;
}

.form label {
  display: block;
  margin-bottom: 14px;
  font-weight: 500;
  font-size: .9rem;
}

.form input, .form select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.form-inline label { margin: 0; flex: 1; min-width: 140px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-text { background: none; color: var(--accent); padding: 4px 8px; font-weight: 500; }
.btn-block { width: 100%; }
.btn-lg { padding: 16px; font-size: 1.1rem; }

.hidden { display: none !important; }
.error { color: var(--danger); }
.status { text-align: center; font-size: .9rem; color: var(--muted); min-height: 1.2em; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar h1 { margin: 0; font-size: 1.2rem; }

.quick-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.quick-actions .btn { flex: 1; }

.stats {
  font-size: .95rem;
  margin: 0 0 12px;
  padding: 10px;
  background: var(--accent-light);
  border-radius: 8px;
}

.employee-list {
  list-style: none;
  padding: 0;
  margin: 0 0 100px;
}

.employee-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
}

.employee-row.marked-present { border-color: var(--success); }
.employee-row.marked-absent { border-color: var(--danger); }
.employee-row.marked-other { border-color: #e67e22; }

.emp-info { display: flex; gap: 10px; flex: 1; min-width: 0; }
.emp-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.emp-name { font-weight: 600; font-size: .95rem; }
.emp-position { font-size: .8rem; }

.mark-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.mark-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}

.mark-btn.present.active { background: var(--success); color: #fff; border-color: var(--success); }
.mark-btn.absent.active { background: var(--danger); color: #fff; border-color: var(--danger); }

.mark-other {
  width: 48px;
  padding: 8px 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: .85rem;
}

.sticky-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.95);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.summary-bar {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--card);
  border-radius: 8px;
  font-size: .9rem;
}

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.timesheet {
  border-collapse: collapse;
  font-size: .75rem;
  width: max-content;
  min-width: 100%;
}

.timesheet th, .timesheet td {
  border: 1px solid var(--border);
  padding: 4px 3px;
  text-align: center;
  min-width: 26px;
}

.timesheet th {
  background: var(--accent-light);
  font-weight: 600;
  position: sticky;
  top: 0;
}

.timesheet th.name-col, .timesheet td.name-col {
  text-align: left;
  min-width: 140px;
  max-width: 180px;
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 2;
  padding-left: 8px;
}

.timesheet thead th.name-col { background: var(--accent-light); z-index: 3; }

.timesheet td.cell-clickable { cursor: pointer; }
.timesheet td.cell-clickable:hover { background: #fff9e6; }

.timesheet td.code-ya, .timesheet td.code-8 { background: #d4edda; font-weight: 700; }
.timesheet td.code-n { background: #f8d7da; font-weight: 700; }
.timesheet td.code-b { background: #fff3cd; }
.timesheet td.code-o { background: #cce5ff; }
.timesheet td.code-v { background: #e2e3e5; }

.timesheet .weekend { color: var(--danger); }
.timesheet tfoot td { font-weight: 700; background: #f8f9fa; }

.summary-cards {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 500px) {
  .summary-cards { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

.summary-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.summary-card h3 { margin: 0 0 8px; font-size: 1rem; }
.summary-card .nums { display: flex; gap: 12px; font-size: .85rem; }
.summary-card .nums span strong { display: block; font-size: 1.3rem; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
}

.modal-box {
  position: relative;
  background: #fff;
  width: 100%;
  max-width: 400px;
  border-radius: 16px 16px 0 0;
  padding: 20px;
  max-height: 80vh;
  overflow-y: auto;
}

@media (min-width: 500px) {
  .modal { align-items: center; }
  .modal-box { border-radius: 16px; }
}

.code-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.code-grid button {
  padding: 14px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.code-grid button:hover { background: var(--accent-light); }

.sub-tabs { margin-bottom: 12px; }
.sub-tabs .tab { font-size: .9rem; padding: 8px; }

.card-form {
  background: var(--card);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.section-title { margin: 16px 0 10px; font-size: 1.05rem; }

.settings-list {
  list-style: none;
  padding: 0;
  margin: 0 0 80px;
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--card);
  padding: 12px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.settings-fields {
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-fields input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
}

.btn-save-emp, .btn-save-admin-emp {
  padding: 8px 12px;
  font-size: .85rem;
}

.admin-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.admin-card h2 { margin: 0 0 12px; font-size: 1.15rem; }
.admin-card h3 { margin: 16px 0 8px; font-size: .95rem; color: var(--muted); }

.admin-status {
  display: inline-block;
  margin-left: 8px;
  font-size: .85rem;
  color: var(--muted);
}

#view-settings { margin-bottom: 24px; }

/* Дашборд — сводка за день */
.day-totals { margin-bottom: 20px; }

.totals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.total-box {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}

.total-box strong {
  display: block;
  font-size: 1.6rem;
  line-height: 1.2;
}

.total-box span {
  font-size: .7rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.total-danger { border: 2px solid #e74c3c; background: #fdf2f2; }
.total-danger strong { color: #c0392b; }
.total-success { border: 2px solid var(--success); background: #edf9f1; }
.total-success strong { color: var(--success); }
.total-warn strong { color: #e67e22; }
.total-muted strong { color: var(--muted); }

.day-section { margin: 24px 0; }

.day-section-title {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.absent-title { color: #c0392b; }

.count-badge {
  display: inline-block;
  background: #e74c3c;
  color: #fff;
  font-size: .85rem;
  padding: 2px 10px;
  border-radius: 20px;
  vertical-align: middle;
}

.day-hint { margin: 0 0 14px; }

.day-people-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brigade-group-title {
  margin: 16px 0 8px;
  font-size: 1rem;
  color: var(--accent);
  border-bottom: 2px solid var(--accent-light);
  padding-bottom: 4px;
}

.brigade-group-title:first-child { margin-top: 0; }

.person-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border-radius: 12px;
  border-left: 4px solid #ccc;
  box-shadow: 0 1px 6px rgba(0,0,0,.05);
}

.person-row.person-absent { border-left-color: #e74c3c; background: #fff8f8; }
.person-row.person-empty { border-left-color: #f39c12; background: #fffbf5; }
.person-row.person-other { border-left-color: #95a5a6; }

.person-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.person-num {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: .85rem;
  flex-shrink: 0;
}

.person-name { font-weight: 700; font-size: .95rem; }
.person-brigade { font-size: .75rem; color: var(--muted); }
.person-position { font-size: .8rem; color: var(--muted); }

.person-status {
  flex-shrink: 0;
  font-weight: 700;
  font-size: .85rem;
  padding: 6px 10px;
  border-radius: 8px;
  background: #eee;
}

.person-absent .person-status { background: #fdecea; color: #c0392b; }
.person-empty .person-status { background: #fff3cd; color: #856404; }

.day-collapse {
  margin-top: 24px;
  background: var(--card);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.day-collapse summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--success);
}

.day-people-list.compact .person-row {
  padding: 8px 12px;
}

.summary-card.has-absent {
  border: 2px solid #f5c6cb;
}

.summary-card .num-miss strong { color: #c0392b; }
.summary-card .num-ok strong { color: var(--success); }

.empty-day-msg {
  text-align: center;
  padding: 24px;
  color: var(--success);
  font-weight: 600;
}
