/* Quick Bill — public bill builder. Loaded after /style.css (which supplies the --primary / --border /
   --muted … tokens). Single centred column on every screen size: no side-by-side panels, no tables that
   scroll sideways, so nothing can push the page wider than the phone. */

*, *::before, *::after { box-sizing: border-box; }

:root {
    --qb-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
    --qb-radius: 12px;
    --qb-safe-b: env(safe-area-inset-bottom, 0px);
    --qb-safe-t: env(safe-area-inset-top, 0px);
    --qb-col: 820px;
}

/* Sideways-scroll guard: `clip` (unlike `hidden`) does not create a scroll container, so the sticky header
   and sticky action bar keep working. */
html, body { max-width: 100%; overflow-x: clip; }
html { -webkit-text-size-adjust: 100%; }
body { background: #f5f7f6; font-family: var(--qb-font); }
.qb-wrap, .qb-topbar, .qb-modal { font-family: var(--qb-font); }
html.qb-modal-open, html.qb-modal-open body { overflow: hidden; }

/* ------------------------------------------------------------ Header */
.qb-topbar {
    background: #fff; color: var(--text); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30; padding-top: var(--qb-safe-t);
}
.qb-topbar-inner { max-width: var(--qb-col); margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 14px; }
.qb-topbar .qb-brand { font-weight: 800; font-size: 19px; text-decoration: none; color: var(--primary); letter-spacing: -.01em; flex: none; }
.qb-topbar nav { margin-left: auto; display: flex; align-items: center; gap: 18px; font-size: 14px; min-width: 0; }
.qb-topbar nav a { color: var(--text); text-decoration: none; opacity: .85; padding: 6px 2px; white-space: nowrap; }
.qb-topbar nav a:hover, .qb-topbar nav a:focus-visible { opacity: 1; }
.qb-topbar nav a.qb-topbar-cta { background: var(--primary); color: #fff; opacity: 1; padding: 9px 16px; border-radius: 8px; font-weight: 600; font-size: 13.5px; }
.qb-topbar nav a.qb-topbar-cta:hover { background: var(--primary-dark); }
@media (max-width: 480px) {
    .qb-topbar-inner { padding: 10px 14px; gap: 8px; }
    .qb-topbar .qb-brand { font-size: 17px; }
    .qb-topbar nav { gap: 10px; font-size: 13px; }
    .qb-topbar nav a.qb-topbar-cta { padding: 8px 11px; font-size: 12.5px; }
}
@media (max-width: 370px) { .qb-topbar nav a.qb-home-link { display: none; } }

/* ------------------------------------------------------------ Page */
.qb-wrap { max-width: var(--qb-col); margin: 0 auto; padding: 0 20px 40px; }
@media (max-width: 480px) { .qb-wrap { padding-left: 14px; padding-right: 14px; } }

.qb-hero-h1 { margin: 28px 0 6px; font-size: 28px; font-weight: 800; letter-spacing: -.01em; text-align: center; line-height: 1.2; }
.qb-wrap > h1:not(.qb-hero-h1) { margin: 24px 0 2px; font-size: 24px; }
.qb-hero { padding: 0 0 20px; text-align: center; }
.qb-hero .qb-hero-sub { margin: 0 auto 12px; max-width: 520px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.qb-hero-features { display: flex; justify-content: center; gap: 6px 16px; flex-wrap: wrap; font-size: 13px; color: var(--primary-dark); font-weight: 600; }
.qb-hint { font-size: 13px; color: var(--muted); margin: 2px 0 14px; }
@media (max-width: 480px) {
    .qb-hero-h1 { font-size: 22px; margin-top: 20px; }
    .qb-hero .qb-hero-sub { font-size: 14px; }
    .qb-hero-features { font-size: 12px; gap: 4px 12px; }
}

/* ------------------------------------------------------------ Notice */
.qb-notice {
    background: var(--success-bg); border: 1px solid #b9d9cc; border-radius: var(--qb-radius);
    padding: 12px 14px; margin: 0 0 14px; font-size: 13.5px; line-height: 1.45;
    display: flex; align-items: center; justify-content: space-between; gap: 10px 14px; flex-wrap: wrap;
}
.qb-notice > span:first-child { flex: 1 1 200px; min-width: 0; }
.qb-notice-error { background: var(--danger-bg); border-color: #efb9b4; color: #7d1a14; font-weight: 600; }
.qb-notice-links { display: flex; gap: 8px; flex-wrap: wrap; }
.qb-notice-links a, .qb-pill {
    display: inline-flex; align-items: center; justify-content: center; font-weight: 600; text-decoration: none; white-space: nowrap;
    padding: 7px 13px; border-radius: 8px; min-height: 38px; background: #fff; border: 1px solid var(--primary); color: var(--primary);
}
.qb-notice-links a:hover, .qb-notice-links a:focus-visible { background: var(--primary); color: #fff; }
.qb-notice-links a.qb-pill-quiet { border-color: var(--border); color: var(--muted); }
.qb-notice-links a.qb-pill-quiet:hover { background: #eef1ef; color: var(--text); }
@media (max-width: 520px) {
    .qb-notice { flex-direction: column; align-items: stretch; }
    .qb-notice > span:first-child { flex: 0 0 auto; }
    .qb-notice-links { display: grid; grid-template-columns: 1fr 1fr; }
    .qb-notice-links a.qb-pill-quiet { grid-column: 1 / -1; }
}

/* ------------------------------------------------------------ Form cards */
.qb-form { display: block; }
.qb-section { background: var(--card); border: 1px solid var(--border); border-radius: var(--qb-radius); padding: 18px; margin-bottom: 14px; }
.qb-section h3 { margin: 0 0 12px; font-size: 16px; font-weight: 700; }
.qb-section .qb-section-sub { margin: -6px 0 14px; font-size: 13px; color: var(--muted); }
.qb-section label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 5px; font-weight: 500; }
.qb-label-required { color: var(--danger); }
.qb-label-strong { color: var(--text) !important; font-weight: 600 !important; font-size: 14px !important; }
.qb-optional { font-weight: 400; color: #98a29d; margin-left: 4px; }
.qb-field-label { margin: 14px 0 8px; font-size: 13px; color: var(--muted); font-weight: 500; }

.qb-row-2up { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-top: 12px; }
.qb-row-2up > div { min-width: 0; }
.qb-section > .qb-label-strong + input { margin-bottom: 0; }

/* One field style everywhere. 16px text stops iOS Safari zooming the page on focus (a common cause of the
   "page slides sideways" feeling), and 46px height is a comfortable tap target. */
.qb-section input[type=text], .qb-section input[type=tel], .qb-section input[type=number], .qb-section input[type=date],
.qb-section select, .qb-section textarea {
    display: block; width: 100%; max-width: 100%; min-width: 0; height: 46px; padding: 10px 12px;
    border: 1px solid #cfd8d4; border-radius: 10px; background: #fff; color: var(--text);
    font: 16px/1.3 var(--qb-font); -webkit-appearance: none; appearance: none; transition: border-color .12s, box-shadow .12s;
}
.qb-section input[type=date] { min-height: 46px; }
.qb-section select {
    padding-right: 32px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236b7770' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
}
.qb-section textarea { resize: vertical; min-height: 84px; height: auto; margin-bottom: 12px; }
.qb-section input:focus, .qb-section select:focus, .qb-section textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26, 95, 74, .14); }
.qb-section input::placeholder, .qb-section textarea::placeholder { color: #a3aba7; }
.qb-input-priority { font-weight: 600 !important; height: 50px !important; border-width: 1.5px !important; }
.qb-section label + input, .qb-section label + textarea { margin-bottom: 0; }
.qb-section-body > label { margin-top: 12px; }
.qb-section-body > .qb-row-2up:first-child { margin-top: 0; }

/* Collapsible cards */
.qb-section-toggle {
    display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 10px; cursor: pointer;
    background: none; border: 0; padding: 0; margin: 0; text-align: left; font: inherit; color: inherit;
    -webkit-tap-highlight-color: transparent; min-height: 28px;
}
.qb-section-toggle h3 { margin: 0; }
.qb-section-toggle .arrow { color: var(--muted); font-size: 15px; transition: transform .15s; flex: none; }
.qb-section-body { padding-top: 14px; }
.qb-section.collapsed .qb-section-body { display: none; }
.qb-section.collapsed .arrow { transform: rotate(-90deg); }

/* Document type + tax type */
.qb-doctype { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid #cfd8d4; border-radius: 10px; overflow: hidden; background: #fff; }
.qb-doctype label {
    margin: 0; text-align: center; padding: 11px 6px; font-size: 14px; line-height: 1.3; cursor: pointer; color: var(--text);
    display: flex; align-items: center; justify-content: center; border-right: 1px solid #cfd8d4; min-height: 46px; -webkit-tap-highlight-color: transparent;
}
.qb-doctype label:last-child { border-right: 0; }
.qb-doctype input { position: absolute; opacity: 0; width: 0; height: 0; }
.qb-doctype label.active { background: var(--primary); color: #fff; font-weight: 600; }
@media (max-width: 420px) { .qb-doctype label { font-size: 13px; padding: 10px 2px; } }

.qb-statetoggle { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.qb-statetoggle label {
    margin: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; text-align: center;
    border: 1px solid #cfd8d4; border-radius: 10px; padding: 9px 8px; min-height: 56px; font-size: 14px; color: var(--text); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.qb-statetoggle label small { font-size: 12px; color: var(--muted); }
.qb-statetoggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.qb-statetoggle label.active { background: var(--success-bg); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.qb-statetoggle label.active small { color: var(--primary); }
.qb-doctype:focus-within, .qb-statetoggle:focus-within { outline: 2px solid rgba(26, 95, 74, .35); outline-offset: 2px; }

/* ------------------------------------------------------------ Items (cards, never a sideways-scrolling table) */
.qb-items { display: flex; flex-direction: column; gap: 12px; }
.qb-item { border: 1px solid #d7dfdb; border-radius: 12px; background: #fbfcfb; padding: 12px 14px 14px; }
.qb-item-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; min-height: 36px; }
.qb-item-no { font-size: 14px; font-weight: 700; color: var(--text); }
.qb-item-amt { margin-left: auto; font-size: 15px; font-weight: 700; color: var(--primary); }
.qb-item .qb-del {
    flex: none; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
    background: none; border: 0; color: var(--danger); font-size: 24px; line-height: 1; border-radius: 8px; cursor: pointer;
}
.qb-item .qb-del:hover, .qb-item .qb-del:focus-visible { background: var(--danger-bg); }
.qb-item-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.qb-f { min-width: 0; }
.qb-f label { font-size: 12.5px !important; margin-bottom: 4px !important; }
.qb-f-name { grid-column: 1 / -1; }
.qb-f-hsn, .qb-f-qty, .qb-f-unit, .qb-f-rate, .qb-f-disc, .qb-f-gst { grid-column: span 2; }
.qb-f-name input { font-weight: 600; }
.qb-f-qty input, .qb-f-unit input { font-weight: 600; }
.qb-f-qty input { text-align: left; }
@media (max-width: 600px) {
    .qb-item-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .qb-f-hsn, .qb-f-qty, .qb-f-unit, .qb-f-rate, .qb-f-disc, .qb-f-gst { grid-column: auto; }
    .qb-f-qty { order: 1; } .qb-f-unit { order: 2; } .qb-f-rate { order: 3; } .qb-f-disc { order: 4; } .qb-f-hsn { order: 5; } .qb-f-gst { order: 6; }
}
.qb-items-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px 14px; margin-top: 14px; flex-wrap: wrap; }
.qb-items-actions #qbAddItem { min-height: 46px; padding: 0 18px; font-weight: 600; }
.qb-items-actions #qbAddItem:disabled { opacity: .45; cursor: not-allowed; }
.qb-items-limit-note { font-size: 12.5px; color: var(--muted); flex: 1 1 200px; min-width: 0; }
.qb-items-limit-note.qb-items-limit-hit { color: var(--primary-dark); background: var(--success-bg); border-radius: 8px; padding: 8px 12px; }

/* ------------------------------------------------------------ Logo */
.qb-logo-drop {
    border: 1.5px dashed #bcc8c3; border-radius: 12px; padding: 18px 14px; text-align: center; cursor: pointer; font-size: 13px; color: var(--muted);
    background: #fafcfb; transition: border-color .12s, background .12s; -webkit-tap-highlight-color: transparent;
}
.qb-logo-drop:hover, .qb-logo-drop:focus-visible { border-color: var(--primary); background: var(--success-bg); outline: none; }
.qb-logo-drop .qb-logo-drop-title { color: var(--text); font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.qb-logo-uploaded { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: #fafcfb; }
.qb-logo-preview-img { max-height: 56px; max-width: 120px; display: block; border-radius: 6px; background: #fff; border: 1px solid var(--border); padding: 4px; flex: none; }
.qb-logo-meta { display: flex; flex-direction: column; gap: 6px; flex: 1 1 160px; min-width: 0; }
.qb-logo-uploaded-label { font-size: 13px; font-weight: 600; color: var(--primary-dark); }
.qb-logo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.qb-logo-btn { font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 8px; min-height: 38px; cursor: pointer; background: #fff; border: 1px solid #cfd8d4; color: var(--text); }
.qb-logo-btn:hover, .qb-logo-btn:focus-visible { border-color: var(--primary); color: var(--primary); }
.qb-logo-btn-danger { color: var(--danger); }
.qb-logo-btn-danger:hover, .qb-logo-btn-danger:focus-visible { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); }

/* ------------------------------------------------------------ Action bar (sticky, Reset always visible) */
.qb-actionbar {
    position: sticky; bottom: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
    background: rgba(255, 255, 255, .96); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
    border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; margin: 4px 0 0;
    box-shadow: 0 -2px 14px rgba(20, 40, 32, .08);
}
.qb-total { display: flex; flex-direction: column; line-height: 1.2; margin-right: auto; padding-left: 4px; min-width: 0; flex: 1 1 0; overflow: hidden; }
.qb-total span { font-size: 12px; color: var(--muted); }
.qb-total strong { font-size: 18px; font-weight: 800; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qb-actionbar .btn { flex: none; min-height: 48px; font-size: 15px; font-weight: 700; border-radius: 10px; padding: 0 20px; display: inline-flex; align-items: center; justify-content: center; }
.qb-reset-btn { color: #4d5a54 !important; border-color: #cfd8d4 !important; }
.qb-reset-btn:hover { background: #f1f4f2 !important; }
.qb-preview-btn { min-width: 150px; }
.qb-preview-btn:disabled { opacity: .7; cursor: progress; }
@media (max-width: 520px) {
    .qb-wrap { padding-bottom: calc(14px + var(--qb-safe-b)); }
    .qb-actionbar { padding: 8px 10px calc(8px + var(--qb-safe-b)); bottom: 8px; }
    .qb-actionbar .btn { padding: 0 14px; }
    .qb-preview-btn { min-width: 0; }
}
@media (max-width: 360px) { .qb-total strong { font-size: 16px; } .qb-actionbar { gap: 8px; } }

/* ------------------------------------------------------------ Full-screen PDF preview */
.qb-modal { position: fixed; inset: 0; z-index: 100; background: #4b5551; display: flex; flex-direction: column; }
.qb-modal[hidden] { display: none; }
.qb-modal-bar {
    flex: none; display: flex; align-items: center; gap: 10px; background: #fff; border-bottom: 1px solid var(--border);
    padding: calc(10px + var(--qb-safe-t)) 14px 10px;
}
.qb-modal-title { font-size: 14.5px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qb-modal-title strong { color: var(--text); font-size: 16px; }
.qb-modal-actions { margin-left: auto; display: flex; gap: 8px; flex: none; }
.qb-mbtn {
    display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border-radius: 10px;
    border: 1px solid #cfd8d4; background: #fff; color: var(--text); font: 600 14.5px var(--qb-font); text-decoration: none; cursor: pointer; white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.qb-mbtn:hover, .qb-mbtn:focus-visible { border-color: var(--primary); color: var(--primary); }
.qb-mbtn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.qb-mbtn-primary:hover, .qb-mbtn-primary:focus-visible { background: var(--primary-dark); color: #fff; }
.qb-modal-body { flex: 1 1 auto; overflow: auto; -webkit-overflow-scrolling: touch; padding: 16px 12px calc(24px + var(--qb-safe-b)); text-align: center; overscroll-behavior: contain; }
.qb-pdf-stack { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.qb-pdf-page { display: block; background: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); max-width: 100%; }
.qb-pdf-loading { color: #e9efec; font-size: 15px; padding: 60px 16px; line-height: 1.5; }
@media (max-width: 640px) {
    .qb-modal-bar { flex-wrap: wrap; row-gap: 8px; padding-left: 12px; padding-right: 12px; }
    .qb-mbtn-back { order: 1; }
    .qb-modal-actions { order: 2; }
    .qb-modal-title { order: 3; flex: 1 0 100%; font-size: 13.5px; }
    .qb-mbtn { padding: 0 12px; font-size: 14px; }
    .qb-modal-body { padding: 10px 8px calc(20px + var(--qb-safe-b)); }
}

/* ------------------------------------------------------------ Saved screen */
.qb-ready { text-align: center; padding: 36px 0 4px; max-width: 620px; margin: 0 auto; }
.qb-ready .qb-check { width: 56px; height: 56px; border-radius: 50%; background: var(--success-bg); color: var(--primary); font-size: 28px; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.qb-ready h1 { font-size: 24px; }
.qb-ready .qb-ready-total { font-size: 30px; font-weight: 800; color: var(--text); margin: 6px 0 2px; }
.qb-ready-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 20px 0 28px; }
.qb-ready-actions .btn { min-width: 150px; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; font-weight: 600; }
.qb-cta-box { background: var(--success-bg); border: 1px solid #b9d9cc; border-radius: var(--qb-radius); padding: 20px; text-align: left; max-width: 460px; margin: 0 auto; }
.qb-cta-box ul { margin: 12px 0; padding-left: 20px; font-size: 14px; }
.qb-cta-box li { margin-bottom: 5px; }
@media (max-width: 480px) {
    .qb-ready-actions { flex-direction: column; }
    .qb-ready-actions .btn { width: 100%; }
}

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