/* CALENDAR */
.calendar-page {
  max-width: 1200px;
}

.cal-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
}

.cal-bar__nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cal-bar__title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  min-width: 160px;
  text-align: center;
}

.cal-bar__today {
  font-size: 0.85rem;
}

.cal-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  table-layout: fixed;
}

.cal-grid thead th {
  padding: 10px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  background: rgba(237, 232, 224, 0.4);
  border-bottom: 1px solid var(--border);
}

.cal-grid .weekend--sun { color: #c25c5c; }
.cal-grid .weekend--sat { color: #4f7fb3; }

.cal-cell {
  height: 110px;
  vertical-align: top;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 4px 6px;
  position: relative;
  background: var(--surface);
}
.cal-cell:nth-child(7n) { border-right: none; }
tbody tr:last-child .cal-cell { border-bottom: none; }

.cal-cell--out { background: rgba(0,0,0,0.02); }
.cal-cell--out .cal-cell__num { color: var(--text-muted); opacity: 0.5; }

.cal-cell--today { background: rgba(201, 184, 232, 0.15); }
.cal-cell--today .cal-cell__num {
  background: var(--text);
  color: var(--bg);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cal-cell__date {
  display: block;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  padding: 2px 0;
  font: inherit;
}

.cal-cell__num {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
}

.cal-events {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cal-event {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border: none;
  border-radius: 4px;
  font-size: 0.75rem;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: filter 0.15s;
}
.cal-event:hover { filter: brightness(0.95); }

.cal-event__time {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 0.7rem;
  font-weight: 500;
  opacity: 0.7;
}

.cal-event__title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* MODAL */
.ev-modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  max-width: 480px;
  width: 92vw;
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.ev-modal::backdrop {
  background: rgba(45, 45, 45, 0.45);
  backdrop-filter: blur(2px);
}

.ev-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
}

.ev-form__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ev-form__head h2 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.ev-form__close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
}
.ev-form__close:hover { color: var(--text); background: rgba(0,0,0,0.05); }

.ev-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}
.ev-field > span,
.ev-field > legend {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  font-weight: 500;
}
.ev-field input[type="text"],
.ev-field input[type="datetime-local"],
.ev-field input[type="date"],
.ev-field select,
.ev-field textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  outline: none;
  color: var(--text);
}
.ev-field input:focus,
.ev-field select:focus,
.ev-field textarea:focus {
  border-color: var(--accent);
  background: white;
}

.ev-field--inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.ev-field--inline > span { text-transform: none; letter-spacing: 0; font-size: 0.95rem; color: var(--text); }

.ev-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.ev-row[hidden] { display: none; }

.ev-field fieldset { border: none; padding: 0; }

.color-swatches {
  display: flex;
  gap: 8px;
}
.color-swatches label {
  cursor: pointer;
  display: inline-block;
}
.color-swatches input { display: none; }
.color-swatches span {
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
}
.color-swatches input:checked + span {
  border-color: var(--text);
  transform: scale(1.1);
}

.ev-form__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.ev-form__spacer { flex: 1; }

.ev-form__actions [hidden] { display: none; }

@media (max-width: 720px) {
  .cal-cell { height: 90px; padding: 2px 4px; }
  .cal-event { font-size: 0.68rem; padding: 1px 4px; }
  .ev-row { grid-template-columns: 1fr; }
}

/* MODAL POSITIONING — explicit center */
.ev-modal {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(520px, 92vw);
  height: fit-content;
  max-height: 90vh;
  overflow-y: auto;
  animation: ev-modal-in 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes ev-modal-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

.ev-modal::backdrop {
  animation: ev-backdrop-in 0.18s ease-out;
}
@keyframes ev-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* MODAL FIXES */
fieldset.ev-field {
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
  min-width: 0;
}

.ev-form input,
.ev-form select,
.ev-form textarea {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.ev-form input[type="checkbox"],
.ev-form input[type="radio"] {
  width: auto;
}

.ev-form {
  overflow-x: hidden;
}

.ev-row {
  min-width: 0;
}

.ev-row .ev-field {
  min-width: 0;
}

/* MODAL ROUNDED — force radius */
dialog.ev-modal {
  border-radius: 16px !important;
  overflow: hidden;
}
.ev-form {
  border-radius: 16px;
}

/* MODAL HEADER — neutralize global header styles */
.ev-form__head {
  padding: 0 !important;
  border-bottom: none !important;
  background: transparent !important;
  backdrop-filter: none !important;
  position: static !important;
  z-index: auto !important;
  margin-bottom: 4px;
}

.ev-form__close {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}
.ev-form__close:hover {
  background: rgba(0,0,0,0.05);
  color: var(--text);
}

/* MODAL FOOTER ACTIONS — full-width, edge-aligned */
.ev-form__actions {
  margin: 8px -24px -24px !important;
  padding: 16px 20px !important;
  border-top: 1px solid var(--border);
  background: rgba(237, 232, 224, 0.25);
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
}

/* CAL BAR — better balance */
.cal-bar {
  display: grid !important;
  grid-template-columns: 1fr auto 1fr !important;
  align-items: center;
  gap: 12px;
}
.cal-bar > .cal-bar__nav { justify-self: center; }
.cal-bar > .cal-bar__today { justify-self: end; }
.cal-bar__nav .btn { padding: 6px 12px; font-size: 1rem; line-height: 1; }

/* CAL BAR — explicit column placement */
.cal-bar > .cal-bar__nav { grid-column: 2 !important; }
.cal-bar > .cal-bar__today { grid-column: 3 !important; }

/* HOLIDAY STYLES */
.cal-cell__num.holiday { color: #c25c5c; }
.cal-cell__holiday {
  display: block;
  font-size: 0.7rem;
  color: #c25c5c;
  font-weight: 500;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* MOBILE — calendar */
@media (max-width: 720px) {
  .calendar-page { padding: 16px 8px; }

  .cal-bar { gap: 4px; margin-bottom: 12px; }
  .cal-bar__title { font-size: 1rem; min-width: auto; letter-spacing: 0; }
  .cal-bar .btn { padding: 4px 8px; font-size: 0.85rem; line-height: 1; }
  .cal-bar .btn--ghost { padding: 4px 8px !important; }
  .cal-bar__nav { gap: 4px; }

  .cal-grid {
    border-radius: 12px;
    table-layout: fixed;
  }
  .cal-grid thead th {
    padding: 6px 2px;
    font-size: 0.65rem;
    letter-spacing: 0;
  }
  .cal-cell {
    height: 64px;
    padding: 2px 3px;
  }
  .cal-cell__date { padding: 0; }
  .cal-cell__num { font-size: 0.72rem; }
  .cal-cell--today .cal-cell__num {
    width: 18px;
    height: 18px;
    font-size: 0.65rem;
  }
  .cal-cell__holiday {
    font-size: 0.55rem;
    line-height: 1.1;
    margin-top: 0;
  }
  .cal-events { gap: 1px; margin-top: 2px; }
  .cal-event {
    padding: 1px 3px;
    font-size: 0.6rem;
    border-radius: 3px;
    gap: 2px;
  }
  .cal-event__time { display: none; }
}

@media (max-width: 420px) {
  .cal-cell { height: 56px; }
  .cal-grid thead th { font-size: 0.6rem; padding: 4px 1px; }
  .cal-cell__num { font-size: 0.7rem; }
  .cal-cell__holiday { font-size: 0.5rem; }
  .cal-event { font-size: 0.55rem; }
}

/* MOBILE — modal */
@media (max-width: 480px) {
  .ev-modal { width: 96vw; max-height: 95vh; }
  .ev-form { padding: 16px; gap: 12px; }
  .ev-form__actions { margin: 8px -16px -16px !important; padding: 12px 16px !important; }
  .color-swatches span { width: 28px; height: 28px; }
}

/* MOBILE MODAL — tighter */
@media (max-width: 480px) {
  .ev-modal {
    width: 92vw !important;
    max-height: 88vh;
    border-radius: 12px !important;
  }
  .ev-form {
    padding: 14px !important;
    gap: 10px !important;
    font-size: 0.88rem;
  }
  .ev-form__head h2 { font-size: 1rem; }
  .ev-field > span,
  .ev-field > legend {
    font-size: 0.7rem !important;
  }
  .ev-field input[type="text"],
  .ev-field input[type="date"],
  .ev-field select,
  .ev-field textarea {
    font-size: 0.88rem !important;
    padding: 6px 8px !important;
  }
  .ev-field textarea { rows: 2; }
  .color-swatches { gap: 6px; }
  .color-swatches span { width: 22px; height: 22px; }
  .ev-form__actions {
    margin: 4px -14px -14px !important;
    padding: 10px 14px !important;
    gap: 6px !important;
  }
  .ev-form__actions .btn { padding: 6px 12px; font-size: 0.85rem; }
}

/* MOBILE MODAL — even tighter */
@media (max-width: 480px) {
  .ev-modal {
    width: 94vw !important;
    max-width: 94vw !important;
    max-height: 86vh !important;
    border-radius: 10px !important;
  }
  .ev-form {
    padding: 12px 12px 0 !important;
    gap: 8px !important;
    font-size: 0.85rem !important;
  }
  .ev-form__head {
    margin-bottom: 0 !important;
  }
  .ev-form__head h2 { font-size: 0.95rem !important; }
  .ev-form__close {
    width: 28px !important;
    height: 28px !important;
    font-size: 1rem !important;
  }
  .ev-field {
    gap: 3px !important;
  }
  .ev-field > span,
  .ev-field > legend {
    font-size: 0.65rem !important;
    letter-spacing: 0.2px !important;
  }
  .ev-field input[type="text"],
  .ev-field input[type="date"],
  .ev-field select,
  .ev-field textarea {
    font-size: 0.85rem !important;
    padding: 5px 8px !important;
    border-radius: 6px !important;
  }
  .ev-field textarea { min-height: 50px; }
  .ev-row { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .color-swatches { gap: 5px; }
  .color-swatches span { width: 20px; height: 20px; }
  .ev-form__actions {
    margin: 4px -12px 0 !important;
    padding: 8px 12px !important;
    gap: 4px !important;
    border-radius: 0 0 10px 10px;
  }
  .ev-form__actions .btn {
    padding: 5px 10px !important;
    font-size: 0.8rem !important;
    border-radius: 6px !important;
  }
}

/* MOBILE MODAL — aggressive size cap */
@media (max-width: 480px) {
  dialog.ev-modal {
    width: 84vw !important;
    max-width: 84vw !important;
    min-width: 0 !important;
    max-height: 78vh !important;
  }
  .ev-form { padding: 10px 10px 0 !important; gap: 6px !important; font-size: 0.78rem !important; }
  .ev-form__head h2 { font-size: 0.85rem !important; }
  .ev-field > span,
  .ev-field > legend { font-size: 0.6rem !important; }
  .ev-field input[type="text"],
  .ev-field input[type="date"],
  .ev-field select,
  .ev-field textarea {
    font-size: 0.78rem !important;
    padding: 4px 6px !important;
  }
  .ev-field textarea { min-height: 36px; }
  .color-swatches span { width: 18px; height: 18px; }
  .ev-form__actions {
    margin: 4px -10px 0 !important;
    padding: 6px 10px !important;
  }
  .ev-form__actions .btn { padding: 4px 8px !important; font-size: 0.75rem !important; }
}

/* iOS auto-zoom fix */
@media (max-width: 480px) {
  .ev-field input[type="text"],
  .ev-field input[type="date"],
  .ev-field select,
  .ev-field textarea {
    font-size: 16px !important;
  }
}

/* MOBILE MODAL — final cleanup */
@media (max-width: 480px) {
  dialog.ev-modal {
    width: 92vw !important;
    max-width: 92vw !important;
    max-height: 80vh !important;
  }
  .ev-form {
    padding: 14px 14px 0 !important;
    gap: 10px !important;
    font-size: 14px !important;
  }
  .ev-form__head h2 { font-size: 1rem !important; }
  .ev-field > span,
  .ev-field > legend {
    font-size: 11px !important;
    letter-spacing: 0.3px !important;
  }
  .ev-field input[type="text"],
  .ev-field input[type="date"],
  .ev-field select,
  .ev-field textarea {
    font-size: 16px !important;
    padding: 8px 10px !important;
    height: auto;
  }
  .ev-field textarea { min-height: 60px; }
  .ev-row {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    gap: 8px !important;
  }
  .ev-row .ev-field { min-width: 0; }
  .color-swatches { gap: 8px; }
  .color-swatches span { width: 24px; height: 24px; }
  .ev-form__actions {
    margin: 6px -14px 0 !important;
    padding: 10px 14px !important;
    gap: 8px !important;
  }
  .ev-form__actions .btn { padding: 6px 12px !important; font-size: 14px !important; }
}

/* hidden attribute force */
.ev-field[hidden],
.ev-form__actions [hidden] { display: none !important; }

/* collapse row when end wrap hidden */
.ev-row:has(> .ev-field[hidden]) {
  grid-template-columns: 1fr !important;
}

/* iOS date input fix */
.ev-form input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  text-align: left;
}
.ev-form input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
  min-width: 0;
}
@media (max-width: 480px) {
  .ev-form input[type="date"] {
    padding: 6px 6px !important;
  }
}
