/* =====================================================================================
   Calendar page (/calendar). Builds on /shared/base.css.
   Sections: colours · header · toolbar & legend · chips · layout & month grid ·
             online/offline colours · day panel & timeline · deadlines · deadline form · swipe
   Note: a few sections must stay in this order because later rules deliberately win over
   earlier ones of equal weight (online/offline cell colours, then red deadline edges).
   ===================================================================================== */

/* ---------- Colours: event types, online / offline, deadlines (light, then dark) ---------- */
:root {
  --dl: #d6336c;
  --t-class: #1f9d55; --t-exam: #7048e8; --t-holiday: #e8590c; --t-admission: #d9a400; --t-event: #d9a400; --t-guest: #0c8599;
  --online: #1c7ed6; --offline: #1f9d55;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --dl: #ff6b8a; --t-class: #3ecf7c; --t-exam: #9775fa; --t-holiday: #ff8a4c; --t-admission: #fcc419; --t-event: #fcc419; --t-guest: #3bc9db; --online: #4dabf7; --offline: #3ecf7c; }
}
:root[data-theme="dark"] { --dl: #ff6b8a; --t-class: #3ecf7c; --t-exam: #9775fa; --t-holiday: #ff8a4c; --t-admission: #fcc419; --t-event: #fcc419; --t-guest: #3bc9db; --online: #4dabf7; --offline: #3ecf7c; }

/* ---------- Header: title row with the purple "PDF / PPT downloader" button ---------- */
main.wide { max-width: 1180px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.topbar > div:only-child { flex: 1; }
.titlerow { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.titlerow h1 { margin: 0; min-width: 0; }
a.btn-link.dl-btn { background: #5f3dc4; border-color: #5f3dc4; color: #fff; font-size: 14px; padding: 9px 14px; flex: none; }
a.btn-link.dl-btn:hover { background: #4c2fa8; border-color: #4c2fa8; }
a.dl-btn .short { display: none; }
@media (max-width: 520px) { /* phones: shorter button label */
  .titlerow h1 { font-size: 24px; }
  a.btn-link.dl-btn { font-size: 13px; padding: 7px 10px; }
  a.dl-btn .long { display: none; } a.dl-btn .short { display: inline; }
}
.topbar .sub { margin-bottom: 18px; }
a.btn-link { display: inline-block; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); color: var(--text);
  text-decoration: none; font-weight: 600; background: var(--card); white-space: nowrap; }
a.btn-link:hover { border-color: var(--accent-2); }

/* ---------- Toolbar: quarter tabs, month switcher, small buttons, legend ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.quarters { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 8px 16px; border-radius: 99px; background: var(--card); color: var(--text); border: 1px solid var(--border); font-weight: 600; }
.pill.on { background: var(--accent-2); color: #fff; border-color: var(--accent-2); }
.pill .tt { font-size: 12px; opacity: .85; }
.monthnav { display: flex; align-items: center; gap: 8px; }
.monthnav strong { min-width: 150px; text-align: center; font-size: 17px; }
button.icon { width: 38px; height: 38px; padding: 0; font-size: 22px; line-height: 1; }
button.small { padding: 8px 12px; font-size: 14px; }
button:disabled { opacity: .35; cursor: default; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }

/* ---------- Chips (event labels) and Online / Offline badges; --tc = the chip's colour ---------- */
.chip { display: inline-block; font-size: 12px; font-weight: 600; line-height: 1.35; padding: 2px 7px; border-radius: 6px;
  color: var(--tc, var(--text)); background: color-mix(in srgb, var(--tc, var(--muted)) 15%, transparent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.chip.plain { --tc: var(--muted); }
.t-class { --tc: var(--t-class); } .t-exam { --tc: var(--t-exam); } .t-holiday { --tc: var(--t-holiday); }
.t-admission { --tc: var(--t-admission); } .t-event { --tc: var(--t-event); } .t-guest { --tc: var(--t-guest); }
.mode { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 99px; border: 1px solid currentColor; line-height: 1.4; }
.mode.online { color: var(--online); } .mode.offline { color: var(--offline); }
.mode.big { font-size: 13px; padding: 3px 10px; }

/* ---------- Layout and month grid ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; } }
.grid-card { padding: 12px; }
.monthnav.gridnav { justify-content: center; margin: 2px 0 10px; } /* month switcher right on top of the grid (easy on phones) */
.monthnav.gridnav strong { flex: 1; max-width: 260px; }
.monthnav.gridnav #today { margin-left: 4px; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.weekdays span { font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; padding: 4px 0; }
.cell { position: relative; min-height: 104px; padding: 6px; border-radius: 10px; text-align: left; display: flex; flex-direction: column; gap: 3px;
  background: var(--input); color: var(--text); border: 1px solid var(--border); font-weight: 400; cursor: pointer; overflow: hidden; }
.cell.wkend { background: color-mix(in srgb, var(--muted) 8%, var(--input)); }
.cell.out { opacity: .4; }
.cell.has { border-color: color-mix(in srgb, var(--accent-2) 35%, var(--border)); }
.cell:hover { border-color: var(--accent-2); }
.cell.sel { outline: 2px solid var(--accent-2); outline-offset: -1px; }
.cell .num { font-weight: 700; font-size: 14px; }
.cell.today .num { background: var(--accent); color: #fff; border-radius: 99px; padding: 0 7px; align-self: flex-start; }
.cell .mode { position: absolute; top: 6px; right: 6px; }
.cell .chips { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cell .sess { font-size: 11px; color: var(--muted); margin-top: auto; }
@media (max-width: 640px) { /* phones: chips become coloured bars, badges become dots */
  .cell { min-height: 64px; padding: 4px; }
  .cell .chip { font-size: 0; padding: 0; width: 100%; height: 5px; border-radius: 3px; background: var(--tc); }
  .cell .mode { font-size: 0; width: 8px; height: 8px; padding: 0; background: currentColor; top: 5px; right: 5px; }
  .cell .sess { font-size: 10px; } .cell .sess .lbl { display: none; }
  .monthnav strong { min-width: 120px; }
}

/* ---------- Day panel and hour-by-hour timeline ---------- */
.day-card h2 { font-size: 17px; margin: 0; }
.classnav { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: -4px 0 14px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.classnav .hint { font-size: 13px; text-align: center; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.classnav button { white-space: nowrap; }
.dayhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.events { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; font-size: 14px; }
.timeline { position: relative; margin-top: 6px; }
.hour { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--border); }
.hour span { position: absolute; top: -9px; left: 0; font-size: 11px; color: var(--muted); background: var(--card); padding-right: 4px; }
.blocks { position: absolute; left: 62px; right: 0; top: 0; bottom: 0; }
.slot { position: absolute; left: 0; right: 0; border-radius: 8px; padding: 6px 9px; overflow: hidden; font-size: 13px; line-height: 1.3;
  background: color-mix(in srgb, var(--offline) 13%, var(--card)); border-left: 4px solid var(--offline); }
.slot.online { background: color-mix(in srgb, var(--online) 13%, var(--card)); border-left-color: var(--online); }
.slot .when { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; justify-content: space-between; }
.slot .what { margin-top: 2px; }
.slot .who { font-size: 12px; color: var(--muted); }
.slot.par { padding: 5px 7px; }            /* parallel courses (electives) side by side */
.slot.par .when { font-size: 11px; }
.slot.par .what { font-size: 12px; }
.gap { position: absolute; left: 0; right: 0; display: flex; align-items: center; justify-content: center; }
.gap span { font-size: 11px; color: var(--muted); background: var(--card); padding: 0 6px; }

/* ---------- Online vs offline class days: blue vs green, everywhere ---------- */
.chip.m-online { --tc: var(--online); }
.chip.m-offline { --tc: var(--offline); }
.cell.d-online { background: color-mix(in srgb, var(--online) 10%, var(--input)); border-color: color-mix(in srgb, var(--online) 45%, var(--border)); }
.cell.d-offline { background: color-mix(in srgb, var(--offline) 10%, var(--input)); border-color: color-mix(in srgb, var(--offline) 45%, var(--border)); }

/* ---------- Deadlines: red all-day chips, cards in the day panel, "Next deadlines" box ---------- */
.chip.dl { --tc: var(--dl); background: var(--dl); color: #fff; cursor: pointer; }
.cell.has-dl { border-top: 3px solid var(--dl); }
.dlday { display: grid; gap: 8px; margin-bottom: 14px; }
.dlcard { text-align: left; display: grid; gap: 2px; padding: 9px 11px; border-radius: 10px; font-weight: 400;
  background: color-mix(in srgb, var(--dl) 12%, var(--card)); color: var(--text); border: 1px solid color-mix(in srgb, var(--dl) 45%, transparent); border-left: 4px solid var(--dl); }
.dlcard:hover { border-color: var(--dl); }
.dltype { font-size: 12px; font-weight: 700; color: var(--dl); }
.dltitle { font-weight: 600; }
.dlnotes { font-size: 13px; color: var(--muted); }
.dlmeta { font-size: 11px; color: var(--muted); }
button.addDl { justify-self: start; }
.upcoming { padding: 14px 16px; }
.uphead { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.uphead h2 { font-size: 16px; margin: 0; }
.upnav { display: flex; align-items: center; gap: 6px; }
.uplist { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 760px) { .uplist { grid-template-columns: 1fr; } }
.upcard { text-align: left; display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px; font-weight: 400; color: var(--text);
  background: color-mix(in srgb, var(--dl) 9%, var(--card)); border: 1px solid color-mix(in srgb, var(--dl) 35%, transparent); border-left: 4px solid var(--dl); }
.upcard:hover { border-color: var(--dl); }
.updue { font-size: 12px; font-weight: 700; color: var(--dl); text-transform: uppercase; letter-spacing: .03em; }
.update { font-size: 13px; color: var(--muted); }
.uptitle { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uptype { font-size: 12px; color: var(--muted); }

/* ---------- Add / edit deadline form (dialog) ---------- */
dialog.dlg { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--card); color: var(--text); width: min(520px, calc(100vw - 32px)); }
dialog.dlg::backdrop { background: rgb(0 0 0 / .45); }
.dlg form { display: grid; gap: 12px; padding: 20px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.dlg input, .dlg select, .dlg textarea { font: inherit; font-weight: 400; color: var(--text); background: var(--input); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; width: 100%; }
.dlg .frow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .dlg .frow { grid-template-columns: 1fr; } }
.dlg .factions { display: flex; gap: 8px; align-items: center; }
.dlg .factions .grow { flex: 1; }
.dlg .factions button { padding: 10px 14px; }
button.danger { background: transparent; color: var(--err); border: 1px solid var(--err); padding: 6px 10px; font-size: 13px; }
.dlhist ul { margin: 2px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }
.dlhist .hint { font-size: 12px; margin: 0; }

/* ---------- Swipe feedback (phones): the new month / day slides in from the swipe side ---------- */
@keyframes inFromRight { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes inFromLeft { from { transform: translateX(-24px); opacity: .4; } to { transform: none; opacity: 1; } }
.swipe-l .grid, .swipe-l.day-card > * { animation: inFromRight .22s ease-out; }
.swipe-r .grid, .swipe-r.day-card > * { animation: inFromLeft .22s ease-out; }
@media (prefers-reduced-motion: reduce) { .swipe-l .grid, .swipe-r .grid, .swipe-l.day-card > *, .swipe-r.day-card > * { animation: none; } }
.grid-card, .day-card { touch-action: pan-y; }
