/* ==========================================================
   Database Peminjam v5.1 — style.css
   Apple-clean base + warm retro Claude tones
   ========================================================== */

/* ── TOKENS ─────────────────────────────────────────────── */
:root {
  --bg:        #f5f0eb;
  --surface:   #fffdf9;
  --border:    #e5ddd3;
  --text:      #2c2420;
  --muted:     #8a7a70;
  --accent:    #c0622a;
  --accent-lt: #fdf0e8;
  --accent-hv: #a04f1e;
  --radius:    14px;
  --shadow:    0 2px 10px rgba(44,36,32,0.07);
}

/* ── RESET ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* ── HEADER ─────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
}
header h1 {
  font-family: 'Lora', Georgia, serif;
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.3px;
}
header .subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-left: auto;
  font-style: italic;
}

/* ── MAIN ───────────────────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

/* ── REFRESH BAR ────────────────────────────────────────── */
.refresh-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 0.8rem;
  color: var(--muted);
}
#lastUpdatedText {
  font-style: italic;
}
.btn-refresh {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s ease, transform 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-refresh:hover {
  background: var(--accent-lt);
  transform: rotate(20deg);
}

/* ── SECTION TITLE ──────────────────────────────────────── */
.section-title {
  font-family: 'Lora', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}

/* ── DASHBOARD CARDS ────────────────────────────────────── */
.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 32px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
  position: relative;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(44,36,32,0.1);
}
.card.actionable {
  cursor: pointer;
}
.card.actionable:hover {
  border-color: var(--accent);
  background: var(--accent-lt);
}
.card h3 {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.card p {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  font-family: 'Lora', Georgia, serif;
  word-break: break-word;
}
.card-action {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.card.actionable:hover .card-action {
  opacity: 1;
}

/* ── SPARKLINE CHART ────────────────────────────────────── */
.sparkline-container {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: 3px;
  height: 24px;
  margin-top: 8px;
}
.sparkline-bar {
  flex: 1;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}
.sparkline-bar:hover {
  opacity: 1;
}

/* ── TOOLBAR ────────────────────────────────────────────── */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}
.toolbar-group {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.toolbar-group .input-wrap { flex: 1; min-width: 0; }
.toolbar-group .btn        { flex-shrink: 0; white-space: nowrap; }

.toolbar-reset {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.btn-reset {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.btn-reset:hover {
  background: var(--accent-lt);
  border-color: var(--accent);
}

.btn-export {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  transition: background 0.2s ease;
}
.btn-export:hover {
  background: var(--accent-hv);
}

.input-wrap label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 4px;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 10px;
  font-size: 0.95rem;
  pointer-events: none;
  color: var(--muted);
}
input[type="text"],
input[type="date"],
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px 9px 36px;
  font-size: 0.95rem;
  font-family: 'Inter', sans-serif;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}
input[type="date"],
select {
  padding-left: 14px;
}
input[type="text"]:focus,
input[type="date"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(192,98,42,0.12);
}

/* ── AUTOCOMPLETE DROPDOWN ──────────────────────────────── */
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(44,36,32,0.12);
  z-index: 1000;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 4px;
}
.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  transition: background 0.15s ease;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.autocomplete-item:last-child {
  border-bottom: none;
}
.autocomplete-item:hover {
  background: var(--accent-lt);
  color: var(--accent);
}

/* ── FILTER PANEL ───────────────────────────────────────– */
.filter-toggle-container {
  margin-bottom: 16px;
}
.btn-filter-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.btn-filter-toggle:hover {
  background: var(--accent-lt);
  border-color: var(--accent);
}

.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.filter-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  align-items: flex-end;
}
.filter-control {
  display: flex;
  flex-direction: column;
}
.filter-control label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
  font-weight: 600;
}
.filter-control select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border 0.2s ease;
  min-height: 44px;
}
.filter-control select:focus {
  border-color: var(--accent);
  outline: none;
}
.filter-date-range {
  grid-column: 1 / -1;
}
.date-inputs {
  display: flex;
  gap: 8px;
  align-items: center;
}
.date-inputs input[type="date"] {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 44px;
}
.date-separator {
  color: var(--muted);
  font-weight: 600;
}

#btnApplyFilter {
  grid-column: 1 / -1;
  min-height: 44px;
}
.btn-filter-reset {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  transition: background 0.2s ease;
  grid-column: 1 / -1;
  min-height: 44px;
}
.btn-filter-reset:hover {
  background: var(--accent-lt);
  border-color: var(--accent);
}

/* ── ACTIVE FILTER TAGS ─────────────────────────────────– */
.active-filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.filter-tag {
  background: var(--accent-lt);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.filter-tag-close {
  cursor: pointer;
  font-weight: 700;
  transition: opacity 0.2s ease;
}
.filter-tag-close:hover {
  opacity: 0.7;
}

/* ── CHART CARDS ────────────────────────────────────────– */
#chartsContainer {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
}
.chart-card h3 {
  font-family: 'Lora', Georgia, serif;
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 16px;
}

/* Risk Chart */
.risk-chart {
  display: flex;
  gap: 8px;
  align-items: center;
  height: 40px;
  overflow: hidden;
  min-width: 0;
}
.risk-bar-segment {
  height: 100%;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  transition: opacity 0.2s ease;
}
.risk-bar-segment:hover {
  opacity: 0.85;
}
.risk-bar-segment.low { background: #1a7f37; }
.risk-bar-segment.medium { background: #9a5700; }
.risk-bar-segment.high { background: #c0392b; }

/* Purpose Chart */
.purpose-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.purpose-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  min-width: 0;
  overflow: hidden;
}
.purpose-bar-label {
  min-width: 90px;
  font-weight: 500;
  color: var(--text);
}
.purpose-bar-fill {
  flex: 1;
  height: 24px;
  background: var(--accent);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.purpose-bar-count {
  min-width: 40px;
  text-align: right;
  color: var(--muted);
  font-weight: 600;
}

/* ── BUTTONS ────────────────────────────────────────────── */
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 20px;
  cursor: pointer;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  transition: background 0.2s ease, transform 0.15s ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover    { background: var(--accent-hv); transform: translateY(-1px); }
.btn:disabled { background: #ccc; cursor: not-allowed; transform: none; }
.btn.secondary {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn.secondary:hover    { background: var(--accent-lt); }
.btn.secondary:disabled { background: var(--surface); color: #ccc; border-color: #ccc; }
.btn.full-width { width: 100%; }

/* ── TABLE ──────────────────────────────────────────────── */
#tableWrapper { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
th, td {
  padding: 10px 13px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  white-space: nowrap;
}
th {
  background: #f0e8df;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  user-select: none;
}

/* Sortable headers */
.sortable-header {
  cursor: pointer;
  transition: color 0.2s ease;
}
.sortable-header:hover {
  color: var(--accent);
  text-decoration: underline;
}
.sort-indicator {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
}

tr:hover td { background: #fdf6f0; }

/* Row risk indicator (left border) */
tbody tr {
  border-left: 4px solid transparent;
  transition: border-color 0.2s ease;
}
tbody tr.row-risk-high { border-left-color: #c0392b; }
tbody tr.row-risk-medium { border-left-color: #9a5700; }
tbody tr.row-risk-low { border-left-color: #1a7f37; }

/* Clickable names */
.name-link {
  display: inline-block;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  transition: color 0.2s ease;
  text-decoration: none;
  border-bottom: 1px dashed var(--accent);
  padding-bottom: 1px;
}
.name-link:hover {
  color: var(--accent-hv);
  border-bottom-style: solid;
}

td.risk-cell span {
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}

/* ── PAGINATION ─────────────────────────────────────────── */
.pagination-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}
#pageIndicator { color: var(--muted); font-size: 0.88rem; font-weight: 500; }

/* ── EMPTY STATE ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state p {
  font-size: 1.1rem;
  margin: 0;
}

/* ── TOAST NOTIFICATIONS ────────────────────────────────── */
#toastContainer {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 10px;
  box-shadow: 0 4px 16px rgba(44,36,32,0.15);
  font-size: 0.9rem;
  animation: slideDown 0.3s ease forwards;
  pointer-events: auto;
  max-width: 400px;
}
.toast.info {
  border-left: 4px solid #007aff;
  color: #004080;
}
.toast.warning {
  border-left: 4px solid #ff9500;
  color: #664c00;
}
.toast.error {
  border-left: 4px solid #c0392b;
  color: #7a1f1a;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── PROFILE VIEW ───────────────────────────────────────── */
#profileView {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 30px;
  display: none;
  animation: fadeUp 0.45s ease forwards;
  margin-bottom: 28px;
}
#profileView h2 {
  font-family: 'Lora', Georgia, serif;
  font-size: 1.3rem;
  color: var(--accent);
  margin-bottom: 4px;
}
#profileView h3 {
  font-family: 'Lora', Georgia, serif;
  font-size: 1rem;
  margin: 20px 0 8px;
  color: var(--text);
}
#profileView ul { list-style: none; }
#profileView ul li { margin-bottom: 5px; }

/* PJ nasabah names clickable */
#profileView .name-link,
#pjProfileView .name-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  transition: color 0.2s ease;
}
#profileView .name-link:hover,
#pjProfileView .name-link:hover {
  color: var(--accent-hv);
  text-decoration: underline;
}

/* ── PJ PROFILE VIEW ────────────────────────────────────── */
#pjProfileView {
  margin-bottom: 28px;
  display: none;
}

/* ── REKAP CARD ─────────────────────────────────────────── */
.rekap-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 20px;
}
.rekap-card h3 {
  font-family: 'Lora', Georgia, serif;
  color: var(--accent);
  font-size: 1.15rem;
  margin-bottom: 4px;
}
.rekap-card h4 {
  font-family: 'Lora', Georgia, serif;
  font-size: 0.95rem;
  color: var(--text);
  margin: 16px 0 8px;
}
.rekap-total-row { background: #f0e8df; font-weight: 600; }

/* ── HISTORI PJ COLLAPSIBLE ─────────────────────────────── */
details {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
details summary {
  padding: 12px 16px;
  cursor: pointer;
  background: #f0e8df;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  list-style: none;
  min-height: 44px;
}
details summary::-webkit-details-marker { display: none; }
details summary::after {
  content: '▸';
  margin-left: auto;
  color: var(--muted);
  transition: transform 0.2s ease;
}
details[open] summary::after { transform: rotate(90deg); }
details > div { padding: 16px; overflow-x: auto; }

/* Overlap warning legend */
.overlap-legend {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 12px;
  font-style: italic;
}

/* ── SHARED UTILITIES ───────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}

/* ── LOADING ────────────────────────────────────────────── */
#loading { text-align: center; padding: 60px 0; color: var(--muted); font-style: italic; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 12px;
}

/* ── ANIMATIONS ─────────────────────────────────────────── */
@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── RESPONSIVE — TABLET ────────────────────────────────– */
@media (max-width: 1024px) {
  .dashboard-cards {
    grid-template-columns: repeat(3, 1fr);
  }
  .dashboard-cards .card:nth-child(4) { grid-column: 2; }
  .dashboard-cards .card:nth-child(5) { grid-column: 3; }

  #chartsContainer {
    grid-template-columns: 1fr;
  }

  .filter-controls {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── RESPONSIVE — MOBILE ────────────────────────────────– */
@media (max-width: 768px) {
  main { padding: 18px 16px 50px; }
  header { padding: 12px 16px; }
  header h1 { font-size: 1.2rem; }
  header .subtitle { display: none; }

  .dashboard-cards {
    grid-template-columns: repeat(2, 1fr);
    overflow-x: auto;
    scroll-behavior: smooth;
  }
  .dashboard-cards .card:nth-child(4) { grid-column: 1; }
  .dashboard-cards .card:nth-child(5) { grid-column: 2; }
  .card p { font-size: 1rem; }

  .toolbar-group { flex-direction: column; align-items: stretch; }
  .toolbar-group .btn { width: 100%; }

  .toolbar-reset {
    flex-direction: column;
  }
  .toolbar-reset .btn-reset,
  .toolbar-reset .btn-export {
    width: 100%;
  }

  .filter-panel {
    padding: 14px;
  }
  .filter-controls {
    grid-template-columns: 1fr;
  }
  #btnApplyFilter,
  .btn-filter-reset {
    grid-column: 1;
  }

  .filter-date-range {
    grid-column: 1;
  }
  .date-inputs {
    flex-direction: column;
  }
  .date-inputs input[type="date"],
  .filter-control select {
    width: 100%;
  }
  .date-separator {
    display: none;
  }

  #chartsContainer {
    grid-template-columns: 1fr;
  }

  th, td {
    padding: 8px 10px;
    font-size: 0.8rem;
    white-space: normal;
  }
  .card-action { display: none; }

  .autocomplete-item {
    min-height: 44px;
  }

  .pagination-container {
    flex-direction: column;
    gap: 10px;
  }
  .pagination-container .btn {
    width: 100%;
  }

  .active-filter-tags {
    gap: 6px;
  }
  .filter-tag {
    padding: 5px 10px;
    font-size: 0.75rem;
  }
}

/* ── RESPONSIVE — SMALL MOBILE ──────────────────────────– */
@media (max-width: 480px) {
  .dashboard-cards {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .dashboard-cards .card:nth-child(4) { grid-column: 1; }
  .dashboard-cards .card:nth-child(5) { grid-column: 1; }
  .card { padding: 12px 14px; }
  .card p { font-size: 1rem; }

  .toolbar-group { flex-direction: column; align-items: stretch; }
  .toolbar-group .btn { width: 100%; }

  th, td { padding: 8px 6px; font-size: 0.75rem; }
  .card-action { display: none; }
}
