/* =========================================================
   UI/UX POLISH V1
   Visual-only layer. Does not change API, accounting, or PDF logic.
   ========================================================= */

:root {
  --ui-primary: #2563eb;
  --ui-primary-dark: #1d4ed8;
  --ui-success: #16a34a;
  --ui-success-dark: #15803d;
  --ui-danger: #dc2626;
  --ui-warning: #d97706;
  --ui-focus: rgba(37, 99, 235, .18);
  --ui-shadow-soft: 0 8px 24px rgba(16, 24, 40, .07);
  --ui-shadow-action: 0 5px 14px rgba(16, 24, 40, .10);
}

/* ---------- Global interaction ---------- */

.btn,
.icon-btn,
.mini-action {
  transition:
    transform .16s ease,
    box-shadow .16s ease,
    background-color .16s ease,
    border-color .16s ease,
    color .16s ease,
    opacity .16s ease;
}

.btn:not(:disabled):hover,
.icon-btn:not(:disabled):hover,
.mini-action:not(:disabled):hover {
  transform: translateY(-1px);
}

.btn:not(:disabled):active,
.icon-btn:not(:disabled):active,
.mini-action:not(:disabled):active {
  transform: translateY(0);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.mini-action:focus-visible,
.contact-input:focus-visible,
.contact-message:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 1px;
}

/* ---------- Primary buttons ---------- */

.btn {
  min-height: 42px;
  padding: 10px 15px;
  border-radius: 11px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

.btn-primary {
  background: var(--ui-primary);
  border-color: var(--ui-primary);
  box-shadow: 0 5px 14px rgba(37, 99, 235, .20);
}

.btn-primary:hover:not(:disabled) {
  background: var(--ui-primary-dark);
  border-color: var(--ui-primary-dark);
  opacity: 1;
  box-shadow: 0 7px 18px rgba(37, 99, 235, .25);
}

.btn-light {
  background: #fff;
}

.btn-light:hover:not(:disabled) {
  border-color: #b8c2d1;
  background: #f8fafc;
  opacity: 1;
}

/* ---------- PDF / WhatsApp actions ---------- */

[data-pdf-action],
[data-wa-action] {
  position: relative;
  font-weight: 700;
}

.btn[data-pdf-action],
.btn[data-wa-action] {
  min-height: 44px;
  padding-left: 16px;
  padding-right: 16px;
}

.btn[data-pdf-action]:hover:not(:disabled) {
  border-color: #93b4f8;
  background: #f7faff;
  color: var(--ui-primary);
}

.btn-whatsapp,
[data-wa-action].whatsapp-mini {
  box-shadow: 0 5px 14px rgba(22, 163, 74, .18);
}

.btn-whatsapp:hover:not(:disabled),
[data-wa-action].whatsapp-mini:hover:not(:disabled) {
  box-shadow: 0 7px 18px rgba(22, 163, 74, .24);
}

.mini-action {
  min-height: 36px;
  padding: 7px 11px;
  border-radius: 9px;
}

.mini-action[data-pdf-action] {
  color: var(--ui-primary);
  background: #f7faff;
  border-color: #cfe0ff;
}

.mini-action[data-pdf-action]:hover:not(:disabled) {
  background: #eaf2ff;
  border-color: #93b4f8;
}

.mini-action.whatsapp-mini {
  border-color: #b7e6c5;
}

.invoice-actions {
  gap: 8px;
}

/* ---------- Detail action area ---------- */

.detail-footer {
  padding: 14px 18px;
  box-shadow: 0 -6px 18px rgba(16, 24, 40, .04);
}

.detail-footer-left,
.detail-footer-right {
  gap: 9px;
}

.detail-footer-left .btn,
.detail-footer-right .btn {
  white-space: nowrap;
}

.detail-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-heading::before {
  content: "";
  width: 4px;
  height: 18px;
  border-radius: 999px;
  background: var(--ui-primary);
}

/* ---------- Reliable action icons ---------- */

.action-icon {
  width: 17px;
  height: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 17px;
  vertical-align: -3px;
  margin-right: 7px;
}

.action-icon svg {
  width: 17px;
  height: 17px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mini-action .action-icon {
  width: 15px;
  height: 15px;
  flex-basis: 15px;
  margin-right: 5px;
}

.mini-action .action-icon svg {
  width: 15px;
  height: 15px;
}

/* ---------- Reliable data loading spinner ---------- */

.table-state.loading {
  position: relative;
}

.table-state.loading::before {
  display: block !important;
  width: 32px !important;
  height: 32px !important;
  min-width: 32px;
  min-height: 32px;
  margin: 0 0 2px;
  border: 3px solid #e5e7eb !important;
  border-top-color: var(--ui-primary) !important;
  border-right-color: #93b4f8 !important;
  border-radius: 50%;
  animation: uiDataLoadingSpin .72s linear infinite !important;
  transform-origin: center center;
  box-sizing: border-box;
}

@keyframes uiDataLoadingSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ---------- Data loading / empty / error states ---------- */

.table-state {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 34px 20px;
  line-height: 1.5;
}

.table-state.loading {
  color: #475467;
}

.table-state.loading::before {
  content: "";
  width: 30px;
  height: 30px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--ui-primary);
  border-radius: 50%;
  animation: uiSpin .8s linear infinite;
}

.table-state.empty::before {
  content: "✓";
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ecfdf3;
  color: var(--ui-success);
  font-weight: 800;
}

.table-state.error {
  color: #b42318;
}

.table-state.error::before {
  content: "!";
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fef3f2;
  color: var(--ui-danger);
  font-weight: 800;
}

.detail-loading {
  min-height: 190px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  line-height: 1.5;
}

.detail-loading::before {
  content: "";
  display: block !important;
  width: 34px !important;
  height: 34px !important;
  min-width: 34px;
  min-height: 34px;
  border: 3px solid #e5e7eb !important;
  border-top-color: var(--ui-primary) !important;
  border-right-color: #93b4f8 !important;
  border-radius: 50%;
  animation: uiDetailLoadingSpin .72s linear infinite !important;
  transform-origin: center center;
  box-sizing: border-box;
}

.detail-error {
  margin: 8px 0;
  padding: 22px;
  border: 1px solid #fecaca;
  border-radius: 12px;
  background: #fff7f7;
}

/* ---------- PDF generation overlay ---------- */

#pdf-loading-overlay {
  background: rgba(15, 23, 42, .48) !important;
  backdrop-filter: blur(4px) !important;
  -webkit-backdrop-filter: blur(4px) !important;
}

#pdf-loading-overlay .pdf-loading-card {
  width: min(430px, calc(100vw - 36px)) !important;
  min-width: 0 !important;
  padding: 30px 28px !important;
  border: 1px solid rgba(226, 232, 240, .9) !important;
  border-radius: 20px !important;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .24) !important;
}

#pdf-loading-overlay .pdf-loading-spinner {
  width: 48px !important;
  height: 48px !important;
  margin-bottom: 18px !important;
  border-width: 4px !important;
  border-top-color: var(--ui-primary) !important;
}

#pdf-loading-overlay .pdf-loading-title {
  font-size: 18px !important;
  letter-spacing: -.01em;
}

#pdf-loading-overlay .pdf-loading-message {
  max-width: 330px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}

/* ---------- Busy buttons ---------- */

button.ui-busy {
  position: relative;
  pointer-events: none;
  opacity: .78;
}

button.ui-busy::after {
  content: "";
  width: 14px;
  height: 14px;
  margin-left: 8px;
  display: inline-block;
  vertical-align: -2px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: uiSpin .65s linear infinite;
}

/* ---------- Toast ---------- */

.app-toast {
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 12px 16px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(16, 24, 40, .22);
}

.app-toast:not(.error)::before {
  content: "✓";
  display: inline-grid;
  place-items: center;
  width: 21px;
  height: 21px;
  margin-right: 9px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  font-weight: 800;
}

/* ---------- Modal polish ---------- */

.modal-backdrop {
  background: rgba(15, 23, 42, .54);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.modal-panel {
  border: 1px solid rgba(226, 232, 240, .9);
}

.modal-header {
  background: linear-gradient(to bottom, #fff, #fcfdff);
}

.modal-close {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
}

.modal-close:hover {
  background: #f2f4f7;
  color: var(--text);
}

/* ---------- Responsive ---------- */

@media (max-width: 800px) {
  .detail-footer-left,
  .detail-footer-right {
    gap: 8px;
  }

  .detail-footer-left .btn,
  .detail-footer-right .btn {
    min-height: 44px;
  }

  .invoice-actions {
    gap: 7px;
  }
}

@media (max-width: 520px) {
  .page-content {
    padding: 16px;
  }

  .topbar {
    padding: 16px;
  }

  .btn,
  .btn[data-pdf-action],
  .btn[data-wa-action] {
    min-height: 44px;
  }

  .mobile-customer-card {
    margin: 10px 8px;
    padding: 15px;
  }

  .modal {
    padding: 10px;
  }

  .modal-panel {
    border-radius: 16px;
  }

  .modal-header,
  .modal-body {
    padding-left: 17px;
    padding-right: 17px;
  }
}

@keyframes uiDetailLoadingSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes uiSpin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .icon-btn,
  .mini-action,
  .app-toast {
    transition: none;
  }

  .table-state.loading::before,
  .detail-loading::before,
  button.ui-busy::after {
    animation: none;
  }
}

/* =========================================================
   UI/UX POLISH V2 — DESIGN SYSTEM + APP SHELL
   Visual-only layer. Preserves API, accounting, PDF, and state logic.
   ========================================================= */

:root {
  --ui-surface-raised: #ffffff;
  --ui-surface-subtle: #f6f8fb;
  --ui-border-soft: #e7ebf0;
  --ui-border-strong: #d8dee8;
  --ui-text-strong: #111827;
  --ui-text-body: #344054;
  --ui-text-muted: #667085;
  --ui-primary-soft: #eff5ff;
  --ui-success-soft: #ecfdf3;
  --ui-danger-soft: #fef3f2;
  --ui-warning-soft: #fffaeb;
  --ui-radius-sm: 9px;
  --ui-radius-md: 12px;
  --ui-radius-lg: 16px;
  --ui-shadow-card: 0 1px 2px rgba(16,24,40,.03), 0 8px 24px rgba(16,24,40,.045);
  --ui-shadow-card-hover: 0 2px 4px rgba(16,24,40,.04), 0 12px 30px rgba(16,24,40,.07);
}

body {
  color: var(--ui-text-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: #dbeafe;
  color: var(--ui-text-strong);
}

button,
a,
select,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 2px;
}

/* ---------- App shell visual polish ---------- */

.sidebar {
  padding: 20px 12px;
  border-right: 1px solid rgba(255,255,255,.055);
  box-shadow: 8px 0 28px rgba(16,24,40,.08);
}

.brand {
  padding: 7px 9px 24px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  box-shadow: 0 6px 16px rgba(37,99,235,.22);
}

.brand strong {
  font-size: 14px;
  letter-spacing: -.01em;
}

.brand span {
  font-size: 11px;
}

.nav {
  gap: 4px;
}

.nav-item {
  position: relative;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: #cbd5e1;
  transition: background-color .16s ease, color .16s ease, border-color .16s ease, transform .16s ease;
}

.nav-item:hover {
  background: rgba(255,255,255,.055);
  color: #f8fafc;
  transform: translateX(1px);
}

.nav-item.active {
  background: rgba(37,99,235,.16);
  border-color: rgba(147,180,248,.13);
  color: #fff;
  box-shadow: inset 3px 0 0 #60a5fa;
}

.nav-item.active:hover {
  background: rgba(37,99,235,.19);
}

.sidebar-footer {
  margin: auto 3px 0;
  padding: 11px 9px;
  border-top: 1px solid rgba(255,255,255,.07);
  font-size: 11px;
}

.status-dot {
  width: 7px;
  height: 7px;
  box-shadow: 0 0 0 3px rgba(21,128,61,.12);
}

.topbar {
  min-height: 76px;
  padding: 16px 30px;
  box-shadow: 0 1px 0 rgba(16,24,40,.015);
}

.topbar h1 {
  color: var(--ui-text-strong);
  font-size: 21px;
  letter-spacing: -.025em;
}

.eyebrow {
  color: var(--ui-text-muted);
  font-size: 9px;
  letter-spacing: .1em;
}

.environment-badge {
  padding: 7px 10px;
  border-color: var(--ui-border-soft);
  background: var(--ui-surface-subtle);
  color: var(--ui-text-muted);
  font-weight: 600;
}

.page-content {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 28px 30px 42px;
}

.page-heading {
  margin-bottom: 18px;
}

.page-heading h2 {
  color: var(--ui-text-strong);
  letter-spacing: -.035em;
}

.page-description {
  color: var(--ui-text-muted);
  line-height: 1.55;
}

/* ---------- Shared cards / panels ---------- */

.welcome-card,
.stat-card,
.summary-card,
.card.panel,
.dashboard-panel,
.dashboard-kpi {
  border-color: var(--ui-border-soft);
  box-shadow: var(--ui-shadow-card);
}

.welcome-card:hover,
.stat-card:hover,
.summary-card:hover,
.dashboard-kpi:hover {
  box-shadow: var(--ui-shadow-card-hover);
}

.welcome-card,
.stat-card,
.summary-card {
  border-radius: var(--ui-radius-lg);
}

.welcome-card h2 {
  color: var(--ui-text-strong);
  letter-spacing: -.035em;
}

.stat-card strong,
.summary-card strong {
  color: var(--ui-text-strong);
  letter-spacing: -.025em;
}

/* ---------- Controls ---------- */

.btn,
.icon-btn,
.mini-action {
  font-weight: 650;
}

.btn {
  border-radius: var(--ui-radius-md);
  min-height: 42px;
}

.btn-primary {
  box-shadow: 0 5px 15px rgba(37,99,235,.17);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn-light:hover:not(:disabled),
.icon-btn:hover:not(:disabled) {
  background: #f8fafc;
  border-color: var(--ui-border-strong);
}

.search-box {
  border-color: var(--ui-border-soft);
  background: #f8fafc;
  border-radius: var(--ui-radius-md);
  transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}

.search-box:focus-within {
  border-color: #9dbcf6;
  background: #fff;
  box-shadow: 0 0 0 3px var(--ui-focus);
}

.search-box input::placeholder,
.contact-input::placeholder,
.contact-message::placeholder {
  color: #98a2b3;
}

.page-size select,
.dashboard-period select,
.contact-input,
.contact-message {
  border-color: var(--ui-border-soft);
  border-radius: var(--ui-radius-md);
}

.page-size select:focus,
.dashboard-period select:focus,
.contact-input:focus,
.contact-message:focus {
  border-color: #9dbcf6;
  box-shadow: 0 0 0 3px var(--ui-focus);
}

/* ---------- Tables ---------- */

.card.panel {
  border-radius: var(--ui-radius-lg);
}

.toolbar {
  padding: 15px 17px;
  background: rgba(255,255,255,.92);
}

.data-table th {
  background: #f8fafc;
  color: #667085;
  font-weight: 750;
}

.data-table td {
  color: var(--ui-text-body);
}

.data-table tr:hover td {
  background: #f8fbff;
}

.data-table tr:last-child td,
.detail-table tr:last-child td {
  border-bottom: 0;
}

.pagination {
  border-top: 1px solid var(--ui-border-soft);
  background: #fcfdff;
}

/* ---------- Mobile cards ---------- */

.mobile-customer-card {
  border-color: var(--ui-border-soft);
  border-radius: var(--ui-radius-md);
  box-shadow: 0 1px 2px rgba(16,24,40,.025);
}

.mobile-customer-card:active {
  transform: scale(.998);
}

/* ---------- Detail modal ---------- */

.modal-backdrop {
  background: rgba(15,23,42,.56);
}

.modal-panel {
  border-color: var(--ui-border-soft);
  border-radius: 18px;
  box-shadow: 0 28px 80px rgba(15,23,42,.22);
}

.modal-header {
  padding: 18px 21px;
}

.modal-header h3 {
  color: var(--ui-text-strong);
  letter-spacing: -.02em;
}

.modal-body {
  padding: 19px 21px;
}

.detail-customer div,
.aging-card,
.financial-card {
  border-color: var(--ui-border-soft);
}

.detail-customer div {
  background: #f8fafc;
}

.aging-card {
  box-shadow: 0 1px 2px rgba(16,24,40,.025);
}

.aging-danger {
  background: var(--ui-danger-soft);
}

.financial-card.debt {
  background: #172f49;
  border-color: #172f49;
  box-shadow: 0 8px 22px rgba(23,47,73,.14);
}

.financial-card.reconciliation {
  background: #f8fafc;
  border-color: var(--ui-border-soft);
}

.financial-card.reconciliation strong {
  color: var(--ui-text-strong);
}

.detail-table th {
  background: #f8fafc;
  color: #667085;
}

.detail-table td:first-child .invoice-code {
  color: var(--ui-text-strong);
  font-weight: 800;
}

.detail-table .invoice-balance {
  color: var(--ui-text-strong);
  font-weight: 800;
}

.invoice-age {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 750;
}

.invoice-age-current {
  background: #e8eef7;
  color: #344054;
  border: 1px solid #cbd5e1;
}

.invoice-age-attention {
  background: #fff3cd;
  color: #a15c00;
  border: 1px solid #f5c451;
}

.invoice-age-warning {
  background: #ffe4b5;
  color: #9a3412;
  border: 1px solid #fb923c;
}

.invoice-age-danger {
  background: #fee2e2;
  color: #b42318;
  border: 1px solid #f87171;
  box-shadow: 0 0 0 1px rgba(220,38,38,.06);
}

.invoice-age-neutral {
  background: #f1f5f9;
  color: #667085;
  border: 1px solid #dbe2ea;
}

.detail-footer {
  background: rgba(255,255,255,.985);
  border-top-color: var(--ui-border-soft);
}

/* ---------- Toast ---------- */

.app-toast {
  border-radius: 13px;
  font-weight: 600;
}

/* ---------- Desktop spacing ---------- */

@media (min-width: 1200px) {
  .page-content {
    padding-left: 34px;
    padding-right: 34px;
  }
}

/* ---------- Mobile app shell refinement ---------- */

@media (max-width: 800px) {
  .sidebar {
    padding: 17px 12px;
  }

  .topbar {
    min-height: 64px;
    padding: 10px 15px;
    box-shadow: 0 1px 8px rgba(16,24,40,.045);
  }

  .page-content {
    padding: 19px 15px 30px;
  }

  .page-heading h2 {
    font-size: 25px;
  }

  .toolbar {
    gap: 10px;
  }

  .summary-card {
    padding: 16px;
  }

  .modal-panel {
    box-shadow: 0 -12px 45px rgba(15,23,42,.16);
  }
}

@media (max-width: 520px) {
  .page-content {
    padding: 16px 12px 26px;
  }

  .page-heading h2 {
    font-size: 23px;
  }

  .welcome-card {
    padding: 19px;
  }

  .summary-card {
    padding: 15px;
  }

  .btn,
  .btn[data-pdf-action],
  .btn[data-wa-action] {
    border-radius: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nav-item,
  .welcome-card,
  .stat-card,
  .summary-card,
  .dashboard-kpi,
  .search-box {
    transition: none;
  }
}

/* =========================================================
   UI/UX POLISH V2 — DASHBOARD + DATA UX
   ========================================================= */

/* ---------- Dashboard hierarchy ---------- */

.dashboard-kpi {
  position: relative;
  overflow: hidden;
  padding: 17px 18px;
}

.dashboard-kpi-primary {
  border-top-width: 3px;
}

.dashboard-kpi-profit {
  border-top-width: 3px;
}

.dashboard-kpi-icon {
  box-shadow: inset 0 0 0 1px rgba(37,99,235,.06);
}

.dashboard-panel-head {
  min-height: 74px;
  padding: 16px 19px;
}

.dashboard-panel-head h3 {
  color: var(--ui-text-strong);
  letter-spacing: -.018em;
}

.dashboard-panel-value {
  color: var(--ui-text-strong);
}

.dashboard-chart-wrap {
  background: linear-gradient(to bottom, #fff, #fcfdff);
}

.dashboard-definition-list {
  background: #fff;
}

.dashboard-definition-list div {
  padding: 11px 0;
}

.dashboard-definition-list strong {
  color: var(--ui-text-strong);
}

/* ---------- Summary cards: hierarchy without changing values ---------- */

.summary-card {
  position: relative;
  overflow: hidden;
}

.summary-card strong {
  font-size: clamp(19px, 2vw, 23px);
}

.summary-card small {
  line-height: 1.4;
}

/* ---------- Data panel states ---------- */

.table-state,
.dashboard-state.is-loading,
.dashboard-state.is-error {
  border-color: var(--ui-border-soft);
}

.table-state.loading {
  background: linear-gradient(to bottom, #fff, #fcfdff);
}

.table-state.empty {
  background: #fcfffd;
}

.table-state.error {
  background: #fffafa;
}

.detail-loading {
  background: #fcfdff;
}

.detail-error {
  border-color: #f2c8c5;
  background: #fffafa;
}

/* ---------- Action emphasis ---------- */

.btn-whatsapp {
  background: #16a34a;
}

.btn-whatsapp:hover:not(:disabled) {
  background: #15803d;
}

.mini-action {
  min-height: 36px;
}

.mini-action.whatsapp-mini {
  color: #15803d;
  background: #f0fdf4;
}

.mini-action.whatsapp-mini:hover:not(:disabled) {
  color: #166534;
  background: #dcfce7;
  border-color: #86efac;
}

/* ---------- Customer / Piutang card readability ---------- */

.customer-cell strong,
.mobile-customer-head strong {
  color: var(--ui-text-strong);
}

.customer-cell span,
.mobile-customer-head span,
.mobile-customer-total span {
  color: var(--ui-text-muted);
}

.mobile-aging-grid span {
  border: 1px solid var(--ui-border-soft);
  background: #f8fafc;
}

/* ---------- Better narrow screens ---------- */

@media (max-width: 800px) {
  .dashboard-kpi {
    padding: 15px;
  }

  .dashboard-kpi-icon {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .dashboard-chart-grid {
    gap: 13px;
  }

  .dashboard-panel-head {
    min-height: 68px;
  }

  .data-table th,
  .data-table td {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 520px) {
  .dashboard-kpi {
    gap: 11px;
  }

  .dashboard-kpi strong {
    font-size: 20px;
  }

  .dashboard-kpi small {
    font-size: 9px;
  }

  .mobile-customer-card {
    margin-left: 6px;
    margin-right: 6px;
  }
}


/* =========================================================
   UI/UX POLISH V2 — MOBILE VIEWPORT CONSTRAINTS
   Fixes viewport clipping / half-screen rendering and keeps
   dashboard content inside the mobile viewport.
   Visual/layout only. No API or application logic changes.
   ========================================================= */

@media (max-width: 1100px) {

  .topbar {
    width: 100%;
    max-width: 100vw;
    min-width: 0;
  }

  .topbar-left {
    min-width: 0;
    flex: 1 1 auto;
  }

  .topbar-left > div:last-child {
    min-width: 0;
  }

  .topbar h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-content {
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    overflow-x: clip;
  }

  .dashboard-heading,
  .dashboard-toolbar,
  .dashboard-kpis,
  .dashboard-chart-grid,
  .dashboard-panel,
  .dashboard-chart-panel,
  .dashboard-chart-wrap,
  .dashboard-chart,
  .dashboard-definition-list {
    min-width: 0;
    max-width: 100%;
  }

  .dashboard-chart-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .dashboard-chart-wide {
    grid-row: auto;
  }

  .dashboard-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-panel-head {
    min-width: 0;
  }

  .dashboard-panel-head > div {
    min-width: 0;
  }

  .dashboard-panel-value {
    max-width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .dashboard-chart-stage,
  .dashboard-chart svg {
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 520px) {
  .dashboard-kpis {
    grid-template-columns: minmax(0, 1fr);
  }

  .dashboard-toolbar {
    width: 100%;
    max-width: 100%;
  }

  .dashboard-panel-head {
    gap: 10px;
    padding: 14px;
  }

  .dashboard-panel-head h3 {
    font-size: 16px;
  }

  .dashboard-panel-value {
    max-width: 50%;
    font-size: 12px;
  }

  .dashboard-chart-wrap,
  .dashboard-chart-wrap-profit {
    min-height: 270px;
    padding-left: 2px;
    padding-right: 2px;
    overflow: hidden;
  }

  .dashboard-chart {
    height: 250px;
  }
}


/* =========================================================
   DASHBOARD CALENDAR V1
   Frontend-only widget using existing dashboard sales data.
   ========================================================= */

.dashboard-calendar-panel {
  min-width: 0;
}

.dashboard-calendar {
  padding: 18px 19px 17px;
}

.dashboard-calendar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.dashboard-calendar-head h3 {
  margin: 5px 0 0;
  color: var(--ui-text-strong);
  font-size: 17px;
  letter-spacing: -.018em;
  text-transform: capitalize;
}

.dashboard-calendar-legend {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--ui-text-muted);
  font-size: 10px;
  white-space: nowrap;
}

.dashboard-calendar-legend i {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}

.dashboard-calendar-weekdays,
.dashboard-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}

.dashboard-calendar-weekdays {
  margin-bottom: 5px;
}

.dashboard-calendar-weekdays span {
  padding: 4px 0;
  color: var(--ui-text-muted);
  font-size: 9px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.dashboard-calendar-day {
  position: relative;
  min-width: 0;
  min-height: 43px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--ui-text-body);
  cursor: pointer;
  transition: background-color .14s ease, border-color .14s ease, transform .14s ease;
}

.dashboard-calendar-day:hover {
  background: #f5f8fc;
  border-color: var(--ui-border-soft);
}

.dashboard-calendar-day:active {
  transform: scale(.97);
}

.dashboard-calendar-day.is-empty {
  cursor: default;
  pointer-events: none;
}

.dashboard-calendar-number {
  font-size: 12px;
  font-weight: 650;
}

.dashboard-calendar-day.has-data .dashboard-calendar-number {
  color: var(--ui-text-strong);
}

.dashboard-calendar-dot {
  position: absolute;
  left: 50%;
  bottom: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateX(-50%);
}

.dashboard-calendar-day.is-today {
  border-color: #9dbcf6;
  background: var(--ui-primary-soft);
}

.dashboard-calendar-day.is-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 5px 12px rgba(31,111,235,.18);
}

.dashboard-calendar-day.is-selected .dashboard-calendar-number {
  color: #fff;
}

.dashboard-calendar-day.is-selected .dashboard-calendar-dot {
  background: #fff;
}

.dashboard-calendar-detail {
  min-height: 58px;
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 12px;
  align-items: center;
  margin-top: 14px;
  padding: 11px 13px;
  border: 1px solid var(--ui-border-soft);
  border-radius: 11px;
  background: #f8fafc;
}

.dashboard-calendar-detail span {
  grid-column: 1 / -1;
  color: var(--ui-text-muted);
  font-size: 10px;
}

.dashboard-calendar-detail strong {
  color: var(--ui-text-strong);
  font-size: 13px;
}

.dashboard-calendar-detail small {
  color: var(--ui-text-muted);
  font-size: 10px;
  text-align: right;
}

@media (max-width: 800px) {
  .dashboard-calendar {
    padding: 16px;
  }

  .dashboard-calendar-day {
    min-height: 45px;
  }
}

@media (max-width: 520px) {
  .dashboard-calendar {
    padding: 14px;
  }

  .dashboard-calendar-head {
    margin-bottom: 13px;
  }

  .dashboard-calendar-head h3 {
    font-size: 16px;
  }

  .dashboard-calendar-legend {
    font-size: 9px;
  }

  .dashboard-calendar-weekdays,
  .dashboard-calendar-grid {
    gap: 3px;
  }

  .dashboard-calendar-day {
    min-height: 41px;
    border-radius: 8px;
  }

  .dashboard-calendar-number {
    font-size: 11px;
  }

  .dashboard-calendar-detail {
    margin-top: 11px;
  }
}


@media (min-width: 1101px) {
  .dashboard-calendar-panel {
    grid-column: 1;
    grid-row: 3;
  }
}

@media (max-width: 1100px) {
  .dashboard-calendar-panel {
    grid-column: 1;
    grid-row: auto;
  }
}


/* =========================================================
   APP IDENTITY FOOTER
   Global application identity; environment remains technical-only.
   ========================================================= */

.app-footer {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: auto;
  padding: 14px 20px 16px;
  color: var(--ui-text-muted, #667085);
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: .01em;
  text-align: center;
}

.app-footer strong {
  color: var(--ui-text-body, #344054);
  font-weight: 700;
}

.app-version {
  color: var(--ui-text-muted, #667085);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .app-footer {
    padding: 12px 16px 14px;
    font-size: 10px;
    gap: 5px;
  }

  .app-version {
    font-size: 10px;
  }
}


/* ---------- Unified main-page width ---------- */
.page-content > * {
  width: 100%;
  max-width: none;
}

.page-content .page-heading,
.page-content .summary-grid,
.page-content .card.panel,
.page-content .dashboard-chart-grid,
.page-content .dashboard-kpis {
  width: 100%;
}

@media (max-width: 800px) {
  .page-content {
    width: 100%;
    padding: 20px;
  }
}


/* =========================================================
   MOBILE APP HEADER — NUSANTARA BUSINESS MANAGEMENT
   Keeps navigation control outside page content and preserves
   a clear visual hierarchy for mobile pages.
   ========================================================= */

.mobile-app-header {
  display: none;
}

@media (max-width: 1100px) {
  .mobile-app-header {
    position: sticky;
    top: 0;
    z-index: 250;
    width: 100%;
    min-height: 66px;
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: rgba(255,255,255,.96);
    border-bottom: 1px solid var(--ui-border-soft);
    box-shadow: 0 2px 12px rgba(16,24,40,.06);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .mobile-app-brand {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
  }

  .mobile-app-brand-copy {
    min-width: 0;
  }

  .mobile-app-brand-copy h1 {
    margin: 0;
    color: var(--ui-text-strong);
    font-size: 16px;
    line-height: 1.05;
    font-weight: 800;
    letter-spacing: .045em;
  }

  .mobile-app-brand-copy span {
    display: block;
    margin-top: 4px;
    color: var(--ui-text-muted);
    font-size: 9px;
    line-height: 1;
    font-weight: 650;
    letter-spacing: .11em;
    text-transform: uppercase;
  }

  .mobile-menu-toggle {
    width: 42px;
    height: 42px;
    min-width: 42px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0;
    border: 1px solid var(--ui-border-soft);
    border-radius: 11px;
    background: #fff;
    color: var(--ui-text-strong);
    box-shadow: 0 2px 7px rgba(16,24,40,.07);
    cursor: pointer;
  }

  .mobile-menu-toggle span {
    width: 17px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
  }

  .mobile-menu-toggle:active {
    transform: scale(.97);
  }

  .page-content {
    padding-top: 18px;
  }

  .page-heading h2 {
    position: relative;
    z-index: 1;
  }
}

@media (max-width: 520px) {
  .mobile-app-header {
    min-height: 62px;
    padding: 9px 12px;
  }

  .mobile-app-brand {
    gap: 10px;
  }

  .mobile-app-brand-copy h1 {
    font-size: 15px;
  }

  .mobile-app-brand-copy span {
    font-size: 8px;
    letter-spacing: .095em;
  }

  .mobile-menu-toggle {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .page-content {
    padding-top: 16px;
  }
}


/* =========================================================
   PHASE 2 — CUSTOMER DETAIL ACTION HIERARCHY
   Visual-only hierarchy; existing action handlers remain unchanged.
   ========================================================= */

.detail-report-actions {
  align-items: center;
  gap: 8px;
}

.detail-action-group-label {
  margin-right: 2px;
  color: var(--ui-text-muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.detail-action-secondary {
  min-height: 38px;
}

.detail-primary-actions {
  align-items: center;
  gap: 9px;
}

.detail-action-close {
  min-height: 40px;
}

.detail-action-primary {
  min-height: 42px;
  padding-inline: 18px;
  font-weight: 750;
  box-shadow: 0 5px 14px rgba(16,24,40,.12);
}

.detail-action-primary:focus-visible,
.detail-action-secondary:focus-visible,
.detail-action-close:focus-visible {
  outline: 3px solid rgba(37,99,235,.22);
  outline-offset: 2px;
}

@media (max-width: 700px) {
  .detail-report-actions {
    width: 100%;
    display: grid;
    grid-template-columns: auto 1fr 1fr;
  }

  .detail-action-group-label {
    align-self: center;
  }

  .detail-primary-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1.5fr;
  }

  .detail-action-primary,
  .detail-action-close {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .detail-report-actions {
    grid-template-columns: 1fr 1fr;
  }

  .detail-action-group-label {
    grid-column: 1 / -1;
    margin-bottom: 1px;
  }

  .detail-primary-actions {
    grid-template-columns: 1fr;
  }

  .detail-action-primary {
    order: -1;
  }
}


/* =========================================================
   PHASE 3 — PIUTANG COLLECTION FILTERS
   Frontend-only filtering and sorting controls.
   ========================================================= */

.piutang-filter {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ui-text-muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.piutang-filter select {
  min-height: 38px;
  padding: 7px 30px 7px 10px;
  border: 1px solid var(--ui-border-soft);
  border-radius: 10px;
  background: #fff;
  color: var(--ui-text-body);
  font: inherit;
  cursor: pointer;
}

.piutang-filter select:focus {
  border-color: #9dbcf6;
  box-shadow: 0 0 0 3px var(--ui-focus);
  outline: none;
}

.aging-header-filter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  cursor: pointer;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}

.aging-header-filter:hover {
  background: var(--ui-primary-soft);
  border-color: #cfe0ff;
  color: var(--ui-primary);
}

.aging-header-filter:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 1px;
}

@media (max-width: 900px) {
  .toolbar {
    flex-wrap: wrap;
  }

  .piutang-filter {
    flex: 0 0 auto;
  }
}

@media (max-width: 520px) {
  .piutang-filter {
    width: 100%;
    justify-content: space-between;
  }

  .piutang-filter select {
    flex: 1;
    min-width: 0;
  }
}


/* =========================================================
   PHASE 3 — COLLECTION PRIORITY
   ========================================================= */

.collection-priority-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.collection-priority-card {
  appearance: none;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--ui-border-soft);
  border-radius: 12px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}

.collection-priority-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(16, 24, 40, .07);
}

.collection-priority-card.is-active {
  box-shadow: 0 0 0 2px var(--ui-focus);
}

.collection-priority-card span,
.collection-priority-card small {
  display: block;
}

.collection-priority-card span {
  font-size: 12px;
  font-weight: 800;
}

.collection-priority-card strong {
  display: block;
  margin-top: 3px;
  font-size: 22px;
  line-height: 1.1;
}

.collection-priority-card small {
  margin-top: 3px;
  color: var(--ui-text-muted);
  font-size: 10px;
}

.priority-urgent { background: #fff5f5; border-color: #fecaca; }
.priority-urgent span { color: #b42318; }

.priority-high { background: #fff8ed; border-color: #fed7aa; }
.priority-high span { color: #c2410c; }

.priority-monitor { background: #fffdf0; border-color: #fde68a; }
.priority-monitor span { color: #a15c00; }

.priority-normal { background: #f8fafc; border-color: #dbe2ea; }
.priority-normal span { color: #475467; }

.collection-priority-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.priority-badge-urgent {
  background: #fee2e2;
  color: #b42318;
  border: 1px solid #f87171;
}

.priority-badge-high {
  background: #ffe4b5;
  color: #9a3412;
  border: 1px solid #fb923c;
}

.priority-badge-monitor {
  background: #fff3cd;
  color: #a15c00;
  border: 1px solid #f5c451;
}

.priority-badge-normal {
  background: #e8eef7;
  color: #344054;
  border: 1px solid #cbd5e1;
}

.collection-priority-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 112px;
}

.collection-priority-info .collection-priority-badge {
  min-height: 23px;
}

.collection-priority-age {
  color: var(--ui-text-strong);
  font-size: 11px;
  font-weight: 750;
  line-height: 1.2;
}

.collection-priority-context {
  color: var(--ui-text-muted);
  font-size: 10px;
  line-height: 1.25;
  white-space: nowrap;
}

.mobile-collection-info {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 10px 0 12px;
  padding: 9px 10px;
  border: 1px solid var(--ui-border-soft);
  border-radius: 10px;
  background: #f8fafc;
}

.mobile-collection-info strong {
  color: var(--ui-text-strong);
  font-size: 11px;
  font-weight: 750;
}

.mobile-collection-info small {
  margin-left: auto;
  color: var(--ui-text-muted);
  font-size: 10px;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .collection-priority-context {
    white-space: normal;
  }

  .mobile-collection-info {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .mobile-collection-info small {
    width: 100%;
    margin-left: 0;
  }
}

@media (max-width: 760px) {
  .collection-priority-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .collection-priority-card {
    padding: 10px 12px;
  }
}


/* =========================================================
   PIUTANG — DESKTOP FIT / NO HORIZONTAL SCROLL
   Menjaga seluruh tabel tetap berada di dalam panel.
   Pada layar menengah, gunakan card sebelum tabel menjadi sesak.
   ========================================================= */

@media (min-width: 1101px) {
  .table-scroll {
    width: 100%;
    overflow-x: hidden;
  }

  .table-scroll .data-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
  }

  .table-scroll .data-table th,
  .table-scroll .data-table td {
    padding: 10px 8px;
    font-size: 12px;
  }

  .table-scroll .data-table th {
    white-space: normal;
    line-height: 1.25;
  }

  .table-scroll .data-table th:nth-child(1),
  .table-scroll .data-table td:nth-child(1) {
    width: 18%;
  }

  .table-scroll .data-table th:nth-child(2),
  .table-scroll .data-table td:nth-child(2),
  .table-scroll .data-table th:nth-child(3),
  .table-scroll .data-table td:nth-child(3),
  .table-scroll .data-table th:nth-child(4),
  .table-scroll .data-table td:nth-child(4),
  .table-scroll .data-table th:nth-child(5),
  .table-scroll .data-table td:nth-child(5),
  .table-scroll .data-table th:nth-child(6),
  .table-scroll .data-table td:nth-child(6),
  .table-scroll .data-table th:nth-child(7),
  .table-scroll .data-table td:nth-child(7) {
    width: 8%;
  }

  .table-scroll .data-table th:nth-child(8),
  .table-scroll .data-table td:nth-child(8) {
    width: 11%;
  }

  .table-scroll .data-table th:nth-child(9),
  .table-scroll .data-table td:nth-child(9) {
    width: 16%;
  }

  .table-scroll .data-table th:nth-child(10),
  .table-scroll .data-table td:nth-child(10) {
    width: 7%;
  }

  .customer-cell {
    min-width: 0;
    overflow: hidden;
  }

  .customer-cell strong,
  .customer-cell span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .collection-priority-info {
    min-width: 0;
  }

  .collection-priority-context {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .icon-btn {
    padding: 6px 8px;
    font-size: 11px;
  }
}

@media (min-width: 801px) and (max-width: 1100px) {
  /* Jangan memaksa tabel 10 kolom masuk ke ruang yang terlalu sempit. */
  .table-scroll {
    display: none;
  }

  .mobile-data-cards {
    display: block;
  }

  .mobile-customer-card {
    margin: 12px 0;
  }
}


/* =========================================================
   PIUTANG — TABLE GRID ALIGNMENT
   Finishing header/body agar seluruh kolom presisi dan nyaman dibaca.
   ========================================================= */

@media (min-width: 1101px) {
  .table-scroll .data-table th,
  .table-scroll .data-table td {
    box-sizing: border-box;
    vertical-align: middle;
  }

  .table-scroll .data-table th {
    height: 48px;
    padding: 8px 6px;
    text-align: center;
    white-space: normal;
  }

  .table-scroll .data-table td {
    height: 56px;
    padding: 9px 6px;
  }

  .table-scroll .data-table th:first-child,
  .table-scroll .data-table td:first-child {
    text-align: left;
    padding-left: 10px;
  }

  .table-scroll .data-table th:nth-child(8),
  .table-scroll .data-table td:nth-child(8) {
    text-align: right;
    padding-right: 8px;
  }

  .table-scroll .data-table th:nth-child(9),
  .table-scroll .data-table td:nth-child(9) {
    text-align: center;
    padding-inline: 4px;
    vertical-align: middle;
  }

  .table-scroll .data-table th:nth-child(10),
  .table-scroll .data-table td:nth-child(10) {
    text-align: center;
    padding-inline: 4px;
  }

  .table-scroll .data-table th:nth-child(10) {
    font-size: 11px;
    font-weight: 750;
  }

  .table-scroll .data-table td:nth-child(10) .detail-trigger {
    min-width: 52px;
  }

  .table-scroll .aging-header-filter {
    width: 100%;
    min-height: 30px;
    padding: 4px 2px;
    white-space: normal;
    line-height: 1.15;
  }

  .table-scroll .collection-priority-info {
    width: 100%;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 1px;
  }

  .table-scroll .collection-priority-info > * {
    margin-left: auto;
    margin-right: auto;
  }

  .table-scroll .collection-priority-badge {
    min-height: 22px;
    padding: 2px 7px;
  }

  .table-scroll .collection-priority-age {
    font-size: 10px;
  }

  .table-scroll .collection-priority-context {
    width: 100%;
    font-size: 9px;
    line-height: 1.15;
  }

  .table-scroll .customer-cell {
    width: 100%;
  }

  .table-scroll .customer-cell strong {
    font-size: 12px;
    line-height: 1.25;
  }

  .table-scroll .customer-cell span {
    font-size: 10px;
    line-height: 1.2;
  }
}


/* =========================================================
   CUSTOMER V1 — DESKTOP TABLE ALIGNMENT
   Keep customer table header/body on one stable column grid.
   Visual/layout only; no API or business-logic changes.
   ========================================================= */

@media (min-width: 1101px) {
  #customer-table-wrap {
    width: 100%;
    overflow-x: hidden;
  }

  #customer-table-wrap .data-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
  }

  #customer-table-wrap .data-table th,
  #customer-table-wrap .data-table td {
    box-sizing: border-box;
    vertical-align: middle;
    padding: 10px 8px;
    font-size: 12px;
  }

  /* 100% total:
     Pelanggan 28% | Telepon 16% | Tabungan 18% |
     Piutang 18% | Nota 12% | Detail 8% */
  #customer-table-wrap .data-table th:nth-child(1),
  #customer-table-wrap .data-table td:nth-child(1) {
    width: 28%;
    text-align: left;
    padding-left: 10px;
  }

  #customer-table-wrap .data-table th:nth-child(2),
  #customer-table-wrap .data-table td:nth-child(2) {
    width: 16%;
    text-align: left;
  }

  #customer-table-wrap .data-table th:nth-child(3),
  #customer-table-wrap .data-table td:nth-child(3) {
    width: 18%;
    text-align: right;
  }

  #customer-table-wrap .data-table th:nth-child(4),
  #customer-table-wrap .data-table td:nth-child(4) {
    width: 18%;
    text-align: right;
  }

  #customer-table-wrap .data-table th:nth-child(5),
  #customer-table-wrap .data-table td:nth-child(5) {
    width: 12%;
    text-align: right;
  }

  #customer-table-wrap .data-table th:nth-child(6),
  #customer-table-wrap .data-table td:nth-child(6) {
    width: 8%;
    text-align: center;
    padding-inline: 4px;
  }

  #customer-table-wrap .data-table th {
    height: 48px;
    white-space: normal;
    line-height: 1.2;
    text-align: center;
  }

  #customer-table-wrap .data-table th:first-child {
    text-align: left;
    padding-left: 10px;
  }

  #customer-table-wrap .data-table td {
    height: 56px;
    white-space: nowrap;
  }

  #customer-table-wrap .customer-cell {
    width: 100%;
    min-width: 0;
    overflow: hidden;
  }

  #customer-table-wrap .customer-cell strong,
  #customer-table-wrap .customer-cell span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #customer-table-wrap .customer-cell strong {
    font-size: 12px;
    line-height: 1.25;
  }

  #customer-table-wrap .customer-cell span {
    font-size: 10px;
    line-height: 1.2;
  }

  #customer-table-wrap .data-table td:nth-child(2) {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #customer-table-wrap .data-table th:nth-child(6) {
    font-size: 11px;
    font-weight: 750;
  }

  #customer-table-wrap .data-table td:nth-child(6) .icon-btn {
    min-width: 52px;
    padding: 6px 8px;
    font-size: 11px;
  }
}


/* ---------- Dashboard Refresh loading feedback ---------- */

.dashboard-refresh {
  min-width: 100px;
}

.dashboard-refresh-content {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 100%;
}

.dashboard-refresh-spinner {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: dashboardRefreshSpin .72s linear infinite;
}

.dashboard-refresh:disabled {
  cursor: wait;
  opacity: .82;
  transform: none !important;
  box-shadow: 0 4px 12px rgba(37,99,235,.12);
}

@keyframes dashboardRefreshSpin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dashboard-refresh-spinner {
    animation: none;
  }
}

/* ---------- Dashboard Laba Bulanan — thin interaction layer ---------- */

#dashboard-profit-chart.dashboard-profit-chart-interactive {
  position: relative;
}

.dashboard-profit-tooltip {
  position: absolute;
  z-index: 5;
  width: max-content;
  max-width: min(220px, calc(100% - 16px));
  padding: 9px 12px;
  border: 1px solid rgba(15, 23, 42, .10);
  border-radius: 10px;
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
  color: #0f172a;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(3px);
  transition: opacity .14s ease, transform .14s ease, visibility .14s ease;
}

.dashboard-profit-tooltip.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dashboard-profit-tooltip strong,
.dashboard-profit-tooltip span {
  display: block;
}

.dashboard-profit-tooltip strong {
  font-size: 11px;
  font-weight: 750;
  line-height: 1.2;
}

.dashboard-profit-tooltip span {
  margin-top: 3px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
}

@media (prefers-reduced-motion: reduce) {
  .dashboard-profit-tooltip {
    transition: none;
  }
}



/* =========================================================
   SUPPLIER HUTANG — STATUS & NUMERIC READABILITY
   ========================================================= */

.supplier-hutang-summary .supplier-hutang-status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  margin-top: 7px;
  padding: 3px 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px !important;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
}

.supplier-hutang-status[data-state="current"] {
  color: #067647;
  background: #ecfdf3;
  border-color: #abefc6;
}

.supplier-hutang-status[data-state="refreshing"] {
  color: #1849a9;
  background: #eff8ff;
  border-color: #b2ddff;
}

.supplier-hutang-status[data-state="cache"] {
  color: #93370d;
  background: #fffaeb;
  border-color: #fedf89;
}

.supplier-hutang-status[data-state="error"] {
  color: #b42318;
  background: #fef3f2;
  border-color: #fecdca;
}

.supplier-hutang-status[data-state="idle"] {
  color: var(--ui-text-muted, #667085);
  background: #f2f4f7;
  border-color: #eaecf0;
}

.supplier-hutang-summary strong,
.supplier-detail-summary strong,
.supplier-detail-table td:nth-child(4),
.supplier-detail-table td:nth-child(5) {
  font-variant-numeric: tabular-nums;
}

#supplier-hutang-status-detail {
  line-height: 1.45;
}


/* =========================================================
   PIUTANG — TABLET LAYOUT
   Give search and summary cards enough room beside tablet navigation.
   ========================================================= */
@media (min-width: 801px) and (max-width: 1100px) {
  .page-content .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .summary-card {
    min-width: 0;
  }

  .summary-card strong {
    overflow-wrap: anywhere;
    font-size: clamp(16px, 2vw, 21px);
  }

  .collection-priority-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #page-content .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    align-items: end;
  }

  #page-content .toolbar .search-box {
    grid-column: 1 / -1;
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  #page-content .toolbar .piutang-filter {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
  }

  #page-content .toolbar .piutang-filter select {
    flex: 1 1 auto;
    min-width: 0;
  }

  #page-content .toolbar .page-size {
    min-width: 0;
    justify-content: space-between;
  }

  #page-content .toolbar .page-size select {
    min-width: 0;
  }
}

/* ---------- Calm light sidebar theme ---------- */
.sidebar {
  background: #f8f9fb;
  color: #1f2937;
  border-right: 1px solid #e5e7eb;
  box-shadow: 4px 0 16px rgba(16, 24, 40, .035);
}

.brand strong {
  color: #182230;
}

.brand span {
  color: #667085;
}

.brand-mark {
  box-shadow: none;
}

.nav-item {
  color: #475467;
  border-color: transparent;
}

.nav-item:hover {
  background: #eef1f5;
  color: #182230;
  transform: none;
}

.nav-item.active,
.nav-item.active:hover {
  background: #eaf1fb;
  border-color: #d6e3f5;
  color: #1d3557;
  box-shadow: inset 3px 0 0 #3569a8;
}

.sidebar-footer {
  color: #667085;
  border-top-color: #e4e7ec;
}

.api-reconnect {
  border-color: #d0d5dd;
  background: #fff;
  color: #475467;
}

.api-reconnect:hover {
  border-color: #b8c2d1;
  background: #eef1f5;
  color: #182230;
}

@media (max-width: 1100px) {
  .sidebar {
    background: #f8f9fb;
  }

  .sidebar-close {
    border-color: #d0d5dd;
    background: #fff;
    color: #475467;
  }

  .sidebar-close:active {
    background: #eef1f5;
  }
}
