/* ===== Ticket View — Email-style split pane ===== */

.ticket-view {
  display: flex;
  height: 100%;
  gap: 1px;
  background: var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* ── Left: Ticket List ── */
.ticket-list-pane {
  flex: 1;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  overflow: hidden;
}

.ticket-list-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.ticket-list-toolbar .search-input {
  flex: 1;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: var(--font-size-xs);
  font-family: var(--font-family);
  outline: none;
  transition: border-color var(--transition-fast);
}

.ticket-list-toolbar .search-input:focus {
  border-color: var(--accent-primary);
}

.ticket-list-toolbar .filter-btn {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  cursor: pointer;
  font-family: var(--font-family);
  transition: all var(--transition-fast);
}

.ticket-list-toolbar .filter-btn:hover {
  background: var(--glass-bg-heavy);
  color: var(--text-primary);
}

.ticket-list-toolbar .filter-btn.active {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

/* Column headers */
.ticket-list-header {
  display: grid;
  grid-template-columns: 32px 1fr 80px 100px;
  gap: 8px;
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}

.ticket-list-header span:hover {
  color: var(--text-secondary);
}

.ticket-list-header .sort-indicator {
  font-size: 10px;
  margin-left: 2px;
}

/* How much work the board holds: the kernel's per-status counts, so a short list never reads as all of it */
.ticket-board-summary {
  padding: 4px 14px;
  font-size: 11px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.ticket-board-summary:empty {
  display: none;
}

/* "Back to tickets": only a phone with a ticket open shows it (see the 640px block). */
.ticket-back {
  display: none;
  align-items: center;
  gap: 6px;
  flex: none;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: none;
  border-bottom: 1px solid var(--border-color);
  color: var(--accent-primary);
  font-family: var(--font-family);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.ticket-board-more {
  display: block;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--accent-primary);
  font-family: var(--font-family);
  font-size: 12px;
  cursor: pointer;
}

/* Scrollable ticket list */
.ticket-list-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Individual ticket row */
.ticket-row {
  display: grid;
  grid-template-columns: 32px 1fr 80px 100px;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
}

.ticket-row:hover {
  background: var(--glass-bg);
}

.ticket-row.selected {
  background: var(--glass-bg-heavy);
  border-left: 3px solid var(--accent-primary);
  padding-left: 11px;
}

/* Status dot */
.ticket-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  justify-self: center;
  flex-shrink: 0;
}

.ticket-status-dot.backlog { background: var(--text-muted); }
.ticket-status-dot.todo { background: var(--status-warning); }
.ticket-status-dot.in-progress { background: var(--status-active); }
.ticket-status-dot.in-review { background: #a78bfa; }
.ticket-status-dot.customer-action { background: #f59e0b; }
.ticket-status-dot.done { background: var(--status-success); }
.ticket-status-dot.cancelled { background: var(--status-error); opacity: 0.5; }

/* Ticket subject cell */
.ticket-subject {
  min-width: 0;
}

.ticket-subject-title {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticket-subject-meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.ticket-cost-cell {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ticket-date-cell {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}

/* Expandable children */
.ticket-row .expand-chevron {
  display: inline-flex;
  width: 16px;
  font-size: 12px;
  color: var(--text-muted);
  transition: transform var(--transition-fast);
  cursor: pointer;
}

.ticket-row .expand-chevron.expanded {
  transform: rotate(90deg);
}

.ticket-children-rows {
  display: none;
}

.ticket-children-rows.expanded {
  display: block;
}

.ticket-children-rows .ticket-row {
  padding-left: 42px;
  background: rgba(255,255,255,0.01);
}

.ticket-children-rows .ticket-row::before {
  content: '';
  position: absolute;
  left: 24px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border-color);
}

.subtask-badge {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--glass-bg);
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 6px;
  font-weight: 500;
}

/* ── Resize Handle ── */
.ticket-resize-handle {
  width: 5px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  z-index: 10;
  transition: background 0.2s;
}
.ticket-resize-handle:hover,
.ticket-resize-handle:active {
  background: var(--accent-primary);
  opacity: 0.5;
}

/* ── Right: Ticket Detail ── */
.ticket-detail-pane {
  flex: 1;
  min-width: 300px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  background-image: linear-gradient(180deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.01) 100%);
  /* Bounded flex column: the header/actions/tabs stay pinned (flex-shrink:0) and
     ONLY .td-body scrolls. `overflow:hidden` here (not auto) is what stops the
     whole pane — header included — from becoming one giant scroll block that
     pushes the ticket text off-screen on a phone. */
  overflow: hidden;
}

.ticket-detail-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  flex-direction: column;
  gap: 8px;
}

.ticket-detail-empty i {
  font-size: 48px;
  opacity: 0.3;
}

/* Detail header */
.td-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.td-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.td-id {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  font-weight: 600;
}

.td-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--text-primary);
  line-height: var(--line-height-tight);
}

.td-meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.td-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.td-meta-item i {
  font-size: 14px;
}

/* Detail actions */
.td-actions {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.td-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass-bg);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.td-action-btn:hover {
  background: var(--glass-bg-heavy);
  color: var(--text-primary);
}

.td-action-btn.danger:hover {
  background: rgba(248, 113, 113, 0.15);
  color: var(--status-error);
  border-color: rgba(248, 113, 113, 0.3);
}

.td-action-btn i { font-size: 14px; }

/* State dropdown */
.td-state-select {
  padding: 6px 10px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass-bg);
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-family);
  cursor: pointer;
  outline: none;
}

/* Detail tabs */
.td-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.td-tab {
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: var(--font-family);
  transition: all var(--transition-fast);
}

.td-tab:hover {
  color: var(--text-secondary);
}

.td-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

/* Detail body — the single independent scroll region of the detail pane.
   `flex:1 1 auto` fills the space left under the pinned header/tabs, `min-height:0`
   defeats the flexbox min-content floor so it can actually shrink and scroll, and
   `overflow-y:auto` gives the ticket text/feed its own scrollbar. Wide content
   (code blocks, tables) scrolls inside itself rather than widening the page. */
.td-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overflow-wrap: anywhere;
  padding: 16px 20px;
}

.td-body pre,
.td-body table {
  max-width: 100%;
  overflow-x: auto;
}

/* Timeline items */
.td-timeline-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.td-timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-primary);
  margin-top: 5px;
  flex-shrink: 0;
}

.td-timeline-time {
  font-size: 11px;
  color: var(--text-muted);
}

.td-timeline-text {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Work artifacts */
.td-artifact {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--glass-bg);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.td-artifact:hover {
  background: var(--glass-bg-heavy);
}

.td-artifact i {
  font-size: 16px;
  color: var(--accent-primary);
}

.td-artifact-name {
  font-size: var(--font-size-sm);
  color: var(--text-primary);
}

/* Delete confirmation dialog */
.delete-confirm-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 24px;
  z-index: 1000;
  box-shadow: var(--depth-shadow);
  min-width: 320px;
  text-align: center;
}

.delete-confirm-dialog h3 {
  color: var(--status-error);
  margin-bottom: 8px;
}

.delete-confirm-dialog p {
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  margin-bottom: 16px;
}

.delete-confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.delete-confirm-actions button {
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  cursor: pointer;
}

.delete-confirm-actions .cancel-btn {
  background: var(--glass-bg);
  color: var(--text-secondary);
}

.delete-confirm-actions .confirm-delete-btn {
  background: var(--status-error);
  color: #fff;
  border-color: var(--status-error);
}

.delete-confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
}

/* ===== Mobile: 390px phones ===== */
@media (max-width: 640px) {
  /* Stack the split pane vertically; list on top, detail below */
  .ticket-view {
    flex-direction: column;
  }

  /* Each pane takes full width; list gets a capped height so the
     detail panel is still reachable without endless scrolling */
  .ticket-list-pane {
    width: 100%;
    min-width: 0;
    max-height: 45vh;
    flex: none;
  }

  .ticket-detail-pane {
    width: 100%;
    min-width: 0;
    flex: 1;
  }

  /* With a ticket OPEN on a phone the detail is the screen and "Back to tickets"
     returns the list. The earlier 15vh list strip was shorter than the wrapped
     toolbar, so it showed 0 rows and there was no way back but a filter change
     or a reload (2026-10-11). The has-selection class is maintained by
     ticket-board-phone.js; guarded by crates/oshald/tests/ticket_board_open_work.rs
     (real TicketView in headless Chrome at 390x844). */
  .ticket-view.has-selection .ticket-list-pane {
    display: none;
  }

  .ticket-view.has-selection .ticket-back {
    display: flex;
  }

  /* With NO ticket open the list is the screen. The 45vh cap above, minus the wrapped toolbar, left a
     ~3-row strip over an empty "Select a ticket" pane: a person with 525 open tickets saw three and read
     them as the whole board (2026-10-11). Guarded by crates/oshald/tests/ticket_board_open_work.rs. */
  .ticket-view:not(.has-selection) .ticket-list-pane {
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
  }

  .ticket-view:not(.has-selection) .ticket-detail-pane {
    display: none;
  }

  /* Hide the resize handle — dragging is not useful in stacked mode */
  .ticket-resize-handle {
    display: none;
  }

  /* Collapse 4-column grid to 2 columns: dot + subject only */
  .ticket-list-header,
  .ticket-row {
    grid-template-columns: 24px 1fr;
  }

  /* Hide the cost and date columns on small screens */
  .ticket-list-header span:nth-child(3),
  .ticket-list-header span:nth-child(4),
  .ticket-cost-cell,
  .ticket-date-cell {
    display: none;
  }

  /* Tighten horizontal padding so nothing overflows 390px */
  .ticket-list-toolbar {
    padding: 8px 10px;
    flex-wrap: wrap;
  }

  .ticket-list-toolbar .search-input {
    font-size: 16px; /* prevent iOS auto-zoom */
  }

  .ticket-list-header {
    padding: 6px 10px;
  }

  .ticket-row {
    padding: 10px 10px;
  }

  .ticket-row.selected {
    padding-left: 7px;
  }

  /* Detail pane header / actions — compact hard so the pinned header leaves the
     scrolling body real estate. Only .td-body scrolls now, so a bloated header
     would otherwise crush the ticket text into a sliver. */
  .td-header {
    padding: 10px 12px;
    /* The full header (meta rows, contributing bots, project controls) can be
       taller than the entire pane on a 667px phone; with every chrome row
       flex-shrink:0 that pushed .td-body to zero height and overflowed the pane
       by the excess — ticket text a phone user could never reach. Cap the
       header and let ITS overflow scroll internally: the header's top stays
       pinned, everything in it stays reachable, and the body keeps real
       height. Guarded by tests/cockpit-mobile-375-scroll.spec.ts. */
    max-height: 45%;
    overflow-y: auto;
  }

  .td-header-row {
    flex-wrap: wrap;
  }

  .td-title {
    font-size: var(--font-size-md);
  }

  .td-meta-row {
    gap: 8px;
    margin-top: 6px;
  }

  /* Drop the space-hungry free-text "new project" input on phones; the project
     select + Apply button still let you re-file, and the badge still shows the
     current project. Pure width/height reclamation, no lost capability. */
  #tvProjectCustomName {
    display: none;
  }

  /* One row that scrolls sideways, the same idiom as .td-tabs below: wrapping
     into two rows doubled the pinned chrome's height, and every pinned pixel
     comes straight out of the scrolling ticket body on a 667px phone. */
  .td-actions {
    padding: 8px 12px;
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .td-actions > * {
    flex-shrink: 0;
  }

  /* Let the tab strip scroll sideways instead of wrapping into a tall block. */
  .td-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .td-tab {
    flex-shrink: 0;
    padding: 10px 12px;
  }

  .td-body {
    padding: 12px 12px;
  }

  /* Delete dialog: fit inside the phone viewport */
  .delete-confirm-dialog {
    min-width: 0;
    width: calc(100vw - 32px);
    padding: 16px;
  }

  .td-state-select {
    font-size: 16px; /* prevent iOS auto-zoom */
  }
}

/* Ticket cost breakdowns retain readable columns inside narrow detail panes. */
.td-cost-metrics { display:grid; grid-template-columns:repeat(auto-fit,minmax(130px,1fr)); gap:10px; margin-bottom:16px; }
.td-cost-scroll { width:100%; overflow-x:auto; border:1px solid var(--glass-border); border-radius:8px; }
.td-cost-table { width:100%; min-width:700px; border-collapse:collapse; font-size:12px; overflow-wrap:normal; word-break:normal; }
.td-cost-table th,.td-cost-table td { padding:10px 12px; text-align:left; white-space:nowrap; border-bottom:1px solid var(--glass-border); }
.td-cost-table th { font-weight:600; background:rgba(127,127,127,.06); }
.td-cost-table th:nth-child(n+3),.td-cost-table td:nth-child(n+3) { text-align:right; font-variant-numeric:tabular-nums; }
.td-cost-table .td-cost-amount { min-width:120px; }
.td-cost-unit { display:block; margin-top:4px; font-size:11px; line-height:1.5; color:var(--text-secondary); white-space:normal; }
.td-status-history { padding-left:22px; }
.td-status-transition { padding:10px 0; border-bottom:1px solid var(--glass-border); }
.td-status-transition p { margin:6px 0; }
.td-status-meta { margin-top:5px; color:var(--text-secondary); font-size:12px; }
