/* Siatka grafiku + oś czasu stażysty. Klocek = ciągły przedział oddziału w kolorze oddziału. */
:root { --colw: 46px; --w-sup: 132px; --w-lp: 34px; --w-name: 184px; --rowh: 36px; }

.toolbar {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .5rem .6rem; margin-bottom: .6rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1);
}
.tb-break { display: none; }
.tb-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 .25rem; }
.tb-last { max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kbd-help { position: relative; margin-left: auto; }
.kbd-help summary { list-style: none; }
.kbd-help summary::-webkit-details-marker { display: none; }
.kbd-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: min(420px, 90vw); padding: .9rem 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-2); font-size: var(--fs-sm);
}
.kbd-pop ul { margin: 0; padding-left: 1.1rem; display: grid; gap: .3rem; }
kbd { font: 600 .75rem/1 var(--font); padding: .15rem .35rem; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 3px; background: var(--surface-2); margin: 0 .1rem; }

.filters {
  display: flex; flex-wrap: wrap; gap: .6rem .9rem; align-items: flex-end; margin-bottom: .75rem;
}
.filters .field { min-width: 150px; }
.filters .f-num { min-width: 0; width: 84px; }
.filters .f-prob { align-self: flex-end; align-items: center; min-height: 36px; font-size: var(--fs-sm); }
.filters select, .filters input { min-height: 36px; padding: .3rem .5rem; }
.filters input[type=checkbox] { min-height: 0; padding: 0; margin: 0; }

.grid-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
.grid-main { min-width: 0; }
.grid-legend { margin-bottom: .4rem; }
.lg-locked { background: #9bb; }
.lg-auto { background: repeating-linear-gradient(135deg, #cfe3e3 0 3px, #fff 3px 6px); outline: 1.5px dashed #333; outline-offset: -2px; }
.lg-manual { background: #cfe3e3; }
.abs-demo { display: inline-block; font-size: 10px; padding: 0 3px; border-radius: 3px; background: #fff; border: 1px solid var(--ink); color: var(--ink); line-height: 14px; }

.grid-scroll {
  position: relative; overflow: auto; max-height: calc(100vh - 240px); min-height: 320px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  overscroll-behavior: contain;
}
#grid-wrap { position: relative; width: max-content; }
table.grid { border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: var(--fs-xs); }
table.grid:focus-visible { outline: none; }
.grid-scroll:focus-within { box-shadow: 0 0 0 3px rgba(31, 111, 235, .35); }
.col-sup { width: var(--w-sup); } .col-lp { width: var(--w-lp); } .col-name { width: var(--w-name); } .col-wk { width: var(--colw); }

table.grid th, table.grid td { padding: 0; border-right: 1px solid #e3e7e4; border-bottom: 1px solid #e3e7e4; height: var(--rowh); }
table.grid thead th {
  position: sticky; top: 0; z-index: 3; background: var(--surface-2); height: 52px; font-weight: 600;
  color: var(--ink-2); border-bottom: 1px solid var(--line-strong); text-align: left; padding: 0 .4rem;
}
table.grid thead th.wk { text-align: center; padding: 2px 0; line-height: 1.15; }
.wk-dates { display: block; font-size: 11px; font-weight: 650; color: var(--ink); white-space: nowrap; letter-spacing: -.03em; }
.wk-mon { display: block; font-size: 10px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.wk-no { display: block; font-size: 10px; color: var(--ink-3); font-weight: 500; }
th.wk.m-start { border-left: 1px solid var(--line-strong); }
th.wk.is-current { background: var(--accent); color: #fff; }
th.wk.is-current .wk-dates, th.wk.is-current .wk-no, th.wk.is-current .wk-mon { color: #fff; }

.stk { position: sticky; z-index: 2; background: var(--surface); }
.c-sup { left: 0; }
.c-lp { left: var(--w-sup); text-align: center; color: var(--ink-3); }
.c-name { left: calc(var(--w-sup) + var(--w-lp)); box-shadow: 2px 0 0 var(--line-strong); }
.c-occ { left: 0; }
table.grid thead th.stk { z-index: 6; background: var(--surface-2); }
th.c-sup[scope=rowgroup] { vertical-align: top; padding: .45rem .5rem; font-weight: 600; text-align: left; background: #fafbf9; }
.sup-name { display: block; font-size: var(--fs-xs); line-height: 1.25; color: var(--ink); }
.sup-grp { display: block; font-size: 10px; color: var(--ink-3); font-weight: 500; margin-top: .15rem; }
th.c-name { text-align: left; font-weight: 560; padding: 0 .5rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--fs-sm); }
.c-name .nm { overflow: hidden; text-overflow: ellipsis; }
.row-flag { color: var(--danger); width: 14px; height: 14px; margin-right: .2rem; vertical-align: -2px; }
tbody.grp tr:first-child > * { border-top: 2px solid var(--line-strong); }
tbody.grp:first-of-type tr:first-child > * { border-top: 0; }
tr[data-intern]:hover th.c-name, tr.is-row-target th.c-name { background: var(--accent-soft); }
tr.is-row-target td { background: #f3f8f8; }

td.seg { padding: 3px 1px; position: relative; }
td.cell-empty { position: relative; background: #fff; }
td.cell-empty.is-masked { background: repeating-linear-gradient(135deg, #f1f2f0 0 4px, #fafaf9 4px 8px); }
/* poza indywidualnym okresem stażu (przed początkiem / po końcu) — nie można tu wstawiać klocków */
td.cell-empty.is-out { background: repeating-linear-gradient(45deg, #e9eae7 0 3px, #f4f4f2 3px 9px); cursor: not-allowed; }
td.cell-empty.is-out .out-label { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  padding: 0 4px; font-size: .68rem; color: #6b6e68; font-style: italic; text-align: center; }
td.cell-empty.is-partial { background: #f7f7f5; }
.blk {
  position: relative; height: 100%; min-height: 28px; display: flex; align-items: center; gap: 3px; padding: 0 6px;
  background-color: var(--bg); color: var(--fg); border-radius: 4px; border: 1px solid rgba(0, 0, 0, .28);
  font-weight: 650; font-size: 11px; white-space: nowrap; overflow: hidden; cursor: default; user-select: none;
  touch-action: manipulation;
  background-image: repeating-linear-gradient(to right, transparent 0 calc(var(--colw) - 2px), rgba(0, 0, 0, .14) calc(var(--colw) - 2px) calc(var(--colw) - 1px));
}
tr[data-editable] .blk:not(.is-locked)[data-a]:not([data-a=""]) { cursor: grab; touch-action: none; }
.blk-label { overflow: hidden; text-overflow: ellipsis; position: relative; z-index: 1; }
.blk-lock { width: 12px; height: 12px; opacity: .8; position: relative; z-index: 1; }
.blk.is-auto { border: 1.5px dashed rgba(0, 0, 0, .65); }
.blk.is-auto::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(135deg, rgba(255, 255, 255, .38) 0 4px, transparent 4px 9px); pointer-events: none; }
.blk.is-external, .blk.is-elective { border: 2px double rgba(0, 0, 0, .55); }
.blk.is-selected { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--focus); }
.blk.is-dragging-src { opacity: .35; }
.abs {
  position: absolute; z-index: 1; bottom: 1px; left: calc(var(--k) * var(--colw) + var(--colw) - 24px);
  font: 700 9px/12px var(--font); font-style: normal; padding: 0 2px; min-width: 14px; text-align: center;
  border-radius: 3px; background: #fff; color: var(--ink); border: 1px solid var(--ink);
}
td.cell-empty .abs { left: auto; right: 3px; }
/* klocek ze znacznikiem (K/U/L4/LEK): nazwa u góry, znacznik u dołu — nie nachodzą na siebie */
.blk.has-abs { align-items: flex-start; padding-top: 1px; }
.blk.has-abs .blk-label { line-height: 14px; }
.blk.has-abs .blk-lockbtn, .blk.has-abs .blk-lock { margin-top: -1px; }
.abs-u { background: #fff4c2; border-color: #7a4d00; color: #4d3100; }
.abs-l4 { background: #fde2df; border-color: var(--danger); color: #7a1610; }
.abs-k { background: #e2ecfb; border-color: #1d4f91; color: #123a6b; }
.abs-lek { background: #efe3fb; border-color: #5b2a91; color: #3d1a66; }

/* obłożenie pod siatką */
tbody.occ th, tbody.occ td { height: 26px; }
tbody.occ tr.occ-head th { border-top: 3px solid var(--ink); background: var(--surface-2); text-align: left; padding: 0 .5rem; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; }
tbody.occ tr.occ-head td { border-top: 3px solid var(--ink); background: var(--surface-2); }
tbody.occ th.c-occ { text-align: left; padding: 0 .5rem; font-weight: 500; white-space: nowrap; box-shadow: 2px 0 0 var(--line-strong); }
td.occ-c { text-align: center; font-size: 11px; font-weight: 650; color: var(--ink); }
td.occ-c .cap { font-weight: 400; color: var(--ink-3); font-size: 9px; }
td.occ-c.is-over { background: var(--danger); color: #fff; }
td.occ-c.is-over .cap { color: #ffd9d5; }
td.occ-c.is-period { background-image: repeating-linear-gradient(135deg, transparent 0 4px, rgba(0, 0, 0, .06) 4px 5px); }
td.occ-c.is-current, td.occ-sp.is-current { box-shadow: inset 2px 0 0 var(--accent), inset -2px 0 0 var(--accent); }
td.occ-c.is-preview { outline: 2px solid var(--focus); outline-offset: -2px; }

.grid-empty { padding: 2rem !important; text-align: left; font-size: var(--fs-sm); }

/* nakładki: bieżący tydzień, kursor, cel upuszczenia */
.cur-stripe { position: absolute; top: 0; bottom: 0; background: rgba(10, 92, 99, .07); border-left: 2px solid rgba(10, 92, 99, .55); border-right: 2px solid rgba(10, 92, 99, .55); pointer-events: none; z-index: 1; }
.grid-cursor { position: absolute; pointer-events: none; z-index: 1; border: 2px solid var(--focus); border-radius: 4px; box-shadow: 0 0 0 2px rgba(255, 255, 255, .9); }
.drop-ghost { position: absolute; pointer-events: none; z-index: 1; border-radius: 4px; border: 2px dashed var(--ink); background: rgba(10, 92, 99, .16); }
.drop-ghost.is-over { border-color: var(--danger); background: rgba(179, 38, 30, .16); }
.drop-ghost.is-invalid { border-color: var(--ink-3); background: repeating-linear-gradient(135deg, rgba(0,0,0,.08) 0 4px, transparent 4px 8px); }
.drag-avatar { position: fixed; z-index: 80; pointer-events: none; transform: translate(-50%, -60%) rotate(-1.5deg); box-shadow: var(--shadow-2); opacity: .95; border-radius: 4px; }
.drop-tip {
  position: fixed; z-index: 81; pointer-events: none; background: var(--ink); color: #fff; padding: .45rem .6rem;
  border-radius: var(--radius-sm); font-size: var(--fs-xs); line-height: 1.4; box-shadow: var(--shadow-2); max-width: 280px;
}
.drop-tip b { font-weight: 700; }
.drop-tip .over { color: #ffb4ab; font-weight: 700; }
.drop-tip .ok { color: #a8e6bc; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }
#grid-wrap.is-busy { opacity: .6; transition: opacity .15s; }

/* panel boczny */
.grid-side { position: sticky; top: 64px; display: grid; gap: .75rem; max-height: calc(100vh - 80px); overflow: auto; }
.side-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .85rem; box-shadow: var(--shadow-1); }
.side-h { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin: 0 0 .5rem; display: flex; align-items: center; gap: .35rem; }
.palette { display: flex; flex-wrap: wrap; gap: .35rem; }
.pal {
  font: 650 11px/1 var(--font); padding: .45rem .55rem; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .3);
  background: var(--bg, #fff); color: var(--fg, var(--ink)); cursor: grab; touch-action: none; min-height: 30px;
  display: inline-flex; align-items: center; gap: .3rem;
}
.pal[aria-selected="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--focus); }
.pal-erase { background: var(--surface); color: var(--ink); border-style: dashed; }
.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 340px; overflow: auto; }
.iss-btn { display: flex; gap: .4rem; align-items: flex-start; width: 100%; text-align: left; background: none; border: 0; padding: .35rem .4rem; border-radius: 4px; font: inherit; font-size: var(--fs-xs); color: var(--ink); cursor: pointer; }
.iss-btn:hover { background: var(--surface-2); }
.iss-error svg { color: var(--danger); }
.iss-warning svg { color: var(--warn); }
.iss-info svg { color: var(--accent); }
.ok-state { color: var(--ok); font-weight: 600; font-size: var(--fs-sm); display: flex; gap: .35rem; align-items: center; margin: 0; }
.changes { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.chg { display: flex; gap: .5rem; align-items: flex-start; justify-content: space-between; font-size: var(--fs-xs); padding-bottom: .4rem; border-bottom: 1px solid var(--line); }
.chg:last-child { border-bottom: 0; }
.chg-txt { display: grid; gap: .1rem; min-width: 0; }
.chg-label { font-weight: 560; overflow-wrap: anywhere; }
.chg.is-undone .chg-label { text-decoration: line-through; color: var(--ink-3); }

/* oś czasu stażysty (mobile-first) */
.timeline { display: flex; gap: 2px; overflow-x: auto; padding: .25rem 0 .6rem; scroll-snap-type: x proximity; }
.tl-seg { flex: 0 0 calc(var(--n) * 22px); min-width: 22px; height: 44px; border-radius: 4px; position: relative; scroll-snap-align: start; }
.tl-seg.is-block { background: var(--bg); color: var(--fg); border: 1px solid rgba(0,0,0,.25); display: flex; align-items: center; padding: 0 5px; font: 650 10px/1.1 var(--font); overflow: hidden; }
.tl-seg.is-empty { background: repeating-linear-gradient(135deg, var(--surface-2) 0 4px, #fff 4px 8px); border: 1px dashed var(--line-strong); }
.tl-seg.is-auto { border-style: dashed; border-color: rgba(0,0,0,.6); }
.tl-seg.is-now { outline: 3px solid var(--focus); outline-offset: 1px; }
.tl-seg .tl-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1100px) {
  .grid-layout { grid-template-columns: 1fr; }
  .grid-side { position: static; max-height: none; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-width: 700px) {
  :root { --w-sup: 76px; --w-lp: 0px; --w-name: 128px; --colw: 42px; }
  .c-lp { font-size: 0; border-right: 0; }
  .sup-name { font-size: 10px; }
  th.c-name { font-size: var(--fs-xs); }
  .grid-scroll { max-height: 70vh; }
  tbody.occ tr.occ-head th { white-space: normal; line-height: 1.2; padding: .25rem .5rem; height: auto; }
  /* „Zaplanuj resztę” — osobny wiersz, styl drugorzędny, z dala od „Cofnij” (i tak pyta o potwierdzenie) */
  .tb-break { display: block; order: 9; flex-basis: 100%; height: 0; margin-top: .35rem; border-top: 1px solid var(--line); }
  .toolbar #btn-plan { order: 10; margin-top: .35rem; background: var(--surface); color: var(--accent); border-color: var(--line-strong); }
  .toolbar #btn-plan:hover { background: var(--surface-2); }
  .toolbar .tb-sep { display: none; }
}

@media print {
  :root { --colw: 30px; --w-sup: 90px; --w-lp: 22px; --w-name: 120px; --rowh: 20px; }
  .grid-layout { display: block; }
  .grid-scroll { overflow: visible; max-height: none; border: 0; }
  #grid-wrap { width: auto; }
  .stk, table.grid thead th { position: static; }
  .wk-dates, .wk-mon, .wk-no { font-size: 7px; }
  .blk { font-size: 7px; min-height: 16px; padding: 0 2px; }
  .abs { font-size: 6px; line-height: 9px; }
  .cur-stripe, .grid-cursor, .drop-ghost { display: none; }
  table.grid { font-size: 7pt; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
}

/* zaznaczenie wielu klocków */
.tb-sel { display: inline-flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.tb-sel[hidden] { display: none; }
.sel-info { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.kbd-sub { margin: .7rem 0 .3rem; }
.blk.is-picked {
  box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px var(--ink);
  border-color: var(--ink);
}
.blk.is-picked::before {
  content: "✓"; position: relative; z-index: 2; flex: 0 0 auto; width: 14px; height: 14px; border-radius: 50%;
  background: var(--ink); color: #fff; font: 700 9px/14px var(--font); text-align: center;
}
.blk.is-picked.is-selected { box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px var(--ink), 0 0 0 5px var(--focus); }
.drop-ghost.is-multi {
  z-index: 3; border: 2px dashed var(--ink); background: rgba(10, 92, 99, .34);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .85);
}
.drop-ghost.is-multi.is-over { border-color: var(--danger); background: rgba(179, 38, 30, .32); }
.drag-count {
  position: absolute; right: -6px; top: -8px; min-width: 20px; padding: 0 4px; border-radius: 10px; z-index: 3;
  background: var(--ink); color: #fff; font: 700 11px/18px var(--font); text-align: center; border: 1px solid #fff;
}
.drag-avatar { overflow: visible; }
@media print { .blk.is-picked::before { display: none; } .blk.is-picked { box-shadow: none; } }

/* Problemy: wyjaśnianie ostrzeżeń, sekcje zwinięte */
.iss-ack { margin: .2rem 0 .4rem 1.6rem; }
.iss-ack summary { cursor: pointer; color: var(--accent, #0a5c63); }
.iss-ack-form { display: flex; gap: .4rem; margin-top: .3rem; }
.iss-ack-form input[name="note"] { flex: 1; min-width: 0; }
.iss-more { margin-top: .8rem; border-top: 1px solid var(--line, #ddd); padding-top: .5rem; }
.iss-more summary { cursor: pointer; }
.iss-more ul { margin: .4rem 0 0; padding-left: 1.1rem; display: grid; gap: .35rem; }
form.inline { display: inline; }
.btn-link { background: none; border: 0; padding: 0; color: var(--accent, #0a5c63); text-decoration: underline; cursor: pointer; font: inherit; }

/* Kłódka na kaflu: zakłódkuj / odkłódkuj jednym kliknięciem (koordynator). */
.blk-lockbtn {
  position: relative; z-index: 1; flex: none; display: inline-grid; place-items: center;
  width: 16px; height: 16px; padding: 0; margin: 0 1px 0 -2px; border: 0; border-radius: 3px;
  background: transparent; color: inherit; cursor: pointer; opacity: 0;
}
.blk-lockbtn svg { width: 12px; height: 12px; }
.blk.is-locked .blk-lockbtn, .blk:hover .blk-lockbtn, .blk-lockbtn:focus-visible { opacity: .9; }
.blk-lockbtn:hover { background: rgba(0, 0, 0, .18); opacity: 1; }
@media (hover: none) { .blk-lockbtn { opacity: .55; } }
@media print { .blk-lockbtn { display: none; } .blk.is-locked .blk-lockbtn { display: inline-grid; } }
