:root{
  --bg:          oklch(0.97 0.006 80);
  --surface:     #fff;
  --text:        oklch(0.24 0.01 80);
  --muted:       oklch(0.55 0.01 80);
  --muted-2:     oklch(0.6 0.01 80);
  --muted-3:     oklch(0.62 0.01 80);
  --line:        oklch(0.91 0.006 80);
  --line-soft:   oklch(0.94 0.006 80);
  --line-softer: oklch(0.96 0.006 80);
  --line-header: oklch(0.9 0.006 80);
  --accent:      oklch(0.5 0.14 45);
  --accent-hover:oklch(0.42 0.14 45);
  --accent-border: oklch(0.58 0.14 45);
  --dark:        oklch(0.24 0.01 80);
  --danger:      oklch(0.5 0.14 25);
  --weekend-bg:  oklch(0.985 0.012 45);
  --weekday-bg:  oklch(0.99 0.003 80);
  --radius-lg:   16px;
  --radius-md:   10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 { font-weight: 700; margin: 0 0 16px; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2, h3 { font-size: 16px; }

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

/* ---------- Навигация: боковая панель (≥880px) и полоса с меню (телефон) ---------- */
:root { --nav-w: 232px; }

.sidenav {
  position: fixed; inset: 0 auto 0 0; width: var(--nav-w); z-index: 10;
  display: flex; flex-direction: column; gap: 20px; padding: 24px 14px 18px;
  background: var(--surface); border-right: 1px solid var(--line-header); overflow-y: auto;
}
/* Логотип как на aptera.estate: арка #9C3B2E + «Aptera» с засечками */
.brand { display: inline-flex; align-items: center; gap: 10px; padding: 0 10px; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark { flex: none; width: 17px; height: 23px; color: #9C3B2E; transition: transform .4s cubic-bezier(.22,1,.36,1); }
.brand:hover .brand-mark { transform: translateY(-2px); }
.brand-word { display: grid; font-family: "Spectral", Georgia, "Times New Roman", serif; font-size: 23px; font-weight: 400;
  line-height: .95; letter-spacing: .01em; }
.brand-word small { margin-top: 4px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 9px; font-weight: 600; letter-spacing: .32em; text-transform: uppercase; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .brand-mark { transition: none; } }

.nav-section + .nav-section { margin-top: 18px; }
.nav-title { margin: 0 0 4px; padding: 0 10px; font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; }
.nav-section ul { list-style: none; margin: 0; padding: 0; }
.nav-section a {
  display: flex; align-items: center; min-height: 36px; padding: 0 10px; border-radius: 8px;
  color: var(--text); font-size: 14px; font-weight: 500; text-decoration: none;
}
.nav-section a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav-section a[aria-current="page"] { background: var(--bg); font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }
.nav-section a:focus-visible, .brand:focus-visible, .mobile-menu summary:focus-visible { outline: 2px solid var(--dark); outline-offset: 2px; }

.nav-user { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 10px 0; border-top: 1px solid var(--line-soft); font-size: 13px; }
.user-name { color: var(--muted); }
.logout-form { display: inline; margin: 0; }
.logout-form button { background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; padding: 4px 0; }
.logout-form button:hover { color: var(--text); }

.mobilebar { display: none; }

.container {
  max-width: 1360px;
  padding: 40px 40px 80px;
}
body.has-nav .container { margin-left: var(--nav-w); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.flash { margin-bottom: 16px; }
.flash-error { color: var(--danger); }
.flash-success { color: var(--text); }

/* ---------- Логин ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-card {
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.login-card form { display: flex; flex-direction: column; gap: 8px; }

.login-card label { font-size: 13px; color: var(--muted); margin-top: 8px; }

.login-card input, .login-card select {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  font: inherit;
  background: var(--surface);
  color: var(--text);
}

.login-card button {
  margin-top: 16px;
  padding: 10px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--dark);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Дежурства: общая раскладка ---------- */
.duty-header { margin-bottom: 28px; }
.duty-header h1 { font-size: 28px; margin-bottom: 6px; }
.duty-subtitle { margin: 0; font-size: 14px; color: var(--muted); }

.duty-layout {
  display: flex;
  gap: 28px;
  align-items: flex-start;
}

.duty-main { flex: 1; min-width: 0; width: 100%; }

.duty-side {
  width: 300px;
  flex: none;
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.duty-for-user {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 14px;
  color: var(--muted);
}

.duty-for-user select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  min-width: 180px;
}

.month-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}

.month-nav { display: flex; align-items: center; gap: 14px; }

.month-nav-title { font-size: 18px; font-weight: 700; }

.month-nav-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line-header);
  background: var(--surface);
  color: var(--muted-2);
  font-size: 15px;
  text-decoration: none;
}

.month-nav-arrow.disabled { color: var(--line); border-color: var(--line-softer); }

.duty-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.duty-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: oklch(0.95 0.03 45);
  border: 1px solid oklch(0.85 0.05 45);
}

/* ---------- Календарь (десктоп) ---------- */
.month-card { padding: 20px; margin-bottom: 24px; }

.weekday-header {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 0.8fr)) repeat(2, minmax(0, 1.3fr));
  margin-bottom: 6px;
}

.weekday-label {
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 6px 0;
}

.weekday-label.is-weekend { color: var(--accent); }

.month-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 0.8fr)) repeat(2, minmax(0, 1.3fr));
  gap: 6px;
}

.day-cell {
  min-height: 128px;
  min-width: 0;
  overflow: hidden;
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.day-cell form { margin: 0; padding: 0; }

.day-cell.weekday { background: var(--weekday-bg); }

.day-cell.weekend { background: var(--weekend-bg); }

.day-cell.weekend.other-month { background: var(--weekday-bg); }

.day-number { font-size: 12.5px; }

.day-cell.weekday .day-number { font-weight: 500; color: var(--muted-2); }

.day-cell.weekend .day-number { font-weight: 700; color: var(--text); }

.other-month-label {
  font-weight: 400;
  font-size: 10.5px;
  color: var(--muted);
  margin-left: 3px;
  text-transform: lowercase;
}

.avatar {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  flex: none;
}

.avatar-sm { width: 20px; height: 20px; font-size: 10px; }

.slot-pill {
  align-self: flex-start;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 3px 7px;
  border-radius: 12px;
  border: 1px dashed oklch(0.7 0.1 45);
  background: transparent;
  font: inherit;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.slot-pill.past {
  border-style: dashed;
  border-color: var(--line);
  color: var(--muted);
  cursor: default;
}

.grid-slot-taken {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.slot-name {
  font-size: 10.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.cancel-form { display: inline-flex; margin: 0 0 0 auto; flex: none; }

.cancel-btn, .merged-cancel-btn {
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  color: var(--muted-3);
  padding: 0 0 0 4px;
  font-size: 11px;
  line-height: 1;
}

.take-day-link {
  align-self: flex-start;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.merged-block {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 7px;
  padding: 5px 6px;
}

.merged-name {
  font-size: 11px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.merged-cancel-form { margin: 0 0 0 auto; flex: none; }

/* ---------- Мобильная agenda ---------- */
.weekend-agenda { display: none; }

.weekend-agenda-card { margin-bottom: 14px; }

.weekend-agenda-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.weekend-agenda-head h3 { margin: 0; font-size: 16px; }
.weekend-agenda-head form { margin: 0; }

.pill-btn-outline {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--accent-border);
  background: transparent;
  font: inherit;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn-muted {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: transparent;
  font: inherit;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.weekend-agenda-days {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.agenda-day-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 10px;
}

.agenda-merged {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--radius-md);
}

.agenda-merged-left { display: flex; align-items: center; gap: 10px; }
.agenda-merged-left form { margin: 0; }

.agenda-merged-name { font-size: 13.5px; font-weight: 600; }
.agenda-merged-sub { font-size: 11px; color: var(--muted); }

.agenda-slot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

.agenda-slot-row form { margin: 0; }

.agenda-slot-time {
  font-size: 12px;
  color: var(--muted-3);
  font-family: ui-monospace, Menlo, monospace;
}

.agenda-slot-past { font-size: 12px; color: var(--muted); }

.agenda-slot-person { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.agenda-slot-person form { margin: 0; }

.pill-btn-take {
  padding: 6px 13px;
  border-radius: 16px;
  border: 1px solid oklch(0.58 0.14 45 / 0.45);
  background: transparent;
  font: inherit;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.text-link-btn {
  border: none;
  background: none;
  font: inherit;
  color: var(--muted-3);
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.text-link-btn.small { font-size: 12.5px; text-decoration: none; padding: 0 0 0 2px; }

/* ---------- Сайдбар ---------- */
.export-btn {
  display: block;
  text-align: center;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--dark);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.export-btn:hover { color: #fff; text-decoration: none; opacity: .92; }

.duty-side .card { padding: 22px 24px; }
.duty-side h3 { font-size: 16px; margin-bottom: 16px; }

.balance-header {
  display: grid;
  grid-template-columns: 1fr 44px 44px 44px;
  gap: 6px 8px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
}

.balance-header span:not(:first-child) { text-align: right; }

.balance-row {
  display: grid;
  grid-template-columns: 1fr 44px 44px 44px;
  gap: 6px 8px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-softer);
}

.balance-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.balance-num { text-align: right; font-size: 13px; }
.balance-num.muted { color: var(--muted-2); }

.muted-note { color: var(--muted-2); font-size: 11.5px; margin: 14px 0 0; }

/* ---------- /users ---------- */
.counters-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.counters-table th, .counters-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line-soft);
}

.counters-table th { color: var(--muted); font-weight: 600; white-space: nowrap; }

.inline-edit-form {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin: 0 4px 0 0;
}

.inline-edit-form input {
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  width: 90px;
}

.inline-edit-form button {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font: inherit;
}

.add-user-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.add-user-form label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  color: var(--muted);
  gap: 4px;
}

.add-user-form input, .add-user-form select {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  font: inherit;
}

.add-user-form button {
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--dark);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Мобильная версия (<880px) ---------- */
@media (max-width: 880px) {
  .sidenav { display: none; }
  .mobilebar {
    position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line-header);
  }
  .mobilebar .brand { padding: 0; }
  .mobilebar .brand-mark { width: 15px; height: 20px; }
  .mobilebar .brand-word { font-size: 21px; }
  .mobile-menu summary {
    display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; list-style: none; cursor: pointer;
    border: 1px solid var(--line); border-radius: 999px; font-size: 14px; font-weight: 600; white-space: nowrap;
  }
  .mobile-menu summary::-webkit-details-marker { display: none; }
  .mobile-menu .chev { width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg); }
  .mobile-menu[open] .chev { transform: translateY(2px) rotate(-135deg); }
  .mobile-panel {
    position: absolute; left: 0; right: 0; top: 100%; max-height: calc(100vh - 61px); overflow-y: auto;
    padding: 14px 16px 18px; background: var(--surface); border-bottom: 1px solid var(--line-header);
    box-shadow: 0 12px 24px oklch(0 0 0 / .08);
  }
  .mobile-panel .nav-section a { min-height: 44px; font-size: 16px; }
  .mobile-panel .nav-user { margin-top: 14px; }

  body.has-nav .container { margin-left: 0; }
  .container { padding: 24px 16px 60px; }

  .duty-header h1 { font-size: 22px; }

  .duty-layout { flex-direction: column; }
  .duty-side { width: 100%; position: static; }

  .month-grid-wrap { display: none; }
  .weekend-agenda { display: block; }
}

/* логотип на странице входа */
.login-card .brand { padding: 0; margin-bottom: 22px; }
