﻿/* ================================================================
   POSB Net Addition Report — Advanced UI Stylesheet v2
   Font: DM Sans (body) + Merriweather (header)
   Theme: Refined Government Dashboard
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800&family=Merriweather:wght@700;900&display=swap');

/* ── Variables ────────────────────────────────────────────────── */
:root {
  --red:        #B22222;
  --red-dk:     #8B0000;
  --red-lt:     #fdecea;
  --blue:       #1a3a6b;
  --blue-mid:   #2563a8;
  --blue-lt:    #e8eef8;
  --pink:       #e879a0;
  --text:       #18181b;
  --muted:      #52525b;
  --light:      #71717a;
  --border:     #e2e8f0;
  --border-mid: #cbd5e1;
  --bg:         #f1f5f9;
  --surface:    #ffffff;
  --sh-xs: 0 1px 3px rgba(0,0,0,0.07);
  --sh-sm: 0 2px 8px rgba(26,58,107,0.09);
  --sh-md: 0 4px 20px rgba(26,58,107,0.13);
  --r-sm:  7px;
  --r-md:  12px;
  --r-lg:  18px;
  --ease:  cubic-bezier(0.4,0,0.2,1);
  --tr:    0.18s var(--ease);
}

/* ── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  padding: 0 10px 28px;
  -webkit-font-smoothing: antialiased;
}

/* ── H1 — exactly 50px tall ──────────────────────────────────── */
h1 {
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(100% + 20px);
  margin-left: -10px;
  height: 50px;                         /* ← fixed 50px */
  background: linear-gradient(100deg, #6b0000 0%, var(--red-dk) 30%, var(--red) 70%, #c0392b 100%);
  color: #fff;
  font-family: 'Merriweather', Georgia, serif;
  font-size: clamp(11.5px, 1.45vw, 18px);
  font-weight: 900;
  letter-spacing: 0.015em;
  text-align: center;
  padding: 0 22px;
  margin-bottom: 12px;
  box-shadow: 0 3px 14px rgba(139,0,0,0.30);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  line-height: 1.2;
}

h1::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -52deg, transparent 0, transparent 14px,
    rgba(255,255,255,0.028) 14px, rgba(255,255,255,0.028) 28px
  );
  pointer-events: none;
}

h1::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 5%, rgba(255,255,255,0.55) 50%, transparent 95%);
}

/* ── Options Container ────────────────────────────────────────── */
#options-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--red);
  border-radius: var(--r-lg);
  padding: 11px 16px 12px;
  margin-bottom: 10px;
  box-shadow: var(--sh-sm);
}

/* ── Date row — single horizontal line ────────────────────────── */
.date-info-row {
  display: flex;
  flex-direction: row;            /* ← side-by-side */
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

#dataavailablefrom,
#dataavailableupto {
  font-family: Arial, "Times New Roman", serif;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.025em;
  margin: 0;
  padding: 3px 11px;
  border-radius: 20px;
  white-space: nowrap;
}

#dataavailablefrom {
  color: #be185d;
  background: #fdf2f8;
  border: 1px solid #fbcfe8;
}

#dataavailableupto {
  color: var(--blue);
  background: var(--blue-lt);
  border: 1px solid #bfdbfe;
}

/* ── Selects + Buttons — ONE row on desktop ───────────────────── */
.dropdown-and-dropdown-buttons {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: nowrap;              /* ← single line */
}

.selects-row {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 5px;
  min-width: 0;
  flex-wrap: nowrap;              /* ← force all selects in one row */
}

label { display: none; }

select {
  appearance: none;
  -webkit-appearance: none;
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  padding: 7px 22px 7px 8px;
  font-family: Arial, "Times New Roman", serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='5'%3E%3Cpath d='M0 0l4.5 5 4.5-5z' fill='%231a3a6b'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  background-size: 9px;
  border: 1.5px solid var(--border-mid);
  border-bottom: 2.5px solid var(--pink);
  border-radius: var(--r-sm);
  box-shadow: var(--sh-xs);
  cursor: pointer;
  outline: none;
  transition: border-color var(--tr), box-shadow var(--tr);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

select:hover { border-color: var(--red); border-bottom-color: var(--red); }
select:focus { border-color: var(--red); border-bottom-color: var(--red); box-shadow: 0 0 0 3px rgba(178,34,34,0.13); }

/* ── Buttons ──────────────────────────────────────────────────── */
#buttons {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-shrink: 0;
}

button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--r-sm);
  font-family: Arial, "Times New Roman", serif;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.025em;
  cursor: pointer;
  white-space: nowrap;
  outline: none;
  transition: transform var(--tr), box-shadow var(--tr), filter var(--tr);
}

button:active { transform: translateY(1px) scale(0.98); }

button.btn-load {
  background: linear-gradient(135deg, var(--red) 0%, var(--red-dk) 100%);
  color: #fff;
  box-shadow: 0 3px 10px rgba(178,34,34,0.36);
}
button.btn-load:hover { filter: brightness(1.1); box-shadow: 0 5px 16px rgba(178,34,34,0.46); transform: translateY(-1px); }

button.btn-export {
  background: linear-gradient(135deg, var(--blue-mid) 0%, var(--blue) 100%);
  color: #fff;
  box-shadow: 0 3px 10px rgba(26,58,107,0.32);
}
button.btn-export:hover { filter: brightness(1.1); box-shadow: 0 5px 16px rgba(26,58,107,0.40); transform: translateY(-1px); }

/* ── Search Row ───────────────────────────────────────────────── */
#search-container {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  padding: 5px 2px;
}

#showingresults {
  font-size: 16px;
  font-weight: 700;
  color: #0f22b5;
  white-space: nowrap;
  background: var(--blue-lt);
  border-radius: 20px;
  padding: 4px 13px;
  border: 1px solid #c7d9f5;
}


#showingresults span {
  color: var(--red);
  font-weight: 800;
  font-size: 13px;
}

.inputbox {
  flex: 1;
  min-width: 160px;
  max-width: 320px;
  padding: 8px 13px 8px 34px;
  border: 1.5px solid var(--border-mid);
  border-radius: 28px;
  font-family: Arial, "Times New Roman", serif;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%2371717a' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.099zm-5.44 1.406a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z'/%3E%3C/svg%3E")
    no-repeat 10px center;
  box-shadow: var(--sh-xs);
  outline: none;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.inputbox::placeholder { color: #a1a1aa; }
.inputbox:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(178,34,34,0.12); }

/* ── Table Wrapper ────────────────────────────────────────────── */
#data {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--r-md);
  box-shadow: var(--sh-md);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

#data::-webkit-scrollbar { height: 5px; }
#data::-webkit-scrollbar-track { background: var(--bg); }
#data::-webkit-scrollbar-thumb { background: var(--red); border-radius: 3px; }

.table-container {
  max-height: 75vh;
  overflow-y: auto;
  border-radius: var(--r-md);
}

.table-container::-webkit-scrollbar { width: 5px;  }
.table-container::-webkit-scrollbar-track { background: var(--bg); }
.table-container::-webkit-scrollbar-thumb { background: var(--red); border-radius: 3px; }

/* ── Table ────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  font-family: Arial, "Times New Roman", serif;
  /* GPU-accelerated layer for large datasets */
  will-change: transform;
  contain: layout style;
}

.sticky-row th {
  position: sticky;
  top: 0;
  z-index: 10;
}

th {
  background: linear-gradient(180deg, #eedada 0%, #e2c9c9 100%);
  color: var(--red-dk);
  font-family: Arial, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  padding: 9px 22px 9px 8px;
  border-bottom: 2px solid var(--red);
  border-right: 1px solid rgba(178,34,34,0.13);
  letter-spacing: 0.025em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: background var(--tr);
}

th:last-child { border-right: none; }
th:hover { background: linear-gradient(180deg, #fce8e8 0%, #f0d5d5 100%); }

td {
  padding: 7px 9px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid rgba(226,232,240,0.7);
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  /* NO transition — critical for fast rendering of large tables */
}

td:last-child { border-right: none; }

td:first-of-type {
  text-align: left;
  padding: 7px 13px;
  font-weight: 700;
  color: var(--blue);
}

tbody tr:nth-child(even) > td { background-color: #fff; }
tbody tr:hover > td { background-color: #eef3fc; }

/* Total row */
tr:last-of-type > td {
  background: linear-gradient( #e8eaf0);
  font-weight: 800;
  font-size: 18px;
  border-top: 2px solid var(--red);
  color: var(--red-dk);
  padding: 9px;
}

th, td.total-cell { color: #000000; }
.total-cell { font-weight: 800;}
.left-align { text-align: left !important; }

/* ── Sort Icons ───────────────────────────────────────────────── */
th .sort-icons {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-65%);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

th .sort-icons .asc-sort-icon {
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid #c4a0a0;
}

th .sort-icons .desc-sort-icon {
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid #c4a0a0;
}

th .sort-icons .asc-sort-icon.active  { border-bottom-color: var(--red-dk); }
th .sort-icons .desc-sort-icon.active { border-top-color: var(--red-dk); }


select {
        font-size: 15px;
        padding: 7px 20px 7px 7px;
    }

/* ── Name column — wider ──────────────────────────────────────── */
td:first-child,
th:first-child {
  min-width: 160px;
}


/* ── Loading overlay ──────────────────────────────────────────── */
#loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(241,245,249,0.72);
  z-index: 999;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

#loading-overlay.visible { display: flex; }

.loader-box {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 22px 36px;
  box-shadow: var(--sh-md);
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: Arial, "Times New Roman", serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--red-lt);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Notes ────────────────────────────────────────────────────── */
h5 {
  font-family: Arial, "Times New Roman", serif;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--light);
  margin: 10px 2px 3px;
  line-height: 1.5;
}

/* ── Blinking ─────────────────────────────────────────────────── */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.28; }
}
.blinking-text { animation: blink 1.6s ease-in-out infinite; }

/* ── H3 (date badges) ─────────────────────────────────────────── */
h3 { font-size: 11.5px; font-weight: 700; margin: 0; }

/* ================================================================
   RESPONSIVE
   ================================================================ */

/* Tablet ≤ 1100px */
@media screen and (max-width: 1100px) {
  select { font-size: 11.5px; padding: 7px 20px 7px 7px; }
  th { font-size: 11px; padding: 9px 20px 9px 7px; }
  td { font-size: 12.5px; }
  button { padding: 7px 13px; font-size: 12px; }
}

/* Tablet/mobile portrait ≤ 900px */
@media screen and (max-width: 900px) {
  body { padding: 0 8px 20px; }

  h1 {
    width: calc(100% + 16px);
    margin-left: -8px;
    font-size: clamp(11px, 3.8vw, 16px);
    height: auto;
    min-height: 50px;
    padding: 8px 12px;
  }

  .date-info-row {
    justify-content: flex-start;
    gap: 8px;
    margin-bottom: 8px;
  }

  #dataavailablefrom, #dataavailableupto { font-size: 11px; }

  .dropdown-and-dropdown-buttons {
    flex-direction: column;
    gap: 10px;
    flex-wrap: wrap;
  }

  .selects-row {
    flex-wrap: wrap;
    gap: 7px;
  }

  select {
    flex: 1 1 calc(50% - 7px);
    max-width: calc(50% - 7px);
    min-width: 130px;
    font-size: 12.5px;
    padding: 9px 24px 9px 10px;
  }

  #buttons { width: 100%; justify-content: stretch; gap: 10px; }
  button { flex: 1; padding: 11px 10px; font-size: 14px; justify-content: center; }
  .table-container { max-height: 75vh; }
}

/* Mobile portrait ≤ 600px */
@media screen and (max-width: 600px) {
  h1 { font-size: clamp(11px, 4.2vw, 15px); }

  #search-container { flex-direction: column; align-items: flex-start; gap: 7px; }

  .inputbox {
    width: 100%;
    max-width: 100%;
    font-size: 14px;
    padding: 10px 13px 10px 34px;
  }

  select {
    flex: 1 1 calc(50% - 7px);
    max-width: calc(50% - 7px);
    font-size: 13px;
  }

  th { font-size: 10.5px; padding: 8px 18px 8px 6px; white-space: nowrap; }
  td { font-size: 11px; padding: 6px 7px; white-space: nowrap; }
  td:first-of-type { padding: 6px 9px; }
  tr:last-of-type > td { font-size: 11.5px; padding: 8px 7px; }
  h5 { font-size: 10.5px; }
  .table-container { max-height: 75vh; }
}

/* Mobile landscape */
@media screen and (max-height: 527px) and (orientation: landscape) {
  h1 { font-size: clamp(11px, 2.4vw, 15px); height: auto; min-height: 40px; padding: 6px 14px; }
  select { font-size: 11px; padding: 5px 20px 5px 7px; }
  button { font-size: 11.5px; padding: 6px 12px; }
  th { font-size: 10.5px; padding: 6px 18px 6px 6px; }
  td { font-size: 11px; padding: 5px 7px; }
  #options-container { padding: 7px 12px; }
  #dataavailablefrom, #dataavailableupto { font-size: 10px; }
  .table-container { max-height: 75vh; }
}

/* iPhone SE ≤ 390px */
@media screen and (max-width: 390px) {
  h1 { font-size: 14px; }
  select { flex: 1 1 100%; max-width: 100%; font-size: 15px; }
  button { font-size: 13px; }
  th { font-size: 16px; }
  td { font-size: 16px; }
  .table-container { max-height: 85vh; }
}