/* ==========================================================================
   Noor-e-Islam • নূর-ই-ইসলাম  (A Project of MKF)
   style.css — application SHELL styles
   --------------------------------------------------------------------------
   Scope: header, quick-settings panel, bottom navigation, page-view routing
   container, shared controls (buttons / segmented chips / select / sr-only).
   Every feature page injects its OWN scoped stylesheet under #mkf-* when it
   mounts, so this file only has to style the shell + shared chrome.
   Themes: light · dark · OLED (pure #000000) — driven by html[data-theme].
   ========================================================================== */

/* ---------- Theme tokens ---------- */
html {
  --shell-max: 900px;
  --header-h: 60px;
  --nav-h: 64px;
  --r: 14px;
  --r-sm: 10px;
  --font-ui: "Hind Siliguri", system-ui, -apple-system, "Segoe UI", Roboto,
             "Noto Sans Bengali", sans-serif;
  --font-head: "Noto Serif Bengali", Georgia, "Times New Roman", serif;
  --font-ar: "Amiri", "Noto Naskh Arabic", serif;
}

html[data-theme="dark"] {
  --bg: #060b12;
  --bg2: #0b1220;
  --surface: #0f1724;
  --surface2: #0b1220;
  --line: #263552;
  --ink: #e9eef9;
  --mut: #93a4c6;
  --gold: #e8c96b;
  --gold-dim: rgba(232, 201, 107, .14);
  --em: #2fd6a6;
  --em-dim: rgba(47, 214, 166, .13);
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

html[data-theme="light"] {
  --bg: #eef3ef;
  --bg2: #ffffff;
  --surface: #ffffff;
  --surface2: #eef3f1;
  --line: #d3ded6;
  --ink: #14231b;
  --mut: #5c6f63;
  --gold: #8a6a1c;
  --gold-dim: rgba(138, 106, 28, .12);
  --em: #0e9f6e;
  --em-dim: rgba(14, 159, 110, .12);
  --shadow: 0 8px 24px rgba(20, 35, 27, .10);
}

/* OLED = pure black #000000 surfaces (battery-friendly) */
html[data-theme="oled"] {
  --bg: #000000;
  --bg2: #000000;
  --surface: #000000;
  --surface2: #000000;
  --line: #161f2e;
  --ink: #e6ecf6;
  --mut: #93a4c6;
  --gold: #e8c96b;
  --gold-dim: rgba(232, 201, 107, .12);
  --em: #2fd6a6;
  --em-dim: rgba(47, 214, 166, .10);
  --shadow: 0 10px 30px rgba(0, 0, 0, .7);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .18s ease, color .18s ease;
}
h1, h2, h3 { font-family: var(--font-head); line-height: 1.35; }
a { color: var(--em); text-decoration: none; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--gold-dim); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.shell { width: 100%; max-width: var(--shell-max); margin: 0 auto; padding-left: 16px; padding-right: 16px; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 60;
  background: color-mix(in srgb, var(--bg2) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
html[data-theme="oled"] .app-header { background: #000; }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: var(--header-h); gap: 12px; }

.brand { display: flex; align-items: center; gap: 11px; color: var(--ink); min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  box-shadow: 0 0 0 1px var(--line);
}
.brand-name { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-name > span:first-child { font-weight: 700; font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-name .bn { font-family: var(--font-head); color: var(--gold); }
.brand-name .mkf {
  font-size: 10.5px; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--mut);
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; font-size: 1.15rem;
  transition: transform .12s ease, border-color .15s ease;
}
.icon-btn:hover { border-color: var(--gold); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.is-active { border-color: var(--gold); background: var(--gold-dim); }

/* ---------- Quick settings panel ---------- */
.quick-panel {
  position: absolute; top: calc(var(--header-h) + 8px); right: 16px;
  width: min(340px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 12px 14px 10px;
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: opacity .16s ease, transform .16s ease, visibility .16s;
  z-index: 80;
}
.quick-panel.open { opacity: 1; visibility: visible; transform: translateY(0); }
html[data-theme="oled"] .quick-panel { background: #05070c; }
.qp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.qp-head b { font-size: 14.5px; }
.qp-head .icon-btn { width: 32px; height: 32px; font-size: 1.25rem; border: 0; background: transparent; }
.qp-block { padding: 8px 0; border-top: 1px dashed var(--line); }
.qp-block:first-of-type { border-top: 0; }
.qp-label { display: block; font-size: 11px; color: var(--mut); font-weight: 600; margin: 2px 0 6px; }
.qp-note { display: block; font-size: 10.5px; color: var(--mut); margin-top: 6px; }
.qp-select {
  width: 100%; padding: 9px 10px; font-size: 13.5px; color: var(--ink);
  background: var(--surface2); border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; font-family: inherit;
}
.qp-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-top: 9px; margin-top: 4px; border-top: 1px dashed var(--line);
  font-size: 10.5px; color: var(--mut);
}

/* ---------- Segmented chips (shared) ---------- */
.seg-group { display: flex; flex-wrap: wrap; gap: 7px; }
.seg-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; font-size: 13px; font-weight: 600; cursor: pointer;
  color: var(--ink); background: var(--surface2);
  border: 1px solid var(--line); border-radius: 999px;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.seg-btn:hover { border-color: var(--gold); }
.seg-btn.is-on {
  background: var(--em-dim); border-color: var(--em); color: var(--em);
}
html[data-theme="light"] .seg-btn.is-on { color: var(--em); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; border-radius: 11px; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface2); color: var(--ink);
  cursor: pointer; text-decoration: none; font-family: inherit;
  transition: transform .12s ease, border-color .15s ease, background .15s ease;
}
.btn:hover { border-color: var(--gold); }
.btn:active { transform: scale(.97); }
.btn-gold { background: var(--gold-dim); border-color: var(--gold); color: var(--gold); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ---------- Main router container ---------- */
.app-body { padding-top: 18px; padding-bottom: calc(var(--nav-h) + 30px); }
.stacked-views { display: contents; }

.page-view { display: none; }
.page-view.is-active { display: block; animation: viewIn .22s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Bottom navigation ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  background: color-mix(in srgb, var(--bg2) 90%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
html[data-theme="oled"] .bottom-nav { background: #000; }
.nav-inner {
  display: grid; grid-template-columns: repeat(6, 1fr);
  height: calc(var(--nav-h) - env(safe-area-inset-bottom, 0px));
  max-width: var(--shell-max);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 10.5px; font-weight: 600; color: var(--mut);
  -webkit-tap-highlight-color: transparent;
  transition: color .15s ease;
}
.nav-item .nav-ico { font-size: 20px; line-height: 1; filter: grayscale(.35); transition: transform .12s ease, filter .15s ease; }
.nav-item.is-active { color: var(--gold); }
.nav-item.is-active .nav-ico { filter: none; transform: translateY(-1px); }


/* ==========================================================================
   MOBILE HARDENING — viewport bounds · safe areas · fluid cards · touch sizes
   Overrides page-injected feature styles via explicit ancestor selectors so
   nothing bleeds off 320–480px displays (Noor-e-Islam supports edge-to-edge
   phones, iOS standalone PWAs and OLED panels).
   ========================================================================== */

/* 1. Viewport bounds — never a horizontal page pan / rubber-band */
html, body { overflow-x: hidden; width: 100%; max-width: 100vw; }
body { position: relative; overflow-wrap: break-word; }
main, .shell { min-width: 0; max-width: 100%; }
img, picture, video, canvas, table, pre, svg { max-width: 100%; }
.page-view { width: 100%; max-width: 100%; overflow-wrap: break-word; }
.page-view.is-active, .page-view > * { min-width: 0; }

/* 2. Notch / home-indicator safe areas (needs viewport-fit=cover in index.html) */
.app-header { padding-top: env(safe-area-inset-top, 0px); }
.quick-panel { top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 8px); }
.app-body { padding-bottom: calc(75px + env(safe-area-inset-bottom, 0px)); }
.bottom-nav { padding-bottom: env(safe-area-inset-bottom, 0px); }
.nav-inner { height: calc(var(--nav-h) - env(safe-area-inset-bottom, 0px)); }

/* 3. Touch targets — 48×48 minimums, no accidental text selection (WCAG 2.5.5) */
button, [role="button"], .nav-item, .seg-btn, .icon-btn, .btn {
  min-height: 48px;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.nav-item { min-width: 48px; }
.qp-select, .mkf-sel, .qp-foot .btn { min-height: 48px; }

/* 4. Fluid cards / controls — width 100%, box-sizing border-box, wrap-safe */
body #mkf-dash .d1-grid,
body #mkf-dash .dash-tools,
body #mkf-zakat .z-nisab,
body #mkf-zakat .z-rates,
body #mkf-zakat .z-grid,
body #mkf-qibla .q-locgrid,
body #mkf-settings .st-opts,
body #mkf-settings .cal-bar { width: 100%; }

body #mkf-dash .mkf-card,
body #mkf-zakat .z-nisab-card,
body #mkf-zakat .z-field,
body #mkf-zakat .z-result,
body #mkf-qibla .q-stat,
body #mkf-qibla .q-field,
body #mkf-qibla .q-off,
body #mkf-settings .st-card,
body #mkf-settings .st-sec {
  width: 100%; min-width: 0; box-sizing: border-box; padding: 12px 14px;
}

/* flex rows never push the page wider than the viewport */
body #mkf-dash .mkf-cdrow,
body #mkf-dash .s2-row,
body #mkf-qibla .q-offrow,
body #mkf-zakat .z-row { flex-wrap: wrap; min-width: 0; }
body #mkf-dash .mkf-next-name,
body #mkf-dash .mkf-next-t,
body #mkf-dash .mkf-next-cd,
body #mkf-dash .pt-name,
body #mkf-dash .pt-time,
body #mkf-dash .pt-j,
body #mkf-zakat .z-big,
body #mkf-zakat .z-due-big { overflow-wrap: anywhere; min-width: 0; }

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
  .brand-name .mkf { display: none; }
  .brand-name > span:first-child { font-size: 15px; }
}
/* 320–480px phones: form controls ≥16px (no iOS auto-zoom), tighter grids */
@media (max-width: 480px) {
  .shell { padding-left: 12px; padding-right: 12px; }
  input, select, textarea { font-size: 16px; }
  body #mkf-dash .pt-head, body #mkf-dash .pt-row {
    grid-template-columns: 1fr auto auto 10px; gap: 6px; padding-left: 8px; padding-right: 8px;
  }
  body #mkf-dash .pt-head { padding-bottom: 8px; }
  body #mkf-dash .mkf-clock { font-size: 38px; }
  body #mkf-qibla .q-stats { grid-template-columns: 1fr; }
  body #mkf-settings .st-opts { flex-direction: column; align-items: stretch; }
  body #mkf-settings .st-opt { width: 100%; }
}
@media (max-width: 380px) {
  body #mkf-dash .pt-jl { display: none; }
  body #mkf-dash .pt-row { grid-template-columns: 1fr auto 10px; gap: 5px; }
}



/* ==========================================================================
   ULTIMATE ARCHITECTURE FIX — 2026-09-04
   (a) Guidance tab active-highlight hard guarantee (Bug 1)
   (b) Exclusive page sub-tabs need a real display:none for [hidden]
   (c) Portrait-mobile calendar grid: shrink-to-viewport, no overflow (Bug 3)
   All rules are additive & terminal (end of file) so they always win the
   cascade against page-injected feature styles.
   ========================================================================== */

/* ---- hidden attribute is honoured even inside display:grid/flex blocks ---- */
[hidden] { display: none !important; }

/* ---- Bug 3: absolute viewport containment for portrait phones ------------ */
html, body, #app-router, main, .page-container, .shell, .page-view {
  width: 100% !important;
  max-width: 100vw !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
}
#app-router, .stacked-views, .page-view, .page-view.is-active,
.page-view > *, #mkf-dash, #mkf-quran, #mkf-zakat, #mkf-guide,
#mkf-qibla, #mkf-settings { max-width: 100%; min-width: 0; }

/* ---- Bug 3: calendar grids — 7 fluid columns that can never overflow ----- */
.calendar-grid, .cal-grid,
body #mkf-dash #mkf-cal {
  display: grid !important;
  grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  gap: 2px !important;
  overflow: hidden !important;
}
.calendar-day-cell, .cal-day,
body #mkf-dash .cal-cell {
  min-width: 0 !important;          /* CRITICAL: cells may shrink in portrait */
  box-sizing: border-box !important;
  overflow: hidden !important;
}
.calendar-day-cell {
  padding: 4px 1px !important;
  font-size: 0.7rem !important;
  text-align: center !important;
  word-break: break-word !important;
  overflow-wrap: anywhere !important;
}
body #mkf-dash #mkf-cal { padding-left: 6px !important; padding-right: 6px !important; }
body #mkf-dash .cal-wd { min-width: 0; text-align: center; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis; }
body #mkf-dash .cal-cell { min-height: 48px; padding: 3px 1px !important;
  text-align: center !important; word-break: break-word !important;
  overflow-wrap: anywhere !important; border-radius: 8px; }
body #mkf-dash .cal-cell > * { min-width: 0; max-width: 100%; }

/* ---- Bug 1: guidance chip active marker — strict, theme-token backed ----- */
.guidance-tab-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #a0aec0;
  transition: all 0.25s ease;
}
.guidance-tab-btn.active {
  background: rgba(16, 185, 129, 0.18) !important;
  border: 1.5px solid #10b981 !important;
  color: #ffffff !important;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.35) !important;
}
/* real shipped classes the app renders — same guarantee, all three themes */
body #mkf-guide .g-chip { transition: all 0.25s ease; }
body #mkf-guide .g-chip.is-on,
body #mkf-guide .g-chip[aria-pressed="true"] {
  background: var(--accDim) !important;
  border-color: var(--acc) !important;
  color: var(--acc) !important;
  font-weight: 700 !important;
  box-shadow: 0 0 0 1px var(--acc) inset, 0 0 12px var(--accDim) !important;
}

/* ---- Portrait 480px: calendar day/header density (directive exact) ------- */
@media (max-width: 480px) {
  .calendar-day-cell span { display: block; font-size: 0.65rem; line-height: 1.2; }
  .calendar-header-cell { font-size: 0.7rem !important; padding: 2px !important; }
  body #mkf-dash #mkf-cal { gap: 1px; padding-left: 4px !important; padding-right: 4px !important; }
  body #mkf-dash .cal-wd { font-size: 0.7rem !important; padding: 2px 0 !important; }
  body #mkf-dash .cal-cell { min-height: 44px; padding: 2px 1px !important; font-size: 0.72rem; }
  body #mkf-dash .cal-cell small, body #mkf-dash .cal-cell .cal-hijri { font-size: 0.6rem; }
}
@media (max-width: 360px) {
  body #mkf-dash .cal-wd { font-size: 0.62rem !important; letter-spacing: 0; }
  body #mkf-dash .cal-cell { min-height: 40px; padding: 1px 0 !important; }
  .calendar-day-cell { padding: 1px 0 !important; }
}
/* ==========================================================================
   COMPASS LAYOUT REFLOW FIX — PART 1 (terminal overrides).
   The live compass widget (dial + status badges + device-orientation code)
   was removed from the Qibla page, so its chip-strip / GPU-dial rules are
   gone; the portrait calendar-grid overflow fix below remains in force.
   ========================================================================== */

/* ---------------------------------------------------------------------------
   Calendar grid overflow in portrait: 7 equal fluid columns whose cells
   are allowed to shrink (min-width:0) so a 320–480px portrait viewport
   never scrolls horizontally.
   --------------------------------------------------------------------------- */
.calendar-grid,
.cal-grid,
body #mkf-dash #mkf-cal {
  display: grid !important;
  grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  gap: 2px !important;
}
.calendar-day-cell,
.cal-day,
body #mkf-dash .cal-cell {
  min-width: 0 !important;          /* CRITICAL: allow cells to shrink */
  box-sizing: border-box !important;
}
.calendar-day-cell {
  padding: 4px 1px !important;
  font-size: 0.7rem !important;
  text-align: center !important;
  overflow: hidden !important;
  word-break: break-word !important;
  overflow-wrap: anywhere !important;
}
body #mkf-dash .cal-cell {
  min-height: 48px;
  text-align: center !important;
  overflow: hidden !important;
  word-break: break-word !important;
  overflow-wrap: anywhere !important;
}
