/* View: Kalendarz (js/views/calendar.js) — mockup #calendar (final/calendar.css).
   Toolbar → (phone) day strip → boxed, internally scrolling surface → (desktop) legend.
   Phone: day = 1-column time grid without its own day head, week = agenda, month = dots. */
@layer views {
#main:has(.page-cal) { padding-bottom: 0; }
.page-cal {
  min-height: 0;
  height: calc(100dvh - var(--shell-top) - var(--shell-bottom));
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px var(--gutter) 8px;
}

/* ---- toolbar ---- */
.cal-toolbar { display: flex; flex-direction: column; gap: 8px; flex: none; }
.cal-nav { display: flex; align-items: center; gap: 4px; min-width: 0; }
.cal-heading { flex: 1; min-width: 0; }
.cal-title {
  font-size: 22px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-summary { font-size: var(--fs-caption); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-nav .btn-group { flex: none; }
.cal-nav .btn-group .btn { width: 44px; min-height: 44px; padding: 0; }
.cal-tools { display: flex; align-items: center; gap: 8px; }
.cal-tools .segmented { flex: 1; display: flex; }
.cal-tools .segmented button { flex: 1; }
.page-cal .today-btn { flex: none; min-height: 44px; }
.page-cal .show-sm { display: none; }

/* ---- day strip (phones) ---- */
.day-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; flex: none; }
.ds-day {
  position: relative; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 14px; color: var(--ink); transition: background var(--t-fast);
}
.ds-d { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.ds-day b {
  font-family: var(--font-display); font-size: 19px; font-weight: var(--w-display); line-height: 1;
  font-variant-numeric: tabular-nums; font-variation-settings: var(--fvs-display);
}
.ds-dots { display: flex; gap: 3px; height: 5px; }
.ds-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.ds-day.is-sel { background: var(--accent); color: var(--on-accent); }
.ds-day.is-sel .ds-d { color: var(--on-accent); opacity: .8; }
.ds-day.is-sel .ds-dots i { background: var(--on-accent); }
.ds-day.is-today:not(.is-sel) b { color: var(--accent); }
.ds-day.is-today:not(.is-sel)::after { content: ""; position: absolute; inset: 0; border-radius: 14px; box-shadow: inset 0 0 0 1.5px var(--accent-line); pointer-events: none; }

/* ---- boxed surface ---- */
.cal-card {
  flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden;
  /* outline + fill: components/widget.css */
}
.cal-scroll { --hh: 64px; --rail: 46px; flex: 1; min-height: 0; overflow: auto; position: relative; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

/* ---- time grid ---- */
.cal-grid { display: flex; flex-direction: column; min-width: 100%; }
.cal-head {
  position: sticky; top: 0; z-index: 6;
  display: grid; grid-template-columns: var(--rail) repeat(var(--cols), minmax(0, 1fr));
  background: var(--surface); border-bottom: 2px solid var(--rule-2);
}
.cal-corner { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.cal-dayhead {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0;
  padding: 8px 4px; border-left: 1px solid var(--rule); background: var(--surface); color: var(--ink);
}
.cal-dayhead.is-weekend { background: var(--paper-2); }
.cdh-name { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.cdh-num {
  font-family: var(--font-display); font-size: 20px; font-weight: var(--w-display); line-height: 1;
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border-radius: 11px;
  font-variant-numeric: tabular-nums; font-variation-settings: var(--fvs-display);
}
.cal-dayhead.is-today .cdh-num { background: var(--accent); color: var(--on-accent); }
.cdh-meta { font-size: 11px; color: var(--ink-3); white-space: nowrap; font-family: var(--font-num); font-variant-numeric: tabular-nums; min-height: 14px; line-height: 14px; }
.cal-body { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); padding: 10px 0 8px; }
.cal-times { position: sticky; left: 0; z-index: 4; background: var(--surface); border-right: 1px solid var(--rule-2); margin: -10px 0 -8px; padding: 10px 0 8px; }
.cal-time { position: relative; }
.cal-time span {
  position: absolute; top: 0; right: 6px; transform: translateY(-50%);
  font-size: 11px; font-weight: 600; color: var(--ink-3); font-family: var(--font-num); font-variant-numeric: tabular-nums; line-height: 1;
}
.cal-cols { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
.day-col {
  position: relative; border-left: 1px solid var(--rule); cursor: cell;
  background-image: linear-gradient(var(--rule-2) 1px, transparent 1px), linear-gradient(var(--rule) 1px, transparent 1px);
  background-size: 100% var(--hh), 100% calc(var(--hh) / 2);
}
.cal-grid.is-day .day-col { border-left: 0; }
.day-col.is-weekend { background-color: var(--paper-2); }

/* ---- lesson block: student hue fill, 4 px edge + 1.5 px outline in every state; status added on top ---- */
.ev {
  position: absolute; z-index: 2; min-width: 0; overflow: hidden;
  display: flex; flex-direction: column; gap: 1px; padding: 5px 8px 5px 10px;
  border-radius: var(--r-ev); background: linear-gradient(var(--hue-soft), var(--hue-soft)), var(--surface); color: var(--ink); text-align: left; line-height: 1.25;
  box-shadow: inset 4px 0 0 var(--hue), inset 0 0 0 1.5px var(--hue-line);
  outline-offset: 1px; cursor: grab; touch-action: manipulation;
  transition: transform var(--t-fast) var(--ease-out), opacity var(--t-fast);
}
.ev-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; font-size: 13.5px; }
.ev-nm { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-mark { display: inline-flex; flex: none; color: var(--ink-2); }
.ev-mark .ico { width: 13px; height: 13px; }
.ev-time { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.ev-sub { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.short { flex-direction: row; align-items: center; gap: 8px; padding: 3px 8px 3px 10px; }
.ev.short .ev-time { font-size: 11.5px; }
.ev.is-split { padding: 4px 6px 4px 9px; }
.ev.is-split .ev-name { font-size: 12.5px; gap: 4px; }
.ev.is-split .ev-time { font-size: 11px; }
.ev-done { background: linear-gradient(hsl(var(--h, 220) var(--ss) var(--sl) / calc(var(--tint-strength) * .55)), hsl(var(--h, 220) var(--ss) var(--sl) / calc(var(--tint-strength) * .55))), var(--surface); box-shadow: inset 4px 0 0 var(--hue), inset 0 0 0 1px var(--hue-line); }
.ev-done .ev-name { color: var(--ink-2); }
.ev-done .ev-mark { color: var(--good-ink); }
.ev-needs { outline: 2px solid var(--warn); }
.ev-live { outline: 2px solid var(--accent); }
.ev-cancelled_student, .ev-cancelled_tutor, .ev-noshow { background: var(--surface); box-shadow: inset 4px 0 0 var(--rule-3), inset 0 0 0 1px var(--rule-2); }
.ev-cancelled_student .ev-nm, .ev-cancelled_tutor .ev-nm, .ev-noshow .ev-nm { text-decoration: line-through; color: var(--ink-3); }
.ev.is-dragging { opacity: .35; cursor: grabbing; }
body.is-dragging-ev, body.is-dragging-ev .ev { cursor: grabbing; }
.ev-ghost {
  position: absolute; left: 4px; right: 4px; z-index: 6; pointer-events: none;
  border-radius: var(--r-ev); border: 2px dashed var(--hue); background: var(--hue-soft);
  display: grid; place-items: center; color: var(--ink); font-size: 12px; font-family: var(--font-num); font-variant-numeric: tabular-nums;
}
.ev-ghost b { font-weight: 600; }

/* ---- now line ---- */
.now-line { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--danger); z-index: 3; pointer-events: none; }
.now-line i { position: absolute; left: -5px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.now-tag {
  position: absolute; left: 10px; top: -10px; padding: 3px 6px; border-radius: var(--r-pill);
  background: var(--danger); color: var(--paper); font-size: 10.5px; font-weight: 700; line-height: 1; font-family: var(--font-num); font-variant-numeric: tabular-nums;
}

/* ---- agenda (phone week) ---- */
.agenda { padding: 0 12px 12px; }
.aday .dayhead {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: 4px 0 2px; background: var(--surface); border-bottom: 2px solid var(--rule-2);
}
.aday .dayhead .kicker { color: var(--ink); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aday .dayhead em { font-style: normal; color: var(--accent); }
.aday .dayhead .cap { flex: none; margin-left: auto; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.aday-add { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: var(--r-ctl); color: var(--ink-2); }
.aday-add:hover { color: var(--ink); background: var(--paper-2); }
.aday.is-free .dayhead { border-bottom-color: var(--rule); }
.aday.is-free .dayhead .kicker, .aday.is-free .dayhead .cap { color: var(--ink-3); }
.ag { display: flex; align-items: center; gap: 8px; min-height: 60px; color: inherit; }
.ag-open { flex: 1; min-width: 0; display: grid; grid-template-columns: 46px 4px minmax(0, 1fr); gap: 0 12px; align-items: center; padding: 8px 0; text-align: left; color: inherit; }
.ag-online { display: inline-flex; margin-left: 6px; color: var(--ink-3); vertical-align: -2px; }
.ag-done { display: inline-flex; width: 28px; justify-content: center; color: var(--good); }
.ag-tm { display: flex; flex-direction: column; line-height: 1.15; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.ag-tm b { font-weight: 600; font-size: var(--fs-body); }
.ag-tm span { font-size: var(--fs-caption); color: var(--ink-3); }
.ag-bar { width: 4px; height: 40px; border-radius: 2px; background: var(--hue); }
.ag-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ag-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-sub { font-size: var(--fs-caption); color: var(--ink-2); line-height: 1.35; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.ag-side { flex: none; display: flex; align-items: center; gap: 6px; }
.ag-side .btn { min-height: 44px; }
.ag.is-done .ag-name { color: var(--ink-2); }
.ag.is-done .ag-bar { opacity: .45; }
.ag.is-cancelled_student .ag-name, .ag.is-noshow .ag-name { color: var(--ink-3); text-decoration: line-through; }

/* ---- month ---- */
.month { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; overscroll-behavior: contain; }
.month-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 2px solid var(--rule-2); }
.month-head span { padding: 10px 4px; text-align: center; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.month-body { flex: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: repeat(var(--rows), minmax(72px, 1fr)); }
.mcell {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; padding: 6px;
  border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); text-align: left; color: var(--ink);
}
.mcell:nth-child(7n) { border-right: 0; }
.mcell.is-weekend { background: var(--paper-2); }
.mcell.is-out { color: var(--ink-3); }
.mcell-num {
  font-family: var(--font-display); font-size: 15px; font-weight: var(--w-display); line-height: 1;
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px;
  font-variant-numeric: tabular-nums; font-variation-settings: var(--fvs-display);
}
.mcell.is-today .mcell-num { background: var(--accent); color: var(--on-accent); }
.mcell-list { display: none; }
.mcell-dots { display: flex; flex-wrap: wrap; gap: 3px; }
.mcell-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--hue); }
.mcell.is-out .mcell-dots { opacity: .55; }

/* ---- legend (desktop) ---- */
.cal-legend { display: none; }

/* ---- phone ---- */
@media (max-width: 760px) {
  .page-cal .show-sm { display: inline-flex; }
  .cal-grid.is-day .cal-head { display: none; }
}
@media (max-width: 380px) {
  .cal-title { font-size: 17.5px; }
  .ds-day b { font-size: 17px; }
  .cal-scroll { --rail: 42px; }
}
@media (max-width: 760px) and (max-height: 520px) {
  .day-strip { display: none; }
}

/* ---- desktop ---- */
@media (min-width: 761px) {
  .page-cal { gap: 0; padding-top: 0; padding-bottom: 12px; }
  .cal-toolbar { flex-direction: row; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 0 12px; }
  .cal-nav { gap: 8px; }
  .cal-heading { flex: 0 1 auto; }
  .cal-title { font-size: 28px; }
  .cal-nav .btn-group .btn { width: 40px; min-height: 40px; }
  .page-cal .today-btn, .cal-new { min-height: 40px; }
  .cal-tools .segmented { flex: none; }
  .cal-tools .segmented button { flex: none; }
  .day-strip { display: none; }
  .cal-scroll { --hh: 72px; --rail: 56px; }
  .cal-dayhead { padding: 10px 8px; }
  .cdh-num { font-size: 22px; width: 36px; height: 36px; }
  .cal-time span { right: 10px; font-size: 11.5px; }
  .cal-grid.is-day .day-col { border-left: 1px solid var(--rule); }
  .ev:hover { transform: translateY(-1px); }
  .cal-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; flex: none; padding: 10px 2px 0; font-size: var(--fs-caption); color: var(--ink-2); }
  .cal-hint { margin-left: auto; }
  .month-body { grid-template-rows: repeat(var(--rows), minmax(104px, 1fr)); }
  .mcell-dots { display: none; }
  .mcell-list { display: flex; flex-direction: column; gap: 3px; width: 100%; min-width: 0; }
  .mpill {
    display: block; width: 100%; padding: 2px 7px; border-radius: 6px; font-size: 12px;
    background: var(--hue-soft); box-shadow: inset 3px 0 0 var(--hue); color: var(--ink-2);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .mpill b { color: var(--ink); font-weight: 600; font-family: var(--font-num); font-variant-numeric: tabular-nums; margin-right: 4px; }
  .mpill.is-done { opacity: .6; }
  .mcell.is-out .mpill { opacity: .5; }
  .mmore { font-size: 12px; color: var(--ink-3); padding-left: 7px; }
  .mcell:hover { background: var(--paper-2); }
}
@media (min-width: 761px) and (max-width: 1000px) {
  .cal-title { font-size: 22px; }
  .cal-hint { display: none; }
}
}
