:root {
  /* Core Palette: Light Mode (Warm Paper Ledger) */
  --bg-page: #FAF7F2;
  --bg-surface: #FFFFFF;
  --bg-row-highlight: #F3EFE6;
  --bg-row-active: #EBF5F3;
  --text-primary: #18181B;
  --text-secondary: #52525B;
  --border-strong: #18181B;
  --border-subtle: #71717A;
  --accent-primary: #0F766E;
  --accent-deduction: #B91C1C;
  --bg-error: #FEF2F2;
  --border-error: #B91C1C;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* Radii & Shadows (R-11, R-12: crisp ledger boundaries, offset shadow only on primary action) */
  --radius-sm: 2px;
  --radius-md: 4px;
  --shadow-offset: 3px 3px 0px var(--border-strong);
  --shadow-offset-active: 1px 1px 0px var(--border-strong);
}

[data-theme="dark"] {
  /* Core Palette: Dark Mode (Carbon Ledger) */
  --bg-page: #121316;
  --bg-surface: #1A1C20;
  --bg-row-highlight: #22252A;
  --bg-row-active: #132A28;
  --text-primary: #F4F4F5;
  --text-secondary: #A1A1AA;
  --border-strong: #E4E4E7;
  --border-subtle: #71717A;
  --accent-primary: #2DD4BF;
  --accent-deduction: #F87171;
  --bg-error: #2C1517;
  --border-error: #F87171;
  --shadow-offset: 3px 3px 0px #000000;
  --shadow-offset-active: 1px 1px 0px #000000;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  min-height: 100dvh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Keyboard Focus Visibility (R-32) */
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2.5px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Page Shell & Rhythm */
.page-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2.5rem) clamp(1rem, 3vw, 2rem) 4rem;
}

/* Header */
.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-block {
  flex: 1 1 auto;
}

.app-title {
  margin: 0 0 0.25rem 0;
  font-size: clamp(1.25rem, 2.2vw, 1.5rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.app-subtitle {
  margin: 0;
  font-size: clamp(0.875rem, 1.5vw, 0.95rem);
  color: var(--text-secondary);
}

.top-actions {
  flex-shrink: 0;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.5rem 0.875rem;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-secondary:hover {
  background-color: var(--bg-row-highlight);
}

/* Controls Section */
.controls-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.field-label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
}

.field-hint {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent-primary);
}

/* Top Nominal Input */
.nominal-input-wrapper {
  display: flex;
  align-items: stretch;
  background-color: var(--bg-surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  min-height: 52px;
  transition: border-color 0.15s ease;
}

.nominal-input-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 1px var(--accent-primary);
}

.currency-prefix {
  display: inline-flex;
  align-items: center;
  padding: 0 0.75rem 0 1rem;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  user-select: none;
}

.nominal-input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.05rem, 2vw, 1.25rem);
  font-weight: 600;
  padding: 0.65rem 0.5rem 0.65rem 0;
}

.nominal-input:focus-visible {
  outline: none;
}

.btn-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 44px;
  margin: 3px;
  padding: 0 0.75rem;
  background-color: var(--bg-row-highlight);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-clear:hover {
  border-color: var(--border-strong);
}

/* Tax Options: PPN dan PPh ditumpuk satu kolom di semua lebar, agar select PPh tidak terjepit */
.tax-options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

.ppn-controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.875rem;
}

.pph-controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.select-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.ppn-select-wrap {
  min-width: 110px;
}

.pph-select-wrap {
  width: 100%;
  max-width: 480px;
}

.field-select {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
}

/* Checkbox with 44px Minimum Touch Target (R-03) */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  user-select: none;
}

.checkbox-input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.checkbox-text {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Custom PPh Input */
.custom-rate-box {
  display: inline-flex;
  align-items: center;
  background-color: var(--bg-surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  min-height: 44px;
  padding: 0 0.65rem;
  width: 130px;
}

.custom-rate-box[hidden] {
  display: none;
}

.custom-rate-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 0.4rem 0;
}

.custom-rate-input:focus-visible {
  outline: none;
}

.percent-suffix {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 0.25rem;
}

/* Ledger Toolbar & Salin Button */
.ledger-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ledger-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.status-banner {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  flex: 1 1 260px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-primary);
  flex-shrink: 0;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  min-width: 104px;
  padding: 0.5rem 1rem;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-offset);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.15s ease;
}

.btn-action:hover {
  background-color: var(--bg-row-highlight);
}

.btn-action:active {
  transform: translate(2px, 2px);
  box-shadow: var(--shadow-offset-active);
}

.btn-print {
  background-color: var(--bg-surface);
}

.btn-copy.copied {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* Error Banner (R-27) */
.error-banner {
  padding: 0.75rem 1rem;
  background-color: var(--bg-error);
  border: 1.5px solid var(--border-error);
  border-radius: var(--radius-sm);
  color: var(--accent-deduction);
  font-size: 0.875rem;
}

/* 5-Row Interactive Ledger Table */
.ledger-table {
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface);
  overflow: hidden;
}

.ledger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  transition: background-color 0.12s ease;
}

.ledger-row:last-child {
  border-bottom: none;
}

.ledger-row.row-highlight {
  background-color: var(--bg-row-highlight);
}

.ledger-row.is-source {
  background-color: var(--bg-row-active);
}

.ledger-cell-label {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-width: 0;
}

.vendor-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.row-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}

.row-title-strong {
  font-weight: 700;
  color: var(--text-primary);
}

.row-subhint {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.rate-pill {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.active-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-primary);
  background-color: var(--bg-surface);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-sm);
}

.active-badge[hidden] {
  display: none;
}

/* Editable Value Cell inside Ledger Row */
.ledger-cell-value {
  flex: 0 0 auto;
  width: min(100%, 260px);
}

.inline-currency-field {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 44px;
  padding: 0 0.65rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.inline-currency-field:hover {
  border-color: var(--border-strong);
}

.inline-currency-field:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 1.5px var(--accent-primary);
}

.row-prefix {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-right: 0.4rem;
  white-space: nowrap;
  user-select: none;
}

.row-prefix-strong {
  font-weight: 700;
  color: var(--text-primary);
}

.deduction-prefix {
  color: var(--accent-deduction);
  font-weight: 600;
}

.row-input {
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  font-weight: 500;
  text-align: right;
  padding: 0.4rem 0;
}

.row-input:focus-visible {
  outline: none;
}

.row-input-strong {
  font-weight: 700;
  font-size: 1rem;
}

.deduction-input {
  color: var(--accent-deduction);
  font-weight: 600;
}

/* Tablet State (600px - 860px) */
@media (min-width: 600px) and (max-width: 860px) {
  .ledger-cell-value {
    width: 230px;
  }
}

/* Mobile Reflow State (< 600px) - Guarantees zero collision and full-width thumb targets */
@media (max-width: 599px) {
  .top-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    display: flex;
    justify-content: flex-end;
  }

  .pph-select-wrap {
    max-width: 100%;
  }

  .custom-rate-box {
    width: 100%;
  }

  .ledger-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions {
    width: 100%;
    flex-direction: column;
  }

  .btn-action {
    width: 100%;
  }

  .ledger-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
    padding: 0.75rem;
  }

  .ledger-cell-label {
    justify-content: space-between;
  }

  .ledger-cell-value {
    width: 100%;
  }
}


.ledger-row[hidden] {
  display: none;
}

/* Invoice Print Container */
.invoice-print-container {
  display: none;
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .page-shell > header,
  .calculator-main {
    display: none !important;
  }

  .invoice-print-container {
    display: block !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    font-family: var(--font-sans);
    color: #000000;
  }

  .inv-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid #000000;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
  }

  .inv-title {
    margin: 0 0 0.25rem 0;
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
  }

  .inv-subtitle {
    margin: 0;
    font-size: 0.875rem;
    color: #444444;
  }

  .inv-meta table td {
    padding: 0.15rem 0.5rem;
    font-size: 0.875rem;
  }

  .inv-parties {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 1.5rem;
    border: 1px solid #cccccc;
    padding: 1rem;
  }

  .party-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    color: #555555;
    display: block;
    margin-bottom: 0.25rem;
  }

  .party-name {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 0.25rem 0;
  }

  .party-desc {
    margin: 0;
    font-size: 0.8125rem;
    color: #333333;
    line-height: 1.4;
  }

  .inv-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
  }

  .inv-table th,
  .inv-table td {
    border: 1px solid #000000;
    padding: 0.6rem 0.75rem;
    font-size: 0.875rem;
  }

  .inv-table th {
    background-color: #f0f0f0 !important;
    font-weight: 700;
    text-align: left;
  }

  .text-right {
    text-align: right;
  }

  .inv-desc-notes {
    font-size: 0.75rem;
    color: #555555;
    margin-top: 0.25rem;
  }

  .inv-calc-breakdown {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 2.5rem;
  }

  .inv-notes {
    flex: 1 1 auto;
    font-size: 0.8125rem;
    padding: 0.75rem;
    border: 1px dashed #888888;
  }

  .notes-title {
    font-weight: 700;
    display: block;
    margin-bottom: 0.25rem;
  }

  .inv-summary-table {
    width: 380px;
    border-collapse: collapse;
  }

  .inv-summary-table td {
    padding: 0.35rem 0.5rem;
    font-size: 0.875rem;
    border-bottom: 1px solid #dddddd;
  }

  .inv-summary-table .inv-highlight-row td {
    border-top: 1.5px solid #000000;
    border-bottom: 1.5px solid #000000;
    background-color: #f5f5f5 !important;
  }

  .inv-summary-table .inv-deduct-row td {
    color: #880000 !important;
  }

  .inv-summary-table .inv-net-row td {
    border-top: 2px solid #000000;
    border-bottom: 2px solid #000000;
    font-size: 0.95rem;
    background-color: #f0f0f0 !important;
  }

  .inv-signatures {
    display: flex;
    justify-content: space-between;
    gap: 3rem;
    margin-top: 2rem;
    page-break-inside: avoid;
  }

  .sig-box {
    flex: 1;
    text-align: center;
    font-size: 0.875rem;
  }

  .sig-space {
    height: 70px;
  }

  .sig-name {
    margin: 0;
    font-weight: 600;
  }
}

