/* Formcrete Manuals - field stylesheet
   Accent color matches onboarding portal branding.
   Adjust --fc-accent below if the brand color differs. */

:root {
    --fc-dark: #2b2d31;
    --fc-darker: #1f2124;
    --fc-accent: #e8742c;
    --fc-light: #f4f4f2;
    --fc-border: #d8d8d4;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
    background: var(--fc-light);
    overscroll-behavior: none;
}

body { display: flex; flex-direction: column; height: 100vh; height: -webkit-fill-available; }

/* ---------- Top bar ---------- */
#topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    background: var(--fc-dark);
    color: #fff;
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top));
    gap: 10px;
    z-index: 50;
}

#topbar button {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 20px;
    padding: 8px 10px;
    cursor: pointer;
}

#brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
#brand img { height: 28px; }
#brand span { font-weight: 700; letter-spacing: 1px; font-size: 15px; }
#brand em { font-style: normal; color: var(--fc-accent); font-weight: 400; }

#searchwrap {
    flex: 1 1 auto;
    position: relative;
    display: flex;
    align-items: center;
    background: #3a3d42;
    border-radius: 6px;
    padding: 0 10px;
    max-width: 520px;
    margin: 0 auto;
}
#searchwrap .fa-search { color: #9a9da3; font-size: 14px; }
#txtSearch {
    flex: 1 1 auto;
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    font-size: 16px;
    padding: 9px 8px;
    min-width: 60px;
}
#txtSearch::placeholder { color: #9a9da3; }

#searchresults {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--fc-border);
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.25);
    max-height: 320px;
    overflow-y: auto;
    z-index: 100;
}
#searchresults .sr-item {
    display: block;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    color: #222;
    text-decoration: none;
    cursor: pointer;
}
#searchresults .sr-item:last-child { border-bottom: none; }
#searchresults .sr-item:hover, #searchresults .sr-item.active { background: #fdf0e7; }
#searchresults .sr-title { font-weight: 600; font-size: 14px; }
#searchresults .sr-title .fa { color: #c0392b; margin-right: 6px; }
#searchresults .sr-path { font-size: 11px; color: #888; margin-top: 2px; }
#searchresults .sr-none { padding: 12px; color: #888; font-size: 13px; }

/* ---------- Burger panel ---------- */
#burgerpanel {
    display: none;
    position: absolute;
    top: 52px;
    right: 8px;
    width: 290px;
    background: #fff;
    border: 1px solid var(--fc-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 90;
    padding: 12px;
}
#burgerpanel h4 { margin: 0 0 8px 0; font-size: 13px; color: #555; text-transform: uppercase; letter-spacing: 0.5px; }
#burgerpanel h4 .fa { color: var(--fc-accent); }
#recentlist { list-style: none; margin: 0 0 12px 0; padding: 0; }
#recentlist li { border-bottom: 1px solid #eee; }
#recentlist li a {
    display: block;
    padding: 10px 6px;
    color: #222;
    text-decoration: none;
    font-size: 14px;
}
#recentlist li a:hover { background: #fdf0e7; }
#recentlist li.empty { padding: 10px 6px; color: #999; font-size: 13px; }
#btnRequest {
    width: 100%;
    background: var(--fc-accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 11px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
#btnA2HS {
    width: 100%;
    margin-top: 8px;
    background: #fff;
    color: #2b2d31;
    border: 1px solid var(--fc-border);
    border-radius: 6px;
    padding: 11px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
#btnA2HS .fa { color: var(--fc-accent); }
#burgeruser { margin-top: 10px; font-size: 12px; color: #888; text-align: center; }

/* ---------- Layout ---------- */
#layout { flex: 1 1 auto; display: flex; min-height: 0; }

#sidebar {
    flex: 0 0 300px;
    background: #fff;
    border-right: 1px solid var(--fc-border);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: margin-left 0.2s ease;
}
#sidebar.collapsed { margin-left: -300px; }

#treewrap { padding: 8px 0; }

ul.ftree { list-style: none; margin: 0; padding: 0; }
ul.ftree ul { list-style: none; margin: 0; padding-left: 18px; }

ul.ftree li.folder > a.folder-toggle {
    display: block;
    padding: 10px 12px;
    color: #2b2d31;
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    border-bottom: 1px solid #f0f0ee;
}
ul.ftree li.folder > a .caret { font-size: 11px; width: 12px; color: #999; transition: transform 0.15s; }
ul.ftree li.folder.open > a .caret { transform: rotate(90deg); }
ul.ftree li.folder > a .fld { color: var(--fc-accent); }
ul.ftree li.folder > a .cnt {
    float: right;
    background: #eee;
    color: #777;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
}
ul.ftree li.folder > ul.children { display: none; }
ul.ftree li.folder.open > ul.children { display: block; }

ul.ftree li.manual a {
    display: block;
    padding: 9px 12px;
    color: #333;
    text-decoration: none;
    font-size: 14px;
    border-bottom: 1px solid #f5f5f3;
}
ul.ftree li.manual a .fa { color: #c0392b; margin-right: 4px; }
ul.ftree li.manual a.current { background: #fdf0e7; border-left: 3px solid var(--fc-accent); padding-left: 9px; }

/* ---------- Main / viewer ---------- */
#main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #8a8d92; }

#welcome {
    margin: auto;
    text-align: center;
    color: #f0f0ee;
    padding: 30px;
}
#welcome .fa { font-size: 56px; color: #d0d2d6; }
#welcome h2 { margin: 14px 0 6px 0; font-weight: 600; }
#welcome p { color: #d8dade; margin: 0; }

#viewer { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

#viewertoolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    background: var(--fc-darker);
    color: #fff;
    padding: 6px 12px;
    gap: 12px;
    font-size: 13px;
}
#doctitle {
    flex: 1 1 auto;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#pageinfo { color: #b8bac0; white-space: nowrap; }
#viewerbtns { display: flex; gap: 4px; }
#viewerbtns button, #viewerbtns a {
    background: #3a3d42;
    border: none;
    border-radius: 5px;
    color: #fff;
    font-size: 15px;
    padding: 7px 11px;
    cursor: pointer;
    text-decoration: none;
}
#viewerbtns button:active, #viewerbtns a:active { background: var(--fc-accent); }

#pagescroll {
    flex: 1 1 auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 0;
}
#pagecontainer { margin: 0 auto; }
.pdfpage {
    margin: 0 auto 14px auto;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    position: relative;
}
.pdfpage canvas { display: block; }
.pdfpage .pagenum {
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 10px;
    color: #bbb;
}
#loadingmsg { text-align: center; color: #f0f0ee; padding: 40px; font-size: 15px; }
#loadingmsg .fa { font-size: 28px; display: block; margin-bottom: 10px; }

/* ---------- Add to Home Screen banner ---------- */
#a2hsbanner {
    display: none;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    background: var(--fc-dark);
    color: #f0f0ee;
    border: 1px solid #4a4d52;
    border-left: 4px solid var(--fc-accent);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    padding: 12px 14px;
    align-items: center;
    gap: 12px;
    z-index: 150;
    font-size: 14px;
    line-height: 1.45;
}
#a2hsbanner .a2hsicon { font-size: 26px; color: var(--fc-accent); flex: 0 0 auto; }
#a2hstext { flex: 1 1 auto; }
#a2hstext .fa { color: var(--fc-accent); }
#a2hsclose {
    flex: 0 0 auto;
    background: transparent;
    border: none;
    color: #9a9da3;
    font-size: 24px;
    padding: 4px 8px;
    cursor: pointer;
}

/* ---------- Request modal ---------- */
#requestmodal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
#requestbox {
    background: #fff;
    border-radius: 10px;
    width: 100%;
    max-width: 440px;
    padding: 20px;
}
#requestbox h3 { margin: 0 0 6px 0; }
#requestbox p { margin: 0 0 10px 0; color: #666; font-size: 14px; }
#txtRequest {
    width: 100%;
    border: 1px solid var(--fc-border);
    border-radius: 6px;
    padding: 10px;
    font-size: 16px;
    font-family: inherit;
    resize: vertical;
}
#requestbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
#requestbtns button { border: none; border-radius: 6px; padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer; }
#btnRequestCancel { background: #e4e4e0; color: #444; }
#btnRequestSend { background: var(--fc-accent); color: #fff; }
#requestmsg { margin-top: 10px; font-size: 13px; color: #2c7a2c; }
#requestmsg.error { color: #c0392b; }

/* ---------- Register page ---------- */
body.registerpage { display: block; background: var(--fc-dark); }
#registerbox {
    max-width: 380px;
    margin: 60px auto;
    background: #fff;
    border-radius: 10px;
    padding: 28px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
#registerbrand img { height: 44px; }
#registerbrand h1 { font-size: 20px; letter-spacing: 2px; margin: 8px 0 18px 0; }
#registerbrand em { font-style: normal; color: var(--fc-accent); font-weight: 400; }
#registerbox h2 { font-size: 18px; margin: 0 0 6px 0; }
#registerbox p { color: #666; font-size: 14px; margin: 0 0 16px 0; }
.codeinput {
    width: 100%;
    text-align: center;
    font-size: 30px;
    letter-spacing: 12px;
    text-transform: uppercase;
    border: 2px solid var(--fc-border);
    border-radius: 8px;
    padding: 12px 0 12px 12px;
    font-family: "Courier New", monospace;
}
.codeinput:focus { border-color: var(--fc-accent); outline: none; }
.registerbtn {
    width: 100%;
    margin-top: 16px;
    background: var(--fc-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 14px;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
}
.registermsg { display: block; margin-top: 14px; color: #c0392b; font-size: 14px; }

/* ---------- Narrow screens (iPad portrait / phones) ---------- */
@media (max-width: 900px) {
    #brand span { display: none; }
    /* Sidebar becomes an overlay; main content always spans the full width */
    #layout { position: relative; display: block; }
    #main { width: 100%; height: calc(100vh - 52px); height: calc(100dvh - 52px); }
    #sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        width: 300px;
        max-width: 85%;
        z-index: 40;
        margin-left: 0;
        box-shadow: 4px 0 14px rgba(0,0,0,0.25);
        transition: transform 0.2s ease;
    }
    /* Use transform (not margin/left) so it never affects main's width */
    #sidebar.collapsed { margin-left: 0; transform: translateX(-105%); }
    /* Dim backdrop when sidebar is open over content */
    #sidebar:not(.collapsed)::after {
        content: "";
        position: fixed;
        top: 0; right: 0; bottom: 0; left: 300px;
        background: rgba(0,0,0,0.25);
        z-index: -1;
    }
}

/* ---------- Shared-manual banner ---------- */
#sharebanner {
    background: #fdf0e7;
    border-bottom: 1px solid var(--fc-accent);
}
.shareitem {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-bottom: 1px solid #f3ddcc;
    font-size: 14px;
    color: #5a3214;
}
.shareitem:last-child { border-bottom: none; }
.shareitem .fa-share-alt { color: var(--fc-accent); }
.shareitem a.share-open { color: #5a3214; text-decoration: none; flex: 1 1 auto; }
.shareitem a.share-open strong { color: #2b2d31; }
.shareitem .share-dismiss {
    background: transparent;
    border: none;
    color: #b08055;
    font-size: 20px;
    padding: 2px 8px;
    cursor: pointer;
}
