/* calendar.css — Archie Calendar page */

.cal-body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

/* ── Topbar ──────────────────────────────────────────────────── */

#cal-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-surface);
}

#cal-back {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-sec);
  text-decoration: none;
  font-size: 13px;
  font-family: var(--font-mono);
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color var(--duration);
}
#cal-back:hover { color: var(--accent); }

#cal-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

#cal-nav h1 {
  font-size: 15px;
  font-weight: 600;
  min-width: 160px;
  text-align: center;
}

#btn-cal-prev,
#btn-cal-next {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-sec);
  font-size: 18px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--duration), border-color var(--duration);
}
#btn-cal-prev:hover,
#btn-cal-next:hover { color: var(--accent); border-color: var(--accent-dim); }

#cal-topbar-actions { display: flex; gap: 8px; }

/* ── Layout ──────────────────────────────────────────────────── */

#cal-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  flex: 1;
  overflow: hidden;
}

/* ── Grid ────────────────────────────────────────────────────── */

#cal-grid-wrap {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

#cal-dow-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#cal-dow-header span {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 6px 0;
}

#cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 1fr;
  flex: 1;
  overflow-y: auto;
  align-content: start;
}

.cal-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 4px 6px;
  cursor: pointer;
  min-height: 80px;
  transition: background var(--duration);
  overflow: hidden;
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell:hover { background: var(--bg-hover); }
.cal-cell.cal-cell-out { background: transparent; cursor: default; opacity: 0.3; }
.cal-cell.is-today .cal-day-num {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cal-cell.is-selected { background: rgba(99,102,241,0.08); }
.cal-cell.is-selected .cal-day-num { color: var(--accent); font-weight: 700; }

.cal-day-num {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-sec);
  margin-bottom: 3px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-ev-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.cal-ev-dot {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.cal-ev-more {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 2px;
}

/* ── Sidebar ─────────────────────────────────────────────────── */

#cal-sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-surface);
}

#cal-sidebar-date {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.sidebar-date-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

#cal-sidebar-events {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-empty {
  padding: 20px 14px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.sidebar-event {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,0.04));
  cursor: pointer;
  transition: background var(--duration);
}
.sidebar-event:hover { background: var(--bg-hover); }

.sidebar-ev-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.sidebar-ev-body { flex: 1; overflow: hidden; }

.sidebar-ev-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-ev-time {
  font-size: 11px;
  color: var(--text-sec);
  margin-top: 2px;
}

.sidebar-ev-loc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-ev-edit {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color var(--duration);
  flex-shrink: 0;
}
.sidebar-ev-edit:hover { color: var(--accent); }

/* ── Modal ───────────────────────────────────────────────────── */

#cal-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

#cal-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(420px, 92vw);
  max-height: 90vh;          /* never taller than the viewport … */
  display: flex;
  flex-direction: column;
  overflow: hidden;          /* … header + footer stay pinned, body scrolls */
}

#cal-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;            /* stay pinned while the body scrolls */
}

#btn-modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
}
#btn-modal-close:hover { color: var(--text); }

#cal-modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;          /* scroll the fields if they exceed the capped height */
  min-height: 0;             /* allow the flex child to shrink below content size */
}

.ev-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-top: 6px;
}
.ev-label:first-child { margin-top: 0; }
.ev-hint { font-weight: 400; text-transform: none; letter-spacing: 0; }
.ev-inline { font-size: 13px; text-transform: none; letter-spacing: 0; font-weight: 400; }

.ev-allday-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
}

#cal-modal-body input[type="text"],
#cal-modal-body input[type="date"],
#cal-modal-body input[type="time"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}
#cal-modal-body input:focus { border-color: var(--accent-dim); }

#ev-time-fields {
  display: flex;
  gap: 8px;
  flex-direction: column;
}

#cal-modal-status {
  font-size: 12px;
  min-height: 18px;
  margin-top: 4px;
}
.modal-status-err { color: var(--red); }
.modal-status-ok  { color: var(--green); }

#cal-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;            /* Save/Delete always visible, never pushed off-screen */
}

/* ── Shared button styles ─────────────────────────────────────── */

.btn-primary-sm {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 500;
  transition: opacity var(--duration);
}
.btn-primary-sm:hover { opacity: 0.85; }
.btn-primary-sm:disabled { opacity: 0.4; cursor: default; }

.btn-danger-sm {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  cursor: pointer;
  font-weight: 500;
}
.btn-danger-sm:hover { background: rgba(199,91,91,0.1); }

.btn-ghost {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-sec);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: color var(--duration), border-color var(--duration);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-hover); }
.btn-sm { font-size: 11px; padding: 3px 8px; }

/* ── Toast ───────────────────────────────────────────────────── */

#cal-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  z-index: 9999;
  pointer-events: none;
}
.cal-toast-ok  { background: var(--green); color: #000; }
.cal-toast-err { background: var(--red);   color: #fff; }

/* ── Category filter chips ───────────────────────────────────── */

#cal-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
#cal-filter-chips:empty { display: none; }

.cal-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-input);
  color: var(--text-sec);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: opacity var(--duration), border-color var(--duration);
}
.cal-chip:hover { border-color: var(--border-hover); }
.cal-chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.cal-chip.is-off { opacity: 0.4; text-decoration: line-through; }

/* ── Category field in event modal ───────────────────────────── */

.ev-cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
#ev-category {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
}
#ev-category:focus { border-color: var(--accent-dim); }

/* ── Manage-categories modal ─────────────────────────────────── */

#cat-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
#cat-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(400px, 92vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#cat-modal-header { flex-shrink: 0; }
#cat-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
}
#btn-cat-modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
}
#btn-cat-modal-close:hover { color: var(--text); }

#cat-modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
}
.cat-empty { font-size: 13px; color: var(--text-muted); padding: 4px 0; }

.cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cat-row-color,
#cat-new-color {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  cursor: pointer;
  flex-shrink: 0;
}
.cat-row-name {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  outline: none;
}
.cat-row-name:focus { border-color: var(--accent-dim); }
.cat-row-del {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}
.cat-row-del:hover { color: var(--red); }

#cat-add-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
#cat-new-name {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  outline: none;
}
#cat-new-name:focus { border-color: var(--accent-dim); }
#cat-modal-status { font-size: 12px; min-height: 16px; }

/* ── Mobile ──────────────────────────────────────────────────── */

@media (max-width: 700px) {
  #cal-layout { grid-template-columns: 1fr; }
  #cal-sidebar { display: none; }
  #cal-grid-wrap { border-right: none; }
  .cal-cell { min-height: 56px; }
}
