/* ==========================================================================
   Home editor (static/js/home-editor.js): the real Home page in edit mode.
   Modules keep their exact shape. Edit mode fades them, draws a dashed edge
   and adds a drag handle and a gear. The controls live in the sidebar, or in
   a bottom dock below 1280px where the sidebar is a drawer.
   Every colour is a tl token. Pico styles buttons, so every button here
   resets what it relies on.
   ========================================================================== */

.hme-sr {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ---- modules in edit mode -------------------------------------------------- */
body.hme-editing .hm-mod { position: relative; border-radius: var(--tl-r-card); outline: 1.5px dashed var(--tl-line-18); outline-offset: 3px; }
body.hme-editing .hm-mod.is-band { border-radius: 0; outline-offset: -2px; }
body.hme-editing .hm-mod > :not(.hme-tools) { opacity: 0.55; pointer-events: none; user-select: none; -webkit-user-select: none; }
body.hme-editing .hm-mod.is-dragging { outline: 2px solid var(--tl-ink); }
body.hme-editing .hm-mod.is-dragging > :not(.hme-tools) { opacity: 0.9; }
/* The sticky News bar would ride over modules while dragging. */
body.hme-editing .hm-news-bar { position: static; }
/* Modules that have nothing to show today still take their place. */
.hm-mod.is-empty { display: none; }
body.hme-editing .hm-mod.is-empty { display: flex; }
.hme-empty { padding: 14px 18px 18px; }
.hme-empty .tl-card-title { margin: 0 0 6px; }
.hme-empty-note { margin: 0; font-size: 13px; color: var(--tl-ink-55); }

.hme-tools {
  position: absolute; z-index: 5; top: -15px; right: 14px;
  display: flex; align-items: center; gap: 2px; padding: 2px;
  border: 1px solid var(--tl-line-10); border-radius: var(--tl-r-btn);
  background: var(--tl-card); box-shadow: var(--tl-card-shadow);
}
.hm-mod.is-band > .hme-tools { top: 50%; right: 28px; transform: translateY(-50%); }
.hme-tool {
  display: inline-grid !important; place-items: center; width: 28px !important; height: 28px; margin: 0 !important; padding: 0 !important;
  border: 0 !important; border-radius: 6px !important; background: transparent !important; box-shadow: none !important;
  color: var(--tl-ink-60) !important; cursor: pointer;
}
.hme-tool:hover { color: var(--tl-ink) !important; background: var(--tl-fill-05) !important; }
.hme-tool:focus-visible { outline: none; box-shadow: var(--tl-focus-ring) !important; }
.hme-grip { cursor: grab; touch-action: none; }
body.hme-dragging, body.hme-dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }

.hme-ghost {
  position: fixed; z-index: 90; left: 0; top: 0; pointer-events: none;
  padding: 6px 10px; border-radius: 6px; background: var(--tl-ink); color: var(--tl-on-ink);
  font-size: 12.5px; font-weight: 600; white-space: nowrap; box-shadow: var(--tl-card-shadow-hover);
}

/* ---- gear popover ------------------------------------------------------------- */
.hme-pop {
  position: absolute; z-index: 80; width: 250px; padding: 12px;
  border: 1px solid var(--tl-line-10); border-radius: var(--tl-r-card);
  background: var(--tl-card); box-shadow: var(--tl-card-shadow-hover);
}
.hme-pop-title { margin: 0 0 10px; font-size: 13.5px; font-weight: 650; color: var(--tl-ink); }
.hme-pop-label { margin: 0 0 6px; font-family: var(--tl-mono); font-size: 10.5px; letter-spacing: 0.6px; text-transform: uppercase; color: var(--tl-ink-45); }
.hme-pop-note { margin: 8px 0 0; font-size: 12px; line-height: 1.4; color: var(--tl-ink-55); }
.hme-widths { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2px; padding: 2px; border-radius: var(--tl-r-chip); background: var(--tl-fill-05); }
.hme-width {
  height: 28px; margin: 0 !important; padding: 0 !important; width: auto !important;
  border: 0 !important; border-radius: var(--tl-r-seg-in) !important; background: transparent !important; box-shadow: none !important;
  font-size: 12.5px; font-weight: 600; color: var(--tl-ink-60) !important; cursor: pointer;
}
.hme-width.is-on { background: var(--tl-control) !important; color: var(--tl-ink) !important; box-shadow: var(--tl-seg-on-shadow) !important; }
.hme-width:disabled { opacity: 0.35; cursor: default; }
.hme-pop > .hme-btn { width: 100%; margin-top: 12px !important; }

/* Content settings in the gear: one select per field. */
.hme-pop { width: 280px; }
.hme-pop .hme-pop-label { margin: 10px 0 5px; }
.hme-pop .hme-pop-title + .hme-pop-label, .hme-pop .hme-pop-title + .hme-pop-note + .hme-pop-label { margin-top: 0; }
.hme-select-input {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 30px !important;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%) !important;
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52% !important;
  background-size: 5px 5px, 5px 5px !important; background-repeat: no-repeat !important;
}

/* A module re-rendering with new settings: dimmed, with a sweep. */
.hm-mod.is-loading { position: relative; }
.hm-mod.is-loading > :not(.hme-tools) { opacity: 0.25 !important; transition: opacity 0.15s; }
.hm-mod.is-loading::after {
  content: ''; position: absolute; inset: 0; z-index: 4; border-radius: var(--tl-r-card); pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--tl-fill-05), transparent) no-repeat;
  background-size: 280px 100%; animation: hme-sweep 1.1s linear infinite;
}
@keyframes hme-sweep { from { background-position: -280px 0; } to { background-position: calc(100% + 280px) 0; } }

/* ---- controls panel ------------------------------------------------------------ */
.hme-panel { display: flex; flex-direction: column; gap: 8px; }
.hme-panel[hidden] { display: none; }
.hme-label { font-family: var(--tl-mono); font-size: 10.5px; letter-spacing: 0.6px; color: var(--tl-ink-40); }
.hme-switch { position: relative; }
.hme-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; min-height: 32px; margin: 0 !important; padding: 0 12px !important;
  border: 1px solid var(--tl-line-12) !important; border-radius: var(--tl-r-btn) !important;
  background: var(--tl-control) !important; box-shadow: none !important;
  font: inherit; font-size: 13px; font-weight: 600; line-height: 1.2; color: var(--tl-ink) !important; cursor: pointer;
}
.hme-btn:hover:not(:disabled) { background: var(--tl-page) !important; border-color: var(--tl-line-18) !important; }
.hme-btn:disabled { opacity: 0.45; cursor: default; }
.hme-btn:focus-visible { outline: none; box-shadow: var(--tl-focus-ring) !important; }
.hme-btn--solid { background: var(--tl-ink) !important; border-color: transparent !important; color: var(--tl-on-ink) !important; }
.hme-btn--solid:hover:not(:disabled) { background: var(--tl-ink-hover) !important; border-color: transparent !important; }
.hme-btn--danger { border-color: var(--tl-down) !important; color: var(--tl-down) !important; }
.hme-btn--danger:hover:not(:disabled) { background: var(--tl-down) !important; color: #fff !important; }
.hme-select { justify-content: space-between; }
.hme-select::after { content: ''; width: 7px; height: 7px; margin: -3px 2px 0 8px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); flex: none; }
.hme-select[aria-expanded="true"]::after { transform: rotate(-135deg); margin-top: 3px; }
.hme-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hme-status { margin: 0; font-size: 12px; line-height: 1.4; color: var(--tl-down); }

.hme-menu {
  position: absolute; z-index: 70; top: calc(100% + 6px); left: 0; right: 0;
  max-height: 60vh; overflow: auto; padding: 5px;
  border: 1px solid var(--tl-line-08); border-radius: var(--tl-r-card);
  background: var(--tl-card); box-shadow: var(--tl-card-shadow-hover);
}
.hme-item {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 32px; margin: 0 !important; padding: 6px 9px 6px 26px !important;
  border: 0 !important; border-radius: 6px !important; background: transparent !important; box-shadow: none !important;
  font: inherit; font-size: 13px; font-weight: 550; text-align: left; color: var(--tl-ink) !important; cursor: pointer; position: relative;
  justify-content: flex-start !important;
}
.hme-item:hover, .hme-item:focus-visible { background: var(--tl-fill-05) !important; outline: none; }
.hme-item.is-on::before { content: ''; position: absolute; left: 11px; top: 50%; width: 6px; height: 10px; margin-top: -7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); }
.hme-rule { display: block; height: 1px; margin: 5px 4px; background: var(--tl-line-08); }

/* In the sidebar: under the Home head, above SPORT. */
.tl-side-home .hme-panel { padding: 0 8px; margin: -4px 0 20px; }

/* Below 1280px the sidebar is a drawer: the controls dock to the bottom. */
.hme-panel.is-dock {
  position: fixed; z-index: 60; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1.4fr); align-items: center; gap: 8px;
  padding: 10px; border: 1px solid var(--tl-line-10); border-radius: var(--tl-r-card);
  background: var(--tl-card); box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.16);
}
.hme-panel.is-dock[hidden] { display: none; }
.hme-panel.is-dock .hme-label { display: none; }
.hme-panel.is-dock .hme-menu { top: auto; bottom: calc(100% + 6px); }
.hme-panel.is-dock .hme-status { grid-column: 1 / -1; }
body.hme-editing:has(.hme-panel.is-dock:not([hidden])) .hm-page { padding-bottom: 90px; }
@media (max-width: 560px) {
  .hme-panel.is-dock { grid-template-columns: 1fr 1fr; }
  .hme-panel.is-dock .hme-actions { grid-column: 1 / -1; }
}

/* ---- switching layouts: the canvas fades out, rearranges, fades back ------ */
#hmLayout { transition: opacity 0.2s ease, filter 0.2s ease, transform 0.2s var(--tl-ease); }
#hmLayout.is-switching { opacity: 0.12; filter: blur(3px); transform: translateY(6px); transition-duration: 0.16s; }

/* ---- new layout: template picker over the live preview ---------------------- */
.hme-picker {
  position: fixed; z-index: 110; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); width: min(1040px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 12px; padding: 16px;
  border: 1px solid var(--tl-line-10); border-radius: var(--tl-r-card);
  background: var(--tl-card); box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
}
.hme-picker-head { display: flex; flex-direction: column; gap: 3px; }
.hme-templates { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
/* Beside the sidebar: centre over the page, not the window. */
@media (min-width: 1280px) {
  .hme-picker { left: calc(50% + var(--tl-sidebar-w) / 2); width: min(1040px, calc(100vw - var(--tl-sidebar-w) - 48px)); }
}
.hme-template {
  display: flex !important; flex-direction: column; align-items: flex-start; gap: 3px; width: 100%;
  min-height: 58px; margin: 0 !important; padding: 10px 12px !important; text-align: left;
  border: 1px solid var(--tl-line-10) !important; border-radius: var(--tl-r-btn) !important;
  background: var(--tl-control) !important; box-shadow: none !important; color: var(--tl-ink) !important; cursor: pointer;
}
.hme-template:hover { border-color: var(--tl-line-18) !important; background: var(--tl-page) !important; }
.hme-template:focus-visible { outline: none; box-shadow: var(--tl-focus-ring) !important; }
.hme-template.is-on { border-color: var(--tl-ink) !important; box-shadow: inset 0 0 0 1px var(--tl-ink) !important; }
.hme-template-name { font-size: 13.5px; font-weight: 650; line-height: 1.25; }
.hme-template-blurb { font-size: 12px; line-height: 1.35; color: var(--tl-ink-55); }
.hme-picker .hme-actions { justify-self: end; width: min(320px, 100%); margin-left: auto; }
body.hme-picking .hme-tools { display: none; }
body.hme-picking .hm-page { padding-bottom: 240px; }
body.hme-picking .hme-panel.is-dock { display: none; }
.hme-picking-note { margin: 0; font-size: 12.5px; color: var(--tl-ink-55); }
@media (max-width: 640px) {
  .hme-templates { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hme-template-blurb { display: none; }
  .hme-picker .hme-actions { width: 100%; }
}

/* ---- Standard Home in edit mode: read-only, with a notice ------------------ */
body.hme-locked .hm-mod > :not(.hme-tools) { opacity: 0.35; }
body.hme-locked .hm-mod { outline-color: var(--tl-line-10); }
.hme-lock {
  position: fixed; z-index: 100; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(400px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 10px; padding: 20px;
  border: 1px solid var(--tl-line-10); border-radius: var(--tl-r-card);
  background: var(--tl-card); box-shadow: var(--tl-card-shadow-hover);
}
.hme-lock .hme-btn { width: auto; align-self: flex-start; margin-top: 4px !important; }
@media (min-width: 1280px) {
  .hme-lock { left: calc(50% + var(--tl-sidebar-w) / 2); }
}

/* ---- a blank layout: an empty canvas with a hint --------------------------- */
.hme-blank {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 320px; padding: 24px; text-align: center;
  border: 1.5px dashed var(--tl-line-18); border-radius: var(--tl-r-card);
}
.hme-blank-title { margin: 0; font-size: 16px; font-weight: 650; color: var(--tl-ink); }
.hme-blank-text { margin: 0; max-width: 360px; font-size: 13.5px; line-height: 1.45; color: var(--tl-ink-55); }

/* ---- in-page dialogs (confirm, rename) -------------------------------------- */
.hme-modal {
  position: fixed; z-index: 120; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 12, 16, 0.32);
}
.hme-modal-box {
  width: min(380px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 18px;
  border: 1px solid var(--tl-line-10); border-radius: var(--tl-r-card);
  background: var(--tl-card); box-shadow: var(--tl-card-shadow-hover);
}
.hme-modal-title { margin: 0; font-size: 15px; font-weight: 650; color: var(--tl-ink); }
.hme-modal-text { margin: 0; font-size: 13.5px; line-height: 1.45; color: var(--tl-ink-60); }
.hme-modal .hme-actions { margin-top: 6px; }
.hme-input {
  width: 100%; height: 36px !important; margin: 0 !important; padding: 0 10px !important;
  border: 1px solid var(--tl-line-18) !important; border-radius: var(--tl-r-btn) !important;
  background: var(--tl-control) !important; box-shadow: none !important;
  font: inherit; font-size: 14px; color: var(--tl-ink) !important;
}
.hme-input:focus { outline: none; box-shadow: var(--tl-focus-ring) !important; }
.hme-modal .hme-status:empty { display: none; }

@media (prefers-reduced-motion: reduce) {
  .hme-select::after { transition: none; }
  #hmLayout, #hmLayout.is-switching { transition: none; transform: none; filter: none; }
  .hm-mod.is-loading::after { animation: none; }
}
