/* ═══════════════════════════════════════════════════════════════════
   Mr. Jaws Guitar — RAILDOCK v1.0
   Док-панель #rail: тянущаяся ширина, масштабирование содержимого,
   перенос блоков между панелью и основным окном, пустая панель = 0.
   Подключается ПОСЛЕ styles.css и точечно переопределяет только рейл.
   ═══════════════════════════════════════════════════════════════════ */

/* ── 1. Ширина панели: сетка контента слушает переменную ─────────── */
#content {
	position: relative;                                   /* якорь разделителя */
	grid-template-columns: minmax(0, 1fr) var(--railw, 324px);
}
/* styles.css в медиазапросе ≤1240px схлопывает колонку — повторяем,
   иначе это правило (более позднее) перебило бы его */
@media (max-width: 1240px) {
	#content { grid-template-columns: minmax(0, 1fr); }
}

/* пустая панель: колонка 0, зазор 0, сам рейл скрыт */
.rail-empty #content { grid-template-columns: minmax(0, 1fr) 0; column-gap: 0; }
.rail-empty #rail { display: none; }
.rail-empty #railSizer { display: none; }

/* ── 2. Разделитель ширины (живёт в #content, в зазоре перед рейлом) */
#railSizer {
	position: absolute;
	top: 0; bottom: 0;
	right: calc(var(--railw, 324px) + 21px);   /* центр 18px-зазора */
	width: 12px;
	z-index: 35;
	cursor: ew-resize;
	touch-action: none;
	display: flex; align-items: center; justify-content: center;
}
#railSizer::before {
	content: "";
	width: 3px; height: 64px;
	border-radius: 99px;
	background: var(--brd2);
	opacity: .5;
	transition: background-color .2s ease, opacity .2s ease, height .25s var(--ease), box-shadow .25s ease;
}
#railSizer:hover::before,
#railSizer:focus-visible::before,
body.rail-resizing #railSizer::before {
	background: var(--acc);
	opacity: 1;
	height: 112px;
	box-shadow: 0 0 12px var(--glow);
}
body.rail-resizing { user-select: none; -webkit-user-select: none; }
body.rail-resizing * { cursor: ew-resize !important; }
@media (max-width: 1240px) { #railSizer { display: none; } }
html.appshell #railSizer { display: none; }

/* ── 3. Сам рейл: скролл вместо обрезки, естественная высота карточек */
#rail {
	gap: var(--railgap, 12px);
	overflow-y: auto;
	overflow-x: hidden;
	scrollbar-width: thin;
	scrollbar-color: var(--brd2) transparent;
}
#rail::-webkit-scrollbar { width: 8px; }
#rail::-webkit-scrollbar-track { background: transparent; }
#rail::-webkit-scrollbar-thumb {
	background: var(--brd2); border-radius: 99px; border: 2px solid var(--bg);
}
#rail::-webkit-scrollbar-thumb:hover { background: color-mix(in oklab, var(--acc) 45%, var(--brd2)); }

#rail > .rail-card,
#rail > .card {
	flex: none;
	position: relative;
	container-type: inline-size;   /* содержимое масштабируется от ширины карточки */
}
#rail > .card { margin: 0; overflow-x: auto; }
#rail #railTrainer { flex: none; }
#rail #trToday { flex: none; overflow: visible; min-height: 0; }
#rail #ligaList { max-height: clamp(176px, 62cqw, 480px); }
#rail #tRing { width: clamp(232px, 72cqw, 430px); height: auto; }
#rail .fnotes { min-height: clamp(140px, 40cqw, 320px); }

/* в широком режиме рейл ≈ ширина карточки: именованный контейнер
   для паддингов/радиусов/шрифтовых переменных самих карточек */
@media (min-width: 1241px) {
	#rail { container-type: inline-size; container-name: railw; }
}
@container railw (min-width: 430px) {
	#rail > .rail-card, #rail > .card { padding: 18px; border-radius: 16px; }
	#rail > .card { --fs-base: 16px; --fs-small: 14px; --fs-h3: 19px; }
}
@container railw (min-width: 580px) {
	#rail > .rail-card, #rail > .card { padding: 22px; border-radius: 18px; }
	#rail > .card { --fs-base: 17px; --fs-small: 15px; --fs-h3: 21px; }
}
@container railw (min-width: 780px) {
	#rail > .rail-card, #rail > .card { padding: 26px; border-radius: 20px; }
	#rail > .card { --fs-base: 18px; --fs-small: 16px; --fs-h3: 23px; }
}

/* ── 4. Масштаб содержимого «Тренера» и «Лиги» (cqw = ширина карточки).
   clamp не даёт ни мелочи на 324px, ни гиганта на 1080px; длинные
   строки остаются с многоточием — наложений нет при любой ширине. */
#rail .rhead { gap: clamp(8px, 2.4cqw, 14px); margin-bottom: clamp(10px, 3.2cqw, 18px); }
#rail .rhead h3 { font-size: clamp(13px, 4.6cqw, 24px); letter-spacing: .06em; }
#rail .rhead h3 .ic { width: clamp(15px, 5cqw, 26px); height: clamp(15px, 5cqw, 26px); }
#rail .rlink {
	font-size: clamp(13px, 4.3cqw, 21px);
	padding: clamp(4px, 1.3cqw, 9px) clamp(8px, 2.6cqw, 15px);
	border-radius: clamp(8px, 2.6cqw, 12px);
}
#rail .tr-rsec { margin-bottom: clamp(8px, 2.8cqw, 18px); }
#rail .tr-rhead { font-size: clamp(12.5px, 4.1cqw, 21px); gap: clamp(8px, 2.4cqw, 14px); margin: 2px 0 clamp(4px, 1.3cqw, 9px); }
#rail .tr-mins { font-size: clamp(12px, 3.8cqw, 19px); padding: 1px clamp(8px, 2.5cqw, 14px); }
#rail .tr-ritem {
	font-size: clamp(13px, 4.4cqw, 22px);
	line-height: 1.45;
	padding: clamp(3px, 1cqw, 8px) clamp(8px, 2.7cqw, 16px);
	margin: clamp(2px, .7cqw, 6px) 0;
	border-left-width: clamp(2px, .65cqw, 4px);
}
#rail .tr-empty { font-size: clamp(12.5px, 4cqw, 19px); }
#rail .lrow {
	grid-template-columns: clamp(24px, 8cqw, 46px) minmax(0, 1fr) auto;
	gap: clamp(8px, 2.6cqw, 15px);
	padding: clamp(5px, 1.7cqw, 11px) clamp(8px, 2.6cqw, 15px);
	border-radius: clamp(10px, 3.2cqw, 16px);
}
#rail .lpos { width: clamp(22px, 7.4cqw, 42px); height: clamp(22px, 7.4cqw, 42px); font-size: clamp(11px, 3.6cqw, 19px); }
#rail .lname { font-size: clamp(13px, 4.4cqw, 22px); }
#rail .lmin { font-size: clamp(13px, 4.3cqw, 22px); }
#rail .ldots { font-size: clamp(13px, 4.3cqw, 20px); }

/* ── 5. Шапка панели ─────────────────────────────────────────────── */
#railHead {
	position: sticky; top: 0; z-index: 10;
	display: flex; align-items: center; gap: 8px;
	padding: 6px 8px;
	border: 1px solid var(--brd);
	border-radius: 12px;
	background: color-mix(in oklab, var(--panel) 88%, transparent);
	-webkit-backdrop-filter: blur(8px);
	backdrop-filter: blur(8px);
}
#railHead .rh-label {
	display: inline-flex; align-items: center; gap: 6px;
	font: 700 11px var(--f-body); letter-spacing: .12em; text-transform: uppercase;
	color: var(--faint);
}
#railHead .rh-label .ic { color: var(--acc); }
#railHead .rh-n {
	font: 700 11px var(--f-mono); color: var(--muted);
	padding: 1px 7px; border-radius: 99px;
	background: var(--panel2); border: 1px solid var(--brd);
}
#railHead .rh-w {
	display: none;
	font: 700 11px var(--f-mono); color: var(--acc);
	padding: 1px 7px; border-radius: 99px;
	background: var(--acc-soft); border: 1px solid color-mix(in oklab, var(--acc) 40%, transparent);
}
body.rail-resizing #railHead .rh-w { display: inline-block; }
#railHead .rh-sp { flex: 1; }
#railEdit.on { color: var(--acc); background: var(--acc-soft); border-color: color-mix(in oklab, var(--acc) 45%, transparent); }

/* ── 6. Чипы переноса на карточках ───────────────────────────────── */
.rd-chips { position: absolute; top: 6px; right: 6px; z-index: 9; display: flex; gap: 4px; }
#rail > * > .rd-chips { top: auto; bottom: 8px; right: 8px; }  /* не перекрывать кнопки в шапках карточек */
.rd-chip {
	width: 28px; height: 28px;
	display: none; place-items: center;
	padding: 0;
	border: 1px solid var(--brd2); border-radius: 9px;
	background: color-mix(in oklab, var(--panel) 92%, transparent);
	color: var(--muted); cursor: pointer;
	box-shadow: var(--shadow-1);
	transition: color .15s ease, border-color .15s ease, transform .15s ease, opacity .15s ease;
}
.rd-chip:hover { color: var(--acc); border-color: var(--acc); transform: translateY(-1px); }
.rd-chip .ic { width: 14px; height: 14px; }
/* «в панель» — на карточках основного окна в режиме правки раскладки */
body.dock-edit #main .card > .rd-chips > .rd-in { display: grid; }
/* «в окно» — на карточках панели: по ховеру/фокусу, в правке — всегда */
#rail > .card > .rd-chips > .rd-out,
#rail > .rail-card > .rd-chips > .rd-out { display: grid; opacity: 0; pointer-events: none; }
#rail > *:hover > .rd-chips > .rd-out,
#rail > *:focus-within > .rd-chips > .rd-out,
body.dock-edit #rail > * > .rd-chips > .rd-out { opacity: 1; pointer-events: auto; }
@media (hover: none) { #rail > * > .rd-chips > .rd-out { opacity: .85; pointer-events: auto; } }
/* ручка порядка внутри панели — только в правке */
.rd-grip { cursor: grab; touch-action: none; }
body.dock-edit #rail > * > .rd-chips > .rd-grip { display: grid; }

/* перетаскиваемая карточка панели */
#rail > .rd-drag { opacity: .85; box-shadow: var(--shadow-2); z-index: 10; animation: none !important; }

/* ── 7. Режим правки: панель ведёт себя как док ──────────────────── */
body.dock-edit #rail > .rail-card,
body.dock-edit #rail > .card { animation: dockWig .34s ease-in-out infinite alternate; }
body.dock-edit #rail > *:nth-child(2n) { animation-delay: -.17s; }
/* DOCK-обработчики не должны трогать карточки, живущие в панели */
body.dock-edit #rail .cardhead { pointer-events: none; }
#rail .drz, #rail .drz-e, #rail .drz-s { display: none !important; }
#rail .dock-head { display: none !important; }

/* ── 8. Пустая панель: вертикальная вкладка «Панель» у правого края */
#railReopen {
	position: fixed; right: 0; top: 50%; transform: translateY(-50%);
	z-index: 46;
	display: none; align-items: center; gap: 8px;
	writing-mode: vertical-rl;
	padding: 14px 7px;
	border: 1px solid var(--brd2); border-right: 0;
	border-radius: 12px 0 0 12px;
	background: var(--panel);
	color: var(--muted);
	font: 700 12px var(--f-body); letter-spacing: .14em; text-transform: uppercase;
	cursor: pointer;
	box-shadow: var(--shadow-1);
	transition: color .2s ease, border-color .2s ease, box-shadow .2s ease;
}
#railReopen .ic { width: 14px; height: 14px; color: var(--acc); }
#railReopen:hover { color: var(--acc); border-color: var(--acc); box-shadow: 0 0 16px -4px var(--glow); }
.rail-empty #railReopen { display: flex; }

/* ── 9. Окна выбора (перенос/добавление) ─────────────────────────── */
.rd-panes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.rd-list {
	display: flex; flex-direction: column; gap: 3px;
	max-height: 52vh; overflow-y: auto; padding: 4px;
	scrollbar-width: thin; scrollbar-color: var(--brd2) transparent;
}
.rd-add {
	display: flex; align-items: center; justify-content: space-between; gap: 10px;
	width: 100%; padding: 9px 12px;
	border: 1px solid transparent; border-radius: 10px;
	background: transparent; color: var(--ink);
	font: 600 calc(var(--fs-small) + 1px) var(--f-body);
	text-align: left; cursor: pointer;
	transition: background-color .15s ease, border-color .15s ease;
}
.rd-add:hover { background: var(--panel2); border-color: var(--brd2); }
.rd-add i {
	font: 600 11px var(--f-mono); font-style: normal; color: var(--faint);
	padding: 1px 8px; border-radius: 99px;
	background: var(--panel2); border: 1px solid var(--brd);
	white-space: nowrap;
}

/* ── 10. Мелочи ──────────────────────────────────────────────────── */
/* осиротевшие обёртки .cols (оба блока унесены в панель) не занимают место */
#main .cols:not(:has(> .card)) { display: none; }

@media (prefers-reduced-motion: reduce) {
	body.dock-edit #rail > .rail-card,
	body.dock-edit #rail > .card { animation: none; }
	#railSizer::before, .rd-chip, #railReopen { transition: none; }
}