:root {
  --ui-brand: #183b66;
  --ui-brand-dark: #102c4d;
  --ui-ink: #172033;
  --ui-muted: #687286;
  --ui-line: #dfe4ec;
  --ui-danger: #b42318;
  --ui-success: #16794b;
  --ui-warning: #a16207;
  --ui-accent: #d89b3c;
  --ui-title-size: clamp(1.55rem, 3.6vw, 2.15rem);
  --ui-section-size: 1.05rem;
  --ui-label-size: .78rem;
  --ui-helper-size: .74rem;
  --ui-shadow-card: 0 10px 30px rgba(23, 32, 51, .065);
  --ui-shadow-raised: 0 16px 42px rgba(23, 32, 51, .11);
}

.app-loader[hidden], .app-confirm-backdrop[hidden] { display: none; }

.app-loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(241, 245, 249, .96);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.app-loader-panel {
  display: flex;
  min-width: 190px;
  max-width: min(88vw, 340px);
  align-items: center;
  gap: 12px;
  padding: 14px 17px;
  border: 1px solid #dbe2eb;
  border-radius: 14px;
  background: #fff;
  color: var(--ui-ink);
  box-shadow: 0 18px 48px rgba(23, 32, 51, .16);
  font-size: .86rem;
  font-weight: 700;
}

.app-loader-spinner {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border: 3px solid #dce5ef;
  border-top-color: var(--ui-brand);
  border-radius: 50%;
  animation: app-loader-spin .72s linear infinite;
}

.app-loader-skeleton { width: min(100%, 1000px); }
.skeleton-header, .skeleton-card { border: 1px solid #e1e6ed; border-radius: 14px; background: #fff; box-shadow: 0 8px 30px rgba(23, 32, 51, .05); }
.skeleton-header { display: flex; height: 58px; align-items: center; justify-content: space-between; margin-bottom: 18px; padding: 15px 18px; }
.skeleton-header span, .skeleton-card span, .skeleton-card::before, .skeleton-card::after { display: block; border-radius: 7px; background: linear-gradient(90deg, #e7ebf0 25%, #f5f7fa 45%, #e7ebf0 65%); background-size: 240% 100%; animation: app-skeleton 1.25s ease-in-out infinite; }
.skeleton-header span:first-child { width: 42px; height: 28px; }
.skeleton-header span:last-child { width: 180px; height: 18px; }
.skeleton-card-large { height: 210px; margin-bottom: 16px; padding: 24px; }
.skeleton-card-large span { width: 34%; height: 16px; margin-bottom: 18px; }
.skeleton-card-large span:nth-child(2) { width: 82%; }
.skeleton-card-large span:nth-child(3) { width: 64%; }
.skeleton-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.skeleton-grid .skeleton-card { height: 110px; padding: 20px; }
.skeleton-grid .skeleton-card::before { content: ""; width: 56%; height: 14px; margin-bottom: 16px; }
.skeleton-grid .skeleton-card::after { content: ""; width: 78%; height: 26px; }
.app-loader[data-variant="skeleton"] .app-loader-panel { position: absolute; bottom: max(24px, 5vh); box-shadow: 0 10px 30px rgba(23,32,51,.13); }
.app-loader[data-variant="compact"] { background: rgba(241,245,249,.84); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.app-loader[data-variant="compact"] .app-loader-skeleton { display: none; }

.app-toast-region { position: fixed; top: 76px; right: 20px; z-index: 1200; display: grid; width: min(390px, calc(100vw - 28px)); gap: 10px; pointer-events: none; }
.app-toast { display: grid; grid-template-columns: 38px 1fr 32px; align-items: start; gap: 10px; padding: 13px 10px 13px 13px; border: 1px solid var(--ui-line); border-left: 4px solid var(--ui-brand); border-radius: 12px; background: #fff; box-shadow: 0 18px 48px rgba(23,32,51,.18); opacity: 0; pointer-events: auto; transform: translateY(-8px); transition: opacity .18s ease, transform .18s ease; }
.app-toast.is-visible { opacity: 1; transform: translateY(0); }
.app-toast.is-leaving { opacity: 0; transform: translateY(-8px); }
.app-toast-success { border-left-color: var(--ui-success); }
.app-toast-error { border-left-color: var(--ui-danger); }
.app-toast-warning { border-left-color: #c47b12; }
.app-toast-icon { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 9px; background: #eaf0f7; color: var(--ui-brand); }
.app-toast-success .app-toast-icon { background: #eaf8f1; color: var(--ui-success); }
.app-toast-error .app-toast-icon { background: #fff0ee; color: var(--ui-danger); }
.app-toast-warning .app-toast-icon { background: #fff6e5; color: #a35e05; }
.app-toast-icon svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.app-toast-copy { display: grid; gap: 3px; color: var(--ui-muted); font: 400 .8rem/1.4 Inter, "Segoe UI", Arial, sans-serif; }
.app-toast-copy strong { color: var(--ui-ink); font-size: .84rem; }
.app-toast > button { display: grid; width: 30px; height: 30px; min-height: 0; place-items: center; padding: 0; border: 0; border-radius: 8px; background: transparent; color: #7a8495; font-size: 1.25rem; }
.app-toast > button:hover { background: #f1f4f8; color: var(--ui-ink); }

.app-confirm-backdrop { position: fixed; inset: 0; z-index: 1250; display: grid; place-items: center; padding: 20px; background: rgba(15,23,42,.48); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.app-confirm { display: grid; width: min(100%, 430px); grid-template-columns: 44px 1fr; gap: 14px; padding: 22px; border-radius: 16px; background: #fff; box-shadow: 0 28px 80px rgba(15,23,42,.28); color: var(--ui-ink); font-family: Inter, "Segoe UI", Arial, sans-serif; }
.app-confirm-icon { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 12px; background: #fff4e2; color: #a35e05; }
.app-confirm-icon svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.app-confirm-copy h2 { margin: 2px 0 6px; font-size: 1.08rem; }
.app-confirm-copy p { margin: 0; color: var(--ui-muted); font-size: .86rem; line-height: 1.55; }
.app-confirm-actions { display: flex; grid-column: 1 / -1; justify-content: flex-end; gap: 9px; margin-top: 8px; }
.app-confirm-actions button { min-height: 41px; padding: 9px 15px; border: 1px solid #ced6e2; border-radius: 9px; background: #fff; color: var(--ui-ink); font-weight: 750; }
.app-confirm-actions .app-confirm-submit { border-color: var(--ui-brand); background: var(--ui-brand); color: #fff; }
.app-confirm-actions .app-confirm-submit[data-variant="danger"] { border-color: var(--ui-danger); background: var(--ui-danger); }

.app-empty-state { display: grid; max-width: 460px; justify-items: center; margin: auto; padding: 44px 18px; text-align: center; }
.empty-cell > .app-empty-state, .empty-state > .app-empty-state { padding-block: 10px; }
.app-empty-icon { display: grid; width: 54px; height: 54px; margin-bottom: 14px; place-items: center; border-radius: 15px; background: #eaf0f7; color: var(--ui-brand); }
.app-empty-icon svg { width: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.app-empty-state strong { color: var(--ui-ink); font-size: 1.02rem; }
.app-empty-state p { margin: 7px 0 16px; color: var(--ui-muted); font-size: .84rem; line-height: 1.5; }
.app-empty-action { min-height: 41px; padding: 9px 15px; border: 0; border-radius: 9px; background: var(--ui-brand); color: #fff; font-weight: 750; }

.field-error { display: block; margin-top: 6px; color: var(--ui-danger); font: 650 var(--ui-helper-size)/1.4 Inter, "Segoe UI", Arial, sans-serif; }
[aria-invalid="true"] { border-color: var(--ui-danger) !important; box-shadow: 0 0 0 3px rgba(180,35,24,.1) !important; }
.field-help, .section-helper { display: block; margin: 6px 0 0; color: var(--ui-muted); font-size: var(--ui-helper-size); font-weight: 450; line-height: 1.45; }
.label-meta { margin-left: 6px; color: var(--ui-muted); font-size: .68rem; font-weight: 550; }
.label-meta.required { color: var(--ui-danger); }
.customer-picker { display: grid; min-width: 220px; gap: 4px; }
.customer-picker > span { color: var(--ui-muted); font-size: .7rem; font-weight: 650; }
.customer-picker input { min-height: 38px; }
.product-input[role="combobox"] { padding-right: 28px; }
.product-input-wrap > .field-error { flex: 1 0 100%; }
.product-item.is-active { background: #eaf0f7; color: var(--ui-brand); }
.product-empty-result { padding: 12px; color: var(--ui-muted); font-size: .76rem; text-align: center; }

@media screen {
  .page-heading h2, .register-heading h2 { font-size: var(--ui-title-size); line-height: 1.12; letter-spacing: -.035em; }
  .section-heading h2, .signature-heading h2, .section-title-row h2, .card h2, .payment-dialog-heading h2 { font-size: var(--ui-section-size); line-height: 1.3; letter-spacing: -.012em; }
  .field > label, .form-group > label, .input-group > label, .amount-words > label, .payment-form-grid label > span, .register-tools label > span { color: #536074; font-size: var(--ui-label-size); font-weight: 700; letter-spacing: 0; text-transform: none; }
  .eyebrow, .page-heading .eyebrow, .header .eyebrow { color: var(--ui-accent); letter-spacing: .08em; }
  .invoice-container, .container, .register-heading, .register-card, .card { box-shadow: var(--ui-shadow-card); }
  .app-menu, .modal-content, .payment-dialog { box-shadow: var(--ui-shadow-raised); }
  .grand-total-row, .payable-row { color: var(--ui-brand); font-weight: 800; }
  .payable-row strong, #outstandingValue { color: var(--ui-danger); }
  .stats-grid strong, .money { color: #102c4d; font-weight: 800; }
}

body.app-loading, body.app-dialog-open { overflow: hidden; }
:where(button, a, input, textarea, select):focus-visible { outline: 3px solid rgba(24,59,102,.18); outline-offset: 2px; }
:where(.action-btn, .table-action, .button, .save-btn, .add-btn, .primary-button, .secondary-button) { transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .15s ease; }
:where(.action-btn, .table-action, .button, .save-btn, .add-btn, .primary-button):active:not(:disabled) { transform: translateY(1px); }
:where(input, textarea, select):disabled, :where(button):disabled { cursor: not-allowed; opacity: .58; }

@keyframes app-loader-spin { to { transform: rotate(360deg); } }
@keyframes app-skeleton { from { background-position: 100% 0; } to { background-position: -100% 0; } }

@media (max-width: 640px) {
  .app-toast-region { top: 68px; right: 14px; }
  .app-confirm { grid-template-columns: 40px 1fr; padding: 19px; }
  .app-confirm-icon { width: 40px; height: 40px; }
  .app-confirm-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .skeleton-grid { grid-template-columns: 1fr; }
  .skeleton-grid .skeleton-card:nth-child(n+3) { display: none; }
  .skeleton-card-large { height: 180px; }
  .customer-picker { width: 100%; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .app-loader-spinner, .skeleton-header span, .skeleton-card span, .skeleton-card::before, .skeleton-card::after { animation-duration: 2.5s; }
  .app-toast { transition: none; }
}

@media print {
  .app-loader, .app-toast-region, .app-confirm-backdrop, .label-meta, .field-help, .field-error, .section-helper, .customer-picker { display: none !important; }
}
