/* ============================================================
   Open Tickets Page
   Depends on base.css being loaded first.
   ============================================================ */

/* ── Page layout ────────────────────────────────────────────── */
.tickets-section {
  padding: 24px;
}

/* ── Section heading ────────────────────────────────────────── */
.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.section-heading h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text);
}
.section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-text-muted);
}

/* ── Tickets Table ──────────────────────────────────────────── */
.tickets-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.tickets-table thead th {
  padding: 9px 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  white-space: nowrap;
}

.tickets-table tbody .ticket-row td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
  vertical-align: middle;
}
.tickets-table tbody .ticket-row:last-child td { border-bottom: none; }

.tickets-table tbody .ticket-row {
  cursor: pointer;
  transition: background .1s;
}
.tickets-table tbody .ticket-row:hover td {
  background: var(--color-primary-light, #eff6ff);
}
.tickets-table tbody .ticket-row.closed td {
  color: var(--color-text-muted);
}

/* Column widths */
.tc-check   { width: 32px;  text-align: center; }
.tc-title   { }
.tc-wo      { width: 130px; }
.tc-req     { width: 140px; }
.tc-date    { width: 100px; white-space: nowrap; }
.tc-items   { width: 56px;  text-align: center; }
.tc-updated { width: 90px;  white-space: nowrap; }
.tc-actions { width: 140px; }

.tc-check input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

/* Selected ticket row */
.tickets-table tbody .ticket-row.selected td {
  background: var(--color-primary-light);
}
.tickets-table tbody .ticket-row.selected:hover td {
  background: var(--color-primary-light);
}

/* Title cell */
.ticket-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}
.ticket-title.untitled {
  color: var(--color-text-faint);
  font-style: italic;
  font-weight: 400;
}

/* Updated cell — muted */
.tc-updated {
  font-size: 12px;
  color: var(--color-text-faint);
}

/* ── Row action buttons ─────────────────────────────────────── */
.ticket-row-actions {
  display: flex;
  gap: 4px;
}

/* ── Empty / loading state row ──────────────────────────────── */
.tickets-table tbody .state-row td {
  padding: 48px 24px;
  text-align: center;
  color: var(--color-text-muted);
  border-bottom: none;
}

/* ── Section heading variant (Closed) ───────────────────────── */
.stacked-heading {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

/* ── Scrollable section (Closed / Deleted) ──────────────────── */
.scroll-section {
  max-height: 500px;
  overflow-y: auto;
  margin-bottom: 8px;
}
.scroll-section .tickets-table { margin-bottom: 0; }

/* Collapsible variant (Deleted) — hidden until toggled */
.scroll-section.collapsible { display: none; }
.scroll-section.collapsible.visible { display: block; }

/* ── Collapsible section toggle (Deleted) ───────────────────── */
.section-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 0;
  background: none;
  border: none;
  border-top: 1px solid var(--color-border);
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
  transition: color .15s;
  margin-top: 28px;
}
.section-toggle:hover { color: var(--color-text); }

.section-toggle-chevron {
  margin-left: auto;
  transition: transform .2s;
  color: var(--color-text-faint);
}
.section-toggle.open .section-toggle-chevron { transform: rotate(180deg); }

/* ── Deleted rows — muted, not clickable ────────────────────── */
.tickets-table tbody .ticket-row.deleted td     { color: var(--color-text-muted); }
.tickets-table tbody .ticket-row.deleted         { cursor: default; }
.tickets-table tbody .ticket-row.deleted:hover td { background: transparent; }

/* ── Templates section ──────────────────────────────────────── */
.templates-heading {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}
.templates-new-btn {
  margin-left: auto;
  font-size: 12px;
}
.tc-actions-wide { width: 360px; }
.template-row .tc-title { font-weight: 500; }

/* ── Mobile: Card Layout ────────────────────────────────────── */
@media (max-width: 900px) {
  .tickets-section { padding: 12px; }

  /* Collapse table to block */
  .tickets-table,
  .tickets-table tbody { display: block; }
  .tickets-table thead { display: none; }

  /* State row stays centered */
  .tickets-table tbody tr.state-row { display: block; }
  .tickets-table tbody tr.state-row td {
    display: block;
    text-align: center;
    border: none !important;
    padding: 40px 20px !important;
    background: transparent !important;
  }

  /* Each ticket row becomes a card */
  .tickets-table tbody tr.ticket-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    padding: 10px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
  }

  /* Reset td styles */
  .tickets-table tbody tr.ticket-row td {
    border: none !important;
    padding: 0 !important;
    background: transparent !important;
    width: auto !important;
    white-space: normal !important;
  }

  /* Disable table hover on cards */
  .tickets-table tbody .ticket-row:hover td { background: transparent !important; }

  /* ── Card rows via flex order ─── */

  /* Row 1: checkbox + title (expands) + updated (right) */
  .tc-check   { order: 0; margin-right: 8px; margin-bottom: 3px; }
  .tc-title   { flex: 1; min-width: 0; order: 1; margin-bottom: 3px; }
  .tc-updated { flex-shrink: 0; order: 1; font-size: 11px; margin-bottom: 3px; }

  /* Row 2: meta fields — full-width row via natural wrap after row 1 fills */
  .tc-wo, .tc-req, .tc-date {
    order: 2;
    font-size: 12px;
    color: var(--color-text-muted) !important;
    margin-right: 10px;
    margin-bottom: 4px;
  }
  .tc-wo:empty, .tc-req:empty, .tc-date:empty { display: none; }

  /* Row 3: item count + action buttons */
  .tc-items {
    order: 3;
    flex: 1;
    font-size: 12px;
    color: var(--color-text-muted);
    align-self: center;
  }
  .tc-items::before { content: 'Items: '; }

  .tc-actions {
    order: 4;
    flex-basis: 100%;
    margin-top: 6px;
  }

  /* Closed cards */
  .ticket-row.closed { opacity: .8; }

  /* FAB replaces the controls bar (which only had the new ticket button) */
  .controls-bar { display: none; }
}
