/* SWIS Calendar - CSS */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #fff;
  color: #1c1c1e;
  min-height: 100vh;
}

.swis-calendar {
  width: 100%;
  min-height: 100vh;
}

/* ==================== Header ==================== */
.calendar-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e5e5ea;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.current-period {
  font-size: 1.5rem;
  font-weight: 600;
}

.current-period .month-name {
  color: #007aff;
}

.header-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.today-btn {
  color: #007aff;
  background: none;
  border: none;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 16px;
  transition: opacity 0.15s;
}

.today-btn:hover {
  opacity: 0.7;
}

.header-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.nav-buttons {
  display: flex;
  gap: 8px;
}

.nav-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: #f2f2f7;
  color: #007aff;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.nav-btn:hover {
  background: #e5e5ea;
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.view-toggle {
  display: flex;
  background: #f2f2f7;
  border-radius: 10px;
  padding: 3px;
  margin-left: auto;
}

.view-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: #8e8e93;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.2s;
}

.view-btn.active {
  background: #fff;
  color: #1c1c1e;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ==================== Calendar Type Filter (Top) ==================== */
.calendar-type-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  flex-wrap: nowrap;
}

.calendar-type-filter .section-chip {
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  flex-shrink: 0;
}

/* ==================== Section Filter ==================== */
.section-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: #f9f9f9;
  flex-wrap: wrap;
}

/* Calendar Type Filter in Header - Full Width */
.calendar-header > .section-filter {
  margin: 0 -20px;
  padding: 12px 20px;
  width: calc(100% + 40px);
}

.section-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  background: #fff;
  border: 1px solid #e5e5ea;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  flex-shrink: 0;
}


/* ปุ่มแสดง/ซ่อนหน่วยงานเพิ่มเติม */
.section-chip.more-btn {
  background: linear-gradient(135deg, #007aff, #5856d6);
  color: #fff;
  border-color: #007aff;
  font-weight: 500;
}

.section-chip.more-btn:hover {
  background: linear-gradient(135deg, #0066dd, #4845c4);
  transform: scale(1.02);
}

/* Hidden chips */
.section-chip.hidden-chip {
  display: none;
}

.section-filter.expanded .section-chip.hidden-chip {
  display: flex;
}

.section-chip:hover {
  background: #f2f2f7;
}

.section-chip.active {
  background: #007aff;
  color: #fff;
  border-color: #007aff;
}

.section-chip.active .chip-dot {
  background: #fff !important;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ==================== Month View ==================== */
.month-view {
  display: flex;
  min-height: calc(100vh - 180px);
}

.calendar-side {
  padding: 16px 24px;
  border-right: 1px solid #e5e5ea;
  max-width: 500px;
  width: 100%;
}

.weekday-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 8px;
}

.weekday {
  text-align: center;
  padding: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #8e8e93;
}

.weekday.weekend {
  color: #ff3b30;
}

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

.day-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  position: relative;
  min-height: 45px;
  transition: all 0.15s;
}

.day-cell:hover {
  background: #f2f2f7;
}

.day-cell.other-month .day-number {
  color: #c7c7cc;
}

.day-cell.weekend .day-number {
  color: #ff3b30;
}

.day-cell.other-month.weekend .day-number {
  color: #e5c7c7;
}

.day-cell.today {
  background: #ff3b30;
}

.day-cell.today .day-number {
  color: #fff !important;
  font-weight: 600;
}

.day-cell.today .event-dot {
  background: #fff !important;
}

.day-number {
  font-size: 1.1rem;
  font-weight: 400;
  color: #1c1c1e;
  line-height: 1;
}

.event-dots {
  display: flex;
  gap: 3px;
  position: absolute;
  bottom: 5px;
}

.event-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.next-month-label {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #e5e5ea;
  font-size: 1rem;
  font-weight: 500;
  color: #8e8e93;
}

/* ==================== Calendar Container ==================== */
.calendar-container {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* ==================== Events Side ==================== */
.events-side {
  flex: 1;
  min-width: 0;
  background: #f9f9f9;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.events-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e5e5ea;
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.events-title {
  font-size: 1rem;
  font-weight: 600;
}

.events-count {
  font-size: 0.85rem;
  color: #8e8e93;
  background: #f2f2f7;
  padding: 4px 10px;
  border-radius: 10px;
}

.events-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
}

.no-events {
  text-align: center;
  padding: 40px 20px;
  color: #8e8e93;
}

.event-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #fff;
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  border-left: 4px solid #3b82f6;
  transition: all 0.15s;
  overflow: hidden;
  max-width: 100%;
}

.event-item:hover {
  transform: translateX(4px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.event-item.admin { border-left-color: #3b82f6; }
.event-item.dev { border-left-color: #10b981; }
.event-item.swisplus { border-left-color: #8b5cf6; }

.event-date {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 40px;
  padding: 4px 0;
}

.event-date .date-day {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1;
  color: #1c1c1e;
}

.event-date.weekend .date-day {
  color: #ff3b30;
}

.event-date .date-weekday {
  font-size: 0.7rem;
  color: #8e8e93;
}

.event-date.weekend .date-weekday {
  color: #ff3b30;
}

.event-timer {
  font-size: 0.75rem;
  color: #007aff;
  background: #e8f4fd;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
  margin-right: 8px;
  font-weight: 500;
}

.event-title {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: #1c1c1e;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.event-place {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 200px;
  flex-shrink: 1;
  font-size: 0.8rem;
  color: #666;
}

.event-place span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-file {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 100px;
  font-size: 0.8rem;
  color: #999;
  font-style: italic;
}

/* ==================== Summary View ==================== */
.summary-view {
  padding: 20px;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: #f2f2f7;
  border-radius: 16px;
  padding: 20px;
  text-align: center;
}

.stat-card.total {
  background: linear-gradient(135deg, #007aff, #5856d6);
  color: #fff;
}

.stat-number {
  display: block;
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.85rem;
  opacity: 0.8;
}

.summary-sections {
  background: #f2f2f7;
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 24px;
}

.summary-sections h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.section-bar-item {
  margin-bottom: 12px;
}

.bar-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.bar-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.bar-count {
  margin-left: auto;
  font-weight: 600;
}

.bar-track {
  height: 8px;
  background: #e5e5ea;
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.summary-search {
  margin-bottom: 20px;
}

.summary-search input {
  width: 100%;
  padding: 14px 18px;
  border: none;
  background: #f2f2f7;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  outline: none;
}

.summary-search input:focus {
  box-shadow: 0 0 0 3px rgba(0,122,255,0.2);
}

.summary-list h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.event-group {
  margin-bottom: 24px;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 2px solid #e5e5ea;
  margin-bottom: 12px;
}

.group-month {
  font-weight: 600;
}

.group-count {
  font-size: 0.8rem;
  color: #8e8e93;
  background: #f2f2f7;
  padding: 4px 10px;
  border-radius: 12px;
}

.summary-event-item {
  display: flex;
  gap: 16px;
  padding: 14px;
  background: #f9f9f9;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 8px;
}

.summary-event-item:hover {
  background: #f2f2f7;
  transform: translateX(4px);
}

.event-date-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 40px;
}

.event-date-col .event-day {
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1;
}

.event-date-col .event-weekday {
  font-size: 0.75rem;
  color: #8e8e93;
}

.event-info-col {
  flex: 1;
  min-width: 0;
}

.event-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

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

.event-title-lg {
  font-weight: 500;
}

.event-meta {
  font-size: 0.85rem;
  color: #8e8e93;
}

/* ==================== Year View ==================== */
.year-view {
  padding: 16px;
}

.year-summary {
  margin-bottom: 20px;
  padding: 16px;
  background: #f2f2f7;
  border-radius: 16px;
}

.year-summary .summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.year-summary h3 {
  font-size: 1rem;
  font-weight: 600;
}

.total-events {
  font-size: 0.85rem;
  color: #8e8e93;
  background: #fff;
  padding: 4px 12px;
  border-radius: 12px;
}

.section-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.section-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  border: 2px solid transparent;
}

.section-stat:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.section-stat.active {
  border-color: #007aff;
}

.stat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.stat-name {
  font-size: 0.85rem;
}

.stat-count {
  font-size: 0.85rem;
  font-weight: 600;
  background: #f2f2f7;
  padding: 2px 8px;
  border-radius: 10px;
}

.months-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.mini-month {
  padding: 12px;
  border-radius: 12px;
  background: #f9f9f9;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
}

.mini-month:hover {
  background: #f2f2f7;
}

.mini-month.has-events {
  border-color: #e5e5ea;
}

.mini-month-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.mini-month-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.mini-month-count {
  font-size: 0.7rem;
  background: #007aff;
  color: #fff;
  padding: 2px 6px;
  border-radius: 8px;
}

.mini-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}

.mini-weekdays span {
  font-size: 0.55rem;
  color: #8e8e93;
  text-align: center;
}

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

.mini-day {
  font-size: 0.65rem;
  text-align: center;
  padding: 3px 0;
  color: #8e8e93;
  border-radius: 4px;
}

.mini-day.today {
  background: #ff3b30;
  color: #fff;
  font-weight: 600;
}

.mini-day.has-events {
  font-weight: 600;
  color: #1c1c1e;
}

/* ==================== Modal ==================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.show {
  display: flex;
}

.modal-content {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  position: relative;
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: #f2f2f7;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1rem;
  color: #8e8e93;
  cursor: pointer;
  transition: all 0.15s;
}

.modal-close:hover {
  background: #e5e5ea;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.modal-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.modal-section {
  font-size: 0.85rem;
  color: #8e8e93;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 20px;
  line-height: 1.4;
}

.modal-info {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-label {
  font-size: 0.8rem;
  color: #8e8e93;
}

.modal-value {
  font-size: 1rem;
}

/* ==================== Responsive ==================== */

/* Tablet */
@media (max-width: 1024px) {
  .months-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .event-place {
    min-width: 140px;
    max-width: 160px;
  }

  /* Calendar Type Filter - Tablet */
  .calendar-header .section-filter:first-of-type {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .calendar-header .section-filter:first-of-type::-webkit-scrollbar {
    display: none;
  }
}

@media (max-width: 768px) {
  .calendar-header {
    padding: 12px 16px;
  }

  /* Main Title - Mobile */
  .main-title {
    font-size: 1.1rem !important;
    padding: 10px 12px !important;
  }

  /* Calendar Type Filter - Mobile */
  .calendar-header > .section-filter {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 10px 16px;
    margin: 0 -16px;
    width: calc(100% + 32px);
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .calendar-header > .section-filter::-webkit-scrollbar {
    display: none;
  }

  .calendar-header > .section-filter .section-chip {
    padding: 6px 12px;
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .header-top {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
  }

  .current-period {
    font-size: 1rem;
    flex: 1;
    min-width: 0;
  }

  /* Buttons wrapper for mobile - right aligned */
  .header-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
  }

  .today-btn {
    font-size: 0.8rem;
    padding: 6px 10px;
  }

  /* Google Calendar Button - Mobile */
  .gcal-btn {
    font-size: 0.7rem !important;
    padding: 6px 10px !important;
  }

  .header-controls {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .nav-buttons {
    order: 1;
  }

  .view-toggle {
    order: 2;
    flex: 1;
  }

  .view-btn {
    flex: 1;
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  .nav-btn {
    width: 32px;
    height: 32px;
  }

  .section-filter {
    padding: 10px 12px;
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .section-chip {
    padding: 5px 10px;
    font-size: 0.75rem;
    flex-shrink: 0;
  }
  
  /* Month View Mobile */
  .month-view {
    flex-direction: column;
  }
  
  .calendar-side {
    max-width: 100%;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid #e5e5ea;
  }
  
  .weekday {
    padding: 6px;
    font-size: 0.8rem;
  }
  
  .day-cell {
    min-height: 36px;
  }
  
  .day-number {
    font-size: 0.95rem;
  }
  
  .event-dot {
    width: 4px;
    height: 4px;
  }
  
  .event-dots {
    bottom: 3px;
    gap: 2px;
  }
  
  .next-month-label {
    display: none;
  }
  
  .events-side {
    max-height: 50vh;
  }
  
  .events-header {
    padding: 12px 16px;
  }
  
  .events-title {
    font-size: 0.9rem;
  }
  
  .events-list {
    padding: 10px;
  }
  
  .event-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
  }
  
  .event-item .event-date {
    flex-direction: row;
    gap: 8px;
    align-items: center;
  }
  
  .event-item .event-title {
    white-space: normal;
  }
  
  .event-item .event-place,
  .event-item .event-file {
    min-width: auto;
    max-width: 100%;
    font-size: 0.75rem;
  }
  
  .event-item-bottom {
    display: flex;
    gap: 12px;
    width: 100%;
    padding-left: 48px;
  }
  
  /* Summary View Mobile */
  .summary-view {
    padding: 16px;
  }
  
  .summary-stats {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .stat-card {
    padding: 16px;
  }
  
  .stat-number {
    font-size: 1.5rem;
  }
  
  /* Year View Mobile */
  .months-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  
  .mini-month {
    padding: 10px;
  }
  
  .mini-month-name {
    font-size: 0.8rem;
  }
  
  .mini-day {
    font-size: 0.6rem;
  }
}

@media (max-width: 480px) {
  .summary-event-item {
    flex-direction: column;
    gap: 8px;
  }

  .event-date-col {
    flex-direction: row;
    gap: 8px;
  }

  .modal-content {
    padding: 16px;
    margin: 10px;
  }

  .modal-title {
    font-size: 1rem;
  }

  /* Header - Very Small Screens */
  .header-top {
    gap: 4px;
    flex-wrap: nowrap;
  }

  .current-period {
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-buttons {
    gap: 2px;
  }

  .today-btn {
    font-size: 0.7rem;
    padding: 4px 6px;
  }

  .gcal-btn {
    font-size: 0.6rem !important;
    padding: 4px 6px !important;
  }

  /* Calendar Type Filter - Very Small */
  .calendar-header > .section-filter .section-chip {
    padding: 5px 10px;
    font-size: 0.7rem;
  }

  /* Navigation */
  .nav-btn {
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
  }

  .view-btn {
    padding: 5px 8px;
    font-size: 0.7rem;
  }

  /* Year View - Very Small */
  .months-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .mini-month {
    padding: 8px;
  }

  .mini-month-name {
    font-size: 0.75rem;
  }

  .mini-day {
    font-size: 0.55rem;
    padding: 2px 0;
  }

  /* Section Stats */
  .section-stat {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .stat-name {
    font-size: 0.75rem;
  }

  .stat-count {
    font-size: 0.75rem;
    padding: 2px 6px;
  }
}

/* ==================== Animations ==================== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.month-view,
.summary-view,
.year-view {
  animation: fadeIn 0.2s ease;
}
