/* FFM v1.3 — UI consistency layer. Loaded last, after mobile.css.
   One focus style, one set of radii/shadows, one emergency entry point, calmer tables and forms. */
:root{
  --ffm-radius:14px; --ffm-radius-sm:10px;
  --ffm-shadow:0 1px 2px rgba(15,26,43,.05),0 4px 14px rgba(15,26,43,.05);
  --ffm-focus:#2f6fa8;
}

/* ---------- one focus style (brand blue; was orange, heavy on text fields) ---------- */
:where(a,button,input,select,textarea,summary,[tabindex]):focus-visible{
  outline:2px solid var(--ffm-focus)!important;outline-offset:2px!important;box-shadow:none!important;
}
.form-control:focus,.form-select:focus,.ffm-chips-select .chips-input:focus-within{
  border-color:var(--ffm-focus)!important;box-shadow:0 0 0 3px rgba(47,111,168,.16)!important;outline:none!important;
}
.ffm-skip{position:absolute;left:.6rem;top:-60px;z-index:20001;background:#0f1a2b;color:#fff;padding:.5rem .8rem;border-radius:8px;text-decoration:none}
.ffm-skip:focus{top:.6rem}

/* ---------- app shell ---------- */
.app-sidebar{box-shadow:none}                       /* the old shadow bled in from off-screen on phones */
.app-sidebar.mobile-open{box-shadow:0 0 40px rgba(0,0,0,.35)}
.app-header .ffm-brand-text strong{max-width:none;font-size:1rem}
@media (min-width:901px){
  .app-header .ffm-brand-text strong{max-width:260px}
  .ffm-fab-emergency{display:none!important}         /* desktop already has the banner — one entry point, not two */
}
.ffm-emergency-bar{padding:.35rem 1.2rem}
#save-btn.needs-save{background:var(--ffm-primary,#245c88);border-color:var(--ffm-primary,#245c88);color:#fff}
#save-btn.needs-save:hover{filter:brightness(1.08)}

/* ---------- cards, KPI tiles, tables share one look ---------- */
.card,.ffm-table-wrap,.widget,.kpi-card{border-radius:var(--ffm-radius)}
.app-main>.row{max-width:none}                       /* bootstrap's negative gutter was being clamped, leaving a lopsided right margin */
.ffm-view-options>summary{display:none}
.ffm-view-options{border-bottom:1px solid var(--ffm-border,#e3e9f1)}
.ffm-view-options .ffm-table-toolbar{border-bottom:0}
.ffm-table tbody tr:hover td{background:#f7f9fc}
.row-actions button{border-radius:8px}
.row-actions button:hover{background:#eef3f9}
.row-actions button.del:hover{background:#fdecea;color:#c4554a}
.empty-state{padding:2.2rem 1rem}

/* ---------- tree ---------- */
.tree-link{stroke-width:2}
.tree-node rect{stroke-width:1.8}
.tree-node text{font-size:16px;font-weight:600}
.tree-node.leaf text{font-size:14px;font-weight:500}
.tree-node.dim{opacity:.55}
.tree-node.root text{font-size:17px}

/* ---------- standalone pages (landing / create / open): footer always at the bottom ---------- */
/* Landing/create/open: let the browser window scroll (not a nested 100%-high body), so phone toolbars collapse and printing/capture get the whole page */
html:not(:has(.app-shell)),body:not(:has(.app-shell)){height:auto;min-height:100%;overflow-x:clip;overflow-y:visible}
body:not(:has(.app-shell)){min-height:100vh;min-height:100dvh;display:flex;flex-direction:column}
body:not(:has(.app-shell))>footer{margin-top:auto}

/* ---------- phones ---------- */
@media (max-width:900px){
  .ffm-emergency-bar{display:none}                    /* the round Emergency button stays; the banner only ate a quarter of the screen */
  .app-main>.row{margin-left:calc(var(--bs-gutter-x,1rem)*-.5);margin-right:calc(var(--bs-gutter-x,1rem)*-.5)}
}
@media (max-width:768px){
  .widget .kpi{font-size:clamp(1.3rem,6vw,1.55rem)!important;line-height:1.15;overflow-wrap:normal}
  .widget h6{font-size:.7rem}

  /* list pages: search on its own row, Export + Add New side by side */
  .page-actions{display:grid!important;grid-template-columns:auto 1fr;gap:.5rem;width:100%}
  .page-actions .search-mini{grid-column:1/-1}
  .page-actions .btn{width:100%}
  .page-actions #m-export{width:auto;padding-left:1rem;padding-right:1rem}
  /* sort / group / rows live behind one tidy disclosure */
  .ffm-view-options>summary{display:flex;align-items:center;gap:.5rem;padding:.7rem 1rem;font-weight:600;font-size:.9rem;cursor:pointer;list-style:none;min-height:44px}
  .ffm-view-options>summary::-webkit-details-marker{display:none}
  .ffm-view-options>summary::after{content:"\F282";font-family:"bootstrap-icons";margin-left:auto;font-size:.8rem;transition:transform .2s}
  .ffm-view-options[open]>summary::after{transform:rotate(180deg)}
  .ffm-table-toolbar{flex-direction:column;align-items:stretch;gap:.6rem}
  .ffm-table-toolbar .left,.ffm-table-toolbar .right{display:grid;grid-template-columns:auto 1fr;gap:.4rem .6rem;align-items:center;width:100%}
  .ffm-table-toolbar .left label.ms-2{margin-left:0!important}
  .ffm-table-toolbar select{width:100%}

  /* Emergency Mode header: title on top, three clear buttons below */
  .emg-header{display:grid!important;grid-template-columns:repeat(3,1fr);align-items:center;gap:.6rem;padding:.9rem}
  .emg-header>i{display:none}
  .emg-header>div:first-of-type{grid-column:1/-1}
  .emg-header .btn-label{display:inline!important}
  .emg-header .btn{width:100%;justify-content:center;gap:.35rem}
  .emg-grid{padding:0!important}
  .emg-header .ffm-save-status{grid-column:1/-1;justify-self:start}
  .emg-header .ffm-save-status .st-text{display:inline}
  .ffm-table tbody td[data-label="Actions"]::before{display:none}
  .ffm-table tbody td[data-label="Actions"] .row-actions{justify-content:space-between;width:100%}
}
@media (max-width:480px){
  .page-header h1{font-size:1.25rem}
  .app-header .ffm-brand-mark{max-width:36vw}
}

/* ---------- brand mark: logo + name, no tagline ---------- */
.ffm-brand-mark .ffm-brand-text small{display:none!important}
.navbar .ffm-brand-mark,.ffm-topbar .ffm-brand-mark{gap:.65rem;align-items:center}
.navbar .ffm-brand-mark img{height:40px;width:40px;border-radius:10px;padding:0;box-shadow:0 1px 3px rgba(15,26,43,.12)}
.navbar .ffm-brand-mark .ffm-brand-text strong{font-size:1.15rem;font-weight:700;letter-spacing:-.005em;line-height:1.2;white-space:nowrap}
@media (max-width:480px){ .navbar .ffm-brand-mark img{height:34px;width:34px} .navbar .ffm-brand-mark .ffm-brand-text strong{font-size:1.02rem} }

/* ---------- footer link ---------- */
.ffm-powered{color:#fff!important;font-weight:700;text-decoration:none;border-bottom:1px dotted rgba(255,255,255,.55)}
.ffm-powered:hover{border-bottom-style:solid}

/* ---------- file picker (drop zone) ---------- */
.ffm-drop{position:relative;border:2px dashed #b9c9dc;border-radius:var(--ffm-radius);background:#f7faff;transition:border-color .15s,background .15s,box-shadow .15s}
.ffm-drop:hover{border-color:var(--ffm-focus);background:#f0f6fd}
.ffm-drop.drag{border-color:var(--ffm-focus);background:#e8f1fb;box-shadow:0 0 0 4px rgba(47,111,168,.14)}
.ffm-drop:focus-within{border-color:var(--ffm-focus);box-shadow:0 0 0 3px rgba(47,111,168,.2)}
.ffm-drop.has-file{border-style:solid;border-color:#2e8a78;background:#f1faf7}
.ffm-drop-input{position:absolute;inset:0;width:100%;height:100%;opacity:0;cursor:pointer;z-index:2;font-size:0}
.ffm-drop-ui{display:flex;align-items:center;gap:1rem;padding:1.1rem 1.2rem;min-height:84px}
.ffm-drop-icon{flex:0 0 auto;width:48px;height:48px;border-radius:12px;background:#e3edf8;color:#245c88;display:flex;align-items:center;justify-content:center;font-size:1.5rem}
.ffm-drop.has-file .ffm-drop-icon{background:#d7f0e8;color:#1f7a66}
.ffm-drop-text{display:flex;flex-direction:column;min-width:0;flex:1}
.ffm-drop-text strong{font-size:1rem;color:#1a2233;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ffm-drop-text small{color:#536579;font-size:.84rem}
.ffm-drop-btn{flex:0 0 auto;background:#245c88;color:#fff;border-radius:10px;padding:.5rem 1rem;font-weight:600;font-size:.9rem}
.ffm-drop:hover .ffm-drop-btn{filter:brightness(1.08)}
@media (max-width:480px){ .ffm-drop-btn{display:none} .ffm-drop-ui{padding:1rem} }

/* open page: the chosen file name is already shown inside the drop zone — keep the text for screen readers only */
#drop-zone + #file-name{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
@media (max-width:600px){
  #open-btn,#open-btn + .btn{width:100%}
  #open-btn{margin-bottom:.5rem}
}

/* closing logo: never wider than the screen */
.ffm-endlogo{width:100%;max-width:420px;height:auto;border-radius:var(--ffm-radius)}

/* footer: tidy wrapping on narrow screens — each item stays on one line */
.ffm-site-footer-inner{display:flex;flex-wrap:wrap;justify-content:center;align-items:center;column-gap:.3rem;row-gap:.3rem}
.ffm-site-footer-inner>span,.ffm-site-footer-inner>a{white-space:nowrap}
@media (max-width:600px){ .ffm-site-footer-inner .sep{display:none} .ffm-site-footer-inner>span,.ffm-site-footer-inner>a{padding:0 .4rem} }

/* ================= v1.3.2 ================= */
/* --- Save / Download status + buttons --- */
.ffm-save-status.saved{color:#1f4f7a;background:#e8f1fb;border:1px solid #b9d2ea;padding:.2rem .55rem;border-radius:999px;font-weight:600}
.ffm-save-status.saved .bi{color:#2f6fa8}
.ffm-save-status.clean .bi{color:#2e8a78}
.btn[aria-disabled="true"]{opacity:.45;cursor:not-allowed;filter:grayscale(.3)}
.btn[aria-disabled="true"]:hover{filter:grayscale(.3)}
#download-btn.needs-save{background:var(--ffm-primary,#245c88);border-color:var(--ffm-primary,#245c88);color:#fff}

/* --- global search: shorter, actions stay on the right --- */
@media (min-width:901px){
  .app-header .ffm-search-wrap-wide{flex:0 1 340px!important;max-width:340px!important;width:auto}
  .app-header .header-actions{margin-left:auto}
}

/* --- sidebar brand: big logo, name on three lines --- */
.side-brand{display:flex;align-items:center;gap:.85rem;padding:1.1rem 1rem 1rem}
.side-brand img{width:56px;height:56px;border-radius:14px;background:#fff;padding:3px;flex:0 0 auto;object-fit:contain}
.side-brand .name{font-size:1.2rem;font-weight:700;line-height:1.15;letter-spacing:.005em;color:#fff}
.collapsed .side-brand{justify-content:center;padding:.9rem .4rem}
.collapsed .side-brand img{width:44px;height:44px}
.collapsed .side-brand .name{display:none}

/* --- footer links readable on the light in-app footer (and the dark one) --- */
.app-footer a{color:#245c88!important}
.app-footer a:hover{color:#0f3d63!important;text-decoration:underline}
.app-footer .ffm-powered{color:#245c88!important;border-bottom:1px dotted #245c88;font-weight:700}
.app-footer .ffm-powered:hover{color:#0f3d63!important;border-bottom-style:solid;text-decoration:none}
.ffm-site-footer a:hover{color:#fff!important;text-decoration:underline}
.ffm-site-footer .ffm-powered{color:#fff!important}

/* --- Emergency Mode: print-only blocks hidden on screen --- */
.emg-print-head,.emg-print-foot{display:none}

@media (max-width:768px){
  .emg-header{grid-template-columns:repeat(2,1fr)}
}

/* --- Emergency Mode: print layout (black on white, A4, one clean column, nothing interactive) --- */
@media print{
  /* page size, margins and the running header/footer now live in print.css */
  html,body{background:#fff!important;height:auto!important;overflow:visible!important}
  body{-webkit-print-color-adjust:exact;print-color-adjust:exact;color:#000;font-size:10.5pt}
  .emg-shell{background:#fff!important;min-height:0!important;padding:0!important}
  .emg-header,.emg-banner,.ffm-fab-emergency,#ffm-toast-host,#ffm-softlock,.no-print{display:none!important}
  .emg-print-head{display:block;border-bottom:2.5pt solid #000;padding-bottom:6pt;margin-bottom:10pt}
  .eph-title{font-size:19pt;font-weight:800;letter-spacing:-.01em}
  .eph-sub{font-size:9.5pt;color:#333;margin-top:2pt}
  .emg-grid{display:block!important;max-width:none!important;margin:0!important;padding:0!important}
  .emg-card{break-inside:avoid;page-break-inside:avoid;border:1pt solid #888!important;border-radius:6pt!important;box-shadow:none!important;background:#fff!important;padding:8pt 10pt!important;margin:0 0 9pt!important}
  .emg-card h5{break-after:avoid;page-break-after:avoid;font-size:12.5pt!important;margin:0 0 5pt!important;padding-bottom:4pt;border-bottom:1pt solid #bbb}
  .emg-card h5 .bi{display:none}
  .emg-step{break-inside:avoid;page-break-inside:avoid;padding:4pt 0!important;border-bottom:.5pt dashed #aaa!important;font-size:10.5pt}
  .emg-step .bi{display:none}
  .emg-step .meta{color:#222!important;font-size:9.5pt!important}
  .emg-step input[type=checkbox]{appearance:none;-webkit-appearance:none;width:11pt!important;height:11pt!important;border:1.2pt solid #000;border-radius:2pt;margin-top:2pt!important;position:relative;flex:0 0 auto}
  .emg-step input[type=checkbox]:checked::after{content:"✓";position:absolute;left:1pt;top:-3pt;font-size:11pt;font-weight:800}
  .badge-soft{background:none!important;color:#000!important;border:.75pt solid #666!important;padding:0 4pt!important}
  a{color:#000!important;text-decoration:none!important}
  .emg-print-foot{display:block;margin-top:10pt;padding-top:6pt;border-top:1.5pt solid #000;font-size:8.5pt;color:#222}
}

/* toasts sit at the bottom on phones so they never cover the header buttons */
@media (max-width:768px){
  #ffm-toast-host{top:auto!important;bottom:calc(env(safe-area-inset-bottom,0px) + 5.2rem)!important;align-items:stretch!important}
  #ffm-toast-host>div{max-width:none!important}
}


/* ================= v1.3.3 — usability refinement ================= */

/* Dashboard: concise cards and a scan-friendly upcoming list. */
.widget{height:auto;min-height:0;padding:.85rem 1rem}
.widget h6{margin-bottom:.55rem}
.widget .kpi{line-height:1.15}
.widget .guidance-card{padding:.7rem .8rem;margin-bottom:.5rem}
.timeline{padding-left:1.05rem}
.timeline:before{left:.38rem}
.timeline-item{padding:.2rem 0 .42rem}
.timeline-item:before{left:-.91rem;top:.52rem;width:8px;height:8px}
.timeline-item strong{font-size:.88rem;line-height:1.35}
.timeline-item small{display:block;font-size:.77rem;margin-top:.08rem}

/* Emergency Mode: allocate space according to content, not equal-width cards. */
.emg-grid{display:grid;grid-template-columns:repeat(12,minmax(0,1fr));align-items:start;gap:.85rem}
.emg-card{min-width:0;padding:.9rem 1rem}
.emg-card:nth-child(1){grid-column:span 7}
.emg-card:nth-child(2){grid-column:span 5}
.emg-card:nth-child(n+3){grid-column:span 6}
.emg-step{min-width:0;overflow-wrap:anywhere}
.emg-step>div{min-width:0}
.emg-step .meta{overflow-wrap:anywhere}
@media(max-width:899px){
  .emg-grid{grid-template-columns:minmax(0,1fr)}
  .emg-card:nth-child(n){grid-column:1}
}
@media(min-width:900px){
  .emg-card:nth-child(2) .emg-step{padding:.38rem 0}
}

/* Long navigation remains independently scrollable without adding a second page scrollbar. */
.app-sidebar{overscroll-behavior:contain;scrollbar-width:thin;scrollbar-color:rgba(205,220,240,.35) transparent}
.app-sidebar::-webkit-scrollbar{width:7px}
.app-sidebar::-webkit-scrollbar-thumb{background:rgba(205,220,240,.3);border-radius:99px}

/* Restore wizard: make the optional hint disclosure look secondary and purposeful. */
.ffm-hint-link{display:inline-flex;align-items:center;gap:.35rem;padding:.2rem 0}
#hint-row{margin-top:.45rem}
#hint-text{display:inline-block;color:#536579;overflow-wrap:anywhere}


/* Emergency print: use the paper width efficiently and allow long sections to flow. */
@media print{
  @page{size:A4 portrait;margin:11mm 11mm 13mm}
  html,body{height:auto!important;min-height:0!important;overflow:visible!important}
  body{font-size:9.5pt!important;line-height:1.32!important}
  .emg-shell{width:100%!important;min-height:0!important}
  .emg-print-head{margin-bottom:7pt!important;padding-bottom:5pt!important}
  .eph-title{font-size:17pt!important}
  .eph-sub{font-size:8.5pt!important}
  .emg-grid{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:6pt!important;
    margin:0!important;padding:0!important;
    max-width:none!important;
    align-items:start!important;
  }
  .emg-card:nth-child(n){grid-column:auto!important}
  .emg-card{
    min-width:0!important;
    margin:0!important;
    padding:6pt 7pt!important;
    border:.7pt solid #999!important;
    border-radius:4pt!important;
    box-shadow:none!important;
    break-inside:auto!important;
    page-break-inside:auto!important;
  }
  .emg-card h5{
    font-size:10.5pt!important;
    margin:0 0 4pt!important;
    padding-bottom:3pt!important;
    break-after:avoid-page!important;
    page-break-after:avoid!important;
  }
  .emg-step{
    padding:3pt 0!important;
    gap:5pt!important;
    font-size:9pt!important;
    line-height:1.25!important;
    break-inside:avoid-page!important;
    page-break-inside:avoid!important;
  }
  .emg-step .meta{font-size:8pt!important;line-height:1.25!important}
  .emg-print-foot{margin-top:7pt!important;padding-top:5pt!important;font-size:7.5pt!important}
  a{overflow-wrap:anywhere}
}


/* ================= v1.4.0 — reliability, clarity and accessibility ================= */
.ffm-save-status.session-warning{color:#8a4b08;background:#fff4df;border:1px solid #f1d49a}
.emg-freshness{font-size:.76rem;opacity:.9;margin-top:.25rem}
.emg-banner{align-items:flex-start}
.emg-banner strong{font-weight:700}
@media print{
  .emg-banner{display:block!important;padding:5pt 7pt!important;font-size:8.5pt!important}
  .emg-print-foot{border-top:1pt solid #8a8a8a!important;padding-top:6pt!important}
}
.form-label[for]{cursor:pointer}
:where(button,a,input,select,textarea,[tabindex]):focus-visible{outline:3px solid var(--ffm-focus)!important;outline-offset:2px!important}
@media(prefers-reduced-motion:reduce){
  *,*::before,*::after{scroll-behavior:auto!important;animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important}
}


/* Collapsible sidebar groups */
.app-sidebar .nav-section-toggle{
  width:100%;display:flex;align-items:center;justify-content:space-between;
  border:0;background:transparent;text-align:left;cursor:pointer;
  font:inherit;font-size:.7rem;text-transform:uppercase;letter-spacing:.08em;
  color:#7a8aa5;padding:.7rem 1rem .3rem;
}
.app-sidebar .nav-section-toggle:hover{color:#dce7f6}
.app-sidebar .nav-section-toggle .bi{font-size:.68rem;transition:transform .15s}
.app-sidebar .nav-section-toggle[aria-expanded="false"] .bi{transform:rotate(-90deg)}
.app-sidebar .nav-item[hidden]{display:none!important}

/* Documents & Folders v1.5.0 */
.ffm-folder-tree{margin:.75rem 0 0;padding:1rem;border-radius:.65rem;background:var(--bs-tertiary-bg);white-space:pre-wrap;overflow-wrap:anywhere;font-size:.82rem;line-height:1.55;color:var(--bs-body-color)}
#docs-records .list-group-item code{white-space:normal;overflow-wrap:anywhere;max-width:100%}
#docs-folder-confirmations .list-group-item{gap:.65rem}

/* Documents & Folders v1.5.0 */
.ffm-folder-tree{margin:.75rem 0 0;padding:1rem;border-radius:.65rem;background:var(--bs-tertiary-bg);white-space:pre-wrap;overflow-wrap:anywhere;font-size:.82rem;line-height:1.55;color:var(--bs-body-color)}
#docs-records .list-group-item code{white-space:normal;overflow-wrap:anywhere;max-width:100%}
#docs-folder-confirmations .list-group-item{gap:.65rem}
.ffm-custom-tree{list-style:none;padding-left:1rem;margin:.75rem 0 0}.ffm-custom-tree>li{margin:.35rem 0}.ffm-custom-tree ul{list-style:none;padding-left:1.35rem;border-left:1px solid var(--bs-border-color);margin:.2rem 0 .35rem .35rem}

/* Documents & Folders filing locations */
.ffm-folder-tree { white-space: pre-wrap; overflow-wrap: anywhere; margin: .75rem 0 0; font-size: .875rem; }
[data-doc-folder-panel] .form-control { overflow-wrap: anywhere; }
#docs-records code { white-space: normal; overflow-wrap: anywhere; }
