*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --surface: #f2f2f7;
  --border: #e5e5ea;
  --text: #000000;
  --text-secondary: #6e6e73;
  --text-other-month: #c7c7cc;
  --today-bg: #000000;
  --today-text: #ffffff;
  --selected-bg: #e5e5ea;
  --accent: #007aff;
  --today-num: #ff3b30;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: var(--bg);
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

h1 {
  font-size: 22px;
  font-weight: 700;
  min-width: 160px;
}

.nav-btn {
  background: none;
  border: none;
  font-size: 26px;
  color: var(--accent);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  line-height: 1;
  padding-bottom: 2px;
}

.nav-btn:hover { background: var(--surface); }

.header-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}

.action-btn:hover { background: var(--surface); }

/* Tabs */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin: 0 -16px;
  padding: 0 16px;
}

.tab {
  background: none;
  border: none;
  padding: 8px 16px 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Views */
.view { display: none; flex: 1; }
.view.active { display: block; }

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
  font-size: 14px;
}

.hidden { display: none !important; }

/* Month Grid */
.weekday-headers {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 8px 16px 4px;
  border-bottom: 1px solid var(--border);
}

.weekday-headers span {
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 2px 0;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 4px 16px;
  gap: 0;
}

.day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 2px 6px;
  cursor: pointer;
  border-radius: 8px;
  min-height: 52px;
  -webkit-tap-highlight-color: transparent;
}

.day-cell:hover { background: var(--surface); }
.day-cell.selected { background: var(--selected-bg); }

.day-num {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 400;
  border-radius: 50%;
}

.day-cell.today .day-num {
  background: var(--today-bg);
  color: var(--today-text);
  font-weight: 600;
}

.day-cell.today-selected .day-num {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.day-cell.other-month .day-num {
  color: var(--text-other-month);
}

/* Event dots */
.event-dots {
  display: flex;
  gap: 3px;
  margin-top: 3px;
  height: 6px;
  align-items: center;
}

.event-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Day events panel (below month grid) */
.day-panel {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  min-height: 140px;
}

.day-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 10px 16px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Events list (shared) */
.events-list {
  padding: 4px 16px 16px;
}

.event-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  border-left: 4px solid transparent;
  transition: opacity 0.1s;
}

.event-item:active { opacity: 0.7; }

.event-item-content {
  flex: 1;
  min-width: 0;
}

.event-item-title {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-item-time {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.event-item-cal {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.no-events {
  color: var(--text-secondary);
  font-size: 14px;
  padding: 20px 0;
  text-align: center;
}

/* Agenda (week/day views) */
.agenda-content {
  padding: 12px 16px;
}

.agenda-day {
  margin-bottom: 20px;
}

.agenda-day-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.agenda-day-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.agenda-day-num {
  font-size: 22px;
  font-weight: 700;
}

.agenda-day-today .agenda-day-num {
  color: var(--accent);
}

/* Event Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal-card {
  position: relative;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 80dvh;
  overflow-y: auto;
  padding: 20px 20px 40px;
  z-index: 1;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: var(--surface);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  padding-top: 4px;
}

.modal-color-bar {
  width: 40px;
  height: 5px;
  border-radius: 3px;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.3;
}

.modal-meta {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.modal-description {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  margin-top: 14px;
  white-space: pre-wrap;
  padding: 12px;
  background: var(--surface);
  border-radius: 10px;
}

/* Calendars side panel */
.side-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 16px;
}

.cal-panel-inner {
  position: relative;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 70dvh;
  overflow-y: auto;
  z-index: 100;
}

.cal-panel-list {
  padding: 8px 0 40px;
}

.cal-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.cal-row:last-child { border-bottom: none; }

.cal-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cal-name {
  flex: 1;
  font-size: 15px;
}

.cal-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}

.cal-check.checked {
  border-color: transparent;
}
