/* Bhumisah design system — Forest & slate (FR-007g–l) */
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:ital,wght@0,400;0,600;0,700;1,400&display=swap');

:root {
  --bs-canvas: #f5f7f6;
  --bs-surface: #ffffff;
  --bs-ink: #1a2420;
  --bs-muted: #5c6b62;
  --bs-primary: #1f3d2b;
  --bs-primary-contrast: #ffffff;
  --bs-border: #d5ddd6;
  --bs-success: #1b7a3d;
  --bs-danger: #b42318;
  --bs-warning: #a15c00;
  --bs-radius: 5px;
  --bs-radius-sm: 4px;
  --bs-radius-lg: 6px;
  --bs-font: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
}

body {
  font-family: var(--bs-font);
  background: var(--bs-canvas);
  color: var(--bs-ink);
}

.navbar-brand {
  font-family: var(--bs-font);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--bs-primary-contrast) !important;
}

.navbar.bg-dark,
.navbar.bg-primary,
.navbar-bhumisah {
  background: var(--bs-primary) !important;
}

.navbar .nav-link {
  color: rgba(255, 255, 255, 0.9);
}

.navbar .nav-link:hover,
.navbar .nav-link:focus {
  color: var(--bs-primary-contrast);
}

.navbar .dropdown-menu {
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius);
  box-shadow: none;
  background: var(--bs-surface);
}

.navbar .dropdown-item {
  color: var(--bs-ink);
}

.navbar .dropdown-item:hover,
.navbar .dropdown-item:focus {
  background: var(--bs-canvas);
  color: var(--bs-ink);
}

.container.py-3 {
  max-width: 1100px;
}

.page-title {
  margin-bottom: 0.25rem;
  color: var(--bs-ink);
  font-weight: 700;
}

.party-context,
.org-context {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.65rem;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.3;
}

.party-context-label,
.org-context-label {
  color: var(--bs-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
}

.party-context-name,
.org-context-name {
  color: var(--bs-primary);
  font-weight: 600;
  text-decoration: none;
}

.party-context-name:hover,
.party-context-name:focus,
.org-context-name:hover,
.org-context-name:focus {
  color: #163022;
  text-decoration: underline;
}

.user-context {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.65rem;
  margin-bottom: 0.35rem;
  font-size: 0.95rem;
  line-height: 1.35;
}

.user-context-label {
  color: var(--bs-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
}

.user-context-email {
  color: var(--bs-ink);
  font-weight: 650;
}

.user-context-name {
  color: var(--bs-muted);
}

.user-context-name::before {
  content: "·";
  margin-right: 0.65rem;
  color: var(--bs-border);
}

.perm-summary {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.perm-summary-label {
  color: var(--bs-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
}

.perm-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.badge-perm {
  background: #e8f0eb;
  color: var(--bs-primary);
  border: 1px solid #c5d5cb;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.35em 0.65em;
}

.perm-add-form form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
}

.perm-add-form .form-group {
  margin-bottom: 0;
  flex: 1 1 240px;
  max-width: 420px;
}

.perm-add-form label {
  font-weight: 600;
  color: var(--bs-ink);
  margin-bottom: 0.25rem;
}

.perm-add-form input[type="submit"],
.perm-add-form .btn {
  margin-bottom: 0;
}

.col-meta {
  color: var(--bs-muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

.page-sub {
  color: var(--bs-muted);
  margin-bottom: 1.25rem;
}

.metric-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.metric-card {
  flex: 1 1 160px;
  background: var(--bs-surface);
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius);
  padding: 0.9rem 1rem;
}

.metric-card .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--bs-muted);
  letter-spacing: 0.04em;
}

.metric-card .value {
  font-size: 1.25rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--bs-ink);
}

.metric-card.good .value { color: var(--bs-success); }
.metric-card.bad .value { color: var(--bs-danger); }
.metric-card.warn .value { color: var(--bs-warning); }

.table {
  background: var(--bs-surface);
  color: var(--bs-ink);
}

.table thead th {
  background: var(--bs-canvas);
  border-bottom: 1px solid var(--bs-border);
  color: var(--bs-ink);
  font-weight: 600;
}

.table td,
.table th {
  border-color: var(--bs-border);
  vertical-align: middle;
}

.table-responsive-bs {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.toolbar .nav-link {
  color: var(--bs-primary);
  border-radius: var(--bs-radius-sm);
}

.toolbar .nav-link.active {
  background: var(--bs-primary);
  color: var(--bs-primary-contrast);
}

.hub-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.hub-tabs .hub-tabs-secondary {
  margin-left: 1.25rem;
}

.project-context {
  background: var(--bs-surface);
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.project-context .page-title {
  margin-bottom: 0.25rem;
}

.project-context .page-sub {
  margin-bottom: 0;
}

.badge-state {
  font-size: 0.85rem;
}

.form-card,
.content-card {
  background: var(--bs-surface);
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.btn-primary,
.btn-bhumisah {
  background: var(--bs-primary);
  border-color: var(--bs-primary);
  color: var(--bs-primary-contrast);
  border-radius: var(--bs-radius-sm);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-bhumisah:hover,
.btn-bhumisah:focus {
  background: #183024;
  border-color: #183024;
  color: var(--bs-primary-contrast);
}

.btn-secondary {
  background: var(--bs-canvas);
  border: 1px solid var(--bs-border);
  color: var(--bs-ink);
  border-radius: var(--bs-radius-sm);
}

.btn-danger {
  background: var(--bs-danger);
  border-color: var(--bs-danger);
}

.btn-success {
  background: var(--bs-success);
  border-color: var(--bs-success);
}

.form-control,
.custom-select,
.form-control:focus {
  border-color: var(--bs-border);
  border-radius: var(--bs-radius-sm);
  color: var(--bs-ink);
}

.form-control:focus {
  box-shadow: 0 0 0 0.15rem rgba(31, 61, 43, 0.15);
}

.party-search .form-control {
  min-width: 16rem;
  max-width: 24rem;
}

.party-search .custom-select {
  width: auto;
  min-width: 9rem;
}

.owner-admin-card {
  border-left: 3px solid var(--bs-primary);
}

/* web2py field validation errors */
.error_wrapper {
  display: block;
  margin-top: 0.35rem;
}

.error,
div.error {
  color: var(--bs-danger);
  font-size: 0.9rem;
  font-weight: 600;
  display: block;
}

input.invalidinput,
select.invalidinput,
textarea.invalidinput,
.form-control.invalidinput,
.custom-select.invalidinput {
  border-color: var(--bs-danger) !important;
  background-color: #fdf2f1;
}

input.invalidinput:focus,
select.invalidinput:focus,
textarea.invalidinput:focus,
.form-control.invalidinput:focus {
  border-color: var(--bs-danger) !important;
  box-shadow: 0 0 0 0.15rem rgba(180, 35, 24, 0.2);
}

.alert-success { border-color: var(--bs-success); color: var(--bs-success); }
.alert-danger { border-color: var(--bs-danger); color: var(--bs-danger); }
.alert-warning { border-color: var(--bs-warning); color: var(--bs-warning); }

.empty-state {
  color: var(--bs-muted);
  padding: 1.5rem 0;
}

.kyc-file-row {
  display: block;
  width: 100%;
  clear: both;
  overflow: hidden;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--bs-border);
}

.kyc-file-row:last-child {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

.file-preview {
  margin-bottom: 0.75rem;
  overflow: hidden;
  position: relative;
}

.file-preview-thumb {
  display: inline-block;
  width: 200px;
  height: 140px;
  padding: 0;
  margin: 0;
  overflow: hidden;
  vertical-align: top;
  cursor: zoom-in;
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius-lg);
  background: var(--bs-canvas);
}

.file-preview-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.file-preview-hint {
  font-size: 0.8rem;
  color: var(--bs-muted);
  margin-top: 0.35rem;
}

.payment-proof-preview .file-preview-thumb {
  width: min(100%, 520px);
  height: 360px;
}
.payment-proof-preview .file-preview-pdf-thumb .file-preview-pdf {
  width: 100%;
  height: 100%;
}

.file-preview-pdf-thumb {
  position: relative;
}

.file-preview-pdf-thumb .file-preview-pdf {
  position: absolute;
  top: 0;
  left: 0;
  width: 800px;
  height: 560px;
  min-height: 0;
  border: 0;
  transform: scale(0.25);
  transform-origin: top left;
  pointer-events: none;
  background: var(--bs-surface);
}

.zoom-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 36, 32, 0.92);
  z-index: 3000;
  overflow: auto;
  padding: 1.5rem;
}

.zoom-overlay.open { display: block; }

.zoom-overlay-inner {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.zoom-overlay img {
  max-width: min(96vw, 1400px);
  height: auto;
  transform: scale(var(--zoom, 1));
  transform-origin: top center;
  cursor: grab;
}

.zoom-overlay-pdf {
  width: min(96vw, 1100px);
  height: 85vh;
  border: 0;
  background: var(--bs-surface);
  border-radius: var(--bs-radius-lg);
}

.zoom-overlay-tools {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.zoom-overlay-tools button {
  background: var(--bs-surface);
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius-sm);
  padding: 0.35rem 0.7rem;
  font-weight: 600;
  color: var(--bs-ink);
}

.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 36, 32, 0.55);
  z-index: 3100;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.confirm-overlay.open { display: flex; }

.confirm-dialog {
  background: var(--bs-surface);
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius);
  padding: 1.25rem 1.4rem;
  max-width: 28rem;
  width: 100%;
  box-shadow: none;
}

.confirm-dialog p {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  color: var(--bs-ink);
}

.confirm-tools {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.confirm-tools button {
  border: 0;
  border-radius: var(--bs-radius-sm);
  padding: 0.4rem 0.85rem;
  font-weight: 600;
}

#confirm-no {
  background: var(--bs-canvas);
  color: var(--bs-ink);
  border: 1px solid var(--bs-border);
}

#confirm-yes {
  background: var(--bs-primary);
  color: var(--bs-primary-contrast);
}

.project-map {
  width: 100%;
  height: 360px;
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius-lg);
  overflow: hidden;
  background: var(--bs-canvas);
}

.project-map iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.money,
.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* Responsive: collapsing navbar already uses Bootstrap; tighten helpers */
@media (max-width: 767.98px) {
  .container.py-3 {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .metric-card {
    flex: 1 1 100%;
  }

  .form-card,
  .content-card {
    padding: 1rem;
  }

  .hub-tabs .nav-link,
  .toolbar .nav-link {
    font-size: 0.9rem;
  }

  .form-card .form-group,
  .form-card .form-row > [class*="col-"] {
    margin-bottom: 0.75rem;
  }

  .table-responsive-bs,
  .table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
  }

  .navbar-collapse {
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
  }
}

@media (min-width: 768px) and (max-width: 991.98px) {
  .metric-card {
    flex: 1 1 200px;
  }
}

/* Icon action buttons (Settings lists, row actions) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  line-height: 1;
}
.btn-icon .bi {
  font-size: 1rem;
  line-height: 1;
}
.btn-icon-lg {
  width: 2.35rem;
  height: 2.35rem;
}
.btn-icon-lg .bi {
  font-size: 1.1rem;
}
.btn-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
/* Keep edit/delete (and other row icons) on one line in tables */
.table .btn-actions {
  flex-wrap: nowrap;
  white-space: nowrap;
}
.table td.text-right {
  white-space: nowrap;
  width: 1%;
}
.project-context {
  margin-bottom: 1rem;
}
.project-context .page-title {
  font-size: 1.75rem;
}
.hub-section-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--bs-ink, #1a2420);
  margin: 0 0 0.25rem;
}
.hub-tabs {
  margin-bottom: 1rem;
}

/* Searchable party picker (Tom Select) on project actor tabs */
.ts-wrapper.js-party-search,
.ts-wrapper.form-control,
.form-card .ts-wrapper,
.content-card .ts-wrapper {
  padding: 0;
  height: auto;
  border: none;
  background: transparent;
  box-shadow: none;
}
.ts-wrapper .ts-control {
  border: 1px solid var(--bs-border, #d5ddd6);
  border-radius: 4px;
  min-height: 2.25rem;
  padding: 0.25rem 0.5rem;
  background: var(--bs-surface, #fff);
  color: var(--bs-ink, #1a2420);
  font-family: inherit;
}
.ts-wrapper.focus .ts-control {
  border-color: var(--bs-primary, #1f3d2b);
  box-shadow: 0 0 0 0.15rem rgba(31, 61, 43, 0.15);
}
.ts-dropdown {
  border: 1px solid var(--bs-border, #d5ddd6);
  border-radius: 4px;
  box-shadow: none;
  font-family: inherit;
  z-index: 2000;
}
.ts-dropdown .option.active,
.ts-dropdown .option:hover {
  background: var(--bs-canvas, #f5f7f6);
  color: var(--bs-ink, #1a2420);
}
.ts-dropdown .no-results {
  padding: 0.5rem 0.75rem;
  color: var(--bs-muted, #5c6b62);
}

/* Sortable table headers (documents, parties, …) */
.doc-table td {
  vertical-align: middle;
}
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable::after {
  content: ' ↕';
  opacity: 0.35;
  font-size: 0.75em;
}
th.sortable.asc::after {
  content: ' ↑';
  opacity: 0.8;
}
th.sortable.desc::after {
  content: ' ↓';
  opacity: 0.8;
}
.doc-table-thumb .file-preview {
  margin: 0;
}
.doc-table-thumb .file-preview-hint {
  display: none;
}
.doc-table-thumb .file-preview-thumb {
  display: block;
  width: 10rem;
  height: 12.5rem;
  overflow: hidden;
  border: 1px solid var(--bs-border, #d5ddd6);
  border-radius: 4px;
  background: var(--bs-canvas, #f5f7f6);
  position: relative;
}
.doc-table-thumb .file-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  border: 0;
}
/* Scale PDF page so the first page fills the thumb box */
.doc-table-thumb .file-preview-pdf-thumb .file-preview-pdf {
  position: absolute;
  top: 0;
  left: 0;
  width: 500%;
  height: 500%;
  min-height: 0;
  border: 0;
  transform: scale(0.2);
  transform-origin: top left;
  pointer-events: none;
  background: var(--bs-surface, #fff);
}

/* Flatpickr above cards / Tom Select dropdowns */
.flatpickr-calendar {
  z-index: 1100;
}
input.js-date {
  max-width: 12rem;
}

/* ----- SQLFORM.grid (Accounts and any future grids) ----- */
.accounts-grid-card {
  padding: 0.85rem 1rem 1rem;
  overflow: visible;
}

.web2py_grid {
  background: transparent;
  border: 0;
  padding: 0;
  font-family: var(--bs-font);
  font-size: 0.9375rem;
  color: var(--bs-ink);
}

.web2py_grid .web2py_console {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.75rem;
  background: var(--bs-canvas);
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius-sm);
}

.web2py_grid .web2py_console form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}

.web2py_grid .web2py_console input[type="text"],
.web2py_grid .web2py_console select {
  height: calc(1.5em + 0.65rem + 2px);
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius-sm);
  background: var(--bs-surface);
  color: var(--bs-ink);
  font-size: 0.9rem;
  min-width: 10rem;
}

.web2py_grid .web2py_console input[type="submit"],
.web2py_grid .web2py_console input[type="button"],
.web2py_grid .web2py_console button,
.web2py_grid .web2py_console a.btn,
.web2py_grid .w2p_export_menu a,
.web2py_grid a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: calc(1.5em + 0.65rem + 2px);
  padding: 0.3rem 0.75rem !important;
  border-radius: var(--bs-radius-sm);
  border: 1px solid var(--bs-border);
  background: var(--bs-surface);
  color: var(--bs-ink);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  box-shadow: none;
}

.web2py_grid .web2py_console input[type="submit"]:hover,
.web2py_grid .web2py_console a.btn:hover,
.web2py_grid .w2p_export_menu a:hover,
.web2py_grid a.button:hover {
  background: var(--bs-canvas);
  border-color: var(--bs-primary);
  color: var(--bs-primary);
  text-decoration: none;
}

.web2py_grid .w2p_export_menu {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin: 0;
}

.web2py_grid .w2p_export_menu a {
  background: var(--bs-primary);
  border-color: var(--bs-primary);
  color: var(--bs-primary-contrast) !important;
}

.web2py_grid .w2p_export_menu a:hover {
  background: #183024;
  border-color: #183024;
  color: var(--bs-primary-contrast) !important;
}

.web2py_table,
.web2py_htmltable {
  clear: both;
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius-sm);
  background: var(--bs-surface);
}

.web2py_grid table {
  width: max-content !important;
  min-width: 100%;
  margin: 0;
  table-layout: auto;
  border-collapse: separate;
  border-spacing: 0;
}

.web2py_grid thead th,
.web2py_grid tbody td {
  padding: 0.55rem 0.75rem;
  white-space: nowrap;
  vertical-align: middle;
  border-bottom: 1px solid var(--bs-border);
  font-size: 0.9rem;
}

.web2py_grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bs-primary) !important;
  color: var(--bs-primary-contrast);
  font-weight: 600;
  border-bottom: 0;
  letter-spacing: 0.01em;
}

.web2py_grid thead th a {
  color: var(--bs-primary-contrast) !important;
  text-decoration: none;
}

.web2py_grid thead th a:hover {
  text-decoration: underline;
}

.web2py_grid tbody tr.odd td,
.web2py_grid tr.odd {
  background: #fafcfb;
}

.web2py_grid tbody tr.even td,
.web2py_grid tr.even {
  background: var(--bs-surface);
}

.web2py_grid tbody tr:hover td,
.web2py_grid tr:hover {
  background: #eef3ef !important;
}

.web2py_grid tbody tr:last-child td {
  border-bottom: 0;
}

.web2py_paginator,
.web2py_counter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.35rem 0.15rem;
  font-size: 0.85rem;
  color: var(--bs-muted);
}

.web2py_paginator a,
.web2py_paginator span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.85rem;
  height: 1.85rem;
  padding: 0 0.4rem;
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-radius-sm);
  background: var(--bs-surface);
  color: var(--bs-ink);
  text-decoration: none;
}

.web2py_paginator a:hover {
  border-color: var(--bs-primary);
  color: var(--bs-primary);
}

.web2py_paginator .current,
.web2py_paginator span.current {
  background: var(--bs-primary);
  border-color: var(--bs-primary);
  color: var(--bs-primary-contrast);
}

.web2py_grid .web2py_breadcrumbs {
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  color: var(--bs-muted);
}

