:root {
  color-scheme: dark;
  --page-bg: #090a0c;
  --panel-bg: #0e1013;
  --panel-soft: #14171b;
  --grid-line: #34383e;
  --border: #293039;
  --text: #f4f6f8;
  --muted: #a9b0ba;
  --blue: #4e9df8;
  --blue-strong: #1769cf;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
  --radius: 28px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% -20%, rgba(45, 95, 157, 0.18), transparent 38rem),
    linear-gradient(160deg, #0c0d0f, #050608);
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

svg {
  display: block;
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  width: min(1600px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0;
}

.calendar-panel {
  overflow: hidden;
  min-height: calc(100vh - 4rem);
  background:
    linear-gradient(180deg, rgba(18, 22, 28, 0.98), rgba(9, 12, 16, 0.98));
  border: 1px solid #263341;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  gap: 1.4rem;
  padding: 2.3rem 2.5rem 1.9rem;
  border-bottom: 1px solid var(--border);
}

.heading-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 72px;
  height: 72px;
  background:
    radial-gradient(circle at 35% 25%, rgba(92, 167, 255, 0.36), transparent 45%),
    #091a30;
  border: 1px solid rgba(71, 143, 230, 0.2);
  border-radius: 50%;
  color: #73b5ff;
  box-shadow: 0 0 38px rgba(45, 116, 219, 0.22);
}

.heading-icon svg {
  width: 34px;
  height: 34px;
}

.panel-heading h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

.panel-heading p {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.25rem);
}

.calendar-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 1.5rem 2.5rem;
  border-bottom: 1px solid var(--border);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.control-group-right {
  justify-content: flex-end;
}

#calendar-title {
  min-width: 15rem;
  margin: 0 0 0 1rem;
  font-size: clamp(1.25rem, 2.3vw, 1.8rem);
  text-transform: capitalize;
}

.control-button,
.icon-button,
.view-button,
.google-button {
  min-height: 48px;
  border: 1px solid #47505b;
  color: var(--text);
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.control-button:hover,
.icon-button:hover,
.view-button:hover {
  background: #20252b;
  border-color: #697481;
}

.control-button:active,
.icon-button:active,
.view-button:active,
.google-button:active {
  transform: translateY(1px);
}

.today-button {
  padding: 0.7rem 1.5rem;
  background: transparent;
  border-radius: 999px;
  font-weight: 700;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  background: transparent;
  border-color: transparent;
  border-radius: 50%;
}

.view-switcher {
  display: flex;
  overflow: hidden;
  border: 1px solid #47505b;
  border-radius: 999px;
}

.view-button {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 106px;
  justify-content: center;
  padding: 0.65rem 1rem;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-weight: 700;
}

.view-button + .view-button {
  border-left: 1px solid #47505b;
}

.view-button.is-active {
  background: #075b88;
  color: #e9f7ff;
}

.google-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.7rem 1.25rem;
  background: linear-gradient(135deg, #1769cf, #1254b1);
  border-color: #287ee3;
  border-radius: 999px;
  font-weight: 700;
  text-decoration: none;
}

.google-button:hover {
  background: linear-gradient(135deg, #2278df, #1762c7);
}

.calendar-wrap {
  position: relative;
  min-height: 700px;
  padding: 0 1.35rem;
}

#calendar {
  min-height: 700px;
}

.loading-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  background: rgba(10, 12, 15, 0.88);
  color: var(--muted);
  backdrop-filter: blur(5px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.loading-layer.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #3d4550;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error-message {
  position: absolute;
  z-index: 10;
  inset: 2rem;
  align-content: center;
  justify-items: center;
  padding: 2rem;
  background: rgba(24, 17, 18, 0.96);
  border: 1px solid rgba(255, 106, 106, 0.35);
  border-radius: 18px;
  text-align: center;
}

.error-message:not([hidden]) {
  display: grid;
}

.error-message strong {
  font-size: 1.2rem;
}

.error-message span {
  margin: 0.45rem 0 1rem;
  color: #c3b5b6;
}

.error-message button {
  padding: 0.7rem 1rem;
  background: #b53e49;
  border: 0;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  font-weight: 700;
}

/* FullCalendar */
.fc {
  --fc-border-color: var(--grid-line);
  --fc-page-bg-color: transparent;
  --fc-neutral-bg-color: #13161a;
  --fc-list-event-hover-bg-color: #1d2228;
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
}

.fc .fc-header-toolbar {
  display: none;
}

.fc .fc-scrollgrid {
  overflow: hidden;
  border-color: var(--grid-line);
  border-radius: 26px;
}

.fc .fc-scrollgrid-section-header > *,
.fc .fc-col-header-cell {
  background: #111316;
}

.fc .fc-col-header-cell-cushion {
  padding: 1rem 0.4rem;
  color: #d3d7dc;
  font-size: 0.88rem;
  font-weight: 800;
  text-decoration: none;
  text-transform: uppercase;
}

.fc .fc-daygrid-day {
  background: #111315;
}

.fc .fc-daygrid-day:hover {
  background: #15181b;
}

.fc .fc-day-other {
  background: #0e1012;
}

.fc .fc-day-other .fc-daygrid-day-top {
  opacity: 0.52;
}

.fc .fc-daygrid-day-number {
  min-width: 32px;
  margin: 0.45rem;
  padding: 0.35rem;
  color: #e7e9ec;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
}

.fc .fc-day-today {
  background: #15191e !important;
}

.fc .fc-day-today .fc-daygrid-day-number {
  display: grid;
  place-items: center;
  background: #a9c9ff;
  border-radius: 50%;
  color: #102448;
}

.fc .fc-daygrid-day-frame {
  min-height: 145px;
}

.fc .fc-daygrid-event {
  min-height: 27px;
  margin: 2px 7px;
  padding: 3px 8px;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
  line-height: 1.25;
}

.fc .fc-event-main {
  overflow: hidden;
}

.fc .fc-event-time {
  font-weight: 800;
}

.fc .fc-event-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fc .fc-daygrid-more-link {
  margin: 0.15rem 0.45rem;
  color: #9cc9ff;
  font-size: 0.82rem;
  font-weight: 700;
}

.fc .fc-list {
  border-color: var(--grid-line);
  border-radius: 20px;
}

.fc .fc-list-day-cushion {
  background: #181c21;
}

.fc .fc-list-event:hover td {
  background: #1a1f25;
}

.fc .fc-list-event-dot {
  border-color: var(--event-color);
}

.fc-theme-standard td,
.fc-theme-standard th {
  border-color: var(--grid-line);
}

.panel-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 2.5rem 1.6rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.panel-footer p {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
}

.event-dialog {
  width: min(520px, calc(100% - 2rem));
  padding: 2rem;
  background: #171a1f;
  border: 1px solid #3d4652;
  border-radius: 22px;
  color: var(--text);
  box-shadow: 0 25px 90px rgba(0, 0, 0, 0.7);
}

.event-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.dialog-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
}

.dialog-color {
  display: block;
  width: 46px;
  height: 8px;
  margin-bottom: 1.2rem;
  border-radius: 999px;
}

.event-dialog h2 {
  padding-right: 2rem;
  margin: 0;
}

.event-dialog dl {
  display: grid;
  gap: 1rem;
  margin: 1.5rem 0;
}

.event-dialog dl > div {
  display: grid;
  gap: 0.2rem;
}

.event-dialog dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.event-dialog dd {
  margin: 0;
  white-space: pre-wrap;
}

.dialog-link {
  display: inline-flex;
  padding: 0.7rem 1rem;
  background: #1769cf;
  border-radius: 10px;
  color: white;
  font-weight: 700;
  text-decoration: none;
}

:focus-visible {
  outline: 3px solid rgba(102, 173, 255, 0.75);
  outline-offset: 3px;
}

@media (max-width: 1050px) {
  .calendar-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .control-group-right {
    justify-content: space-between;
  }

  .fc .fc-daygrid-day-frame {
    min-height: 120px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: 100%;
    padding: 0;
  }

  .calendar-panel {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .panel-heading {
    padding: 1.4rem 1rem;
  }

  .heading-icon {
    width: 54px;
    height: 54px;
  }

  .heading-icon svg {
    width: 26px;
    height: 26px;
  }

  .calendar-controls {
    padding: 1rem;
  }

  .control-group {
    flex-wrap: wrap;
  }

  #calendar-title {
    order: 3;
    width: 100%;
    min-width: 0;
    margin: 0.6rem 0 0;
  }

  .control-group-right {
    flex-direction: column;
  }

  .view-switcher,
  .google-button {
    width: 100%;
  }

  .view-button {
    flex: 1;
  }

  .calendar-wrap {
    min-height: 620px;
    padding: 0 0.45rem;
  }

  .fc .fc-col-header-cell-cushion {
    padding: 0.65rem 0.15rem;
    font-size: 0.68rem;
  }

  .fc .fc-daygrid-day-number {
    min-width: 27px;
    margin: 0.2rem;
    padding: 0.25rem;
    font-size: 0.8rem;
  }

  .fc .fc-daygrid-day-frame {
    min-height: 92px;
  }

  .fc .fc-daygrid-event {
    min-height: 22px;
    margin-inline: 2px;
    padding: 2px 4px;
    border-radius: 5px;
    font-size: 0.68rem;
  }

  .panel-footer {
    align-items: flex-start;
    flex-direction: column;
    padding: 1rem;
  }
}


/* =========================================================
   CORREÇÃO DE DIMENSIONAMENTO E RENDERIZAÇÃO DO FULLCALENDAR
   ========================================================= */

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
}

.app-shell {
  flex: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: clamp(0.35rem, 1vw, 1rem);
  overflow: hidden;
}

.calendar-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.panel-heading {
  flex: 0 0 auto;
  padding: clamp(1rem, 2.2vh, 1.8rem) clamp(1rem, 2vw, 2rem);
}

.heading-icon {
  width: clamp(50px, 5.5vw, 68px);
  height: clamp(50px, 5.5vw, 68px);
}

.panel-heading h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.panel-heading p {
  font-size: clamp(0.95rem, 1.5vw, 1.2rem);
}

.calendar-controls {
  flex: 0 0 auto;
  padding: clamp(0.75rem, 1.5vh, 1.15rem) clamp(1rem, 2vw, 2rem);
}

.calendar-wrap {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  padding: 0 clamp(0.35rem, 0.8vw, 0.85rem);
  overflow: hidden;
}

#calendar {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
}

#calendar > .fc {
  width: 100%;
  height: 100%;
}

.fc .fc-view-harness,
.fc .fc-view-harness-active {
  min-height: 0;
}

.fc .fc-scrollgrid {
  width: 100%;
  height: 100%;
}

.fc .fc-daygrid-body,
.fc .fc-scrollgrid-sync-table {
  width: 100% !important;
}

.fc .fc-daygrid-day-frame {
  min-height: 0;
}

.fc .fc-daygrid-event {
  display: block;
  overflow: hidden;
  color: var(--fc-event-text-color);
  text-decoration: none;
}

.fc .fc-event-main {
  color: inherit;
}

.fc .fc-event-title,
.fc .fc-event-time {
  color: inherit;
  text-decoration: none;
}

.panel-footer {
  flex: 0 0 auto;
  padding: 0.75rem clamp(1rem, 2vw, 2rem);
}

/* Telas com pouca altura */
@media (max-height: 850px) and (min-width: 721px) {
  .panel-heading {
    gap: 1rem;
    padding-block: 0.8rem;
  }

  .heading-icon {
    width: 48px;
    height: 48px;
  }

  .heading-icon svg {
    width: 24px;
    height: 24px;
  }

  .panel-heading h1 {
    font-size: clamp(1.8rem, 3vw, 2.6rem);
  }

  .panel-heading p {
    margin-top: 0.25rem;
    font-size: 0.95rem;
  }

  .calendar-controls {
    padding-block: 0.65rem;
  }

  .control-button,
  .icon-button,
  .view-button,
  .google-button {
    min-height: 42px;
  }

  .panel-footer {
    padding-block: 0.45rem;
  }

  .fc .fc-col-header-cell-cushion {
    padding-block: 0.55rem;
  }

  .fc .fc-daygrid-day-number {
    margin: 0.2rem;
    padding: 0.2rem;
  }

  .fc .fc-daygrid-event {
    min-height: 22px;
    margin-block: 1px;
    padding-block: 2px;
    font-size: 0.76rem;
  }
}

/* Celular: a lista é mais legível e a página pode rolar */
@media (max-width: 720px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    display: block;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    padding: 0;
    overflow: visible;
  }

  .calendar-panel {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .calendar-wrap {
    min-height: 620px;
    overflow: visible;
  }

  #calendar,
  #calendar > .fc {
    min-height: 620px;
    height: auto;
  }

  .panel-heading h1 {
    font-size: clamp(1.8rem, 9vw, 2.5rem);
  }

  .google-button span {
    white-space: normal;
    text-align: center;
  }
}
