/* ==========================================================================
   Zen2B2 Global Mobile Responsiveness & Touch Optimization
   ========================================================================== */

/* Prevent Horizontal Body Overflow on Mobile Devices */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Cookie consent banner (Google Consent Mode). Hidden by default; the
   script in tool_shell.html adds -visible only when no prior choice is
   saved. Lives here (not style.css) for the same reason as .nav-toggle
   above - the one stylesheet every page loads regardless of
   STYLESHEET_MODE. */
.zen-cookie-banner {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: #0f172a;
    color: #fff;
    padding: 1rem 1.25rem;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.18);
}

.zen-cookie-banner.zen-cookie-banner-visible {
    display: flex;
}

.zen-cookie-banner p {
    margin: 0;
    font-size: 0.875rem;
    color: #e2e8f0;
    flex: 1;
    min-width: 200px;
}

.zen-cookie-banner a {
    color: #93c5fd;
}

.zen-cookie-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.zen-cookie-actions button {
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
}

#zen-cookie-accept {
    background: var(--primary, #2563eb);
    color: #fff;
}

#zen-cookie-reject,
#zen-cookie-analytics {
    background: transparent;
    color: #e2e8f0;
    border: 1px solid #475569;
}

/* Hamburger toggle: hidden by default (desktop). This lives here, not just
   in the top-level style.css, because STYLESHEET_MODE:local-only tools
   (shift, payroll, quotation, expense, cv, inventory, invoice, contractgen)
   never load ../style.css at all - global-mobile.css is the only stylesheet
   every tool page loads unconditionally, so it's the only safe place for a
   base rule that must apply everywhere. Without this, those tools rendered
   the hamburger icon on desktop too, since it had no display rule at all
   outside the mobile breakpoint. The mobile @media block below still flips
   this to display:flex via !important, same as before. */
.nav-toggle {
    display: none;
}

/* Expand/focus-mode toggle (floating button, every generated tool page).
   Hides the site chrome (nav, related tools, FAQ) so the tool itself gets
   the full viewport - the main lever for "see more" when a user rotates
   their phone to landscape or just wants more room on a small screen.
   Also attempts real OS fullscreen where the browser supports it (Android
   Chrome/Firefox, desktop); iOS Safari has no Fullscreen API for arbitrary
   elements, so there this CSS-only chrome-hiding is what actually delivers
   the extra space - see the click handler in tool_shell.html. */
.zen-focus-toggle {
    position: fixed;
    bottom: 1.1rem;
    right: 1.1rem;
    z-index: 999;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: #fff;
    color: #0f172a;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}

.zen-focus-toggle .icon-compress {
    display: none;
}

.zen-focus-toggle[aria-pressed="true"] .icon-expand {
    display: none;
}

.zen-focus-toggle[aria-pressed="true"] .icon-compress {
    display: block;
}

body.zen-focus-mode .navbar,
body.zen-focus-mode .logo,
body.zen-focus-mode .nav-toggle,
body.zen-focus-mode .nav-links,
body.zen-focus-mode .related-tools-section,
body.zen-focus-mode .tool-faq-section,
body.zen-focus-mode .tool-guide-section,
body.zen-focus-mode .app-footer,
body.zen-focus-mode .feedback-widget {
    display: none !important;
}

body.zen-focus-mode .app-container,
body.zen-focus-mode .main-content {
    min-height: 100vh !important;
}

/* Touch-friendly Viewport Settings & Breakpoint (< 768px) */
@media (max-width: 768px) {

    /* 1. Universal Layout Stacking */
    .app-container,
    .tool-container,
    .grid-layout,
    .main-content,
    .container,
    .tools-section {
        flex-direction: column !important;
        grid-template-columns: 1fr !important;
        width: 100% !important;
        min-width: 100% !important;
        padding: 12px !important;
        gap: 16px !important;
        box-sizing: border-box !important;
    }

    /* 2. Sidebars and Controls Panels */
    .controls-panel,
    .sidebar,
    .settings-card,
    .editor-container {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        padding: 16px !important;
        border-right: none !important;
        border-bottom: 1px solid #e2e8f0 !important;
        box-sizing: border-box !important;
    }

    /* 3. Preview Panels & Document Containers */
    .preview-panel,
    .result-card,
    .document-preview {
        width: 100% !important;
        padding: 8px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        box-sizing: border-box !important;
    }

    /* 4. A4 Sheet Paper Containers (Invoice, Payroll, CV, Quotation) */
    .invoice-wrapper,
    .payroll-wrapper,
    .cv-wrapper,
    .quotation-wrapper,
    .expense-wrapper,
    .inventory-wrapper,
    .shift-wrapper,
    #invoice-document,
    #payroll-document,
    #cv-document {
        min-width: 600px !important;
        margin: 0 auto !important;
        box-sizing: border-box !important;
    }

    /* 5. Inputs & Form Controls (Prevent iOS Safari Auto-Zoom) */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="date"],
    input[type="password"],
    textarea,
    select,
    .form-control {
        font-size: 16px !important; /* Mandatory 16px font-size to prevent iOS Safari auto-zoom */
        padding: 12px !important;
        min-height: 44px !important;
        box-sizing: border-box !important;
    }

    /* Homepage tool-search box: the generic input padding rule above
       (padding: 12px !important) clobbers the 3rem left padding this input
       needs to clear its absolutely-positioned search icon, making the
       placeholder text render underneath/overlapping the icon on mobile. */
    .search-box input {
        padding-left: 3rem !important;
    }

    /* 6. Buttons & Touch Targets */
    .btn,
    .btn-primary,
    .btn-secondary,
    .btn-danger,
    .actions button {
        width: 100% !important;
        min-height: 44px !important;
        font-size: 15px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        margin-bottom: 8px !important;
        box-sizing: border-box !important;
    }

    /* 7. Navbars & Logos */
    .navbar,
    .app-header,
    header {
        padding: 12px 16px !important;
        flex-wrap: wrap !important;
        gap: 12px !important;
    }

    /* Hamburger toggle: hidden by default, shown only at this breakpoint
       (base, non-mobile CSS keeps .nav-toggle display:none via style.css). */
    .nav-toggle {
        display: flex !important;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        width: 36px;
        height: 36px;
        min-height: 36px;
        background: transparent !important;
        border: none;
        cursor: pointer;
        padding: 6px;
        margin-left: auto;
        box-sizing: border-box;
    }
    .nav-toggle span {
        display: block;
        width: 100%;
        height: 2px;
        background: currentColor;
        border-radius: 2px;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }
    .nav-toggle[aria-expanded="true"] span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }
    .nav-toggle[aria-expanded="true"] span:nth-child(2) {
        opacity: 0;
    }
    .nav-toggle[aria-expanded="true"] span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    /* Nav links collapse behind the toggle by default; .nav-open reveals
       them as a full-width dropdown (the navbar already has flex-wrap from
       rule 7 above, so a 100%-width block naturally wraps onto its own
       row). */
    .nav-links {
        display: none !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 4px !important;
        font-size: 14px !important;
        order: 3;
    }
    .nav-links.nav-open {
        display: flex !important;
    }

    .nav-links a {
        padding: 9px 4px !important;
        display: inline-flex !important;
        align-items: center !important;
        min-height: 40px !important;
        box-sizing: border-box !important;
    }

    .feedback-buttons button {
        min-height: 44px !important;
        padding: 10px 18px !important;
    }

    /* 8. Tables Responsive Wrapping */
    table {
        display: block !important;
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* 9. Hero / Header Banner Adjustments */
    .hero-content h1,
    .tool-header h1,
    .news-header h1 {
        font-size: 1.8rem !important;
        line-height: 1.3 !important;
    }
    
    .hero-content p,
    .subtitle {
        font-size: 0.95rem !important;
    }

    /* 10. Tools Grid & Filter Buttons on Homepage */
    .tools-grid {
        grid-template-columns: 1fr !important;
    }
    .category-filters {
        flex-wrap: wrap !important;
        justify-content: center !important;
    }

    /* 11. Do not force desktop/A4 widths into the phone viewport. */
    .app-container,
    .main-content,
    .content,
    .preview-panel,
    .editor-container,
    .pane {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .invoice-wrapper,
    .payroll-wrapper,
    .cv-wrapper,
    .quotation-wrapper,
    .expense-wrapper,
    .inventory-wrapper,
    .shift-wrapper,
    .po-wrapper,
    .prop-wrapper,
    .mm-wrapper,
    #invoice-document,
    #payroll-document,
    #cv-document {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
    }

    /* Wide business tables remain usable through their local scroll area. */
    .table-responsive,
    .table-container {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    table {
        display: table !important;
        width: max-content !important;
        min-width: 100% !important;
        max-width: none !important;
    }

    .actions,
    .header-actions,
    .editor-controls {
        min-width: 0 !important;
        max-width: 100% !important;
        flex-wrap: wrap !important;
    }

    .actions .btn,
    .header-actions .btn {
        width: 100% !important;
        max-width: 100% !important;
    }

    .hidden-input-inline,
    .form-control,
    input,
    textarea,
    select {
        max-width: 100% !important;
    }

    /* Markdown input and preview must become a single-column flow. */
    .editor-container {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .editor-container textarea {
        width: 100% !important;
        min-width: 0 !important;
    }
}

/* ==========================================================================
   Landscape phones: restore the desktop side-by-side layout.
   The block above (max-width: 768px, no orientation check) still fires when
   a phone is rotated sideways at a narrower landscape width (e.g. iPhone SE:
   667x375 landscape) and was forcing two-panel editor/preview tools (cv,
   contractgen, inventory) and the markdown editor+preview grid to stack
   vertically even though rotating gave them more width to show side by
   side - the opposite of what a user rotating their phone is trying to get.
   Wider phones already escape the block above entirely in landscape (e.g.
   iPhone 14 landscape is 844px, over the 768px cutoff) and never needed
   this. Placed last in the file, and global-mobile.css always loads after
   each tool's own local style.css, so this wins over both.

   .app-container is reused by single-column tools (shift, payroll, expense)
   where it's natively flex-direction:column (header above content, not a
   side panel split) - forcing it to row there would wrongly put their
   header next to the page content. :has() scopes the row-flip to only the
   .app-container that actually wraps one of the two-panel tools' sidebar
   classes, leaving every other tool's .app-container untouched. Browsers
   without :has() support simply skip this rule and keep the existing
   (safe, already-working) stacked layout - no breakage either way. */
@media (orientation: landscape) and (min-width: 560px) and (max-width: 900px) {
    .app-container:has(.controls-panel),
    .app-container:has(.sidebar),
    .app-container:has(.editor-panel) {
        flex-direction: row !important;
    }

    .controls-panel,
    .sidebar,
    .editor-panel {
        width: 280px !important;
        min-width: 280px !important;
        max-width: 280px !important;
        height: auto !important;
        overflow-y: auto !important;
        border-right: 1px solid #e2e8f0 !important;
        border-bottom: none !important;
    }

    .preview-panel {
        width: auto !important;
        flex: 1 !important;
        overflow-y: auto !important;
    }

    .editor-container {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    }
}

/* Tool page H1 (added 2026-09-14): every tool page carries exactly one <h1>.
   .tool-title sits above the controls-panel subtitle on shared-stylesheet
   tools; .tool-title-bar is the variant placed between the app header and
   <main> on the local-only document tools (expense, payroll, shift). */
.tool-title {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.25;
    color: #0f172a;
    margin: 0 0 0.4rem;
}
.tool-title-bar {
    padding: 1.25rem 2rem 0;
    margin: 0;
}
@media (max-width: 768px) {
    .tool-title { font-size: 1.2rem; }
    .tool-title-bar { padding: 1rem 1rem 0; }
}

/* Tool guide section (added 2026-09-14): a short "how to use / when to use"
   block on every tool page, between the tool and Related Tools. Lives here
   because local-only tools do not load style.css. */
.tool-guide-section {
    max-width: 900px;
    margin: 0 auto 40px;
    padding: 0 20px;
    line-height: 1.65;
}
.tool-guide-section h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 16px;
}
.tool-guide-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #0f172a;
    margin: 22px 0 8px;
}
.tool-guide-section p {
    margin: 0 0 12px;
    color: #334155;
}
.tool-guide-section ol,
.tool-guide-section ul {
    margin: 0 0 12px 1.25rem;
    padding: 0;
    color: #334155;
}
.tool-guide-section li { margin-bottom: 6px; }
.tool-guide-section code {
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.92em;
}

/* Static explainer on /news/ so the page has real content of its own. */
.news-about {
    max-width: 900px;
    margin: 0 auto 48px;
    padding: 0 20px;
    line-height: 1.65;
    color: #334155;
}
.news-about h2 { font-size: 1.5rem; font-weight: 700; color: #0f172a; margin: 0 0 16px; }
.news-about h3 { font-size: 1.1rem; font-weight: 600; color: #0f172a; margin: 22px 0 8px; }
.news-about p { margin: 0 0 12px; }
.news-about ul { margin: 0 0 12px 1.25rem; padding: 0; }
.news-about li { margin-bottom: 6px; }
.news-about a { color: #2563eb; }

/* Blog article lists and inline code (added 2026-09-14). style.css zeroes
   every margin/padding with a global reset, which left list markers with
   no room and <code> unstyled inside .article-content on all posts. */
.article-content ul,
.article-content ol {
    padding-left: 1.5rem;
    margin: 0 0 20px;
}
.article-content li { margin-bottom: 8px; }
.article-content code {
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.92em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
