/* ── Time-planner view ──────────────────────────────────────────────────── */

/* Override tree-container overflow so sticky positioning works against .app-scrollable */
.tree-container:has(.time-planner-container) {
  overflow-x: visible;
  overflow-y: visible;
}

.time-planner-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
}

.time-planner-time-region {
  display: flex;
  flex-direction: column;
}

/* ── Range controls bar ─────────────────────────────────────────────────── */

.time-planner-range-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 20;        /* above grid content (max 12) but well below popups (10 000+) */
  background: var(--bg-primary);
}

.time-planner-range-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.time-planner-range-label-text {
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.time-planner-spinner {
  width: 52px;
  padding: 2px 4px;
  font-size: 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-align: center;
}

.time-planner-spinner:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.time-planner-range-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.time-planner-slider-wrapper {
  flex: 1;
  position: relative;
  height: 24px;
  min-width: 120px;
}

.time-planner-slider {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  pointer-events: none;
  margin: 0;
}

.time-planner-slider::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
}

.time-planner-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 2px solid var(--bg-secondary);
  cursor: pointer;
  pointer-events: auto;
  margin-top: -5px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.time-planner-slider::-moz-range-track {
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  border: none;
}

.time-planner-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 2px solid var(--bg-secondary);
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* ── Scrollable timeline grid ───────────────────────────────────────────── */

.time-planner-scroll {
  overflow-x: auto;
  overflow-y: visible;
  flex: 1;
  min-height: 0;
}

.time-planner-grid {
  position: relative;
}

/* ── Date column headers ────────────────────────────────────────────────── */

.time-planner-header-scroll {
  position: sticky;
  top: 41px;
  z-index: 15;        /* above grid content (max 12), below range-controls (20) */
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  scrollbar-width: none;
}

.time-planner-header-scroll::-webkit-scrollbar {
  display: none;
}

.time-planner-header {
  position: relative;
  display: flex;
  height: 38px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.time-planner-col-header {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  user-select: none;
  box-sizing: border-box;
  border-right: 1px solid var(--border-color);
}

.time-planner-col-header.time-planner-col-today {
  background: rgba(99, 102, 241, 0.08);
  color: var(--accent-primary);
  font-weight: 700;
}

.time-planner-col-header.time-planner-col-weekend {
  opacity: 0.6;
}

.time-planner-col-day {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.2;
}

.time-planner-col-date {
  font-size: 0.7rem;
  line-height: 1.2;
}

/* ── Vertical column lines ──────────────────────────────────────────────── */

.time-planner-col-lines {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 0;
}

.time-planner-col-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border-color);
  opacity: 0.35;
}

.time-planner-col-line-today {
  background: var(--accent-primary);
  opacity: 0.25;
  width: 2px;
}

.time-planner-today-highlight {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.16);
  z-index: 10;
  pointer-events: none;
}

/* ── Checkmarks ─────────────────────────────────────────────────────────── */

.time-planner-checkmark {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 12;
  pointer-events: none;
  color: #4ade80;
}

.time-planner-checkmark-today {
  pointer-events: auto;
  cursor: pointer;
  opacity: 1;
}

.time-planner-checkmark-today:hover .tp-checkmark-svg {
  filter: drop-shadow(0 0 6px rgba(74, 222, 128, 0.7));
  transform: scale(1.1);
}

/* Mute with a translucent stroke, not opacity. opacity < 1 on an
   absolute element inside the horizontal scroller is dropped by iOS,
   so historical marks vanished on mobile while today's stayed visible. */
.time-planner-checkmark-historical {
  color: rgba(74, 222, 128, 0.35);
}

.tp-checkmark-svg {
  width: 26px;
  height: 26px;
  filter: drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.3));
  transition: transform 0.15s ease, filter 0.15s ease;
}

/* Invisible click zone for today's column on unchecked items */
.time-planner-checkmark-zone {
  position: absolute;
  top: 0;
  height: 100%;
  z-index: 11;
  cursor: pointer;
  pointer-events: auto;
}

.time-planner-checkmark-zone:hover {
  background: rgba(74, 222, 128, 0.08);
}

/* ── Sections ───────────────────────────────────────────────────────────── */

.time-planner-section {
  position: relative;
  padding-top: 4px;
}

/* When NON-TIME LIMITED is the only section (TIME OVERVIEW is empty/hidden),
   drop the extra top padding so items sit flush at the top of the container. */
.time-planner-container > .time-planner-non-time-section:first-child {
  padding-top: 0;
}

.time-planner-section > .deadline-section-divider {
  max-width: none;
  padding: 6px 8px 2px;
}

/* ── Item rows ──────────────────────────────────────────────────────────── */

.time-planner-row {
  margin-bottom: 8px;
}

/* Disable hover scale effect — items can be very wide so the 2% expansion is jarring */
.time-planner-bar .tree-node-row:hover:not(.dragging) > .tree-node-wrapper:hover > .tree-node {
  transform: none;
}

.time-planner-bar {
  display: block;
  position: relative;
}

.time-planner-bar > .tree-node-row {
  width: 100%;
}

.time-planner-bar > .tree-node-row > .tree-node-wrapper {
  min-width: 0;
  max-width: none;
  width: 100%;
}

/* Only truncate titles inside the time-overview grid (Gantt bars must stay single-line).
   The NON-TIME LIMITED section uses normal wrapping. */
.time-planner-scroll .time-planner-bar > .tree-node-row > .tree-node-wrapper .node-title .node-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ── Sticky content: keep title visible during horizontal scroll ─────── */

/* Default: the wrapper is invisible — its children participate directly
   in the parent's flex layout via display:contents.  Only in the
   time-planner scroll area does it become a real sticky box. */
.tp-sticky-inner {
  display: contents;
}

/* Inner sticky wrapper: groups status icons, title, and indicators.
   Sticks to the viewport left edge when scrolling right, while the drag
   handle stays at the bar's far left edge.
   Scoped to .time-planner-scroll to avoid affecting NON-TIME LIMITED items. */
.time-planner-scroll .time-planner-bar .tp-sticky-inner {
  display: flex;
  position: sticky;
  left: 0;
  align-items: center;
  gap: calc(8px * var(--scale-tree-items, 1));
  width: fit-content;
  max-width: 100%;
}

/* Constrain title width so the sticky wrapper stays narrower than the bar,
   giving it room to slide within the bar. */
.time-planner-scroll .time-planner-bar .tp-sticky-inner .node-title {
  flex: 0 1 auto !important;
  max-width: 300px;
}

/* Let node-title-text fill remaining space and truncate with ellipsis */
.time-planner-scroll .time-planner-bar .tp-sticky-inner .node-title .node-title-text {
  flex: 1 1 0 !important;
}

/* Bars intersecting today: push all node-content children past the today column.
   The drag handle is taken out of flex flow (absolute) so it stays at the bar's
   left edge without pulling subsequent flex items back.
   --tp-content-offset is set as inline style on .time-planner-bar-today */
.time-planner-bar-today > .tree-node-row > .tree-node-wrapper > .tree-node > .node-content {
  padding-left: var(--tp-content-offset) !important;
  position: relative !important;
}

.time-planner-bar-today > .tree-node-row > .tree-node-wrapper > .tree-node > .node-content > .drag-handle {
  position: absolute !important;
  left: 0 !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  margin-left: 0 !important;
}

/* Hide grips unless free sorting is on, matching a normal subtask-of tree.
   The embedded NON-TIME LIMITED tree uses .tree.drag-disabled for the same thing. */
.time-planner-scroll.drag-disabled .drag-handle,
.time-planner-non-time-section.drag-disabled .drag-handle {
  display: none;
}

/* NON-TIME LIMITED section — normal flow, no timeline width */
.time-planner-non-time-section .time-planner-bar-full {
  display: block;
}

.time-planner-non-time-section .time-planner-bar-full > .tree-node-row > .tree-node-wrapper {
  min-width: 280px;
  max-width: 400px;
}

/* ── Mobile: compensate for .app-scrollable padding-top so sticky controls
   stick at the true scrollport edge with no gap for bars to peek through ── */
@media (max-width: 768px) {
  .time-planner-range-controls {
    top: -12px;
  }
  .time-planner-header-scroll {
    top: calc(41px - 12px);
  }
}
