/* ============================================================
   Календар доступності — стилі
   Половинки днів намальовані діагональним градієнтом:
   заїзд закриває нижню-праву частину, виїзд — верхню-ліву.
   ============================================================ */

:root {
  --paper:      #F1EFE6;
  --card:       #FFFFFF;
  --ink:        #1E2A1C;
  --ink-soft:   #6E7768;
  --line:       #E2DFD4;
  --spruce:     #2E4B3A;
  --spruce-deep:#223A2B;
  --closed:     #B94A2F;
  --closed-bg:  #EFC9BD;
  --select:     #E9A13B;
  --paid:       #2F7A55;
  --radius:     14px;
  --shadow:     0 2px 12px rgba(30, 42, 28, .08);
  --mono:       ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --safe-b:     env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
/* Атрибут hidden має перемагати будь-яке власне display.
   Без цього рядка панелі з display:flex не ховаються. */
[hidden] { display: none !important; }


html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

h1, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
button, input { font-family: inherit; font-size: 16px; color: inherit; }
:focus-visible { outline: 2px solid var(--select); outline-offset: 2px; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--spruce-deep); color: #EFEDE2;
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-in {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px; max-width: 720px; margin: 0 auto;
}
.brand { font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.net {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: var(--closed); color: #fff;
}

.link-btn {
  display: inline-block; padding: 6px 12px;
  background: rgba(255, 255, 255, .12); color: #EFEDE2;
  border-radius: 9px; text-decoration: none; font-size: 14px;
}
.link-btn.wide {
  display: block; text-align: center; margin: 12px 0 0;
  background: #E9EDE6; color: var(--spruce); padding: 11px;
}

/* ---------- Вкладки будинків ---------- */
.house-tabs {
  display: flex; gap: 6px; padding: 12px 16px 0;
  max-width: 720px; margin: 0 auto; overflow-x: auto; scrollbar-width: none;
}
.house-tabs::-webkit-scrollbar { display: none; }
.house-tab {
  flex: 1 0 auto; padding: 9px 14px; white-space: nowrap;
  background: transparent; border: 1px solid var(--line);
  border-radius: 999px; font-size: 14px; color: var(--ink-soft); cursor: pointer;
}
.house-tab.active { background: var(--spruce); border-color: var(--spruce); color: #fff; }

/* ---------- Каркас ---------- */
.wrap { max-width: 720px; margin: 0 auto; padding: 14px 16px calc(28px + var(--safe-b)); }

.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month-label { font-size: 17px; font-weight: 600; text-transform: capitalize; }

.today-btn {
  display: block; margin: 8px auto 14px; padding: 6px 16px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; font-size: 13px; color: var(--ink-soft); cursor: pointer;
}

.icon-btn {
  background: none; border: 0; font-size: 24px; line-height: 1;
  padding: 4px 12px; cursor: pointer; color: var(--ink);
}
.topbar .icon-btn { color: #EFEDE2; }

/* ---------- Сітка ---------- */
.weekdays, .grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px;
}
.weekdays {
  margin-bottom: 6px; font-size: 12px; color: var(--ink-soft); text-align: center;
}

.day {
  position: relative; aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; font-family: var(--mono); font-size: 15px;
  cursor: pointer; overflow: hidden; padding: 0;
}
.day span { position: relative; z-index: 2; }

.day.blank { background: transparent; border-color: transparent; cursor: default; }
.day.past { color: #B4B8AE; }
.day.today { border-color: var(--spruce); border-width: 2px; font-weight: 700; }

/* Колір кожного дня ставить JavaScript — у кожного бронювання свій.
   Правила нижче лишаються запасним варіантом, якщо скрипт не спрацював. */
.day.full, .day.half-in, .day.half-out { color: #2A2418; border-color: #D6D2C4; }
.day.full     { background: var(--closed-bg); }
.day.half-in  { background: linear-gradient(to bottom right, var(--card) 49.4%, var(--closed-bg) 50.6%); }
.day.half-out { background: linear-gradient(to bottom right, var(--closed-bg) 49.4%, var(--card) 50.6%); }

.day.sel     { background: var(--select); border-color: var(--select); color: #3A2A0B; font-weight: 700; }
.day.in-sel  { background: #F7DFB4; border-color: #EFC97F; }
.day.pending { border-style: dashed; border-color: var(--select); border-width: 2px; }

.day.paid-mark::after {
  content: ''; position: absolute; z-index: 3;
  right: 4px; bottom: 4px; width: 5px; height: 5px;
  border-radius: 50%; background: var(--paid);
}
.day.debt-mark::after {
  content: ''; position: absolute; z-index: 3;
  right: 4px; bottom: 4px; width: 5px; height: 5px;
  border-radius: 50%; background: var(--closed);
}

/* ---------- Легенда ---------- */
.legend {
  margin-top: 20px; padding: 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 14px; color: var(--ink-soft);
}
.legend-row { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.sw { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line); flex: 0 0 auto; }
.sw-open { background: var(--card); }
.sw-full { background: linear-gradient(to right, #E4A98F 0 33%, #A9C29B 33% 66%, #9FBACB 66%); }
.sw-in   { background: linear-gradient(to bottom right, var(--card) 49.4%, #E4A98F 50.6%); }
.sw-out  { background: linear-gradient(to bottom right, #E4A98F 49.4%, var(--card) 50.6%); }
.sw-join { background: linear-gradient(to bottom right, #E4A98F 49.4%, #A9C29B 50.6%); }
.sw-paid { background: var(--card); position: relative; }
.sw-paid::after, .sw-debt::after {
  content: ''; position: absolute; right: 3px; bottom: 3px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--paid);
}
.sw-debt { background: var(--card); position: relative; }
.sw-debt::after { background: var(--closed); }
.legend-hint { margin: 12px 0 0; font-size: 13px; line-height: 1.5; }

.pending-note {
  margin-top: 14px; padding: 11px 14px;
  background: #FBF0DC; border: 1px solid #EFD9AC;
  border-radius: 11px; font-size: 14px; color: #6B5320;
}

/* ---------- Панелі ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(24, 34, 22, .5);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 480px; background: var(--paper);
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(18px + var(--safe-b));
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(22px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.sheet h3 { font-size: 17px; margin-bottom: 8px; }
.sheet-dates { font-family: var(--mono); font-size: 15px; margin: 0 0 12px; color: var(--spruce); }
.sheet-note { margin: 0 0 12px; color: var(--ink-soft); font-size: 15px; }
.sheet-label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }

.sheet input {
  width: 100%; padding: 11px 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; -webkit-appearance: none;
}

.sheet-money {
  background: #F7F5EC; border-radius: 11px; padding: 12px; margin-bottom: 12px;
  font-family: var(--mono); font-size: 14px;
}
.sheet-money div { display: flex; justify-content: space-between; padding: 3px 0; }
.sheet-money .due { color: var(--closed); font-weight: 600; }
.sheet-money .ok  { color: var(--paid); font-weight: 600; }

.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }

.btn {
  padding: 12px 16px; border: 1px solid transparent; border-radius: 11px;
  font-size: 15px; font-weight: 550; cursor: pointer; background: transparent;
}
.btn-primary { background: var(--spruce); color: #fff; }
.btn-ghost { background: var(--card); border-color: var(--line); color: var(--ink); }
.btn-danger { background: var(--closed); color: #fff; }
.btn:active { transform: translateY(1px); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 70;
  bottom: calc(24px + var(--safe-b));
  background: var(--spruce-deep); color: #fff;
  padding: 11px 18px; border-radius: 11px; font-size: 14px;
  max-width: 88vw; text-align: center;
}

@media (min-width: 620px) {
  .day { font-size: 17px; }
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 18px; }
}
