/* ==========================================================================
   Swim Page - Horizontal Lane View
   ========================================================================== */

/* Override body max-width so swim lanes can use full viewport */
body:has(.swim-page) {
  max-width: none;
  overflow-x: auto;
}

.swim-page {
  padding: 0.75rem 1rem 2rem;
}

/* ==========================================================================
   Settings Panel
   ========================================================================== */

.swim-settings-panel {
  margin-bottom: 1rem;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: var(--bg-muted, #f8f9fa);
}

.swim-settings-toggle {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  background: none;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px;
  color: var(--fg-dim, #666);
  cursor: pointer;
  text-align: left;
  transition: color 0.15s;
}

.swim-settings-toggle:hover {
  color: var(--fg, #1a1a1a);
}

.swim-settings-body {
  padding: 0 0.75rem 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
}

.swim-settings-body.hidden {
  display: none;
}

.swim-setting {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.swim-setting-label {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 11px;
  color: var(--fg-dim, #666);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.swim-setting-select {
  padding: 0.25rem 0.5rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: var(--bg, #fff);
  color: var(--fg, #1a1a1a);
  cursor: pointer;
}

.swim-setting-range {
  width: 100px;
  cursor: pointer;
}

.swim-setting-checkbox {
  cursor: pointer;
}

.swim-max-lanes-value {
  font-weight: 600;
  color: var(--fg, #1a1a1a);
  min-width: 1.2em;
  display: inline-block;
}

/* ==========================================================================
   Lanes Container
   ========================================================================== */

.swim-container {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.5rem;
  cursor: grab;
}

.swim-container:active {
  cursor: grabbing;
}

.swim-lanes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: min-content;
  /* Headroom for group decoration labels drawn ~20px above the topmost card
     of any group (see drawGroupDecorations in swim.js). Without this, the
     first lane's group label escapes above .swim-lanes and gets overlapped
     by the settings panel. */
  padding-top: 22px;
}

.swim-lane {
  display: flex;
  align-items: stretch;
  min-height: 52px;
  position: relative;
  z-index: 1;
}

.swim-lane-label {
  flex-shrink: 0;
  width: 130px;
  padding: 0.4rem 0.6rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 11px;
  color: var(--fg-dim, #666);
  border-right: 2px solid #e0e0e0;
  display: flex;
  align-items: center;
  word-break: break-word;
  background: var(--bg-muted, #f8f9fa);
  border-radius: 4px 0 0 4px;
}

.swim-lane-items {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.35rem 0.5rem;
  flex-wrap: nowrap;
  min-width: 0;
}

/* Segment containers for global alignment */
.swim-lane-segment {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: nowrap;
  padding-right: 1.5rem;
  border-right: none;
  margin-right: 0.5rem;
}

.swim-lane-segment:last-child {
  border-right: none;
  padding-right: 0;
  margin-right: 0;
}



/* ==========================================================================
   Task Boxes
   ========================================================================== */

.swim-box {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.2rem 0.35rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: var(--bg, #fff);
  cursor: pointer;
  max-width: 200px;
  overflow: hidden;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px;
}

.swim-box:hover {
  background: var(--bg-muted, #f8f9fa);
  border-color: #ccc;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Status accent — left border */
.swim-box.state-started { border-left: 3px solid #d4a600; }
.swim-box.state-completed { border-left: 3px solid #16a085; }
.swim-box.state-canceled { border-left: 3px solid #16a085; }
.swim-box.state-unstarted { border-left: 3px solid #bbb; }
.swim-box.state-backlog { border-left: 3px solid #ddd; }

/* State indicator in box */
.swim-box-state {
  flex-shrink: 0;
  font-size: 13px;
}
.swim-box-state.done { color: #16a085; }
.swim-box-state.in-progress { color: #d4a600; }
.swim-box-state.todo { color: #999; }
.swim-box-state.backlog { color: #ccc; }

.swim-box-title {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: var(--fg, #1a1a1a);
  font-size: 12px;
}

.swim-box-id {
  width: 100%;
  text-align: right;
  color: var(--fg-dim, #aaa);
  font-size: 9px;
  flex-shrink: 0;
}

/* Blocked accent — overrides status border */
.swim-box.blocked {
  border-left: 3px solid #e67e22;
}

.swim-box-blocked-label {
  width: 100%;
  font-size: 9px;
  color: #e67e22;
  opacity: 0.8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Column slot containers for cross-lane alignment */
.swim-column-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-height: 32px;
}

.swim-column-slot:empty {
  /* Empty slots keep their min-width for gap alignment */
}

/* Compact mode */
.swim-box.compact {
  padding: 0.25rem 0.4rem;
  max-width: 120px;
  gap: 0.25rem;
}

.swim-box.compact .swim-box-title {
  display: none;
}

.swim-box.compact .swim-box-id {
  width: auto;
  text-align: left;
  font-size: 11px;
  color: var(--fg, #333);
}

/* ==========================================================================
   Subtask Groups (post-layout SVG decoration)

   Groups are drawn as a shaded rect behind parent+child cards. The SVG layer
   sits beneath connectors and cards so it doesn't interfere with clicks or
   line routing. Works in both column-slot and packed rendering paths.
   ========================================================================== */

.swim-group-decorations {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 0;
}

.swim-group-rect {
  fill: rgba(37, 99, 235, 0.05);
  stroke: rgba(37, 99, 235, 0.35);
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

.swim-group-label-text {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 9px;
  fill: rgba(37, 99, 235, 0.75);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Slight emphasis for the parent card within a group */
.swim-box[data-group-role="parent"] {
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.25);
}

/* ==========================================================================
   Popover
   ========================================================================== */

.swim-popover {
  position: fixed;
  z-index: 100;
  width: 320px;
  max-width: 90vw;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  background: var(--bg, #fff);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 1rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.swim-popover.hidden {
  display: none;
}

.swim-popover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.swim-popover-id {
  font-size: 11px;
  color: var(--fg-dim, #888);
}

.swim-popover-close {
  border: none;
  background: none;
  font-size: 18px;
  color: var(--fg-dim, #999);
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
}

.swim-popover-close:hover {
  color: var(--fg, #1a1a1a);
}

.swim-popover-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--fg, #1a1a1a);
  margin-bottom: 0.5rem;
  word-break: break-word;
}

.swim-popover-meta {
  font-size: 11px;
  color: var(--fg-dim, #666);
  margin-bottom: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
}

.swim-popover-desc {
  font-size: 13px;
  color: var(--fg, #333);
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 0.5rem;
  word-break: break-word;
}

.swim-popover-link {
  font-size: 11px;
  color: var(--fg-dim, #aaa);
  text-decoration: none;
  transition: color 0.15s;
}

.swim-popover-link:hover {
  color: #2563eb;
}

/* ==========================================================================
   SVG Connector Lines
   ========================================================================== */

.swim-connectors {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}

.swim-connector-path {
  fill: none;
  stroke: #e67e22;
  stroke-width: 2;
  stroke-dasharray: 5 3;
  opacity: 0.65;
}

/* Sequential (non-blocking) connectors — grey, subtler */
.swim-sequential-path {
  stroke: #bbb;
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  opacity: 0.4;
}

/* ==========================================================================
   Chain Highlighting (hover)
   ========================================================================== */

/* When chain is active, dim everything that isn't in the chain */
.swim-lanes.swim-chain-active .swim-box {
  opacity: 0.35;
  transition: opacity 0.15s;
}

.swim-lanes.swim-chain-active .swim-connector-path {
  opacity: 0.08;
}

/* Chain nodes stay fully visible with a subtle highlight */
.swim-lanes.swim-chain-active .swim-box.swim-chain-node {
  opacity: 1;
  box-shadow: 0 0 0 2px #e67e22;
}

/* Chain links stay fully visible and get bolder */
.swim-lanes.swim-chain-active .swim-connector-path.swim-chain-link {
  opacity: 0.85;
  stroke-width: 2.5;
}

/* Sequential chain links — visible but lighter than blocking */
.swim-lanes.swim-chain-active .swim-sequential-path.swim-chain-link {
  opacity: 0.55;
  stroke-width: 2;
}

/* ==========================================================================
   Label Filter — Goal Markers
   ========================================================================== */

.swim-box.swim-goal {
  box-shadow: 0 0 0 2px #2563eb;
  border-color: #2563eb;
}

/* ==========================================================================
   Critical Path Filter
   ========================================================================== */

.swim-cp-hidden {
  display: none !important;
}

.swim-cp-hidden-lane {
  display: none !important;
}

.swim-cp-hidden-segment {
  display: none !important;
}

/* Target task gets a distinct highlight */
.swim-cp-active .swim-box.swim-cp-target {
  box-shadow: 0 0 0 2px #2563eb;
  border-color: #2563eb;
}

/* Clear filter pill */
.swim-cp-clear-pill {
  display: inline-block;
  margin-bottom: 0.5rem;
  padding: 0.3rem 0.75rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 11px;
  color: #2563eb;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.swim-cp-clear-pill:hover {
  background: #dbeafe;
  color: #1d4ed8;
}

/* Popover critical path button */
.swim-popover-critical-path {
  display: block;
  margin-top: 0.5rem;
  padding: 0.3rem 0;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 11px;
  color: #2563eb;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s;
}

.swim-popover-critical-path:hover {
  color: #1d4ed8;
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.swim-empty {
  text-align: center;
  color: var(--fg-dim, #666);
  padding: 3rem 1rem;
  font-style: italic;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px;
}

/* ==========================================================================
   Responsive - Desktop
   ========================================================================== */

@media (min-width: 641px) {
  .swim-page {
    padding: 1rem 2rem 3rem;
  }

  .swim-lane-label {
    width: 160px;
    font-size: 12px;
  }
}

/* ==========================================================================
   Vertical Orientation

   Mirror of the horizontal layout: lanes become columns laid out left-to-right,
   items within a lane stack top-to-bottom, labels sit on top of each lane.
   The swim algorithm is unchanged — only the visual axes are swapped.
   ========================================================================== */

.swim-page[data-orientation="vertical"] .swim-container {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 140px);
}

/* .swim-lanes padding-top is for horizontal mode (first row's group label
   escaping above). In vertical mode, every lane starts below its own lane
   label, so the headroom belongs on .swim-lane-items instead. */
.swim-page[data-orientation="vertical"] .swim-lanes {
  padding-top: 0;
}

.swim-page[data-orientation="vertical"] .swim-lanes {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
}

.swim-page[data-orientation="vertical"] .swim-lane {
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
  width: 160px;
  flex-shrink: 0;
}

.swim-page[data-orientation="vertical"] .swim-lane-label {
  width: auto;
  padding: 0.35rem 0.5rem;
  font-size: 10px;
  line-height: 1.3;
  border-right: none;
  border-bottom: 2px solid #e0e0e0;
  border-radius: 4px 4px 0 0;
  justify-content: center;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.swim-page[data-orientation="vertical"] .swim-lane-items {
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  /* 22px top padding reserves headroom for group decoration labels drawn
     ~20px above the topmost card. Without it, the group label would
     overlap the lane-label directly above. */
  padding: 22px 0.35rem 0.4rem;
}

.swim-page[data-orientation="vertical"] .swim-lane-segment {
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  padding-right: 0;
  margin-right: 0;
  padding-bottom: 0.75rem;
  margin-bottom: 0.25rem;
}

.swim-page[data-orientation="vertical"] .swim-lane-segment:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
}

.swim-page[data-orientation="vertical"] .swim-column-slot {
  min-height: 28px;
  flex-direction: row;
  justify-content: center;
}

/* Tight cards: fill the lane, compact padding, 3-line title clamp */
.swim-page[data-orientation="vertical"] .swim-box {
  max-width: none;
  width: 100%;
  box-sizing: border-box;
  padding: 0.3rem 0.45rem;
  gap: 0.15rem 0.3rem;
  border-left: 1px solid #e0e0e0;
}

.swim-page[data-orientation="vertical"] .swim-box-title {
  -webkit-line-clamp: 3;
  line-height: 1.3;
  font-size: 11px;
}

.swim-page[data-orientation="vertical"] .swim-box-id {
  font-size: 9px;
}

/* Status accent — top border instead of left border in vertical mode */
.swim-page[data-orientation="vertical"] .swim-box.state-started { border-left: 1px solid #e0e0e0; border-top: 3px solid #d4a600; }
.swim-page[data-orientation="vertical"] .swim-box.state-completed { border-left: 1px solid #e0e0e0; border-top: 3px solid #16a085; }
.swim-page[data-orientation="vertical"] .swim-box.state-canceled { border-left: 1px solid #e0e0e0; border-top: 3px solid #16a085; }
.swim-page[data-orientation="vertical"] .swim-box.state-unstarted { border-left: 1px solid #e0e0e0; border-top: 3px solid #bbb; }
.swim-page[data-orientation="vertical"] .swim-box.state-backlog { border-left: 1px solid #e0e0e0; border-top: 3px solid #ddd; }
.swim-page[data-orientation="vertical"] .swim-box.blocked { border-left: 1px solid #e0e0e0; border-top: 3px solid #e67e22; }

/* Compact mode in vertical: full-width chip, ID only (title hidden by base rule) */
.swim-page[data-orientation="vertical"] .swim-box.compact {
  max-width: none;
  width: 100%;
  padding: 0.2rem 0.4rem;
}

/* Desktop — slightly roomier lanes when there's real estate */
@media (min-width: 1280px) {
  .swim-page[data-orientation="vertical"] .swim-lane {
    width: 170px;
  }
}

/* Tablet / small laptop */
@media (max-width: 900px) {
  .swim-page[data-orientation="vertical"] .swim-lane {
    width: 150px;
  }
}

/* Phone */
@media (max-width: 640px) {
  .swim-page[data-orientation="vertical"] .swim-lane {
    width: 130px;
  }
  .swim-page[data-orientation="vertical"] .swim-lane-items {
    padding: 0.35rem 0.3rem;
  }
}

/* Small phone */
@media (max-width: 400px) {
  .swim-page[data-orientation="vertical"] .swim-lane {
    width: 114px;
  }
  .swim-page[data-orientation="vertical"] .swim-box {
    padding: 0.25rem 0.35rem;
  }
  .swim-page[data-orientation="vertical"] .swim-box-title {
    font-size: 10px;
    -webkit-line-clamp: 3;
  }
  .swim-page[data-orientation="vertical"] .swim-lane-label {
    font-size: 9px;
    padding: 0.3rem 0.4rem;
  }
}

/* ==========================================================================
   Responsive - Small Phones
   ========================================================================== */

@media (max-width: 400px) {
  .swim-page {
    padding: 0.5rem 0.5rem 1.5rem;
  }

  .swim-lane-label {
    width: 80px;
    font-size: 10px;
    padding: 0.3rem 0.4rem;
  }

  .swim-box {
    padding: 0.25rem 0.4rem;
    font-size: 11px;
    max-width: 140px;
  }

  .swim-lane-items {
    gap: 5px;
    padding: 0.25rem 0.4rem;
  }

  .swim-settings-body {
    flex-direction: column;
    gap: 0.5rem;
  }
}
