/* ============================================================
   CSS CUSTOM PROPERTIES
   ============================================================ */
:root {
  --brand:        #0065ab;
  --brand-light:  #4da6ff;
  --brand-xlight: #e0f0ff;
  --brand-dark:   #004b80;
  --success:      #16a34a;
  --success-bg:   #dcfce7;
  --warning:      #d97706;
  --warning-bg:   #fef3c7;
  --danger:       #dc2626;
  --danger-bg:    #fee2e2;
  --neutral:      #6b7280;
  --neutral-bg:   #f3f4f6;
  --text:         #1f2937;
  --text-muted:   #6b7280;
  --border:       #d1d5db;
  --bg:           #f0f7ff;
  --surface:      #ffffff;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08);
  --shadow:       0 4px 12px rgba(0,0,0,.12);
  --shadow-lg:    0 8px 28px rgba(0,0,0,.18);
  --transition:   .18s ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body.rpc-app {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

img { display: block; max-width: 100%; height: auto; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.1rem;
  font-size: .9rem;
  font-weight: 600;
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition), opacity var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
  text-decoration: none;
  vertical-align: middle;
  line-height: 1.4;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }

.btn__icon { width: 1em; height: 1em; flex-shrink: 0; }

.btn--primary   { background: var(--brand-light); color: #fff; border-color: var(--brand-light); }
.btn--primary:hover { background: var(--brand); border-color: var(--brand); }

.btn--success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn--success:hover { background: #15803d; border-color: #15803d; }

.btn--secondary { background: var(--neutral-bg); color: var(--text); border-color: var(--border); }
.btn--secondary:hover { background: #e5e7eb; }

.btn--outline   { background: transparent; color: var(--brand); border-color: var(--brand-light); }
.btn--outline:hover { background: var(--brand-xlight); }

.btn--ghost     { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn--ghost:hover { background: var(--neutral-bg); }

.btn--danger-hover:hover { color: var(--danger); background: var(--danger-bg); }

.btn--sm  { padding: .3rem .7rem; font-size: .82rem; }
.btn--lg  { padding: .65rem 1.4rem; font-size: 1rem; }

.btn--action {
  background: var(--brand-xlight);
  color: var(--brand);
  border-color: var(--brand-light);
  font-weight: 600;
}
.btn--action:hover { background: var(--brand-light); color: #fff; }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0065ab 0%, #4da6ff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 440px;
  text-align: center;
}

.login-card__logo {
  width: 100px;
  margin: 0 auto 1.2rem;
}
.login-card__logo img { border-radius: 8px; }

.login-card__title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: .3rem;
}

.login-card__subtitle {
  font-size: .9rem;
  color: var(--text-muted);
  margin-bottom: 1.8rem;
}

.login-form { text-align: left; }

.login-form__group { margin-bottom: 1.2rem; }

.login-form__label {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .45rem;
}

.login-form__hint-badge {
  font-size: .72rem;
  font-weight: 500;
  background: var(--brand-xlight);
  color: var(--brand);
  padding: .15rem .45rem;
  border-radius: 20px;
  border: 1px solid var(--brand-light);
}

.login-form__input {
  width: 100%;
  padding: .7rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.login-form__input:focus {
  border-color: var(--brand-light);
  box-shadow: 0 0 0 3px rgba(77,166,255,.2);
}
.login-form__input--password { letter-spacing: .08em; }

.login-form__error {
  display: none;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: .6rem .9rem;
  font-size: .85rem;
  margin-bottom: 1rem;
}

.login-form__btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: .8rem;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
  margin-top: .5rem;
}
.login-form__btn:hover { background: var(--brand-dark); box-shadow: 0 4px 12px rgba(0,101,171,.35); }
.login-form__btn:disabled { opacity: .6; cursor: not-allowed; }

.login-form__btn-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.login-form__btn-spinner.active { display: block; }

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ============================================================
   HEADER
   ============================================================ */
.header {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  padding: .75rem 1.5rem;
  border-bottom: 2px solid var(--brand-xlight);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}

.header__logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
}

.header__content {
  flex: 1;
  min-width: 0;
}

.header__title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header__stats {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .35rem;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: var(--brand-xlight);
  border: 1px solid var(--brand-light);
  border-radius: 20px;
  padding: .2rem .65rem;
  font-size: .8rem;
}

.stat-chip__label { color: var(--brand-dark); font-weight: 500; }
.stat-chip__value { color: var(--brand); font-weight: 700; min-width: 1.5ch; }

.stat-chip--collected { background: var(--success-bg); border-color: #86efac; }
.stat-chip--collected .stat-chip__label { color: #166534; }
.stat-chip--collected .stat-chip__value { color: var(--success); }

.stat-chip--pending { background: var(--warning-bg); border-color: #fcd34d; }
.stat-chip--pending .stat-chip__label { color: #92400e; }
.stat-chip--pending .stat-chip__value { color: var(--warning); }

.header__actions {
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-shrink: 0;
}

/* ============================================================
   MAIN
   ============================================================ */
.main {
  flex: 1;
  padding: 1.25rem 1.5rem;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ============================================================
   STATS BAR
   ============================================================ */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
  margin-bottom: 1.1rem;
}

.stats-bar__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.stats-bar__value {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--brand);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stats-bar__label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.stats-bar__card--collected {
  border-color: #86efac;
  background: var(--success-bg);
}
.stats-bar__card--collected .stats-bar__value { color: var(--success); }

.stats-bar__card--pending {
  border-color: #fcd34d;
  background: var(--warning-bg);
}
.stats-bar__card--pending .stats-bar__value { color: var(--warning); }

@media (max-width: 480px) {
  .stats-bar { grid-template-columns: repeat(3, 1fr); gap: .4rem; }
  .stats-bar__value { font-size: 1.4rem; }
  .stats-bar__card { padding: .6rem .5rem; }
  .stats-bar__label { font-size: .7rem; }
}

/* ============================================================
   SEARCH SECTION
   ============================================================ */
.search-section {
  margin-bottom: 1.1rem;
}

.search-bar {
  display: flex;
  gap: .5rem;
  align-items: stretch;
}

.search-bar__input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-bar__icon {
  position: absolute;
  left: .85rem;
  width: 1.2rem;
  height: 1.2rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-bar__input {
  width: 100%;
  padding: .7rem .9rem .7rem 2.6rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.05rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  min-width: 0;
}
.search-bar__input:focus {
  border-color: var(--brand-light);
  box-shadow: 0 0 0 3px rgba(77,166,255,.18);
}
.search-bar__input::placeholder { color: #adb5bd; }

.search-hint {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin-top: .5rem;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  font-size: .85rem;
  background: var(--neutral-bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: background var(--transition), color var(--transition);
}

.search-hint__icon { width: 1rem; height: 1rem; flex-shrink: 0; }

.search-hint--ok   { background: var(--success-bg); color: #166534; border-color: #86efac; }
.search-hint--warn { background: var(--warning-bg); color: #92400e; border-color: #fcd34d; }
.search-hint--info { background: var(--brand-xlight); color: var(--brand-dark); border-color: var(--brand-light); }

/* ============================================================
   DATA TABLE WRAPPER
   ============================================================ */
.table-wrapper {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* DataTables layout overrides */
.dt-layout-row { display: block !important; }
.dt-layout-table { overflow-x: auto; }
div.dt-container { padding: .75rem; }
div.dt-container .dt-layout-row:first-child,
div.dt-container .dt-layout-row:last-child { padding: .25rem 0; }

/* ============================================================
   TABLE
   ============================================================ */
.rpc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

.rpc-table thead tr {
  background: var(--brand-xlight);
}

.rpc-table thead th {
  padding: .65rem .75rem;
  text-align: left;
  font-weight: 700;
  color: var(--brand-dark);
  border-bottom: 2px solid var(--brand-light);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.rpc-table thead th:last-child { cursor: default; text-align: center; }

.rpc-cell {
  padding: .55rem .75rem;
  border-bottom: 1px solid #f0f4f8;
  vertical-align: top;
  color: var(--text);
}

.rpc-row:hover .rpc-cell { background: #f5faff; }
.rpc-row--collected .rpc-cell { background: #f0fdf4; }
.rpc-row--collected:hover .rpc-cell { background: #dcfce7; }

.col-action { text-align: center !important; white-space: nowrap; }

.remark-tag {
  display: block;
  margin-top: .3rem;
  font-size: .78rem;
  color: var(--danger);
  font-weight: 600;
}

/* ============================================================
   STATUS BADGE
   ============================================================ */
.status-badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge--collected {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #86efac;
}

.badge--pending {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid #fcd34d;
}

.badge--no {
  background: var(--neutral-bg);
  color: var(--neutral);
  border: 1px solid var(--border);
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 1rem;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-16px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--brand-xlight);
  flex-shrink: 0;
}

.modal__title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand);
}

.modal__close-btn {
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 .25rem;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}
.modal__close-btn:hover { color: var(--danger); background: var(--danger-bg); }

.modal__body {
  padding: 1.1rem 1.25rem;
  overflow-y: auto;
  flex: 1;
}

.modal__footer {
  display: flex;
  gap: .6rem;
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Participant detail grid */
.detail-grid { display: flex; flex-direction: column; gap: .5rem; }

.detail-row {
  display: flex;
  gap: .5rem;
  padding: .5rem .6rem;
  border-radius: 6px;
  background: #f9fafb;
  border: 1px solid #f0f4f8;
  align-items: flex-start;
}

.detail-label {
  flex: 0 0 130px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  padding-top: .05rem;
}

.detail-value {
  flex: 1;
  font-size: .9rem;
  color: var(--text);
  font-weight: 500;
  word-break: break-word;
}

.remark-value { color: var(--danger); font-weight: 600; }

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(1px);
}

.loading-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem 2.5rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 5px solid var(--brand-xlight);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--brand);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 3000;
  display: flex;
  flex-direction: column-reverse;
  gap: .5rem;
  pointer-events: none;
}

.toast {
  padding: .75rem 1.1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: .88rem;
  font-weight: 500;
  max-width: 340px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: auto;
}

.toast--visible { opacity: 1; transform: none; }

.toast--info  { background: var(--brand-xlight); color: var(--brand-dark); border-left: 4px solid var(--brand-light); }
.toast--error { background: var(--danger-bg);    color: var(--danger);     border-left: 4px solid var(--danger); }
.toast--success { background: var(--success-bg); color: #166534;           border-left: 4px solid var(--success); }

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  background: var(--brand);
  color: #fff;
  padding: .75rem 1.5rem;
  font-size: .8rem;
  margin-top: auto;
}

.footer__refresh {
  font-size: .78rem;
  color: rgba(255,255,255,.75);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   DATATABLES OVERRIDES
   ============================================================ */
.dt-search { display: none !important; } /* We use our own search */

table.dataTable thead .dt-ordering-asc  .dt-column-title::after { content: " ▲"; font-size: .7em; }
table.dataTable thead .dt-ordering-desc .dt-column-title::after { content: " ▼"; font-size: .7em; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .header { padding: .6rem 1rem; }
  .main   { padding: 1rem; }
  .header__actions .btn span:not(.btn__icon) { display: none; }
  .header__actions .btn { padding: .45rem .6rem; }
}

@media (max-width: 640px) {
  .header__title { font-size: .95rem; }

  .search-bar { flex-wrap: wrap; }
  .search-bar__input-wrap { flex: 1 1 100%; }
  .search-bar .btn { flex: 1; justify-content: center; }

  /* Card-style rows on mobile */
  .table-wrapper { border-radius: var(--radius); overflow: hidden; }

  .rpc-table thead { display: none; }
  .rpc-table, .rpc-table tbody, .rpc-row, .rpc-cell { display: block; width: 100%; }
  .rpc-table tbody { display: flex; flex-direction: column; gap: .75rem; padding: .75rem; }

  .rpc-row {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
  }
  .rpc-row--collected { border-color: #86efac; }

  .rpc-cell {
    display: flex;
    gap: .5rem;
    border-bottom: 1px solid #f0f4f8;
    padding: .5rem .75rem;
  }
  .rpc-cell::before {
    content: attr(data-label);
    flex: 0 0 42%;
    font-weight: 600;
    font-size: .8rem;
    color: var(--text-muted);
    padding-top: .05rem;
  }
  .rpc-cell:last-child { border-bottom: none; justify-content: flex-end; }
  .rpc-cell:last-child::before { display: none; }
  .rpc-cell.col-action { justify-content: stretch; }
  .rpc-cell.col-action .btn--action { width: 100%; justify-content: center; }

  .modal__footer { flex-direction: column; }
  .modal__footer .btn { width: 100%; justify-content: center; }

  .detail-label { flex: 0 0 110px; }

  .toast-container { left: 1rem; right: 1rem; bottom: 1rem; }
  .toast { max-width: 100%; }

  .footer { flex-direction: column; text-align: center; gap: .25rem; }
}

@media (max-width: 400px) {
  .stat-chip { font-size: .74rem; padding: .15rem .45rem; }
  .header__logo { width: 40px; height: 40px; }
}
