/**
 * ARK Grid System — financial & tabular layouts (RO, invoice, estimates, reports).
 * Headers and data rows MUST share the same grid-template-columns (same modifier class).
 */

/* —— Core grid —— */
.ark-grid {
  display: grid;
  align-items: center;
  column-gap: var(--ark-grid-gap);
}

/* Primary financial row: desc | price | qty | subtotal | tax | shop fee | line total | actions */
.ark-grid-financial {
  grid-template-columns:
    minmax(0, 1fr)
    var(--ark-col-price)
    var(--ark-col-qty)
    var(--ark-col-subtotal)
    var(--ark-col-tax)
    var(--ark-col-shop-fee)
    var(--ark-col-line-total)
    var(--ark-col-actions);
}

/* Compact (mobile / tight spaces) */
.ark-grid-financial-sm {
  grid-template-columns:
    minmax(0, 1fr)
    70px
    60px
    90px
    70px;
}

/* Report / read-only: no actions column */
.ark-grid-financial-report {
  grid-template-columns:
    minmax(0, 1fr)
    100px
    80px
    120px;
}

/* Line-item drawer / editor header: item | cost | sell | qty | subtotal | actions */
.ark-grid-item-drawer-header {
  grid-template-columns: minmax(0, 1fr) 80px 80px 60px 90px 90px;
}

.ark-grid-item-drawer-header .col-qty {
  text-align: center;
}

.ark-grid-item-drawer-header .col-actions {
  justify-content: center;
}

/* Collapsed concern total row: label | KPI pills | price | qty | subtotal | actions */
.ark-grid.ark-concern-total-financial {
  grid-template-columns:
    minmax(0, 1fr)
    auto
    var(--ark-col-price)
    var(--ark-col-qty)
    var(--ark-col-subtotal)
    var(--ark-col-tax)
    var(--ark-col-shop-fee)
    var(--ark-col-line-total)
    var(--ark-col-actions);
}

.ark-concern-total-financial .concern-total-kpis {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
}

/* Customer estimate: description | amount */
.ark-grid-financial-estimate {
  grid-template-columns: minmax(0, 1fr) 110px;
}

.ark-grid-financial-estimate .col-amount {
  min-width: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: var(--ark-font-md);
}

/**
 * @deprecated Use .ark-grid.ark-grid-financial — kept so legacy markup still aligns.
 * Single-class alias: display + columns + gap (same tracks as .ark-grid-financial).
 */
.ark-line-grid {
  display: grid;
  align-items: center;
  column-gap: var(--ark-grid-gap);
  grid-template-columns:
    minmax(0, 1fr)
    var(--ark-col-price)
    var(--ark-col-qty)
    var(--ark-col-subtotal)
    var(--ark-col-tax)
    var(--ark-col-shop-fee)
    var(--ark-col-line-total)
    var(--ark-col-actions);
}

/* —— Column cells —— */
.col-desc {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-price,
.col-qty,
.col-subtotal,
.col-tax,
.col-shop-fee,
.col-line-total {
  min-width: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: var(--ark-font-md);
}

.col-subtotal {
  font-weight: 600;
}

.col-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

/* —— Header row —— */
.ark-line-header {
  font-size: var(--ark-font-sm);
  color: var(--ark-text-muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: var(--ark-space-sm) var(--ark-card-padding);
}

.ark-line-header .col-price,
.ark-line-header .col-qty,
.ark-line-header .col-subtotal,
.ark-line-header .col-tax,
.ark-line-header .col-shop-fee,
.ark-line-header .col-line-total {
  font-size: var(--ark-font-sm);
  font-weight: 600;
}

/* —— Data rows —— */
.ark-line-item-row {
  padding: var(--ark-space-sm) var(--ark-card-padding);
  border-bottom: 1px solid var(--ark-border-subtle);
  min-height: var(--ark-row-height);
}

.ark-line-item-row:hover {
  background: #f9fafb;
}

/* —— Typography —— */
.ark-line-item-title {
  font-size: var(--ark-font-lg);
  font-weight: 600;
  line-height: 1.2;
}

.ark-line-item-meta {
  font-size: var(--ark-font-sm);
  color: var(--ark-text-muted);
  margin-top: 2px;
}

/* Subtotal column: GP pill / buttons align to numeric rail */
.ark-grid .col-subtotal .concern-metric,
.ark-line-grid .col-subtotal .concern-metric {
  display: block;
  width: 100%;
  text-align: right;
}

.ark-grid .col-subtotal .gp-pill,
.ark-line-grid .col-subtotal .gp-pill {
  display: inline-flex;
  justify-content: flex-end;
  max-width: 100%;
}

/* —— Action icon buttons —— */
.ark-action-util {
  height: var(--ark-control-height);
  width: var(--ark-control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ark-radius-sm);
  border: 1px solid #e5e7eb;
  background: #fff;
  box-sizing: border-box;
  padding: 0;
}

/* —— Financial tables (multi-column detail: tax, shop fee, etc.) —— */
table.ark-table-financial {
  width: 100%;
  max-width: 100%;
  font-variant-numeric: tabular-nums;
  border-collapse: separate;
  border-spacing: 0;
}

table.ark-table-financial thead:not(.table-dark) th {
  font-size: var(--ark-font-sm);
  color: var(--ark-text-muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--ark-border-subtle);
  vertical-align: middle;
  background: transparent;
}

table.ark-table-financial tbody td {
  font-size: var(--ark-font-md);
  padding: 8px 10px;
  border-bottom: 1px solid var(--ark-border-subtle);
  vertical-align: middle;
}

table.ark-table-financial .ark-td-num,
table.ark-table-financial th.text-end {
  text-align: right !important;
  white-space: nowrap;
}

table.ark-table-financial tbody tr:hover {
  background: #f9fafb;
}

/* Concern cards on narrow viewports: tighter numeric tracks (same class names, no per-screen overrides in Blade) */
@media (max-width: 576px) {
  .ark-concern-line-items .ark-grid-financial,
  .ark-concern-column-headers.ark-grid-financial {
    grid-template-columns:
      minmax(0, 1fr)
      64px
      52px
      76px
      58px
      58px
      72px
      64px;
    column-gap: var(--ark-grid-gap-tight);
  }

  .ark-grid.ark-concern-total-financial {
    grid-template-columns:
      minmax(0, 1fr)
      auto
      64px
      52px
      76px
      58px
      58px
      72px
      64px;
    column-gap: var(--ark-grid-gap-tight);
  }
}
