/* Madini – mobile-first app styles (Bootstrap 5 companion) */
:root {
  --brand: #0f766e;
  --brand-rgb: 15, 118, 110;
  --bottom-nav-h: 64px;
  --radius: 14px;
  --surface: #ffffff;
  --page-bg: #f4f6f8;
  --muted-border: rgba(0, 0, 0, .07);
}
[data-bs-theme="dark"] { --surface: #1c2127; --page-bg: #12161a; --muted-border: rgba(255, 255, 255, .08); }

html, body { max-width: 100%; overflow-x: hidden; }
body { background: var(--page-bg); font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body.has-bottom-nav { padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 8px); }
@media (min-width: 992px) { body.has-bottom-nav { padding-bottom: 0; } }

img, canvas, video, table { max-width: 100%; }
.text-brand { color: var(--brand) !important; }
.bg-brand { background: var(--brand) !important; color: #fff; }
.btn-brand { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-color: #fff;
  --bs-btn-hover-bg: color-mix(in srgb, var(--brand) 85%, #000); --bs-btn-hover-border-color: color-mix(in srgb, var(--brand) 85%, #000);
  --bs-btn-hover-color: #fff; --bs-btn-active-bg: color-mix(in srgb, var(--brand) 75%, #000); --bs-btn-active-color: #fff; }
.btn-outline-brand { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand);
  --bs-btn-hover-color: #fff; --bs-btn-hover-border-color: var(--brand); --bs-btn-active-bg: var(--brand); --bs-btn-active-color: #fff; }
.text-bg-orange { background: #fd7e14 !important; color: #fff !important; }
.text-orange { color: #fd7e14 !important; }

/* Cards */
.app-card { background: var(--surface); border: 1px solid var(--muted-border); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.app-card > .card-header, .app-card .app-card-header { background: transparent; border-bottom: 1px solid var(--muted-border); padding: .75rem 1rem; font-weight: 600; }
.app-card .card-body { padding: 1rem; }
@media (max-width: 575.98px) { .app-card .card-body { padding: .85rem; } main.container-xxl { padding-left: 12px !important; padding-right: 12px !important; } }
.kpi { padding: .9rem 1rem; }
.kpi .kpi-value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }
.kpi .kpi-label { font-size: .78rem; color: var(--bs-secondary-color); text-transform: uppercase; letter-spacing: .04em; }
.kpi-icon { width: 42px; height: 42px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.2rem;
  background: rgba(var(--brand-rgb), .1); color: var(--brand); }
.page-title { font-weight: 700; font-size: 1.35rem; margin: 0; }
.section-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--bs-secondary-color); font-weight: 600; }

/* Touch-friendly controls */
.btn, .form-control, .form-select { min-height: 44px; }
.btn-sm, .form-control-sm, .form-select-sm { min-height: 36px; }
.form-control-color { min-height: 44px; width: 64px; }
.tap-row { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-bottom: 1px solid var(--muted-border); text-decoration: none; color: inherit; }
.tap-row:last-child { border-bottom: 0; }
.tap-row:active { background: rgba(var(--brand-rgb), .06); }
.avatar { width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
  background: rgba(var(--brand-rgb), .12); color: var(--brand); flex-shrink: 0; }
.min-w-0 { min-width: 0; }

/* Top navbar */
.app-navbar { background: var(--surface); border-bottom: 1px solid var(--muted-border); }
.app-navbar .nav-link { font-weight: 500; border-radius: 10px; padding: .5rem .8rem !important; }
.app-navbar .nav-link.active { background: rgba(var(--brand-rgb), .1); color: var(--brand); }
.brand-logo { height: 34px; width: auto; border-radius: 8px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; }

/* Bottom navigation (native-app feel) */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--muted-border);
  display: flex; justify-content: space-around; align-items: stretch; box-shadow: 0 -4px 16px rgba(0,0,0,.05); }
.bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .68rem; color: var(--bs-secondary-color); text-decoration: none; font-weight: 500; }
.bottom-nav a i { font-size: 1.3rem; }
.bottom-nav a.active { color: var(--brand); }
.bottom-nav .fab { position: relative; top: -18px; flex: 0 0 auto; width: 60px; height: 60px; border-radius: 50%; background: var(--brand);
  color: #fff; box-shadow: 0 6px 18px rgba(var(--brand-rgb), .45); border: 4px solid var(--page-bg); }
.bottom-nav .fab i { font-size: 1.5rem; }

/* Maps */
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; }
.map { height: 380px; width: 100%; z-index: 1; }
.map-lg { height: 460px; }
@media (max-width: 575.98px) { .map { height: 300px; } .map-lg { height: 340px; } }
.map-legend { position: absolute; right: 10px; bottom: 22px; z-index: 500; background: rgba(255,255,255,.92); color: #222; border-radius: 10px;
  padding: 6px 10px; font-size: .72rem; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.legend-ramp { width: 120px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #2c7bb6, #abd9e9, #ffffbf, #fdae61, #d7191c); }
.target-marker { background: #111; color: #fff; border: 2px solid #fff; border-radius: 50%; width: 26px; height: 26px; display: flex;
  align-items: center; justify-content: center; font-size: .72rem; font-weight: 700; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.target-marker.prio-A { background: #d7191c; } .target-marker.prio-B { background: #f28e2b; } .target-marker.prio-C { background: #4e79a7; }

/* Score gauge */
.gauge { --val: 0; --col: var(--brand); width: 132px; height: 132px; border-radius: 50%;
  background: conic-gradient(var(--col) calc(var(--val) * 1%), rgba(0,0,0,.08) 0); display: grid; place-items: center; margin: 0 auto; }
.gauge::before { content: ""; grid-area: 1/1; width: 104px; height: 104px; border-radius: 50%; background: var(--surface); }
.gauge > span { grid-area: 1/1; z-index: 1; font-size: 1.8rem; font-weight: 800; }
.bar { height: 8px; border-radius: 4px; background: rgba(0,0,0,.07); overflow: hidden; }
.bar > div { height: 100%; border-radius: 4px; background: var(--brand); }

/* Deposit model selector */
.deposit-option { display: block; cursor: pointer; border: 2px solid var(--muted-border); border-radius: var(--radius); padding: .8rem; height: 100%;
  background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.btn-check:checked + .deposit-option { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(var(--brand-rgb), .15); }
.deposit-icon { width: 38px; height: 38px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 1.1rem; }
.swiper { width: 100%; }
.swiper-slide { height: auto; }
.swiper-pagination-bullet-active { background: var(--brand) !important; }
.swiper-padded { padding-bottom: 28px !important; }

/* HTMX states */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }
.run-overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(10, 20, 25, .55); display: none; align-items: center; justify-content: center; }
.run-overlay.htmx-request { display: flex; }
.htmx-swapping { opacity: .3; transition: opacity .2s; }
.htmx-added { animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.flash-saved { animation: flash 1.2s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(25,135,84,.5); } 100% { box-shadow: 0 0 0 14px rgba(25,135,84,0); } }

/* Toasts above bottom nav */
.toast-stack { position: fixed; z-index: 2100; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottom-nav-h) + 16px); width: min(420px, calc(100% - 24px)); }
@media (min-width: 992px) { .toast-stack { left: auto; right: 20px; transform: none; bottom: 20px; } }

/* Modal forms: <form> wraps header/body/footer, keep the scrollable-dialog layout working */
.modal-content > form { display: flex; flex-direction: column; min-height: 0; max-height: 100%; overflow: hidden; }
.modal-content > form > .modal-body { overflow-y: auto; }

/* Modal as bottom sheet on phones */
@media (max-width: 575.98px) {
  .modal-sheet .modal-dialog { margin: 0; position: fixed; bottom: 0; left: 0; right: 0; max-width: 100%; }
  .modal-sheet .modal-content { border-radius: 20px 20px 0 0; max-height: 92vh; }
  .modal-sheet.fade .modal-dialog { transform: translateY(100%); }
  .modal-sheet.show .modal-dialog { transform: none; }
}

/* Tables */
.table-compact td, .table-compact th { padding: .5rem .6rem; font-size: .88rem; vertical-align: middle; }
.table-responsive { -webkit-overflow-scrolling: touch; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: rgba(var(--brand-rgb), .1); color: var(--brand); }
.mode-live { background: rgba(25,135,84,.12); color: #198754; }
.mode-local { background: rgba(13,110,253,.12); color: #0d6efd; }
.mode-synthetic, .mode-fallback { background: rgba(253,126,20,.15); color: #c35a00; }
.mode-missing, .mode-disabled { background: rgba(108,117,125,.15); color: #6c757d; }
.mode-context { background: rgba(111,66,193,.12); color: #6f42c1; }

/* Landing */
.hero { background: radial-gradient(1200px 500px at 10% -10%, rgba(var(--brand-rgb), .35), transparent),
  linear-gradient(135deg, #0b1f24 0%, #12343b 60%, #1b4d4f 100%); color: #fff; border-radius: 0 0 28px 28px; }
.hero .lead { color: rgba(255,255,255,.8); }
.hero-badge { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); color: #fff; border-radius: 999px; padding: .35rem .8rem; font-size: .8rem; }
.feature-icon { width: 52px; height: 52px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.4rem;
  background: rgba(var(--brand-rgb), .1); color: var(--brand); }
.step-num { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }

/* Sortable blueprint */
.bp-item { cursor: grab; }
.bp-item.dragging { opacity: .5; }

/* Report */
.report-paper { background: #fff; color: #1d2329; border-radius: var(--radius); }
.report-paper h2 { font-size: 1.15rem; font-weight: 700; border-bottom: 2px solid var(--accent, var(--brand)); padding-bottom: .35rem; margin-top: 1.6rem; color: var(--accent, var(--brand)); }
.report-paper .report-cover { border-left: 6px solid var(--accent, var(--brand)); }
.report-paper table { font-size: .85rem; }
.report-paper .disclaimer-box { background: #fff8e6; border: 1px solid #f3d27a; border-radius: 10px; padding: .9rem; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff !important; padding: 0 !important; }
  .no-print, .bottom-nav, .app-navbar, footer, .toast-stack { display: none !important; }
  .report-paper { box-shadow: none !important; border: 0 !important; padding: 0 !important; }
  .report-paper section { page-break-inside: avoid; }
  a[href]:after { content: none !important; }
}

/* ===== New-analysis wizard ===== */
.wiz-stepper { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--muted-border);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; position: sticky; top: 62px; z-index: 20;
  box-shadow: 0 2px 10px rgba(0,0,0,.04); scroll-margin-top: 70px; }
.wiz-step { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 4px 6px; border-radius: 10px;
  color: var(--bs-secondary-color); font-weight: 600; font-size: .85rem; white-space: nowrap; min-height: 40px; }
.wiz-step:hover { background: rgba(var(--brand-rgb), .06); }
.wiz-dot { width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--muted-border); background: var(--surface); font-size: .8rem; transition: all .2s; flex-shrink: 0; }
.wiz-step.current { color: var(--brand); }
.wiz-step.current .wiz-dot { border-color: var(--brand); background: var(--brand); color: #fff; box-shadow: 0 0 0 4px rgba(var(--brand-rgb), .15); }
.wiz-step.done { color: var(--bs-body-color); }
.wiz-step.done .wiz-dot { border-color: #198754; background: #198754; color: transparent; position: relative; }
.wiz-step.done .wiz-dot::after { content: "\F26E"; font-family: "bootstrap-icons"; color: #fff; position: absolute; font-size: .95rem; }
.wiz-line { flex: 1; height: 2px; background: var(--muted-border); min-width: 10px; }
@media (max-width: 575.98px) {
  .wiz-stepper { top: 56px; padding: 8px 10px; }
  .wiz-step .wiz-label { display: none; }
  .wiz-step.current .wiz-label { display: inline; }
}
.wiz-pane { display: none; }
.wiz-pane.active { display: block; animation: wizIn .28s ease; }
@keyframes wizIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
.wiz-shake { animation: wizShake .35s; }
@keyframes wizShake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }
.wiz-map { height: 440px; }
@media (max-width: 575.98px) { .wiz-map { height: 52vh; min-height: 300px; } }

.aoi-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.aoi-tabs::-webkit-scrollbar { display: none; }
.aoi-tab { flex: 1 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 1px solid var(--muted-border);
  background: var(--surface); border-radius: 12px; padding: 8px 10px; font-size: .75rem; font-weight: 600; color: var(--bs-secondary-color);
  min-width: 74px; transition: all .15s; }
.aoi-tab i { font-size: 1.15rem; }
.aoi-tab.active { border-color: var(--brand); color: var(--brand); background: rgba(var(--brand-rgb), .07); box-shadow: inset 0 -3px 0 var(--brand); }
.aoi-summary { background: rgba(25,135,84,.07); border: 1px solid rgba(25,135,84,.25); border-radius: 12px; padding: 10px 12px; }
.wiz-drop { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; cursor: pointer;
  border: 2px dashed var(--muted-border); border-radius: 14px; padding: 22px 14px; background: var(--page-bg); transition: all .15s; margin: 0; }
.wiz-drop:hover, .wiz-drop.over { border-color: var(--brand); background: rgba(var(--brand-rgb), .06); }

.wiz-chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--muted-border); background: var(--surface);
  border-radius: 999px; padding: 4px 12px 4px 4px; font-size: .82rem; font-weight: 500; min-height: 36px; }
.wiz-chip:hover { border-color: var(--brand); }
.wiz-models { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
@media (max-width: 575.98px) { .wiz-models { grid-template-columns: 1fr 1fr; } }

.wiz-summary { position: sticky; top: 140px; }
.wiz-sum-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0;
  border-bottom: 1px solid var(--muted-border); padding: 11px 16px; color: inherit; }
.wiz-sum-row:hover { background: rgba(var(--brand-rgb), .05); }
.wiz-sum-row > i:first-child { font-size: 1.1rem; }
.wiz-review .wiz-sum-row { border: 1px solid var(--muted-border); border-radius: 12px; margin-bottom: 8px; }

.wiz-actions { position: sticky; bottom: 12px; z-index: 25; margin-top: 14px; display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--muted-border); border-radius: 16px; padding: 10px 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.12); }
.wiz-actions .btn { min-width: 52px; }
.wiz-progress { flex: 1; min-width: 0; text-align: center; }
.wiz-progress .bar { height: 5px; border-radius: 3px; background: rgba(0,0,0,.08); margin-top: 4px; overflow: hidden; }
.wiz-progress .bar > div { height: 100%; background: var(--brand); transition: width .3s ease; }
#wiz-next { min-width: 110px; }
#wiz-next.wiz-ready { box-shadow: 0 0 0 0 rgba(var(--brand-rgb), .5); animation: wizPulse 1.8s infinite; }
@keyframes wizPulse { 70% { box-shadow: 0 0 0 10px rgba(var(--brand-rgb), 0); } 100% { box-shadow: 0 0 0 0 rgba(var(--brand-rgb), 0); } }
@media (max-width: 991.98px) {
  .wiz-actions { position: fixed; left: 10px; right: 10px; bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 10px); margin: 0; }
  body.wiz-page main { padding-bottom: 96px !important; }
  body.wiz-page .toast-stack { bottom: calc(var(--bottom-nav-h) + 90px); }
}

@media (max-width: 575.98px) {
  .aoi-tab { flex: 1 1 0; min-width: 0; padding: 7px 2px; font-size: .68rem; }
  .aoi-tabs { gap: 4px; }
  .app-navbar .navbar-brand span.fw-bold { max-width: 38vw !important; }
}

/* Tanzania licence boundaries strip (under the analysis map) */
.licence-strip { padding: 10px 16px; border-bottom: 1px solid var(--muted-border); background: rgba(var(--brand-rgb), .03); }
.lic-flag { display: inline-block; width: 18px; height: 12px; margin-right: 6px; vertical-align: -1px; border-radius: 2px;
  background: linear-gradient(153deg, #1eb53a 0 38%, #fcd116 38% 42%, #000 42% 58%, #fcd116 58% 62%, #00a3dd 62%); }
.lic-type { --c: #999; padding: 2px 9px; min-height: 28px; font-size: .72rem; font-weight: 700; border: 1px solid var(--c); color: var(--c); background: transparent; }
.btn-check:checked + .lic-type { background: var(--c); color: #fff; }
.lic-pl { --c: #ff9f1c; } .lic-pml { --c: #e63946; } .lic-ml { --c: #7209b7; } .lic-sml { --c: #3a86ff; }
.lic-tip { font-weight: 600; font-size: .72rem; }

/* Find a licence (madini.ai-style lookup) */
.find-lic-label { display: block; font-size: .68rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--bs-secondary-color); margin-bottom: 4px; }
.find-lic-result { margin-top: 12px; padding: 12px; border-radius: 12px; border: 1px solid rgba(var(--brand-rgb), .3);
  background: rgba(var(--brand-rgb), .05); animation: wizIn .25s ease; }
.find-lic-result .find-lic-label { font-family: Consolas, monospace; letter-spacing: .08em; color: var(--brand); }
