*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0f0f12;
  --bg-secondary: #1a1a20;
  --bg-card: #22222a;
  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent: #7c6aef;
  --accent-soft: rgba(124, 106, 239, 0.15);
  --border: #2a2a35;
  --error: #ef6a6a;
  --success: #6aef7c;
  --radius: 8px;
  --radius-sm: 4px;
  --scrollbar-bg: transparent;
  --scrollbar-thumb: #555560;
  --scrollbar-thumb-hover: #666670;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-bg);
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: var(--scrollbar-bg);
}

*::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

.header-toggle-inline {
  padding: 4px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}

.header-toggle-inline:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.header-toggle-inline svg {
  transition: transform 0.2s ease;
}

.header-toggle-inline.expanded svg {
  transform: rotate(180deg);
}

.view-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.calendar-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.viewer-header {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.viewer-header.collapsed {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
  position: absolute;
  width: 100%;
}

.url-form {
  display: flex;
  gap: 8px;
  max-width: 600px;
  margin: 0 auto;
}

.url-form input {
  flex: 1;
  padding: 8px 12px;
  font-size: 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  transition: border-color 0.15s;
}

.url-form input::placeholder {
  color: var(--text-muted);
}

.url-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-load {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-load:hover {
  opacity: 0.9;
}

.btn-load:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-collapse {
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}

.btn-collapse:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.calendar-container {
  flex: 1;
  overflow: hidden;
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px;
  color: var(--text-secondary);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error {
  padding: 16px;
  background: rgba(239, 106, 106, 0.1);
  border: 1px solid var(--error);
  border-radius: var(--radius);
  color: var(--error);
  text-align: center;
  margin-bottom: 16px;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}

.hidden {
  display: none !important;
}

.events-list {
  max-width: 1000px;
  margin: 0 auto;
}

.event-group {
  margin-bottom: 24px;
}

.event-group-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.event-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.event-time {
  flex-shrink: 0;
  width: 100px;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
}

.event-time.all-day {
  color: var(--text-muted);
  font-style: italic;
}

.event-details {
  flex: 1;
  min-width: 0;
}

.event-title {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 4px;
  word-break: break-word;
}

.event-location {
  font-size: 13px;
  color: var(--text-secondary);
}

/* View Controls */
.view-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.view-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-btn {
  padding: 6px 12px;
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.nav-btn:hover {
  background: var(--bg-secondary);
  border-color: var(--accent);
}

.nav-today {
  margin-left: 8px;
}

.nav-label {
  font-size: 14px;
  font-weight: 500;
  min-width: 140px;
  text-align: center;
}

.view-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  padding: 4px;
  border-radius: var(--radius);
  margin-left: auto;
}

.view-btn {
  padding: 6px 12px;
  font-size: 13px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.view-btn:hover {
  color: var(--text-primary);
}

.view-btn.active {
  background: var(--accent);
  color: white;
}

.view-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
}

/* Week View */
.week-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.week-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.week-header {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-secondary);
}

.week-time-gutter {
  width: 50px;
  flex-shrink: 0;
}

.week-number {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.week-header-day {
  flex: 1;
  padding: 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
}

.week-header-day .day-num {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  margin-left: 4px;
}

.week-header-day.today {
  background: var(--accent-soft);
}

.week-header-day.today .day-num {
  background: var(--accent);
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.week-body {
  flex: 1;
  display: flex;
  overflow-y: auto;
}

.week-body > .week-time-gutter {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
}

.week-hour-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  padding-right: 8px;
  position: relative;
  top: -7px;
}

.week-days-grid {
  flex: 1;
  display: flex;
  background: var(--bg-primary);
}

.week-day-column {
  flex: 1;
  position: relative;
  border-left: 1px solid var(--border);
  background: var(--bg-primary);
}

.week-day-column.today {
  background: var(--accent-soft);
}

.week-hour-slot {
  border-bottom: 1px solid var(--border);
}

.week-event {
  position: absolute;
  box-sizing: border-box;
  padding: 4px 6px;
  padding-right: 4px;
  margin-right: 2px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  z-index: 1;
  transition: opacity 0.15s;
}

.week-event:hover {
  opacity: 0.9;
}

.week-event-allday {
  position: relative;
  top: auto;
  height: auto;
  margin-bottom: 2px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
}

.week-event-time {
  font-size: 10px;
  opacity: 0.9;
}

.week-event-title {
  font-size: 11px;
  font-weight: 500;
  color: white;
  word-break: break-word;
}

.week-event-allday .week-event-title {
  color: var(--text-primary);
}

.week-event-location {
  font-size: 10px;
  opacity: 0.8;
}

/* Month View */
.month-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.month-grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex: 1;
}

.month-header {
  display: flex;
  background: var(--bg-secondary);
}

.month-week-num-header {
  width: 32px;
  flex-shrink: 0;
}

.month-header-cell {
  flex: 1;
  background: var(--bg-secondary);
  padding: 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.month-row {
  display: flex;
  flex: 1;
  gap: 1px;
}

.month-week-num {
  width: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.month-week-num:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.month-day {
  flex: 1;
  min-width: 0;
  background: var(--bg-primary);
  min-height: 80px;
  display: flex;
  flex-direction: column;
}

.month-day.other-month {
  background: var(--bg-secondary);
  opacity: 0.5;
}

.month-day.today {
  background: var(--accent-soft);
}

.month-day-num {
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.month-day.today .month-day-num {
  color: var(--accent);
  font-weight: 600;
}

.month-day-events {
  flex: 1;
  padding: 0 4px 4px;
  overflow: hidden;
}

.month-event {
  padding: 2px 4px;
  margin-bottom: 2px;
  background: var(--accent-soft);
  border-radius: 2px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background 0.15s;
}

.month-event:hover {
  background: var(--accent);
  color: white;
}

.month-event-more {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 4px;
}

/* Event Popup */
.event-popup {
  position: fixed;
  z-index: 1000;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 280px;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.event-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.event-popup-title {
  font-size: 16px;
  font-weight: 600;
  word-break: break-word;
}

.event-popup-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.event-popup-close:hover {
  color: var(--text-primary);
}

.event-popup-time {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
}

.event-popup-location {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.event-popup-desc {
  font-size: 13px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 150px;
  overflow-y: auto;
}

@media (max-width: 600px) {
  .url-form {
    flex-direction: column;
  }
  
  .event-card {
    flex-direction: column;
    gap: 4px;
  }
  
  .event-time {
    width: auto;
  }

  .view-controls {
    flex-wrap: wrap;
  }

  .view-nav {
    order: 2;
    width: 100%;
    justify-content: center;
  }

  .view-toggle {
    order: 1;
  }
}
