/* Shift Scheduler — hand-written UI (no build step) */

:root {
  --bg: #0b1220;
  --bg-elev: #0f172a;
  --card: #16202f;
  --card-2: #1b2635;
  --border: #263349;
  --teal: #2dd4bf;
  --teal-strong: #14b8a6;
  --teal-on: #06201c;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --text-faint: #64748b;
  --danger: #f87171;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --header-h: 56px;
  --nav-h: 64px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  /* Filled in by app.js from Telegram.WebApp.contentSafeAreaInset /
     safeAreaInset — accounts for Telegram's own header chrome, which
     env(safe-area-inset-*) does not know about. */
  --tg-content-safe-top: 0px;
  --tg-content-safe-bottom: 0px;
  --tg-device-safe-top: 0px;
  --tg-device-safe-bottom: 0px;
}

html[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-2: #f1f4f8;
  --border: #e2e8f0;
  --teal-on: #ffffff;
  --text: #0f172a;
  --text-dim: #55617a;
  --text-faint: #94a3b8;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
  min-height: 100%;
}

body { min-height: 100vh; min-height: 100dvh; }

button { font-family: inherit; }

.app-shell {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

/* ---------- Header (fix #2: pushed clear of the status bar) ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  /* clear whichever is taller: the device notch/status-bar, or Telegram's
     own in-app header controls (Close / chevron / •••) */
  padding: calc(max(var(--safe-t), var(--tg-content-safe-top), var(--tg-device-safe-top)) + 22px) 16px 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.app-header__title {
  flex: 1;
  min-width: 0;
  font-size: 19px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header__actions { display: flex; gap: 8px; flex-shrink: 0; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn--accent { background: var(--teal); color: var(--teal-on); border-color: transparent; font-weight: 700; }

/* ---------- Main content ---------- */
.app-main {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + max(var(--safe-b), var(--tg-content-safe-bottom), var(--tg-device-safe-bottom)) + 24px);
  overflow-x: hidden;
}

.page { display: none; animation: fadein .18s ease; }
.page.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none; } }

.greeting { font-size: 26px; font-weight: 800; margin: 4px 0 2px; }
.subtitle { color: var(--text-dim); font-size: 15px; margin: 0 0 18px; }

.section-title { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--teal); font-weight: 700; margin: 0 0 8px; }

/* ---------- Cards / stats grid ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.stat-card--accent { background: var(--teal); color: var(--teal-on); border-color: transparent; }
.stat-card__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; opacity: .85; font-size: 14px; }
.stat-card__value { font-size: 30px; font-weight: 800; line-height: 1; }
.stat-card__label { font-size: 13px; opacity: .75; margin-top: 6px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: var(--teal);
  color: var(--teal-on);
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn--ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--border); }
.btn--block { width: 100%; }
.btn--danger { background: var(--danger); color: #2a0a0a; }

.next-shift-card { display: flex; align-items: center; justify-content: space-between; }
.next-shift-badge {
  width: 46px; height: 46px; border-radius: 14px;
  background: var(--card-2); display: flex; align-items: center; justify-content: center; font-size: 20px;
}

/* ---------- Calendar ---------- */
.month-switcher { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.month-switcher__title { font-size: 20px; font-weight: 800; flex: 1; text-align: center; }
.round-btn {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card-2); color: var(--text); font-size: 16px; cursor: pointer;
}

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.cal-weekdays, .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.cal-weekdays { margin-bottom: 6px; }
.cal-weekdays span {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  padding: 4px 0;
}
.cal-grid { gap: 6px; }

/* fix #6: day cells sized so the shift label sits fully inside the cell */
.cal-cell {
  min-height: 78px;
  border-radius: var(--radius-sm);
  background: var(--card);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px;
  cursor: pointer;
  overflow: hidden;
}
.cal-cell--empty { background: transparent; border-color: transparent; pointer-events: none; }
.cal-cell--today { border-color: var(--teal); box-shadow: 0 0 0 1px var(--teal) inset; }
.cal-cell__num { font-size: 13px; font-weight: 700; padding: 2px 4px; }
.cal-cell__badge {
  width: 100%;
  border-radius: 8px;
  padding: 5px 4px;
  font-size: 10.5px;
  font-weight: 700;
  text-align: center;
  color: #0b1220;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 360px) {
  .cal-cell { min-height: 66px; }
  .cal-cell__badge { font-size: 9.5px; }
}

/* larger screens (iPad) — keep cells comfortably sized, not stretched */
@media (min-width: 700px) {
  .cal-cell { min-height: 96px; padding: 8px; }
  .cal-cell__num { font-size: 15px; }
  .cal-cell__badge { font-size: 12px; padding: 6px; }
}

/* ---------- Modal / sheet ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: none; align-items: flex-end; justify-content: center; z-index: 100;
}
.overlay.active { display: flex; }
.sheet {
  width: 100%; max-width: 640px;
  background: var(--bg-elev);
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + max(var(--safe-b), var(--tg-content-safe-bottom), var(--tg-device-safe-bottom)));
  max-height: 82vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-bottom: none;
}
.sheet__handle { width: 40px; height: 4px; background: var(--border); border-radius: 99px; margin: 0 auto 14px; }
.sheet__title { font-size: 18px; font-weight: 800; margin-bottom: 14px; }

.shift-type-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.shift-type-chip {
  display: flex; align-items: center; gap: 8px;
  border: 1.5px solid var(--border); background: var(--card);
  border-radius: var(--radius-md); padding: 12px; cursor: pointer; text-align: start;
}
.shift-type-chip.selected { border-color: var(--teal); background: color-mix(in srgb, var(--teal) 14%, var(--card)); }
.shift-type-chip__dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.shift-type-chip__name { font-size: 13px; font-weight: 600; }

.field-label { font-size: 13px; color: var(--text-dim); margin: 12px 0 6px; }
.field-input, .field-select {
  width: 100%; background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 12px 14px; font-size: 15px;
}
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }

/* ---------- Settings ---------- */
.settings-group__title { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.settings-group__sub { font-size: 13px; color: var(--text-dim); margin-bottom: 14px; }
.toggle-row { display: flex; gap: 10px; }
.toggle-btn {
  flex: 1; padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--card-2); color: var(--text); font-weight: 700; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.toggle-btn.active { background: var(--teal); color: var(--teal-on); border-color: transparent; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 640px;
  display: flex;
  z-index: 40;
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 8px calc(6px + var(--safe-l)) calc(8px + max(var(--safe-b), var(--tg-content-safe-bottom), var(--tg-device-safe-bottom))) calc(6px + var(--safe-r));
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 11px;
  text-align: center;
  cursor: pointer;
}
.nav-item span { display: block; width: 100%; text-align: center; }
.nav-item__icon { font-size: 19px; }
.nav-item.active { color: var(--teal); background: color-mix(in srgb, var(--teal) 12%, transparent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--nav-h) + max(var(--safe-b), var(--tg-content-safe-bottom), var(--tg-device-safe-bottom)) + 14px);
  background: var(--card-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  z-index: 200; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 88%; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }

.loading-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-top-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- RTL ---------- */
[dir="rtl"] .stat-card__top,
[dir="rtl"] .next-shift-card { flex-direction: row-reverse; }
[dir="rtl"] .shift-type-chip { text-align: right; }

/* ---------- Reports list ---------- */
.report-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.report-row:last-child { border-bottom: none; }
.report-row__label { display: flex; align-items: center; gap: 8px; color: var(--text-dim); }
.report-row__value { font-weight: 700; }

.empty-note { color: var(--text-faint); font-size: 13px; text-align: center; padding: 24px 0; }
