/* ==========================================================================
   SIAP KLU — UI Polish & Layout Layer
   Cosmetic only: no JS, routes, API calls, data, or workflow are changed.
   Remove the <link rel="stylesheet" href="/ui-polish.css"> from index.html
   to revert everything instantly.
   ========================================================================== */

:root {
  --pl-brand: #0d1b3e;
  --pl-brand-600: #1d3468;
  --pl-accent: #d4a017;
  --pl-border: #e2e8f2;
  --pl-border-strong: #cbd5e1;
  --pl-muted: #5a6880;
  --pl-subtle: #8b98ad;
  --pl-danger: #b91c1c;
  --pl-radius: 10px;
  --pl-shadow-sm: 0 1px 2px rgb(16 26 44 / 5%), 0 1px 3px rgb(16 26 44 / 4%);
  --pl-shadow-md: 0 4px 14px rgb(16 26 44 / 8%), 0 2px 4px rgb(16 26 44 / 4%);
  --pl-ring: 0 0 0 3px rgb(29 52 104 / 18%);
  --pl-h: 38px;
  --pl-h-sm: 32px;
  --pl-h-lg: 44px;
  --pl-content: 1440px;
  --pl-gutter: 1.5rem;
}

/* ---------- Base ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

h1, h2, h3, h4 { letter-spacing: -0.012em; text-wrap: balance; }
p, li { text-wrap: pretty; }
table td, table th { font-variant-numeric: tabular-nums; }

/* ---------- Focus (WCAG 2.4.7) ---------- */
:where(a, button, input, select, textarea, [role="button"], [tabindex]):focus-visible {
  outline: 2px solid var(--pl-brand-600);
  outline-offset: 2px;
  border-radius: 6px;
}
@media (forced-colors: active) {
  :where(a, button, input, select, textarea):focus-visible { outline: 3px solid Highlight; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   LAYOUT
   ========================================================================== */

#root, #root > div { min-height: 100dvh; }

/* Never let a wide child break the page width. */
main { min-width: 0; overflow-x: clip; }
main > div, main > section { min-width: 0; }

/* Cap the reading width so tables stay scannable on wide monitors. */
main > div > div,
main > section {
  max-width: var(--pl-content);
  margin-inline: auto;
}

/* Consistent page gutters. */
main { padding-inline: 0; }
main > div { padding-inline: var(--pl-gutter); }

/* Page header rows: keep title and actions on one baseline. */
main .flex.items-start.justify-between,
main .flex.items-center.justify-between {
  row-gap: 0.75rem;
  column-gap: 1rem;
  flex-wrap: wrap;
}

/* Toolbars / filter rows wrap instead of overflowing. */
main .flex.items-center.gap-3,
main .flex.items-center.gap-4,
main .flex.items-center.gap-2 {
  flex-wrap: wrap;
}

/* Cards: consistent border + elevation, no content change. */
main .bg-white.rounded-xl,
main .bg-white.rounded-2xl,
main .bg-white.rounded-lg {
  border: 1px solid var(--pl-border);
  box-shadow: var(--pl-shadow-sm);
}

/* Section spacing rhythm. */
main > div > * + * { margin-top: 1.25rem; }

/* Sticky header must not be covered by content. */
header { z-index: 30; }

/* ==========================================================================
   BUTTONS
   ========================================================================== */

button, [role="button"] {
  font-family: inherit;
  line-height: 1.25;
  white-space: nowrap;
}

button.inline-flex,
a.inline-flex,
[role="button"].inline-flex {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-block-size: var(--pl-h);
  padding-block: 0.5rem;
  padding-inline: 1rem;
  border-radius: var(--pl-radius);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  box-shadow: var(--pl-shadow-sm);
  transition: background-color 140ms ease, color 140ms ease,
              border-color 140ms ease, box-shadow 140ms ease, transform 100ms ease;
}

/* Any button that carries text must size to its content, never to a square.
   (Text nodes are invisible to :has(), so never infer "icon-only" from them.) */
button:not(:empty),
button.inline-flex {
  min-inline-size: auto;
  white-space: nowrap;
}

/* Compact (table row actions) */
button.inline-flex.text-xs,
a.inline-flex.text-xs,
button.inline-flex[class*="py-1.5"],
a.inline-flex[class*="py-1.5"] {
  min-block-size: var(--pl-h-sm);
  padding-block: 0.375rem;
  padding-inline: 0.75rem;
  font-size: 0.8125rem;
  border-radius: 8px;
  box-shadow: none;
}

/* Large CTA */
button.inline-flex[class*="px-6"],
a.inline-flex[class*="px-6"] {
  min-block-size: var(--pl-h-lg);
  padding-inline: 1.5rem;
  font-size: 0.9375rem;
}

/* Icons inside buttons */
button.inline-flex > svg,
a.inline-flex > svg,
[role="button"].inline-flex > svg {
  inline-size: 1.05em;
  block-size: 1.05em;
  flex: 0 0 auto;
}

/* States */button:not(:disabled):hover,
[role="button"]:not([aria-disabled="true"]):hover { box-shadow: var(--pl-shadow-md); }
button:not(:disabled):active,
[role="button"]:not([aria-disabled="true"]):active { transform: translateY(1px); }

button:disabled,
[role="button"][aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
  transform: none;
}

/* Destructive actions */
button[class*="bg-red-600"],
a[class*="bg-red-600"] {
  background-color: #dc2626 !important;
  color: #fff !important;
  border-color: #dc2626 !important;
}
button[class*="bg-red-600"]:not(:disabled):hover,
a[class*="bg-red-600"]:hover { background-color: #b91c1c !important; }

/* Soft destructive */
button[class*="bg-red-50"], a[class*="bg-red-50"] {
  color: var(--pl-danger) !important;
  border: 1px solid #fecaca !important;
  background-color: #fef2f2 !important;
}
button[class*="bg-red-50"]:not(:disabled):hover,
a[class*="bg-red-50"]:hover { background-color: #fee2e2 !important; }

/* Secondary (bordered) */
button[class*="border-gray-300"], a[class*="border-gray-300"] {
  background-color: #fff !important;
  border-color: var(--pl-border-strong) !important;
  color: #334155 !important;
  box-shadow: none;
}
button[class*="border-gray-300"]:not(:disabled):hover,
a[class*="border-gray-300"]:hover {
  background-color: #f8fafc !important;
  border-color: #94a3b8 !important;
}

/* ==========================================================================
   TABLES
   ========================================================================== */

table { border-collapse: separate; border-spacing: 0; }

table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f7f9fd;
  font-size: 0.72rem;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  color: var(--pl-muted);
  font-weight: 700;
  white-space: nowrap;
  backdrop-filter: blur(6px);
}

table tbody tr { transition: background-color 120ms ease; }
table tbody tr:hover { background-color: #f6f9fe; }
table tbody tr:nth-child(even) { background-color: #fcfdff; }
table tbody tr:nth-child(even):hover { background-color: #f4f8ff; }
table td { vertical-align: middle; }

/* Numeric columns read better right-aligned; action cells never wrap. */
table td:last-child { white-space: nowrap; }
table td:last-child > * + * { margin-inline-start: 0.375rem; }

/* Horizontal scroll stays inside the table box, not the page. */
.overflow-x-auto, .overflow-auto {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  max-width: 100%;
}

/* ==========================================================================
   FORMS
   ========================================================================== */

input:not([type="checkbox"]):not([type="radio"]),
select, textarea {
  transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus, textarea:focus {
  box-shadow: var(--pl-ring);
  border-color: var(--pl-brand-600);
  outline: none;
}

input::placeholder, textarea::placeholder { color: #94a3b8; }

input:user-invalid, select:user-invalid, textarea:user-invalid {
  border-color: var(--pl-danger);
  background-color: #fef2f2;
}

select { padding-inline-end: 2rem; }

input[type="file"]::file-selector-button {
  margin-inline-end: 0.75rem;
  padding: 0.375rem 0.75rem;
  border: 0;
  border-radius: 8px;
  background: #eef2f9;
  color: #1e293b;
  font-weight: 600;
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: #e2e8f2; }

/* ==========================================================================
   BADGES & SIDEBAR
   ========================================================================== */

span[class*="rounded-full"][class*="text-xs"] {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.55rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}

nav a {
  transition: background-color 130ms ease, color 130ms ease;
  border-radius: 8px;
}

/* ==========================================================================
   LOADING / EMPTY STATES (visual only)
   ========================================================================== */

@keyframes pl-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.animate-pulse { animation: pl-pulse 1.6s ease-in-out infinite; }

/* ==========================================================================
   SCROLLBARS
   ========================================================================== */

* { scrollbar-width: thin; scrollbar-color: #c3cddf transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: #c9d3e3;
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: #a9b7cd; background-clip: content-box; }

/* ==========================================================================
   TABLET
   ========================================================================== */

@media (max-width: 1024px) {
  :root { --pl-gutter: 1rem; --pl-content: 100%; }
  main > div { padding-inline: var(--pl-gutter); }
}

/* ==========================================================================
   MOBILE — the important part
   ========================================================================== */

@media (pointer: coarse) {
  button, [role="button"], a.inline-flex { min-block-size: 44px; }
  button.inline-flex.text-xs, a.inline-flex.text-xs { min-block-size: 40px; }
  table td, table th { padding-block: 0.65rem; }
}

@media (max-width: 768px) {
  :root { --pl-gutter: 0.875rem; }

  body { overflow-x: hidden; }

  /* Type scale down, still readable */
  h1 { font-size: 1.375rem; line-height: 1.3; }
  h2 { font-size: 1.125rem; }
  h3 { font-size: 1rem; }

  /* Page gutters and card padding */
  main > div { padding-inline: var(--pl-gutter); }
  main > div > * + * { margin-top: 1rem; }
  .p-6 { padding: 1rem; }
  .p-8 { padding: 1.125rem; }
  .px-6 { padding-inline: 1rem; }
  .py-6 { padding-block: 1rem; }

  /* Header: allow wrapping, keep tap targets */
  header { padding-inline: var(--pl-gutter) !important; }
  header .flex { flex-wrap: wrap; row-gap: 0.5rem; }

  /* Stacked action rows go full width */
  .flex-col > button.inline-flex,
  .flex-col > a.inline-flex { inline-size: 100%; }

  /* Filter bars: inputs take the full row */
  main .flex.items-center.gap-3 > input,
  main .flex.items-center.gap-3 > select,
  main .flex.items-center.gap-4 > input,
  main .flex.items-center.gap-4 > select {
    inline-size: 100%;
  }

  /* Tables: allow horizontal pan inside their container */
  .overflow-x-auto { border-radius: 10px; }
  table { min-width: 640px; }
  table td, table th { padding-inline: 0.75rem; font-size: 0.8125rem; }

  /* Dialogs fit the viewport */
  dialog, [role="dialog"] {
    max-width: calc(100vw - 1.25rem) !important;
    max-height: calc(100dvh - 1.5rem) !important;
    margin: auto;
  }

  /* Sticky headers must not eat the screen */
  table thead th { position: static; backdrop-filter: none; }
}

@media (max-width: 480px) {
  :root { --pl-gutter: 0.75rem; }

  h1 { font-size: 1.25rem; }

  /* Badges and chips shrink */
  span[class*="rounded-full"][class*="text-xs"] { font-size: 0.6875rem; }

  /* Prevent 2-column stat grids from becoming unreadable */
  .grid-cols-2 { grid-template-columns: 1fr !important; }

  table { min-width: 560px; }
}

/* ==========================================================================
   LOGIN PAGE — readability, density, mobile (visual only)
   Scoped so it cannot affect the rest of the application.
   ========================================================================== */

/* Secondary text on the dark brand panel must stay legible (WCAG 1.4.3). */
.login-page :is(p, span, li) {
  text-wrap: pretty;
}

/* The intro copy sits on a dark translucent panel: raise its lightness. */
.login-page p.text-blue-200,
.login-page p.text-blue-100\/80,
.login-page p.text-blue-100\/70,
.login-page p.text-blue-300\/70,
.login-page p.text-blue-300\/60 {
  color: #dce8fb !important;
}

/* Slightly tighter card so the form does not need scrolling on laptops. */
.login-page .rounded-2xl.shadow-2xl {
  padding: 1.75rem !important;
}

/* Keep the form comfortable but not oversized. */
.login-page form .space-y-5 > * + * {
  margin-top: 1rem;
}

/* Submit button: clear loading/disabled affordance without changing behaviour. */
.login-page button[type="submit"] {
  min-block-size: 46px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.login-page button[type="submit"]:disabled {
  opacity: 0.65;
  cursor: progress;
}

/* Password toggle: comfortable hit area over the input. */
.login-page button.absolute.right-3 {
  inline-size: 40px;
  block-size: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
}
.login-page button.absolute.right-3:hover {
  background-color: #f1f5f9;
}

/* Inputs at 16px on mobile prevents iOS zoom-on-focus. */
@media (max-width: 640px) {
  .login-page input {
    font-size: 16px;
  }
  .login-page .rounded-2xl.shadow-2xl {
    padding: 1.25rem !important;
  }
  /* Collapse the long intro column into a compact header. */
  .login-page .grid > .hidden.lg\:block {
    display: none !important;
  }
  .login-page .space-y-4 > .rounded-2xl {
    padding: 0.875rem !important;
  }
}

/* ==========================================================================
   CONTRAST FIXES — WCAG 2.2 AA (measured with Lighthouse)
   Text-on-colour pairs that failed 4.5:1 / 3:1.
   ========================================================================== */

/* White text on green-600 (#16a34a) measured 3.29:1 → use green-700 */
button[class*="bg-green-600"],
a[class*="bg-green-600"] {
  background-color: #15803d !important;
}
button[class*="bg-green-600"]:not(:disabled):hover,
a[class*="bg-green-600"]:hover {
  background-color: #166534 !important;
}

/* White text on emerald-600 measured 3.76:1 → use emerald-700 */
button[class*="bg-emerald-600"],
a[class*="bg-emerald-600"] {
  background-color: #047857 !important;
}
button[class*="bg-emerald-600"]:not(:disabled):hover,
a[class*="bg-emerald-600"]:hover {
  background-color: #065f46 !important;
}

/* Yellow headline text (#ca8a04) measured 2.93:1 → use amber-700 */
.text-yellow-600 {
  color: #a16207 !important;
}

/* Light grey helper text on white: raise to slate-600 */
.text-gray-400,
.text-slate-400 {
  color: #64748b !important;
}

/* Muted brand text on the dark panel */
.text-blue-300\/70,
.text-blue-300\/60 {
  color: #c7dbf5 !important;
}

/* Small badges keep a solid, readable background */
.badge,
[class*="rounded-full"][class*="text-xs"] {
  font-weight: 700;
}

/* ==========================================================================
   POTONGAN TUNKIN — card layout on small screens (visual only)
   The transfer status block is injected by the app and marked with
   data-p3-rekening-card-v2; we only restyle it.
   ========================================================================== */

/* Status transfer: readable badge, not a squeezed button */
[data-p3-rekening-card-v2] [data-transfer-status] {
  min-block-size: 34px;
  padding-inline: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  border-radius: 8px;
}

/* Timestamp beside the badge must not collapse into a tiny sliver */
[data-p3-rekening-card-v2] [data-transfer-detail] {
  display: inline-block;
  font-size: 0.75rem;
  color: #475569;
}

/* Rekening values wrap instead of overflowing the card */
[data-p3-rekening-card-v2] b,
[data-p3-rekening-card-v2] div {
  overflow-wrap: anywhere;
}

@media (max-width: 768px) {
  /* One card per row on phones */
  main .grid.grid-cols-1.sm\:grid-cols-2.xl\:grid-cols-3,
  main .grid.grid-cols-1.md\:grid-cols-2.xl\:grid-cols-3,
  main .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-3 {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* Status block: badge first, timestamp underneath */
  [data-p3-rekening-card-v2] > div:last-child {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin-top: 10px;
  }

  [data-p3-rekening-card-v2] [data-transfer-status] {
    inline-size: 100%;
    min-block-size: 44px;
    font-size: 0.8125rem;
  }

  [data-p3-rekening-card-v2] [data-transfer-detail] {
    margin-inline-start: 0 !important;
    inline-size: 100%;
    font-size: 0.75rem;
  }

  /* Action buttons stack full width and stay tappable */
  main .grid button,
  main .grid a[role="button"] {
    min-block-size: 44px;
  }
}

/* ==========================================================================
   PRINT — kitir / slip / laporan
   ========================================================================== */

@media print {
  nav, aside, header, footer,
  button, [role="button"],
  .no-print, .print\:hidden {
    display: none !important;
  }
  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 11pt;
  }
  main > div { max-width: none; padding-inline: 0; }
  table { page-break-inside: auto; border-collapse: collapse; min-width: 0; }
  table thead { display: table-header-group; }
  table thead th {
    position: static;
    background: #fff !important;
    color: #000 !important;
    backdrop-filter: none;
  }
  table tr { page-break-inside: avoid; }
  table tbody tr:nth-child(even) { background: #fff !important; }
  a[href]::after { content: ""; }
  .shadow, .shadow-sm, .shadow-md { box-shadow: none !important; }
}
