:root {
  --tg-bg: var(--tg-theme-bg-color, #ffffff);
  --tg-text: var(--tg-theme-text-color, #222222);
  --tg-hint: var(--tg-theme-hint-color, #888888);
  --tg-link: var(--tg-theme-link-color, #2481cc);
  --tg-btn: var(--tg-theme-button-color, #2481cc);
  --tg-btn-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #f4f4f5);
  --radius: 12px;
  --nav-h: 62px;
  --nav-bottom: 14px;
  --nav-side: 18px;
  --header-h: 52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  min-height: 100dvh;
  overflow-x: hidden;
}

#app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ── Navigation — iOS 26 Liquid Glass floating style ─────────── */
.bottom-nav {
  position: fixed;
  bottom: calc(var(--nav-bottom) + env(safe-area-inset-bottom));
  left: var(--nav-side);
  right: var(--nav-side);
  height: var(--nav-h);
  border-radius: 28px;
  background: color-mix(in srgb, var(--tg-secondary-bg) 82%, transparent);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border: 0.5px solid rgba(255,255,255,0.18);
  box-shadow:
    0 8px 32px rgba(0,0,0,0.13),
    0 2px 6px rgba(0,0,0,0.07),
    inset 0 0.5px 0 rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  z-index: 100;
  padding: 6px;
}

.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  border: none; background: none; color: var(--tg-hint);
  font-size: 10px; font-weight: 500; cursor: pointer;
  border-radius: 28px;
  padding: 7px;
  transition: color .2s ease, background .2s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

/* active pill background */
.nav-btn.active {
  color: var(--tg-btn);
  background: color-mix(in srgb, var(--tg-btn) 13%, transparent);
}

.nav-icon {
  width: 26px; height: 26px;
  position: relative; flex-shrink: 0;
}
.nav-icon svg {
  position: absolute; inset: 0;
  width: 26px; height: 26px;
  transition: opacity .2s ease, transform .2s cubic-bezier(.34,1.56,.64,1);
}

.icon-off { opacity: 1;  transform: scale(1); }
.icon-on  { opacity: 0;  transform: scale(.8); fill: currentColor; }

.nav-btn.active .icon-off { opacity: 0; transform: scale(1.15); }
.nav-btn.active .icon-on  { opacity: 1; transform: scale(1); }

.nav-btn span       { color: var(--tg-hint); transition: color .2s ease; }
.nav-btn.active span { color: var(--tg-btn);  font-weight: 600; }

.nav-btn.hidden { display: none; }

/* ── Pages ───────────────────────────────────────────────────── */
.page {
  display: none; flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--nav-bottom) + env(safe-area-inset-bottom) + 12px);
}
.page.active { display: flex; }

.page-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--tg-bg);
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.page-header h1 { font-size: 18px; font-weight: 700; }

.content-wrap { padding: 12px 16px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .5px; color: var(--tg-hint); margin-bottom: 10px;
}
.card-main { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.card-sub { font-size: 14px; color: var(--tg-hint); }

/* ── Brigade badge ───────────────────────────────────────────── */
.brigade-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 14px; font-weight: 600; color: #fff;
  margin-bottom: 8px;
}
.brigade-dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.6); }

/* ── Worker rows ─────────────────────────────────────────────── */
.worker-list { display: flex; flex-direction: column; gap: 8px; }
.worker-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--tg-bg);
  border-radius: 10px;
  padding: 10px 12px;
}
.worker-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.avatar-wrap {
  width: 40px; height: 40px; border-radius: 50%;
  overflow: hidden; flex-shrink: 0;
  background: var(--tg-secondary-bg);
}
.avatar-img {
  width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .25s ease;
  display: block;
}
.leader-badge {
  display: inline-block;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .4px; color: #fff;
  background: #FF9800; border-radius: 4px;
  padding: 1px 5px; margin-right: 5px;
  vertical-align: middle; line-height: 16px;
}
.worker-info { flex: 1; min-width: 0; }
.worker-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.worker-pos { font-size: 12px; color: var(--tg-hint); }
.worker-phone { font-size: 12px; color: var(--tg-link); margin-top: 2px; }
.worker-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Action buttons ──────────────────────────────────────────── */
.act-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: opacity .15s;
  text-decoration: none; flex-shrink: 0;
}
.act-btn:active { opacity: .7; }
.act-btn.call { background: #4CAF50; }
.act-btn.msg  { background: #2196F3; }
.act-btn.tg   { background: #0088cc; }
.act-icon { width: 18px; height: 18px; object-fit: contain; display: block; }

/* ── Next week card ──────────────────────────────────────────── */
.next-week-card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius); padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.next-week-icon { font-size: 24px; }
.next-week-info { flex: 1; }
.next-week-label { font-size: 11px; color: var(--tg-hint); font-weight: 600; text-transform: uppercase; }
.next-week-name { font-size: 16px; font-weight: 700; margin-top: 2px; }
.next-week-admin { font-size: 13px; color: var(--tg-hint); }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 24px; text-align: center;
}
.empty-state-icon { font-size: 52px; margin-bottom: 16px; opacity: .7; }
.empty-state-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.empty-state-text { font-size: 14px; color: var(--tg-hint); line-height: 1.6; }

/* ── Skeleton ────────────────────────────────────────────────── */
.skeleton-card {
  height: 100px; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--tg-secondary-bg) 25%, rgba(0,0,0,.04) 50%, var(--tg-secondary-bg) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  margin-bottom: 12px;
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ── Calendar ────────────────────────────────────────────────── */
.calendar-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
#cal-month-label { font-size: 16px; font-weight: 700; text-align: center; flex: 1; }
.icon-btn {
  background: var(--tg-secondary-bg); border: none; border-radius: 8px;
  width: 36px; height: 36px; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--tg-text);
}

.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  margin-bottom: 12px;
}
.cal-day-header {
  text-align: center; font-size: 11px; font-weight: 600;
  color: var(--tg-hint); padding: 4px 0;
}
.cal-day {
  aspect-ratio: 1; border-radius: 8px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  cursor: pointer; position: relative;
  background: var(--tg-secondary-bg);
  transition: opacity .15s;
  padding: 2px;
}
.cal-day:active { opacity: .7; }
.cal-day.empty { background: none; cursor: default; }
.cal-day.today { outline: 2px solid var(--tg-btn); outline-offset: -2px; }
.cal-day.selected { background: var(--tg-btn) !important; color: var(--tg-btn-text) !important; }
.cal-day .day-num { font-size: 13px; font-weight: 600; line-height: 1; }
.cal-day .day-dot {
  width: 6px; height: 6px; border-radius: 50%;
  margin-top: 2px; flex-shrink: 0;
}
.cal-day.weekend .day-num { color: #e53935; }
.cal-day.selected .day-num { color: inherit; }
.cal-day.selected .day-dot { background: rgba(255,255,255,.7) !important; }

.day-detail {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius); padding: 14px;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }
.day-detail.hidden { display: none; }
.day-detail-date { font-size: 13px; color: var(--tg-hint); margin-bottom: 8px; }

/* ── Brigades page ───────────────────────────────────────────── */
.brigade-section { margin-bottom: 16px; }
.brigade-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.brigade-color-bar { width: 4px; height: 20px; border-radius: 2px; flex-shrink: 0; }
.brigade-name { font-size: 16px; font-weight: 700; }
.brigade-count { font-size: 13px; color: var(--tg-hint); margin-left: auto; }

/* ── Admin panel ─────────────────────────────────────────────── */
.admin-tabs {
  display: flex; gap: 6px; overflow-x: auto;
  padding-bottom: 2px; margin-bottom: 14px;
  scrollbar-width: none;
}
.admin-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  padding: 7px 14px; border-radius: 20px; border: none;
  background: var(--tg-secondary-bg); color: var(--tg-hint);
  font-size: 13px; font-weight: 500; cursor: pointer;
  white-space: nowrap; flex-shrink: 0; transition: all .2s;
}
.tab-btn.active { background: var(--tg-btn); color: var(--tg-btn-text); }

.add-btn {
  width: 100%; padding: 12px; border-radius: var(--radius);
  border: 2px dashed rgba(0,0,0,.12); background: none;
  color: var(--tg-link); font-size: 15px; font-weight: 500;
  cursor: pointer; margin-bottom: 12px; transition: background .15s;
}
.add-btn:active { background: var(--tg-secondary-bg); }

.list-item {
  background: var(--tg-secondary-bg); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px;
}
.list-item-info { flex: 1; min-width: 0; }
.list-item-name { font-size: 15px; font-weight: 600; }
.list-item-sub { font-size: 13px; color: var(--tg-hint); margin-top: 2px; }
.list-item-actions { display: flex; gap: 6px; }
.edit-btn, .del-btn {
  border: none; border-radius: 8px; width: 32px; height: 32px;
  cursor: pointer; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.edit-btn { background: rgba(33,150,243,.12); color: #2196F3; }
.del-btn  { background: rgba(229,57,53,.12);  color: #e53935; }

/* ── Schedule editor ─────────────────────────────────────────── */
.schedule-editor { }
.sch-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sch-month { font-size: 15px; font-weight: 700; }
.sch-grid { display: flex; flex-direction: column; gap: 6px; }
.sch-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--tg-secondary-bg); border-radius: 10px; padding: 10px 12px;
}
.sch-date { font-size: 14px; font-weight: 600; width: 70px; flex-shrink: 0; }
.sch-select {
  flex: 1; background: var(--tg-bg); border: 1px solid rgba(0,0,0,.1);
  border-radius: 8px; padding: 6px 8px; font-size: 13px; color: var(--tg-text);
}

/* ── Schedule clear buttons ──────────────────────────────────── */
.clear-row {
  display: flex; gap: 8px; margin-top: 10px;
}
.btn-clear {
  flex: 1; padding: 11px; border-radius: var(--radius);
  border: 1.5px solid rgba(229,57,53,.35);
  background: rgba(229,57,53,.07);
  color: #e53935; font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background .15s;
}
.btn-clear:active { background: rgba(229,57,53,.15); }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 200; display: flex; align-items: flex-end;
  animation: fadeIn .15s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }

.modal {
  background: var(--tg-bg); border-radius: 16px 16px 0 0;
  width: 100%; max-height: 90dvh;
  display: flex; flex-direction: column;
  animation: slideUpModal .2s ease;
}
@keyframes slideUpModal { from{transform:translateY(100%)} to{transform:none} }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px; border-bottom: 1px solid rgba(0,0,0,.06);
}
.modal-header h2 { font-size: 17px; font-weight: 700; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 16px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }

/* ── Form ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--tg-hint); margin-bottom: 6px; display: block; }
.form-input, .form-select {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid rgba(0,0,0,.12); background: var(--tg-secondary-bg);
  font-size: 15px; color: var(--tg-text); outline: none;
}
.form-input:focus, .form-select:focus { border-color: var(--tg-btn); }

.btn-primary {
  width: 100%; padding: 13px; border-radius: var(--radius);
  background: var(--tg-btn); color: var(--tg-btn-text);
  border: none; font-size: 16px; font-weight: 600; cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:active { opacity: .8; }

.btn-danger {
  width: 100%; padding: 13px; border-radius: var(--radius);
  background: #e53935; color: #fff;
  border: none; font-size: 16px; font-weight: 600; cursor: pointer;
  transition: opacity .15s;
}
.btn-danger:active { opacity: .8; }

/* ── Color picker ────────────────────────────────────────────── */
.color-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.color-swatch {
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; transition: transform .15s;
}
.color-swatch.selected { border-color: var(--tg-text); transform: scale(1.15); }

/* ── Admin contact card ──────────────────────────────────────── */
.admin-contact-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--tg-bg); border-radius: 10px; padding: 10px 12px;
}
.admin-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--tg-btn); color: var(--tg-btn-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; flex-shrink: 0;
}
.admin-info { flex: 1; min-width: 0; }
.admin-name { font-size: 14px; font-weight: 600; }
.admin-phone-text { font-size: 12px; color: var(--tg-link); }

/* ── Access blocked screen ───────────────────────────────────── */
.screen-blocked {
  position: fixed; inset: 0; z-index: 300;
  background: var(--tg-bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px 24px; text-align: center;
}
.screen-blocked.hidden { display: none; }
.blocked-icon { font-size: 64px; margin-bottom: 16px; }
.blocked-title { font-size: 22px; font-weight: 700; margin-bottom: 10px; }
.blocked-text { font-size: 15px; color: var(--tg-hint); line-height: 1.5; margin-bottom: 16px; }
.blocked-id { font-size: 12px; color: var(--tg-hint); background: var(--tg-secondary-bg); padding: 6px 12px; border-radius: 8px; }

/* ── Toggle switch ───────────────────────────────────────────── */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--tg-secondary-bg); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px;
}
.toggle-info { flex: 1; min-width: 0; }
.toggle-name { font-size: 15px; font-weight: 600; }
.toggle-sub  { font-size: 12px; color: var(--tg-hint); margin-top: 2px; }
.toggle-wrap { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.toggle-label { font-size: 12px; color: var(--tg-hint); }
.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: rgba(0,0,0,.15);
  border-radius: 24px; cursor: pointer; transition: background .2s;
}
.slider:before {
  content: ''; position: absolute;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: transform .2s;
}
.switch input:checked + .slider { background: var(--tg-btn); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* ── Utilities ───────────────────────────────────────────────── */
.text-hint { color: var(--tg-hint); font-size: 14px; }
.mt-8 { margin-top: 8px; }
.divider { height: 1px; background: rgba(0,0,0,.06); margin: 12px 0; }
.section-label {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .5px; color: var(--tg-hint); margin-bottom: 8px;
}
.pill {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 12px; font-weight: 600; background: var(--tg-secondary-bg);
  color: var(--tg-hint);
}
