:root {
  color-scheme: light;
  --fcal-blue: #006FCF;
  --fcal-blue-hover: #005BB5;
  --fcal-navy: #00175A;
  --fcal-bg: #F5F7FA;
  --fcal-card: #FFFFFF;
  --fcal-border: #C8C8C8;
  --fcal-text: #00175A;
  --fcal-muted: #5A6478;
  --fcal-accent: #006FCF;
  --fcal-clear: rgba(0, 133, 124, 0.12);
  --fcal-clear-border: rgba(0, 133, 124, 0.35);
  --fcal-clear-text: #006B63;
  --fcal-busy: #E8E8E8;
  --fcal-busy-text: #5A6478;
  --fcal-shadow: 0 2px 10px rgba(0, 23, 90, 0.07);
  --fcal-radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

body.fcal-page {
  margin: 0;
  min-height: 100dvh;
  background: var(--fcal-bg);
  color: var(--fcal-text);
  line-height: 1.45;
}

.fcal-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
}

.fcal-header h1 {
  margin: 0 0 4px;
  font-size: clamp(1.35rem, 4vw, 1.75rem);
  color: var(--fcal-navy);
  font-weight: 700;
}

.fcal-sub,
.fcal-meta,
.fcal-hint {
  margin: 0;
  color: var(--fcal-muted);
  font-size: 0.875rem;
}

.fcal-card {
  background: var(--fcal-card);
  border: 1px solid var(--fcal-border);
  border-radius: var(--fcal-radius);
  padding: 18px;
  box-shadow: var(--fcal-shadow);
}

.fcal-banner {
  margin: 16px 0;
}

.fcal-banner--error {
  border-color: rgba(220, 38, 38, 0.45);
  background: #FEF2F2;
}

.fcal-layout {
  display: grid;
  gap: 16px;
}

@media (min-width: 720px) {
  .fcal-layout {
    grid-template-columns: 200px 1fr;
    align-items: start;
  }
}

.fcal-legend h2 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--fcal-navy);
}

.fcal-legend p {
  margin: 0 0 8px;
  font-size: 0.85rem;
}

.fcal-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-right: 6px;
}

.fcal-pill--clear {
  background: var(--fcal-clear);
  border: 1px solid var(--fcal-clear-border);
  color: var(--fcal-clear-text);
}

.fcal-pill--busy {
  background: var(--fcal-busy);
  border: 1px solid var(--fcal-border);
  color: var(--fcal-busy-text);
}

.fcal-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.fcal-nav__month {
  flex: 1 1 100%;
  text-align: center;
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--fcal-navy);
}

@media (min-width: 560px) {
  .fcal-nav__month {
    flex: 1 1 auto;
    text-align: left;
  }
}

.fcal-nav__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  justify-content: space-between;
}

@media (min-width: 560px) {
  .fcal-nav__controls {
    width: auto;
  }
}

.fcal-nav__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--fcal-border);
  background: var(--fcal-card);
  color: var(--fcal-navy);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  transition: background 0.15s, border-color 0.15s;
}

.fcal-nav__btn:hover {
  background: #EEF2F7;
  border-color: #A8A8A8;
}

.fcal-nav__btn--today {
  color: var(--fcal-blue);
  border-color: var(--fcal-blue);
  background: rgba(0, 111, 207, 0.06);
}

.fcal-grid-wrap {
  overflow-x: auto;
}

.fcal-weekdays,
.fcal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  min-width: 280px;
}

.fcal-weekdays {
  margin-bottom: 8px;
  color: var(--fcal-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
}

.fcal-day {
  position: relative;
  min-height: 56px;
}

.fcal-day__surface {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-height: 56px;
  border: 1px solid var(--fcal-border);
  border-radius: 10px;
  background: var(--fcal-card);
  color: var(--fcal-text);
  padding: 8px 6px;
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
}

.fcal-day__surface:disabled {
  cursor: default;
  opacity: 0.85;
}

.fcal-day--busy .fcal-day__surface {
  background: linear-gradient(180deg, #ECECEC, #E0E0E0);
  color: var(--fcal-busy-text);
}

.fcal-day--outside {
  opacity: 0.4;
}

.fcal-day__surface:not(:disabled):hover,
.fcal-day__surface:not(:disabled):focus-visible {
  border-color: var(--fcal-blue);
  outline: none;
  box-shadow: 0 1px 4px rgba(0, 23, 90, 0.1);
}

.fcal-day__num {
  font-weight: 700;
  font-size: 1rem;
}

.fcal-day__badge {
  margin-top: auto;
  padding-top: 4px;
  width: 100%;
  max-width: 100%;
  font-size: 0.5rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--fcal-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .fcal-day__badge {
    font-size: 0;
    line-height: 0;
    padding-top: 6px;
  }

  .fcal-day__badge::before {
    content: '';
    display: block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--fcal-busy-text);
  }
}

.fcal-day__dots {
  position: absolute;
  right: 6px;
  top: 6px;
  z-index: 2;
  min-width: 18px;
  min-height: 18px;
  padding: 2px 5px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(0, 111, 207, 0.18);
  border: 1px solid rgba(0, 111, 207, 0.35);
  color: var(--fcal-blue);
  cursor: pointer;
  font-family: inherit;
}

.fcal-day__dots:hover,
.fcal-day__dots:focus-visible {
  background: rgba(0, 111, 207, 0.28);
  outline: 2px solid var(--fcal-blue);
  outline-offset: 1px;
}

.cal-day-popover {
  position: absolute;
  z-index: 200;
  max-width: min(92vw, 300px);
  filter: drop-shadow(0 4px 16px rgba(0, 23, 90, 0.15));
}

.cal-day-popover[hidden] {
  display: none !important;
}

.cal-day-popover__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 6px;
}

.cal-day-popover__date {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.3;
}

.cal-day-popover__close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}

.cal-day-popover__list {
  margin: 0;
  padding: 8px 12px 10px;
  list-style: none;
  max-height: min(50vh, 240px);
  overflow-y: auto;
}

.cal-day-popover__item {
  display: grid;
  gap: 2px;
  padding: 8px 0;
}

.cal-day-popover__status {
  font-size: 0.78rem;
  font-weight: 700;
}

.cal-day-popover__time {
  font-size: 0.75rem;
}

.cal-day-popover__note {
  font-size: 0.72rem;
}

.cal-day-popover__arrow {
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  transform: rotate(45deg);
}

.cal-day-popover--below .cal-day-popover__arrow {
  bottom: auto;
  top: -6px;
  transform: rotate(225deg);
}

.cal-day-popover--fcal .cal-day-popover__inner {
  border: 1px solid var(--fcal-border);
  border-radius: var(--fcal-radius);
  background: var(--fcal-card);
  color: var(--fcal-text);
  box-shadow: var(--fcal-shadow);
}

.cal-day-popover--fcal .cal-day-popover__date {
  color: var(--fcal-navy);
}

.cal-day-popover--fcal .cal-day-popover__time {
  color: var(--fcal-blue);
}

.cal-day-popover--fcal .cal-day-popover__note {
  color: var(--fcal-muted);
}

.cal-day-popover--fcal .cal-day-popover__close {
  border-color: var(--fcal-border);
  color: var(--fcal-navy);
}

.cal-day-popover--fcal .cal-day-popover__arrow {
  background: var(--fcal-card);
  border-color: var(--fcal-border);
}

.cal-day-popover--fcal .cal-day-popover__header {
  border-bottom-color: var(--fcal-border);
}

.cal-day-popover--fcal .cal-day-popover__item {
  border-bottom-color: rgba(0, 23, 90, 0.08);
}

.fcal-meta {
  margin-top: 12px;
}

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

.fcal-modal[hidden] {
  display: none;
}

body.fcal-modal-open {
  overflow: hidden;
}

.fcal-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 23, 90, 0.45);
}

.fcal-modal__sheet {
  position: relative;
  width: min(100%, 420px);
  max-height: 80dvh;
  overflow: auto;
  background: var(--fcal-card);
  border: 1px solid var(--fcal-border);
  border-radius: 16px 16px 0 0;
  padding: 22px 18px max(22px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(0, 23, 90, 0.12);
}

@media (min-width: 520px) {
  .fcal-modal {
    align-items: center;
  }

  .fcal-modal__sheet {
    border-radius: var(--fcal-radius);
    margin: 16px;
  }
}

.fcal-modal__title {
  margin: 0 0 4px;
  font-size: 1.1rem;
  color: var(--fcal-navy);
}

.fcal-modal__subtitle {
  margin: 0 0 12px;
  color: var(--fcal-muted);
  font-size: 0.875rem;
}

.fcal-slot-list strong {
  display: block;
  color: var(--fcal-navy);
}

.fcal-slot-list span {
  display: block;
  font-size: 0.85rem;
  color: var(--fcal-muted);
  margin-top: 2px;
}

.fcal-slot-list > div {
  padding: 10px 0;
  border-bottom: 1px solid var(--fcal-border);
}

.fcal-btn {
  margin-top: 12px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--fcal-blue);
  background: var(--fcal-blue);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, border-color 0.15s;
}

.fcal-btn:hover {
  background: var(--fcal-blue-hover);
  border-color: var(--fcal-blue-hover);
}

.fcal-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--fcal-border);
  font-size: 0.8rem;
  color: var(--fcal-muted);
  line-height: 1.5;
}

.fcal-footer p {
  margin: 0 0 6px;
}

.fcal-footer a {
  color: var(--fcal-blue);
  font-weight: 600;
  text-decoration: none;
}

.fcal-footer a:hover {
  text-decoration: underline;
}

.fcal-footer__owner {
  margin-top: 8px;
  font-size: 0.75rem;
  opacity: 0.85;
}
