/* ══════════════════════════════════════════════════════════
   DiamondFlow — invoice-ui-upgrade.css
   Premium SaaS invoice UI upgrade layer.

   Fixes:
   · Currency symbol ₹ + en-IN formatting (via script.js patch)
   · Right-aligned numeric columns with monospace font
   · Misaligned table headers ↔ row values
   · Broken spacing & padding in item rows
   · Weak layout hierarchy in totals panel
   · Thin visual weight on grand total

   Load LAST — after all other CSS files.
   THIS FILE IS THE SOLE AUTHORITY on invoice grid layout.
   All other files (responsive.css, style.css) must NOT
   override grid-template-columns on .items-header / .item-row.
══════════════════════════════════════════════════════════ */


/* ══════════════════════════════════════════════════════════
   0. GLOBAL SAFETY — apply to entire page
══════════════════════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
}

/* ══════════════════════════════════════════════════════════
   0a. MASTER GRID — single source of truth
   7 columns: Description | Qty | Weight | PPC | VAT% | VAT Amt | Total | ×
   Proportions tuned for large Indian rupee numbers (crore range).
══════════════════════════════════════════════════════════ */

:root {
  --inv-cols: 1.6fr 0.45fr 0.7fr 0.85fr 0.55fr 0.95fr 1.1fr 34px;
}

/* Override anything responsive.css may have set */
.items-header,
.item-row {
  grid-template-columns: var(--inv-cols) !important;
  gap: 4px !important;
}

/* Ensure every direct child of grid never overflows its cell */
.items-header > *,
.item-row > * {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
}

/* Description: allow text wrap, don't truncate */
.item-row .item-name,
.items-header .col-name {
  white-space: normal;
  word-break: break-word;
  overflow: visible;
}

/* All numeric columns: no wrap, right-aligned */
.item-row .item-qty,
.item-row .item-weight,
.item-row .item-ppc,
.item-row .item-vat,
.item-row .item-price {
  white-space: nowrap;
  text-align: right;
  font-family: 'DM Mono', 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  padding-right: 6px !important;
}

.item-row .item-qty {
  text-align: center;
}

/* Subtotal cell: full width in its column, single line short format */
.item-subtotal,
.item-row .item-subtotal {
  width: 100% !important;
  min-width: 0 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  box-sizing: border-box !important;
}


/* ══════════════════════════════════════════════════════════
   1. ITEMS TABLE — header + row alignment
   Force numeric columns to right-align with tabular nums.
   Names/descriptions stay left-aligned.
══════════════════════════════════════════════════════════ */

/* ── Header row ─────────────────────────────────────────── */
.items-header {
  padding: 0 8px 12px;
  border-bottom: 2px solid var(--accent);
  margin-bottom: 6px;
  background: transparent;
}

.items-header > div {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--accent);
}

/* Numeric column headers: right-align to match value cells */
.items-header .col-weight,
.items-header .col-ppc,
.items-header .col-vat,
.items-header .col-subtotal,
.items-header .col-price {
  text-align: right;
}

/* Qty centered */
.items-header .col-qty {
  text-align: center;
}


/* ── Item rows ──────────────────────────────────────────── */
.item-row {
  padding: 10px 8px;
  border-radius: 8px;
  border-bottom: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.item-row:not(:last-child) {
  border-bottom-color: var(--border);
  border-radius: 0;
}

.item-row:hover {
  background: rgba(28, 53, 87, 0.035);
  border-radius: 8px;
}

/* All numeric inputs inside a row: right-align */
.item-row .item-weight,
.item-row .item-ppc,
.item-row .item-vat,
.item-row .item-price,
.item-row .item-qty {
  text-align: right;
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  padding-right: 6px !important;
  letter-spacing: 0;
}

.item-row .item-qty {
  text-align: center;
  font-size: 12px;
}

/* Item name input: slightly bolder */
.item-row .item-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
}


/* ── Row Total cell ─────────────────────────────────────── */
.item-subtotal {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  background: rgba(28, 53, 87, 0.06);
  border: 1px solid rgba(28, 53, 87, 0.12);
  border-radius: 6px;
  padding: 6px 6px;
  text-align: right;
  white-space: normal;       /* allow wrap */
  word-break: break-all;
  overflow-wrap: anywhere;
  letter-spacing: 0;
  width: 100%;
  box-sizing: border-box;
  line-height: 1.3;
}


/* ══════════════════════════════════════════════════════════
   2. TOTALS PANEL — premium right-column summary
══════════════════════════════════════════════════════════ */

.right-totals {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(28, 53, 87, 0.07), 0 1px 3px rgba(28, 53, 87, 0.04);
  gap: 0;
}

/* ── Section header inside totals panel ─────────────────── */
.right-totals::before {
  content: 'Invoice Summary';
  display: block;
  padding: 10px 16px 9px;
  background: var(--accent);
  font-family: 'DM Sans', sans-serif;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.7);
}

/* ── Rows inside summary ────────────────────────────────── */
.rt-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

.rt-row:not(.rt-grand) + .rt-row:not(.rt-grand) {
  border-top: 1px solid var(--border);
}

/* ── Labels ─────────────────────────────────────────────── */
.rt-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-mid);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Values ─────────────────────────────────────────────── */
.rt-value {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-align: right;
  letter-spacing: 0;
  min-width: 0;
  white-space: nowrap;
}

/* ── Divider before Grand Total ──────────────────────────── */
.rt-divider {
  height: 0;
  margin: 0;
  border: none;
  border-top: 2px solid var(--accent);
  opacity: 0.15;
}

/* ── Grand Total row — premium treatment ────────────────── */
.rt-grand {
  background: linear-gradient(135deg, #1C3557 0%, #0f2240 100%);
  padding: 14px 16px;
  margin-top: 0;
  border-top: 2px solid var(--accent);
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.rt-grand .rt-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
  flex-shrink: 0;
}

.rt-grand .rt-value {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #F0D080;
  letter-spacing: 0;
  text-shadow: 0 1px 8px rgba(240, 208, 128, 0.3);
  text-align: right;
  white-space: nowrap;
}


/* ══════════════════════════════════════════════════════════
   3. INVOICE BADGE — number display
══════════════════════════════════════════════════════════ */

.create-right .invoice-badge {
  background: linear-gradient(135deg, #1C3557 0%, #0f2240 100%);
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: 0 4px 16px rgba(28, 53, 87, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.create-right .badge-label {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.45);
  font-family: 'DM Sans', sans-serif;
}

.create-right .badge-number {
  font-family: 'DM Mono', monospace;
  font-size: 13.5px;
  color: #F0D080;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}


/* ══════════════════════════════════════════════════════════
   4. ACTION BUTTONS — right column
══════════════════════════════════════════════════════════ */

.right-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Primary download button */
#downloadBtn {
  background: linear-gradient(135deg, #C89A3A 0%, #b8882e 100%);
  color: #fff;
  border: none;
  box-shadow: 0 2px 10px rgba(200, 154, 58, 0.3);
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: box-shadow 0.2s, transform 0.15s;
}

#downloadBtn:hover {
  box-shadow: 0 4px 18px rgba(200, 154, 58, 0.42);
  transform: translateY(-1px);
}

/* Save button */
#saveBtn {
  background: var(--surface);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

#saveBtn:hover {
  background: var(--accent);
  color: #fff;
}


/* ══════════════════════════════════════════════════════════
   5. ITEMS SECTION HEADER
══════════════════════════════════════════════════════════ */

.cp-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}


/* ══════════════════════════════════════════════════════════
   6. ADD ITEM BUTTON
══════════════════════════════════════════════════════════ */

.btn-add-item {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  border: 1.5px dashed rgba(28, 53, 87, 0.35);
  border-radius: 8px;
  padding: 10px 16px;
  background: rgba(28, 53, 87, 0.025);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}

.btn-add-item:hover {
  background: rgba(28, 53, 87, 0.06);
  border-color: var(--accent);
  border-style: solid;
  color: var(--accent);
}


/* ══════════════════════════════════════════════════════════
   7. HISTORY TABLE — numeric columns
══════════════════════════════════════════════════════════ */

/* Amount/Total column in history table: right-align, monospace */
#historyBody td:last-child,
.hist-amount,
td.col-amount,
td.col-total {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--ink);
  white-space: nowrap;
}

/* History table header: right-align amount column */
#historyTable th:last-child,
th.col-amount,
th.col-total {
  text-align: right;
}

/* Grand total cells in history  */
#historyBody td .grand-total-cell,
#historyBody td[data-col="grandTotal"] {
  font-family: 'DM Mono', monospace;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--accent);
}


/* ══════════════════════════════════════════════════════════
   8. PURCHASE MODE TOTALS
   PSM stone entries section
══════════════════════════════════════════════════════════ */

#purchaseTotalsBar,
.purchase-totals-bar {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 24px;
  margin-top: 8px;
  box-shadow: 0 1px 6px rgba(28, 53, 87, 0.05);
}

.purchase-total-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.purchase-total-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-light);
}

.purchase-total-value {
  font-family: 'DM Mono', monospace;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.purchase-total-value--grand {
  font-size: 18px;
  color: var(--gold);
  font-weight: 700;
}


/* ══════════════════════════════════════════════════════════
   9. PSM STONE TABLE — numeric alignment
══════════════════════════════════════════════════════════ */

.psm-table td,
.psm-stone-table td {
  font-size: 13px;
}

/* Numeric PSM columns */
.psm-table td:not(:first-child),
.psm-stone-table td:not(:first-child) {
  font-family: 'DM Mono', monospace;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* PSM value column */
.psm-table .psm-col-value,
.psm-stone-table .psm-col-value {
  font-weight: 600;
  color: var(--accent);
}


/* ══════════════════════════════════════════════════════════
   10. EDIT MODAL — totals footer
══════════════════════════════════════════════════════════ */

.edit-totals-footer {
  border-top: 2px solid var(--border);
  padding-top: 12px;
  margin-top: 4px;
}

#edit_grand {
  font-family: 'DM Mono', monospace;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}

#edit_subtotal,
#edit_gst {
  font-family: 'DM Mono', monospace;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* Edit modal item row subtotal */
#editItemsContainer .item-subtotal {
  font-family: 'DM Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  color: var(--accent);
  background: rgba(28, 53, 87, 0.05);
  border: 1px solid rgba(28, 53, 87, 0.1);
  border-radius: 6px;
  padding: 8px 10px;
}


/* ══════════════════════════════════════════════════════════
   11. FORM INPUTS — numeric fields focus polish
══════════════════════════════════════════════════════════ */

/* Remove number spinners for cleaner look */
input[type="number"].form-input::-webkit-inner-spin-button,
input[type="number"].form-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"].form-input {
  -moz-appearance: textfield;
}

/* Focused number inputs: subtle accent ring */
.item-row input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2.5px rgba(28, 53, 87, 0.1);
  outline: none;
}


/* ══════════════════════════════════════════════════════════
   12. SALES vs PURCHASE MODE — type badge in right panel
══════════════════════════════════════════════════════════ */

.invoice-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-family: 'DM Sans', sans-serif;
}

.invoice-type-badge--sales {
  background: rgba(200, 154, 58, 0.12);
  color: #b8882e;
  border: 1px solid rgba(200, 154, 58, 0.3);
}

.invoice-type-badge--purchase {
  background: rgba(37, 99, 235, 0.1);
  color: #1e40af;
  border: 1px solid rgba(37, 99, 235, 0.2);
}


/* ══════════════════════════════════════════════════════════
   13. RESPONSIVE
══════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
  .right-totals {
    box-shadow: 0 1px 8px rgba(28, 53, 87, 0.06);
  }

  .rt-grand .rt-value {
    font-size: 18px;
  }
}

@media (max-width: 600px) {
  .rt-row {
    padding: 9px 14px;
  }

  .rt-grand {
    padding: 12px 14px;
  }

  .rt-grand .rt-value {
    font-size: 17px;
  }

  .rt-label {
    font-size: 12.5px;
  }

  .rt-value {
    font-size: 13px;
  }

  /* Stack item rows as cards on very small screens */
  .item-row .item-weight,
  .item-row .item-ppc,
  .item-row .item-price {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .right-totals::before {
    font-size: 9px;
    padding: 9px 14px 8px;
  }

  .rt-grand .rt-value {
    font-size: 16px;
  }
}


/* ══════════════════════════════════════════════════════════
   14. UTILITY — tabular nums on all mono displays
══════════════════════════════════════════════════════════ */

.mono,
[class*="mono"] {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
}

/* Currency amounts anywhere in the app */
[id$="Display"],
[id$="display"],
[id$="Total"],
[id$="Subtotal"],
[id$="Amount"] {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}