/* ===================================
   Outlook-Style Calendar UI
   =================================== */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  color: #323130;
  background: #faf9f8;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Detect iframe embedding */
body.in-iframe .calendar-sidebar {
  display: none;
}

body.in-iframe .calendar-main {
  margin-left: 0;
}

/* ===================================
   Top Toolbar
   =================================== */

.calendar-toolbar {
  height: 48px;
  background: #fff;
  border-bottom: 1px solid #edebe9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  background: #0078d4;
  color: #fff;
  border: none;
  border-radius: 2px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: #106ebe;
}

.btn-primary i {
  font-size: 12px;
}

.view-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 2px;
  padding: 6px 12px;
  font-size: 13px;
  color: #323130;
  cursor: pointer;
  transition: all 0.15s;
}

.view-btn:hover {
  background: #f3f2f1;
}

.view-btn.active {
  background: #edebe9;
  border-color: #8a8886;
}

.toolbar-btn {
  background: transparent;
  border: none;
  padding: 6px 12px;
  font-size: 13px;
  color: #323130;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 2px;
  transition: background 0.15s;
}

.toolbar-btn:hover {
  background: #f3f2f1;
}

.toolbar-btn i {
  font-size: 14px;
}

/* ===================================
   Main Layout
   =================================== */

.calendar-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===================================
   Left Sidebar
   =================================== */

.calendar-sidebar {
  width: 220px;
  background: #faf9f8;
  border-right: 1px solid #edebe9;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px;
  gap: 16px;
  flex-shrink: 0;
}

/* Mini Calendar */

.mini-calendar {
  background: #fff;
  border: 1px solid #edebe9;
  border-radius: 2px;
  padding: 8px;
}

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

.mini-nav-btn {
  background: transparent;
  border: none;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 2px;
  color: #605e5c;
}

.mini-nav-btn:hover {
  background: #f3f2f1;
}

.mini-month-display {
  font-size: 13px;
  font-weight: 600;
  color: #323130;
}

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

.mini-weekday {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: #605e5c;
  padding: 4px 0;
}

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

.mini-date {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  border-radius: 50%;
  cursor: pointer;
  color: #323130;
}

.mini-date.other-month {
  color: #a19f9d;
}

.mini-date.today {
  background: #0078d4;
  color: #fff;
  font-weight: 600;
}

.mini-date.selected {
  background: #deecf9;
  color: #0078d4;
  font-weight: 600;
}

.mini-date:hover:not(.today):not(.selected) {
  background: #f3f2f1;
}

/* Add Calendar Button */

.add-calendar-btn {
  background: transparent;
  border: 1px solid #edebe9;
  border-radius: 2px;
  padding: 8px;
  font-size: 13px;
  color: #323130;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

.add-calendar-btn:hover {
  background: #f3f2f1;
  border-color: #8a8886;
}

/* My Calendars */

.my-calendars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-header {
  font-size: 12px;
  font-weight: 600;
  color: #605e5c;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.calendar-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calendar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.15s;
}

.calendar-item:hover {
  background: #f3f2f1;
}

.calendar-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.calendar-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.calendar-name {
  font-size: 13px;
  color: #323130;
  flex: 1;
}

/* ===================================
   Main Calendar Area
   =================================== */

.calendar-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

/* Calendar Header */

.calendar-header {
  height: 56px;
  border-bottom: 1px solid #edebe9;
  display: flex;
  align-items: center;
  padding: 0 24px;
  flex-shrink: 0;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-btn {
  background: transparent;
  border: 1px solid #8a8886;
  border-radius: 2px;
  padding: 6px 12px;
  font-size: 13px;
  color: #323130;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

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

.nav-btn-icon {
  background: transparent;
  border: 1px solid #8a8886;
  border-radius: 2px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-btn-icon:hover {
  background: #f3f2f1;
}

.current-month {
  font-size: 18px;
  font-weight: 600;
  color: #323130;
  margin-left: 8px;
}

/* ===================================
   Calendar Views Container
   =================================== */

.calendar-view {
  flex: 1;
  overflow: auto;
  position: relative;
}

/* ===================================
   Month View
   =================================== */

.month-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.weekday-headers {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid #edebe9;
  flex-shrink: 0;
}

.weekday-header {
  padding: 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #605e5c;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  flex: 1;
  border-right: 1px solid #edebe9;
  border-bottom: 1px solid #edebe9;
}

.calendar-day {
  border-left: 1px solid #edebe9;
  border-top: 1px solid #edebe9;
  padding: 4px;
  min-height: 80px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: background 0.15s;
  overflow: hidden;
}

.calendar-day:hover {
  background: #f3f2f1;
}

.calendar-day.other-month {
  background: #faf9f8;
  color: #a19f9d;
}

.day-number {
  font-size: 12px;
  color: #323130;
  font-weight: 500;
  padding: 4px 6px;
  display: inline-block;
  align-self: flex-start;
}

.calendar-day.other-month .day-number {
  color: #a19f9d;
}

.calendar-day.today .day-number {
  background: #0078d4;
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.calendar-day.selected {
  background: #deecf9;
}

.day-events {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.event-item {
  background: #e3f2fd;
  border-left: 3px solid #0078d4;
  padding: 2px 6px;
  font-size: 11px;
  color: #323130;
  border-radius: 2px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s;
}

.event-item:hover {
  background: #bbdefb;
}

.event-time {
  font-weight: 600;
  margin-right: 4px;
}

.more-events {
  font-size: 11px;
  color: #605e5c;
  padding: 2px 6px;
  cursor: pointer;
}

.more-events:hover {
  text-decoration: underline;
}

/* ===================================
   Week View
   =================================== */

.week-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.week-header {
  display: grid;
  grid-template-columns: 60px repeat(7, 1fr);
  border-bottom: 1px solid #edebe9;
  flex-shrink: 0;
}

.week-day-header {
  padding: 12px 8px;
  text-align: center;
  border-left: 1px solid #edebe9;
}

.week-day-name {
  font-size: 11px;
  font-weight: 600;
  color: #605e5c;
  text-transform: uppercase;
}

.week-day-date {
  font-size: 18px;
  font-weight: 600;
  color: #323130;
  margin-top: 4px;
}

.week-day-header.today .week-day-date {
  background: #0078d4;
  color: #fff;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
}

.week-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 60px repeat(7, 1fr);
}

.time-slot {
  border-top: 1px solid #edebe9;
  border-left: 1px solid #edebe9;
  padding: 4px 8px;
  font-size: 11px;
  color: #605e5c;
  text-align: right;
  height: 48px;
}

.hour-cell {
  border-top: 1px solid #edebe9;
  border-left: 1px solid #edebe9;
  min-height: 48px;
  position: relative;
  cursor: pointer;
}

.hour-cell:hover {
  background: #f3f2f1;
}

/* ===================================
   Day View
   =================================== */

.day-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.day-header {
  padding: 16px 24px;
  border-bottom: 1px solid #edebe9;
  flex-shrink: 0;
}

.day-title {
  font-size: 20px;
  font-weight: 600;
  color: #323130;
}

.day-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 60px 1fr;
}

/* ===================================
   Event Modal
   =================================== */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal-dialog {
  position: relative;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid #edebe9;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: #323130;
}

.modal-close {
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 2px;
  color: #605e5c;
}

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

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #323130;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid #8a8886;
  border-radius: 2px;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: #0078d4;
}

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

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: normal;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid #edebe9;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.btn-secondary {
  background: transparent;
  border: 1px solid #8a8886;
  border-radius: 2px;
  padding: 6px 16px;
  font-size: 14px;
  color: #323130;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover {
  background: #f3f2f1;
}

.btn-danger {
  background: #d13438;
  color: #fff;
  border: none;
  border-radius: 2px;
  padding: 6px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger:hover {
  background: #a4262c;
}

/* ===================================
   Utilities
   =================================== */

.hidden {
  display: none !important;
}

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

@media (max-width: 768px) {
  .calendar-sidebar {
    position: absolute;
    left: -220px;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: left 0.3s;
  }
  
  .calendar-sidebar.open {
    left: 0;
  }
  
  .toolbar-center {
    flex-wrap: wrap;
  }
  
  .toolbar-btn span {
    display: none;
  }
}

@media print {
  .calendar-toolbar,
  .calendar-sidebar,
  .modal {
    display: none !important;
  }
  
  .calendar-main {
    width: 100%;
  }
  
  .calendar-day:hover {
    background: #fff;
  }
}
