/*
 * Project check-in styles. Uses redesign rd-* tokens so the visual
 * language matches the rest of the app. Index/show shells are handled by
 * rd-card; this file styles the index list rows and the structured
 * report body (flags, metrics, grouped work items, milestones, budget,
 * allocations, invoices, communications).
 */

@layer components {
  /* ==========================================================================
     Index — list rows (wrapped in rd-card with flush body)
     ========================================================================== */

  .rd-checkin-list {
    display: flex;
    flex-direction: column;
  }

  .rd-checkin-row {
    padding: 12px 16px;
    border-bottom: 1px solid var(--rd-border);
    transition: background var(--rd-dur-fast) var(--rd-ease);
  }

  .rd-checkin-row:last-child {
    border-bottom: 0;
  }

  .rd-checkin-row:hover {
    background: var(--rd-bg-hover);
  }

  .rd-checkin-row-pending {
    opacity: 0.75;
  }

  .rd-checkin-row-failed {
    border-inline-start: 3px solid var(--rd-danger);
  }

  .rd-checkin-title:hover {
    color: var(--rd-accent) !important;
  }

  /* ==========================================================================
     Show — report body wrapper
     ========================================================================== */

  .rd-checkin-report {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  /* Spin animation for the generating-state loader icon. */
  @keyframes rd-checkin-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
  }

  .rd-checkin-spin {
    animation: rd-checkin-spin 1.4s linear infinite;
  }

  /* Raw JSON toggle block */
  .rd-checkin-raw summary {
    list-style: none;
    user-select: none;
    padding: 2px 0;
  }

  .rd-checkin-raw summary::-webkit-details-marker {
    display: none;
  }

  .rd-checkin-raw summary:hover {
    color: var(--rd-fg);
  }

  .rd-checkin-json {
    margin-top: 12px;
    padding: 12px;
    background: var(--rd-bg-sunken);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    font-family: var(--rd-font-mono);
    font-size: var(--rd-text-xs);
    line-height: 1.5;
    max-height: 420px;
    overflow: auto;
  }

  .rd-checkin-json code {
    background: none;
    padding: 0;
    white-space: pre;
  }

  /* ==========================================================================
     Structured Report — sections (cards)
     ========================================================================== */

  .checkin-structured-report {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .checkin-section {
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-lg);
    padding: 16px;
  }

  .checkin-section-executive {
    border-color: transparent;
    background: var(--rd-accent-soft);
  }

  .checkin-executive-summary {
    margin: 0;
    font-size: var(--rd-text-base);
    line-height: 1.6;
    color: var(--rd-fg);
  }

  .checkin-section-summary {
    margin: 0 0 12px;
    font-size: var(--rd-text-sm);
    line-height: 1.5;
    color: var(--rd-fg-muted);
  }

  .checkin-section-description {
    margin: 0 0 12px;
    color: var(--rd-fg-muted);
    font-size: var(--rd-text-sm);
    line-height: 1.5;
  }

  .checkin-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--rd-text-lg);
    font-weight: 600;
    color: var(--rd-fg);
    margin: 0 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--rd-border);
    letter-spacing: -0.005em;
  }

  /* ==========================================================================
     Flags
     ========================================================================== */

  .checkin-flags-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .checkin-flag {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 10px 12px;
    background: var(--rd-bg-sunken);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    border-inline-start: 3px solid var(--rd-border-strong);
  }

  .checkin-flag-critical {
    background: var(--rd-danger-soft);
    border-color: transparent;
    border-inline-start-color: var(--rd-danger);
  }

  .checkin-flag-warning {
    background: var(--rd-warn-soft);
    border-color: transparent;
    border-inline-start-color: var(--rd-warn);
  }

  .checkin-flag-info {
    background: var(--rd-info-soft);
    border-color: transparent;
    border-inline-start-color: var(--rd-info);
  }

  .checkin-flag-icon {
    font-size: var(--rd-text-lg);
    line-height: 1;
    flex-shrink: 0;
  }

  .checkin-flag-content {
    flex: 1;
    min-width: 0;
  }

  .checkin-flag-message {
    font-weight: 600;
    font-size: var(--rd-text-base);
    margin: 0;
    color: var(--rd-fg);
  }

  .checkin-flag-details {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-muted);
    margin: 4px 0 0;
  }

  /* ==========================================================================
     Metrics grid
     ========================================================================== */

  .checkin-metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
  }

  .checkin-metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 4px;
    padding: 12px;
    background: var(--rd-bg-sunken);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
  }

  .checkin-metric-warning {
    background: var(--rd-warn-soft);
    border-color: transparent;
  }

  .checkin-metric-critical,
  .checkin-metric-over {
    background: var(--rd-danger-soft);
    border-color: transparent;
  }

  .checkin-metric-value {
    font-size: var(--rd-text-xl);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    color: var(--rd-fg);
    line-height: 1.1;
  }

  .checkin-metric-label {
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }

  /* ==========================================================================
     Work item groups (overdue, due-soon, recently-completed)
     ========================================================================== */

  .checkin-work-item-group {
    margin-bottom: 16px;
  }

  .checkin-work-item-group:last-child {
    margin-bottom: 0;
  }

  .checkin-group-title {
    font-size: var(--rd-text-xs);
    font-weight: 600;
    color: var(--rd-fg-muted);
    margin: 0 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }

  .checkin-group-description {
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-subtle);
    margin: 0 0 8px;
    font-style: italic;
  }

  .checkin-work-item-group-critical .checkin-group-title {
    color: var(--rd-danger);
  }

  .checkin-work-item-group-warning .checkin-group-title {
    color: var(--rd-warn);
  }

  .checkin-work-item-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .checkin-work-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    font-size: var(--rd-text-base);
  }

  .checkin-work-item-overdue {
    border-inline-start: 3px solid var(--rd-danger);
  }

  .checkin-work-item-due-soon {
    border-inline-start: 3px solid var(--rd-info);
  }

  .checkin-work-item-completed {
    border-inline-start: 3px solid var(--rd-success);
    opacity: 0.8;
  }

  .checkin-work-item-chronic {
    border-inline-start: 3px solid var(--rd-danger);
    background: var(--rd-danger-soft);
  }

  .checkin-work-item-long-term {
    border-inline-start: 3px solid var(--rd-warn);
  }

  .checkin-work-item-badge {
    font-size: var(--rd-text-sm);
    margin-inline-start: 6px;
  }

  .checkin-work-item-link {
    color: var(--rd-fg);
    text-decoration: none;
    font-weight: 500;
  }

  .checkin-work-item-link:hover {
    color: var(--rd-accent);
  }

  .checkin-work-item-name {
    font-weight: 500;
    color: var(--rd-fg);
  }

  .checkin-work-item-inline-flag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    padding: 0 6px;
    background: var(--rd-bg-sunken);
  }

  .checkin-work-item-inline-tags {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-inline-start: 6px;
  }

  .checkin-work-item-meta {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-muted);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-inline-start: auto;
    white-space: nowrap;
  }

  /* ==========================================================================
     Milestones
     ========================================================================== */

  .checkin-milestone-snapshot {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
  }

  .checkin-milestone-insight {
    margin: 0 0 12px;
    padding: 8px 12px;
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    font-size: var(--rd-text-sm);
    font-weight: 500;
    color: var(--rd-fg);
  }

  .checkin-milestone-insight-warning {
    border-color: transparent;
    background: var(--rd-warn-soft);
  }

  .checkin-milestone-insight-success {
    border-color: transparent;
    background: var(--rd-success-soft);
  }

  .checkin-milestones-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .checkin-milestone {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
  }

  .checkin-milestone-completed {
    border-inline-start: 3px solid var(--rd-success);
  }

  .checkin-milestone-overdue {
    border-inline-start: 3px solid var(--rd-danger);
  }

  .checkin-milestone-pending {
    border-inline-start: 3px solid var(--rd-info);
  }

  .checkin-milestone-link {
    color: var(--rd-fg);
    text-decoration: none;
    font-weight: 500;
  }

  .checkin-milestone-link:hover {
    color: var(--rd-accent);
  }

  .checkin-milestone-meta {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-muted);
    white-space: nowrap;
  }

  /* ==========================================================================
     Allocations
     ========================================================================== */

  .checkin-allocation-snapshot {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
  }

  .checkin-allocations-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .checkin-allocations-list-detailed {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .checkin-allocation {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--rd-bg-sunken);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
  }

  .checkin-allocation-user {
    font-weight: 500;
    color: var(--rd-fg);
  }

  .checkin-allocation-percentage {
    font-weight: 600;
    color: var(--rd-accent);
    font-variant-numeric: tabular-nums;
  }

  .checkin-allocation-row {
    display: grid;
    grid-template-columns: 1.2fr auto 1fr 1fr;
    align-items: center;
    gap: 8px 12px;
    width: 100%;
  }

  .checkin-allocation-window,
  .checkin-allocation-status {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-muted);
  }

  @media (max-width: 800px) {
    .checkin-allocation-row {
      grid-template-columns: 1fr auto;
    }

    .checkin-allocation-window,
    .checkin-allocation-status {
      grid-column: 1 / -1;
    }
  }

  /* ==========================================================================
     Invoices
     ========================================================================== */

  .checkin-invoices-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .checkin-invoice {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 12px;
    background: var(--rd-danger-soft);
    border: 1px solid transparent;
    border-inline-start: 3px solid var(--rd-danger);
    border-radius: var(--rd-radius-md);
  }

  .checkin-invoice-id {
    font-family: var(--rd-font-mono);
    font-size: var(--rd-text-sm);
    color: var(--rd-fg);
  }

  .checkin-invoice-amount {
    font-weight: 600;
    margin-inline-start: auto;
    font-variant-numeric: tabular-nums;
  }

  .checkin-invoice-due {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-muted);
  }

  /* ==========================================================================
     Communications
     ========================================================================== */

  .checkin-comms-summary {
    font-size: var(--rd-text-base);
    line-height: 1.6;
    color: var(--rd-fg);
    margin: 0 0 12px;
  }

  .checkin-comms-highlights {
    margin: 0 0 12px;
    padding-inline-start: 16px;
    color: var(--rd-fg-muted);
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .checkin-comms-categories {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
  }

  .checkin-comms-category {
    border: 1px solid var(--rd-border);
    background: var(--rd-bg-sunken);
    border-radius: var(--rd-radius-md);
    padding: 10px 12px;
  }

  .checkin-comms-category-list {
    margin: 0;
    padding-inline-start: 16px;
    list-style: disc;
    list-style-position: outside;
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--rd-fg);
    font-size: var(--rd-text-sm);
  }

  .checkin-comms-category-list li::marker {
    color: var(--rd-fg-subtle);
  }

  .checkin-comms-link {
    color: var(--rd-accent);
    text-decoration: none;
    font-weight: 500;
  }

  .checkin-comms-link:hover {
    text-decoration: underline;
  }

  .checkin-comms-sentiment-badge {
    margin-bottom: 12px;
    padding: 6px 10px;
    font-size: var(--rd-text-sm);
  }

  /* ==========================================================================
     Budget table
     ========================================================================== */

  .checkin-budget-table {
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    overflow: hidden;
    margin-top: 8px;
  }

  .checkin-budget-row {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) minmax(120px, 1fr) minmax(120px, 1fr) minmax(90px, 0.7fr);
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--rd-border);
    font-size: var(--rd-text-base);
  }

  .checkin-budget-row:first-child {
    border-top: 0;
  }

  .checkin-budget-row-header {
    background: var(--rd-bg-sunken);
    font-size: var(--rd-text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--rd-fg-subtle);
  }

  .checkin-budget-row span:nth-child(n+2) {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  @media (max-width: 760px) {
    .checkin-budget-row {
      grid-template-columns: 1fr 1fr;
    }

    .checkin-budget-row-header {
      display: none;
    }

    .checkin-budget-row span:nth-child(1) {
      grid-column: 1 / -1;
      font-weight: 600;
    }
  }
}
