:root {
  --sidebar-w: 256px;
  --sidebar-bg: #14263b;
  --sidebar-fg: #cbd5e1;
  --sidebar-active: #2563a8;
  --page-bg: #f3f5f8;
}

body { background: var(--page-bg); }
.min-w-0 { min-width: 0; }

/* ---- login pages ---- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 430px; border: 0; }
.auth-card.wide { max-width: 760px; }
.auth-logo { width: 56px; height: 56px; border-radius: 14px; background: var(--sidebar-active); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 1.7rem; margin-bottom: .5rem; }
.auth-logo-img { width: 132px; height: 132px; border-radius: 18px; object-fit: cover; margin-bottom: .75rem; box-shadow: 0 2px 8px rgba(0, 0, 0, .18); }
.brand-logo { width: 40px; height: 40px; border-radius: 9px; object-fit: cover; flex-shrink: 0; }
.otp-input { letter-spacing: .5em; }

/* ---- panel shell ---- */
.sidebar-inner { background: var(--sidebar-bg); color: var(--sidebar-fg); min-height: 100%; width: 100%; display: flex; flex-direction: column; }
.sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.1rem; color: #fff; }
.sidebar .nav-link { color: var(--sidebar-fg); border-radius: .45rem; padding: .55rem .8rem; display: flex; align-items: center; gap: .65rem; margin-bottom: 2px; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar .nav-link.active { background: var(--sidebar-active); color: #fff; }
.sidebar .nav-link.sub { padding-left: 2.6rem; font-size: .94rem; }
.sidebar .nav-link .chevron { transition: transform .15s; }
.sidebar .nav-link.collapsed .chevron { transform: rotate(-90deg); }
.sidebar.offcanvas-lg { --bs-offcanvas-width: var(--sidebar-w); }
@media (min-width: 992px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: var(--sidebar-w); overflow-y: auto; }
  .main { margin-left: var(--sidebar-w); }
}
.topbar { background: #fff; border-bottom: 1px solid #e2e6ec; position: sticky; top: 0; z-index: 1020; min-height: 56px; }
.card { border-color: #e2e6ec; }
.tile-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; }
.chart-box { position: relative; height: 280px; }
/* Dashboard tiles: icon and figure on one line, label underneath. The figure shrinks rather than wraps. */
.tile-value { font-size: clamp(1rem, 1.35vw, 1.3rem); line-height: 1.2; min-width: 0; white-space: nowrap; }
.card-body > .d-flex > .tile-icon { width: 40px; height: 40px; font-size: 1.15rem; border-radius: 10px; }
/* Phones: two narrow tiles per row, so the icon gets smaller and a very long figure may wrap instead of being cut off. */
@media (max-width: 575.98px) { .tile-value { font-size: .95rem; white-space: normal; overflow-wrap: anywhere; } .card-body > .d-flex > .tile-icon { width: 26px; height: 26px; font-size: .85rem; border-radius: 7px; } }

/* ---- popups and the right-side view ---- */
.modal-content > form.modal-form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.modal-content > form.modal-form > .modal-body { overflow-y: auto; }
.drawer { --bs-offcanvas-width: min(780px, 100vw); }

/* Add / edit / delete popups slide in from the right, the same way the view panel does. */
#app-modal .modal-dialog { position: fixed; top: 0; right: 0; bottom: 0; margin: 0; height: 100%; max-width: none; width: min(760px, 100vw);
  transform: translateX(100%); transition: transform .25s ease-out; }
#app-modal.show .modal-dialog { transform: none; }
#app-modal .modal-dialog.modal-md { width: min(520px, 100vw); }
#app-modal .modal-dialog.modal-lg { width: min(760px, 100vw); }
#app-modal .modal-dialog.modal-xl { width: min(1080px, 100vw); }
#app-modal .modal-content { height: 100%; border: 0; border-radius: 0; }
#app-modal .modal-header { background: #f6f8fb; }
#app-modal .modal-title, .drawer .offcanvas-title { font-weight: 700; }
@media (prefers-reduced-motion: reduce) { #app-modal .modal-dialog { transition: none; } }

/* View panel sections */
.detail-section { margin-bottom: 1.25rem; }
.detail-section-title { font-weight: 700; font-size: .95rem; color: #0f2a47; background: #eef3f9; border-left: 4px solid var(--sidebar-active);
  padding: .45rem .7rem; margin: 0 0 .25rem; border-radius: .25rem; }
.detail-list dt { font-weight: 500; color: #5b6676; }
.detail-list dd { font-weight: 500; color: #111827; }

/* Searchable dropdowns */
.ts-dropdown { z-index: 2100; }
.ts-wrapper.form-select, .ts-wrapper.form-control { padding: 0; }
.ts-wrapper .ts-control { min-height: calc(1.5em + .75rem + 2px); }
.was-validated .ts-wrapper.invalid .ts-control, .ts-wrapper.is-invalid .ts-control { border-color: #dc3545; }
.ts-dropdown .option .sub { color: #6c757d; font-size: .82em; }
.detail-list dt, .detail-list dd { padding-top: .35rem; padding-bottom: .35rem; margin-bottom: 0; border-bottom: 1px solid #f0f2f5; }
.history li { padding: .5rem 0 .5rem .9rem; border-left: 2px solid #d5dbe3; margin-left: .3rem; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }

/* ---- plot map ---- */
.plot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: .5rem; }
.plot-tile { border: 1px solid #b9c2cf; border-radius: .5rem; padding: .5rem .25rem; display: flex; flex-direction: column; align-items: center; color: #1b1f24; line-height: 1.2; min-height: 58px; justify-content: center; }
.plot-tile:hover, .plot-tile:focus { outline: 2px solid var(--sidebar-active); }
.legend-dot { display: inline-block; width: 14px; height: 14px; border: 1px solid #b9c2cf; border-radius: 3px; vertical-align: -2px; }

/* ---- step-by-step forms ---- */
.wizard-pills { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .25rem; }
.wizard-pill { border: 1px solid #cfd6df; background: #fff; border-radius: 2rem; padding: .35rem .9rem; white-space: nowrap; color: #55606e; }
.wizard-pill .num { display: inline-flex; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: #e7ebf0; align-items: center; justify-content: center; margin-right: .35rem; font-size: .85rem; }
.wizard-pill.active { border-color: var(--sidebar-active); color: var(--sidebar-active); font-weight: 600; }
.wizard-pill.active .num { background: var(--sidebar-active); color: #fff; }
.wizard-pill.done .num { background: #16a34a; color: #fff; }
.review-list dt { color: #6c757d; font-weight: 400; }

/* ---- sponsor tree ---- */
.tree ul { list-style: none; padding-left: 1.25rem; margin: 0; border-left: 2px solid #d5dbe3; }
.tree > ul { border-left: 0; padding-left: 0; }
.tree li { padding: .3rem 0 .3rem .6rem; }
.tree-node { display: inline-flex; align-items: center; gap: .6rem; background: #fff; border: 1px solid #dfe4ea; border-radius: .5rem; padding: .4rem .7rem; max-width: 100%; }
.tree-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* ---- uploaded files: picture or PDF tile, and the preview under an upload box ---- */
.file-tile { display: inline-flex; flex-direction: column; align-items: center; gap: .2rem; text-decoration: none; color: #334155; }
.file-tile img, .file-tile-doc { width: 96px; height: 72px; border-radius: .4rem; border: 1px solid #d5dbe3; background: #eef1f5; object-fit: cover; }
.file-tile.lg img, .file-tile.lg .file-tile-doc { width: 150px; height: 112px; }
.file-tile-doc { display: flex; flex-direction: column; align-items: center; justify-content: center; color: #b42318; font-size: .7rem; font-weight: 600; }
.file-tile-doc i { font-size: 1.6rem; line-height: 1; }
.file-tile-label { font-size: .78rem; max-width: 150px; text-align: center; }
.file-tile:hover img, .file-tile:hover .file-tile-doc { outline: 2px solid var(--sidebar-active); }
.file-preview-new, .file-preview-current { display: flex; align-items: center; gap: .75rem; margin-top: .5rem; }
.file-preview-new[hidden] { display: none; }
.file-preview-current.replaced { opacity: .45; }

/* ---- "add more" rows, project pages ---- */
.formset-row { border: 1px solid #dfe4ea; border-radius: .5rem; padding: .75rem .9rem .1rem; margin-bottom: .75rem; background: #fbfcfe; }
.formset-row-title { font-weight: 600; color: #0f2a47; }
.project-logo { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; border: 1px solid #dfe4ea; }
.project-cover { width: 100%; max-height: 340px; object-fit: cover; border-radius: .6rem; border: 1px solid #dfe4ea; }
.amenity-chip { background: #eef6ee; color: #14532d; border: 1px solid #cfe6cf; border-radius: 2rem; padding: .25rem .7rem; font-size: .9rem; }
.project-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; }
.project-gallery-item { display: block; text-decoration: none; color: #334155; font-size: .85rem; }
.project-gallery-item img { width: 100%; height: 140px; object-fit: cover; border-radius: .5rem; border: 1px solid #dfe4ea; display: block; margin-bottom: .25rem; }
.rich-editor { background: #fff; }
.rich-editor.ql-container { height: auto; }   /* the editor grows with its text instead of spilling over the next field */
.rich-editor .ql-editor { min-height: 220px; font-size: 1rem; }
.ql-toolbar.ql-snow { border-radius: .375rem .375rem 0 0; } .ql-container.ql-snow { border-radius: 0 0 .375rem .375rem; }

/* ---- lists ---- */
.thumb { width: 64px; height: 48px; object-fit: cover; border-radius: .35rem; border: 1px solid #dfe4ea; background: #eef1f5; }
.detail-list .thumb { width: 120px; height: 90px; }
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover { text-decoration: underline; }
#list-body.htmx-request { opacity: .55; transition: opacity .15s; }
.permission-grid th[scope=row] { min-width: 190px; }
.settings-nav { position: sticky; top: 72px; }

@media (max-width: 767.98px) {
  /* Tables become cards on phones: each cell shows its column name. */
  .list-table thead { display: none; }
  .list-table, .list-table tbody, .list-table tr, .list-table td { display: block; width: 100%; }
  .list-table tr { border-bottom: 8px solid var(--page-bg); padding: .4rem 0; }
  .list-table td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .3rem .9rem; text-align: right; }
  .list-table td::before { content: attr(data-label); font-weight: 600; color: #6c757d; text-align: left; flex-shrink: 0; }
  .list-table td.row-actions { justify-content: flex-end; padding-top: .5rem; }
  .list-table td.row-actions::before { content: none; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; white-space: nowrap; }
  .settings-nav .list-group-item { border-width: 1px; width: auto; }
}

/* "add more" lists: empty state */
.formset-empty { border: 1px dashed #cfd6df; border-radius: .5rem; padding: .9rem 1rem; margin-bottom: .75rem; color: #6c757d; font-size: .875rem; background: #fbfcfe; }

/* tab bars on record pages: wrap on a computer, slide sideways on a phone */
@media (max-width: 767.98px) {
  .tabs-scroll { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .tabs-scroll::-webkit-scrollbar { display: none; }
  .tabs-scroll .nav-link { white-space: nowrap; }
}

/* installed app: keep clear of the phone's notch and home bar */
.standalone-app .topbar { padding-top: env(safe-area-inset-top); }
.standalone-app .content { padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
