/* ==========================================================================
   Telegram Calendar Mini App
   Material 3 Expressive / Google Calendar Mobile inspired
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS VARIABLES
   -------------------------------------------------------------------------- */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #007aff);
  --button: var(--tg-theme-button-color, #007aff);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --destructive: var(--tg-theme-destructive-text-color, #ff3b30);
  --accent: var(--tg-theme-accent-text-color, var(--button));
  --border: rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --spacing: 16px;
  --nav-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --event-color-1: #4285f4;
  --event-color-2: #ea4335;
  --event-color-3: #34a853;
  --event-color-4: #fbbc04;
  --event-color-5: #ff6d01;
}

/* --------------------------------------------------------------------------
   2. RESET & BASE
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, 'SF Pro Display', BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   3. LOADING SCREEN
   -------------------------------------------------------------------------- */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s;
}

.loading-screen .loading-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--button);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

/* --------------------------------------------------------------------------
   4. HEADER
   -------------------------------------------------------------------------- */
#header {
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  background: var(--bg);
  z-index: 100;
}

#header-title {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  padding-left: 8px;
  letter-spacing: -0.3px;
}

.header-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s;
}

.header-btn:active {
  background: rgba(0, 0, 0, 0.04);
}

#header-right {
  display: flex;
  align-items: center;
}

/* --------------------------------------------------------------------------
   5. VIEW TOGGLE
   -------------------------------------------------------------------------- */
.view-toggle {
  display: flex;
  margin: 0 var(--spacing);
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.view-toggle-btn {
  flex: 1;
  padding: 7px 0;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.view-toggle-btn.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* --------------------------------------------------------------------------
   6. PAGES
   -------------------------------------------------------------------------- */
.page {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.page::-webkit-scrollbar {
  display: none;
}

.page.active {
  display: flex;
  flex-direction: column;
}

.page {
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
}

/* --------------------------------------------------------------------------
   7. MONTH NAVIGATION
   -------------------------------------------------------------------------- */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px var(--spacing);
}

.month-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.month-btn:active {
  background: rgba(0, 0, 0, 0.04);
}

.month-title {
  font-size: 15px;
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   8. CALENDAR GRID - "CHOCOLATE BAR" STYLE
   -------------------------------------------------------------------------- */
.calendar-grid {
  padding: 0 12px 8px;
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--hint);
  padding: 0 2px 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.day-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 6px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
  color: var(--text);
  background: var(--bg-secondary);
  min-height: 44px;
  gap: 2px;
  overflow: hidden;
}

.day-cell:active {
  transform: scale(0.95);
  opacity: 0.8;
}

.day-cell.other-month {
  color: var(--hint);
  opacity: 0.35;
  background: transparent;
}

.day-cell.today .day-number {
  background: var(--button);
  color: var(--button-text);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.day-cell.selected {
  background: color-mix(in srgb, var(--button) 12%, transparent);
  outline: 2px solid var(--button);
  outline-offset: -2px;
}

.day-cell.selected.today {
  background: color-mix(in srgb, var(--button) 15%, transparent);
}

.day-number {
  font-size: 13px;
  line-height: 1;
}

.event-count {
  font-size: 10px;
  font-weight: 600;
  color: #ea4335;
  margin-top: 2px;
}

/* --------------------------------------------------------------------------
   9. EVENT CHIPS IN CALENDAR
   -------------------------------------------------------------------------- */
.event-chip {
  width: calc(100% - 4px);
  height: 4px;
  border-radius: 2px;
  background: var(--button);
  flex-shrink: 0;
}

.event-chip:nth-child(2) {
  background: var(--event-color-2);
}

.event-chip:nth-child(3) {
  background: var(--event-color-3);
}

.event-chip.more {
  background: var(--hint);
  opacity: 0.5;
}

/* --------------------------------------------------------------------------
   10. DAY EVENTS SECTION
   -------------------------------------------------------------------------- */
.day-events {
  padding: 12px var(--spacing);
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title .add-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  border: none;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
}

.section-title .add-btn:active {
  transform: scale(0.9);
}

/* --------------------------------------------------------------------------
   11. EVENT CARD
   -------------------------------------------------------------------------- */
.event-card {
  display: flex;
  align-items: stretch;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid var(--border);
}

.event-card:active {
  transform: scale(0.98);
}

.event-card-accent {
  width: 4px;
  background: var(--button);
  flex-shrink: 0;
  border-radius: 4px 0 0 4px;
}

.event-card-body {
  flex: 1;
  padding: 12px 14px;
}

.event-card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 3px;
}

.event-card-meta {
  font-size: 12px;
  color: var(--hint);
  display: flex;
  gap: 10px;
  align-items: center;
}

/* --------------------------------------------------------------------------
   12. SCHEDULE VIEW / EVENTS LIST
   -------------------------------------------------------------------------- */
.events-list {
  padding: 4px var(--spacing);
}

.event-date-group {
  margin-bottom: 16px;
}

.event-date-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 0 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.event-date-header .date-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--button);
}

.event-date-header.today-header {
  color: var(--button);
}

.event-date-header.today-header .date-dot {
  background: var(--button);
}

/* --------------------------------------------------------------------------
   13. EMPTY STATE
   -------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px var(--spacing);
  text-align: center;
}

.empty-icon {
  font-size: 56px;
  margin-bottom: 20px;
}

.empty-state p {
  color: var(--hint);
  font-size: 15px;
  margin-bottom: 24px;
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   14. EVENT DETAIL
   -------------------------------------------------------------------------- */
.event-detail {
  padding: 20px var(--spacing);
}

.detail-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 16px;
  letter-spacing: -0.5px;
}

.detail-meta {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.detail-meta-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  color: var(--hint);
}

.detail-meta-item svg {
  width: 20px;
  height: 20px;
  color: var(--accent);
  flex-shrink: 0;
}

.detail-description {
  font-size: 15px;
  line-height: 1.6;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}

.detail-section {
  margin-top: 28px;
}

.detail-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--hint);
  letter-spacing: 0.8px;
  margin-bottom: 14px;
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

/* --------------------------------------------------------------------------
   15. BUTTONS
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 28px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 48px;
  letter-spacing: -0.2px;
}

.btn:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.btn-primary {
  background: var(--button);
  color: var(--button-text);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text);
}

.btn-danger {
  background: color-mix(in srgb, var(--destructive) 12%, transparent);
  color: var(--destructive);
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 10px 18px;
  font-size: 13px;
  min-height: 40px;
  border-radius: var(--radius-xs);
}

.btn-join {
  background: var(--button);
  color: var(--button-text);
}

.btn-joined {
  background: var(--bg-secondary);
  color: var(--destructive);
}

/* --------------------------------------------------------------------------
   16. FORM
   -------------------------------------------------------------------------- */
.event-form {
  padding: 20px var(--spacing);
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--hint);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg);
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.form-input:focus {
  border-color: var(--button);
}

.form-input::placeholder {
  color: var(--hint);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* --------------------------------------------------------------------------
   17. PARTICIPANTS
   -------------------------------------------------------------------------- */
.participants-list {
  padding: var(--spacing);
}

.participant-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.participant-item:last-child {
  border-bottom: none;
}

.participant-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  margin-right: 14px;
  flex-shrink: 0;
}

.participant-info {
  flex: 1;
}

.participant-name {
  font-size: 15px;
  font-weight: 600;
}

.participant-username {
  font-size: 13px;
  color: var(--hint);
}

.participant-remove {
  color: var(--destructive);
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
  font-size: 13px;
  min-height: 44px;
}

/* --------------------------------------------------------------------------
   18. BOTTOM NAV
   -------------------------------------------------------------------------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--hint);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 20px;
  transition: color 0.2s;
  min-width: 64px;
  min-height: 44px;
}

.nav-btn.active {
  color: var(--button);
}

.create-btn {
  background: var(--button);
  color: var(--button-text);
  width: 52px;
  height: 52px;
  border-radius: 16px;
  padding: 0;
  box-shadow: var(--shadow-lg);
  margin-top: -24px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}

.create-btn:active {
  transform: scale(0.92);
}

/* --------------------------------------------------------------------------
   19. ANIMATIONS
   -------------------------------------------------------------------------- */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.animate-in {
  animation: fadeIn 0.25s ease-out;
}

.slide-in {
  animation: slideIn 0.2s ease-out;
}

/* --------------------------------------------------------------------------
   20. TOAST
   -------------------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}

.toast.visible {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   21. PARTICIPANTS CHECKBOXES
   -------------------------------------------------------------------------- */
.participants-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px 0;
}

.participant-checkbox {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.participant-checkbox:active {
  background: var(--hover);
}

.participant-checkbox input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
}

.participant-checkbox .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.participant-checkbox .info {
  flex: 1;
  min-width: 0;
}

.participant-checkbox .name {
  font-weight: 500;
  font-size: 15px;
  color: var(--text);
}

.participant-checkbox .username {
  font-size: 13px;
  color: var(--hint);
}

.participants-empty {
  padding: 16px;
  text-align: center;
  color: var(--hint);
  font-size: 14px;
}

/* --------------------------------------------------------------------------
   22. UTILITIES
   -------------------------------------------------------------------------- */
.hidden {
  display: none !important;
}
