/* Custom animations and overrides not easily done with Tailwind utilities */

/* ===== TEMA RAMP — Sistem Khairat As-Solihin =====
   Gaya: meja kewangan editorial (Ramp, styles.refero.design).
   Kanvas Bone #f4f2f0, kad Paper #ffffff, teks Ink #0c0a08,
   aksen Highlighter #e4f222 HANYA utk tindakan duit.
   Kad guna sempadan hairline, BUKAN bayang (ikut panduan Ramp). */

:root {
  --ramp-bone: #f4f2f0;
  --ramp-paper: #ffffff;
  --ramp-ink: #0c0a08;
  --ramp-obsidian: #1a1919;
  --ramp-ash: #6d6c6b;
  --ramp-smoke: #d3d3d3;
  --ramp-hairline: #e5e7eb;
  --ramp-hi: #e4f222;
  --ramp-hi-dark: #c9d91c;
}

body {
  background: var(--ramp-bone) !important;
  color: var(--ramp-ink);
  letter-spacing: 0;
}

/* Ramp mengatasi Tailwind CDN: semua kanvas slate/neutral jadi Bone,
   supaya krim #f4f2f0 kekal walaupun kelas lama masih ada. */
.bg-slate-50, .bg-slate-100, .bg-neutral-50, .bg-neutral-100,
.bg-gray-50, .bg-gray-100 {
  background-color: var(--ramp-bone) !important;
}
/* Kad putih kekal putih, tapi sempadan ikut hairline Ramp */
.bg-white {
  border-color: var(--ramp-hairline);
}
/* Teks slate gelap jadi Ink Ramp */
.text-slate-800, .text-slate-900, .text-neutral-900 {
  color: var(--ramp-ink) !important;
}
.text-slate-500, .text-slate-600, .text-neutral-500 {
  color: var(--ramp-ash) !important;
}

/* Label mikro huruf besar — ikut Ramp: tracking positif */
.micro-label {
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 10px;
  color: var(--ramp-ash);
}

/* Kad Ramp: sempadan hairline, tanpa bayang, radius 16px */
.ramp-card {
  background: var(--ramp-paper);
  border: 1px solid var(--ramp-hairline);
  border-radius: 16px;
  box-shadow: none;
}

/* Butang duit utama: kuning highlighter + teks hitam */
.btn-ramp {
  background: var(--ramp-hi);
  color: var(--ramp-ink);
  border-radius: 6px;
  font-weight: 600;
  border: 1px solid var(--ramp-ink);
}
.btn-ramp:hover { background: var(--ramp-hi-dark); }

/* Butang gelap sekunder (panel songsang Ramp) */
.btn-ramp-dark {
  background: var(--ramp-obsidian);
  color: #fff;
  border-radius: 6px;
  font-weight: 600;
}
.btn-ramp-dark:hover { background: var(--ramp-ink); }

/* Input Ramp: radius 10px, fokus garis highlighter */
input[type="text"]:not(.no-ramp),
input[type="password"]:not(.no-ramp),
input[type="number"]:not(.no-ramp),
input[type="date"]:not(.no-ramp),
select:not(.no-ramp),
textarea:not(.no-ramp) {
  border-radius: 10px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--ramp-hi-dark) !important;
}

/* Nombor duit hidup: aksen kecil, angka kekal mudah dibaca */
.money-live {
  background: transparent;
  color: var(--ramp-ink);
  border-radius: 0;
  padding: 0;
  font-weight: 700;
  box-shadow: inset 0 -0.28em 0 rgba(228, 242, 34, 0.42);
}

.money-live-sm {
  background: transparent;
  color: var(--ramp-ink);
  border-radius: 0;
  padding: 0;
  font-weight: 700;
  box-shadow: inset 0 -0.22em 0 rgba(228, 242, 34, 0.38);
}

.money-live-bg {
  background: var(--ramp-hi);
}

#dash-monthly-chart svg { display: block; }

/* Beta: padatkan menu panjang supaya keperluan skrol sidebar berkurang */
#main-app aside nav .nav-item {
  padding-top: 0.38rem !important;
  padding-bottom: 0.38rem !important;
  min-height: 34px;
}

/* Baris jadual: hover warna Bone */
table tbody tr:hover { background: #faf8f6; }

/* Kepala panel gelap gaya Ramp (panel songsang) */
.ramp-invert {
  background: var(--ramp-obsidian);
  color: #fff;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast {
  background-color: white;
  border-radius: 12px;
  border: 1px solid var(--ramp-hairline);
  box-shadow: none;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideIn 0.3s forwards;
  min-width: 300px;
  border-left: 4px solid #cbd5e1;
}

.toast.success { border-left-color: #10b981; }
.toast.error { border-left-color: #ef4444; }
.toast.info { border-left-color: #3b82f6; }
.toast.warning { border-left-color: #f59e0b; }

.delete-progress-indeterminate {
  position: relative;
  overflow: hidden;
  width: 35% !important;
  animation: deleteProgressSlide 1.2s ease-in-out infinite alternate;
}

@keyframes deleteProgressSlide {
  from { transform: translateX(-20%); opacity: 0.7; }
  to { transform: translateX(185%); opacity: 1; }
}

/* ===== RESPONSIVE: Desktop / Tablet / Mobile ===== */

/* --- Mobile-first: table scroll halus dengan petunjuk --- */
@media (max-width: 767px) {
  /* Table wrapper: scroll mendatar lebih mudah */
  .overflow-x-auto {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  /* Header lajur: elak teks terpotong */
  table th {
    white-space: nowrap;
  }
  /* Sel teks panjang: potong elok */
  table td {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Butang tindakan dalam table: lebih besar untuk sentuh */
  table td.whitespace-nowrap button,
  table td.text-right button {
    min-height: 32px;
    padding: 6px 10px;
  }
  /* Modal: penuh skrin di mobile */
  .fixed.inset-0.z-50 > div.relative {
    max-width: 100% !important;
    margin: 0 8px;
    max-height: 92vh;
  }
  /* Dashboard kad: 1 kolom, gap kecil */
  .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4 {
    gap: 12px;
  }
  /* Tajuk page: lebih kecil */
  #page-title {
    font-size: 1.125rem;
  }
  /* Filter bar: stack menegak */
  .finance-print-toolbar {
    flex-direction: column;
    align-items: stretch !important;
  }
  .finance-print-toolbar > * {
    width: 100%;
  }
  /* Panel header: stack */
  .px-6.py-5.border-b {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 12px;
  }
  /* Log panel butang: penuh lebar */
  #inv-log-body td,
  #audit-log-body td {
    max-width: 160px;
  }
}

/* --- Tablet: 2 kolum dashboard, table masih scroll --- */
@media (min-width: 768px) and (max-width: 1023px) {
  table td {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4 {
    gap: 16px;
  }
}

/* --- Desktop: table penuh, tiada potong --- */
@media (min-width: 1024px) {
  table td {
    max-width: none;
    overflow: visible;
    text-overflow: clip;
  }
}

/* --- Semua saiz: sidebar mobile overlay betul --- */
@media (max-width: 767px) {
  #sidebar {
    position: fixed !important;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 50;
    will-change: transform;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  }
  #sidebar.-translate-x-full {
    box-shadow: none;
  }
  /* Content area: penuh lebar bila sidebar tutup */
  #main-app {
    position: relative;
  }
  /* Overlay: gelapkan skrin bila sidebar buka */
  #sidebar-overlay {
    z-index: 40;
  }
}

/* --- Print: kekal kemas --- */
@media print {
  #sidebar, #sidebar-overlay, header, .finance-print-toolbar,
  #inv-log-table, #audit-log-table, .print\:hidden {
    display: none !important;
  }
}

/* --- Toast: mobile penuh lebar --- */
@media (max-width: 767px) {
  .toast {
    min-width: auto;
    width: calc(100vw - 32px);
  }
  #toast-container {
    left: 16px !important;
    right: 16px !important;
    top: 16px !important;
  }
}

/* ===== JADUAL BUKU KEWANGAN: kotak scroll tinggi tetap ===== */
/* Halaman tidak lagi scroll berpanjangan — hanya kotak jadual yang scroll. */
#finance-table-body-scroll {
  /* Tinggi bergantung viewport: kurang header + kad + toolbar supaya halaman
     Buku Kewangan tidak scroll berpanjangan. */
  height: calc(100vh - 300px);
  min-height: 260px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
/* Header lajur melekit dalam kotak scroll (desktop) */
@media (min-width: 768px) {
  #finance-table-body-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #fff;
    box-shadow: inset 0 -1px 0 var(--ramp-hairline, #e5e7eb);
  }
}
/* Mobile: jadual jadi kad, jangan ikat tinggi — biar halaman scroll sendiri */
@media (max-width: 767px) {
  #finance-table-body-scroll {
    max-height: none;
    min-height: 0;
    overflow: visible;
  }
  #finance-table-body-scroll thead th {
    position: static;
  }
}

/* --- Sticky header lajur: kekal nampak bila scroll mendatar --- */
@media (max-width: 767px) {
  table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #fff;
  }
}

/* ===== MOBILE: TABLE → CARD VIEW (lebih mudah dibaca di telefon) ===== */
@media (max-width: 767px) {
  /* Jadual jadi kad: setiap baris = satu kad */
  table.mobile-cards thead {
    display: none;
  }
  table.mobile-cards,
  table.mobile-cards tbody,
  table.mobile-cards tr,
  table.mobile-cards td {
    display: block;
    width: 100%;
  }
  table.mobile-cards tr {
    background: #fff;
    border: 1px solid var(--ramp-hairline);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 12px 14px;
    position: relative;
  }
  table.mobile-cards td {
    border: none !important;
    padding: 4px 0 !important;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
  }
  /* Label lajur: tunjuk nama header sebelum nilai */
  table.mobile-cards td::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ramp-ash);
    text-align: left;
    flex-shrink: 0;
  }
  /* Checkbox: kekal di kiri atas */
  table.mobile-cards td:has(input[type="checkbox"]) {
    justify-content: flex-start;
  }
  table.mobile-cards td:has(input[type="checkbox"])::before {
    content: "";
  }
  /* Butang tindakan: susun mendatar */
  table.mobile-cards td.whitespace-nowrap {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  /* Baris kosong: buang padding kad */
  table.mobile-cards tr:has(td[colspan]) {
    padding: 24px 14px;
    text-align: center;
  }
  table.mobile-cards tr:has(td[colspan]) td {
    justify-content: center;
    text-align: center;
  }
  table.mobile-cards tr:has(td[colspan]) td::before {
    content: "";
  }
}

.payment-method-row{display:flex;flex-direction:column;gap:2px;min-width:112px;margin:2px 0}
.payment-method-row small{font-size:9px;color:#6d6c6b;text-transform:uppercase}
.payment-method-select{max-width:145px;border:1px solid #e5e7eb;border-radius:5px;padding:3px 5px;font-size:10px;background:#fff}
.payment-method-print{display:none;font-size:9px}
@media print{
  .payment-method-select{display:none!important}
  .payment-method-print{display:inline!important}
}
