/* ============================================================================
   Three-panel workspace ("Lovable-style"): rail | conversation | live report.
   Layered on top of flowell-theme.css (reuses its :root color vars).
   ============================================================================ */
html,body{height:100%}
body.lv-mode{margin:0;overflow:hidden;background:var(--soft)}

/* Column widths are user-draggable (persisted via JS → the --rail-w / --conv-w vars). Two thin
   gutter tracks between the panels are the drag handles; preview takes the remaining 1fr. */
.lv{display:grid;grid-template-columns:var(--rail-w,248px) 6px var(--conv-w,420px) 6px 1fr;height:100vh;height:100dvh;min-height:0}
/* Collapse the rail track (and its gutter) to 0 while KEEPING them grid items so conversation/preview
   stay in their own tracks. min-width:0 + overflow:hidden clip the content. */
body.rail-collapsed .lv{grid-template-columns:0 0 var(--conv-w,420px) 6px 1fr}
body.rail-collapsed .lv-rail{border-right:none;pointer-events:none}

/* Drag handles between panels */
.lv-gutter{cursor:col-resize;position:relative;z-index:6;background:transparent}
/* Short centered grip — only a small bar in the middle shows on hover/drag, not a full-height line. */
.lv-gutter::after{content:"";position:absolute;top:50%;transform:translateY(-50%);height:36px;left:1px;right:1px;border-radius:3px;background:transparent;transition:background .12s}
.lv-gutter:hover::after,.lv-gutter.dragging::after{background:var(--blue);opacity:.5}
/* When collapsed, gutter1's track is 0 (set in the grid above) so it's invisible/undraggable — but it
   must STAY a grid item (no display:none), or the conversation/preview shift into the wrong tracks. */

/* ---------- Left rail (nav) ---------- */
.lv-rail{background:#fff;border-right:1px solid var(--line);
  display:flex;flex-direction:column;min-height:0;min-width:0;overflow:hidden;transition:grid-template-columns .18s}

/* conversation-header toggle to open/close the rail (always reachable) */
.lv-railtoggle{background:none;border:none;cursor:pointer;color:var(--faint);padding:4px;border-radius:7px;display:inline-flex;margin:0;box-shadow:none;flex:none}
.lv-railtoggle:hover{background:var(--soft);color:var(--blue);transform:none;box-shadow:none}
.lv-railtoggle .ic{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.8}
.lv-rail-top{display:flex;align-items:center;justify-content:space-between;padding:15px 16px 10px}
.lv-brand{font-size:20px;font-weight:800;color:var(--blue);text-decoration:none;letter-spacing:.2px}
.lv-brand:hover{color:var(--indigo)}
.lv-railbtn{background:none;border:none;cursor:pointer;color:var(--faint);padding:4px;border-radius:7px;display:inline-flex;box-shadow:none;margin:0}
.lv-railbtn:hover{background:var(--soft);color:var(--blue);transform:none;box-shadow:none}
.lv-railbtn .ic{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.8}

.lv-new{margin:4px 12px 8px;padding:10px 14px;border-radius:10px;font-size:13.5px;font-weight:700;
  display:flex;align-items:center;gap:8px;justify-content:center;box-shadow:none}
.lv-new .ic{width:16px;height:16px;fill:none;stroke:#fff;stroke-width:2}

.lv-railscroll{flex:1;overflow-y:auto;min-height:0;padding:4px 8px 8px}
.lv-railsec{font-size:10.5px;font-weight:700;letter-spacing:1.2px;text-transform:uppercase;color:var(--faint);padding:12px 8px 6px}
/* it's a <button>, so also undo the theme's global button shadow/lift so it
   matches the <a class="lv-raillink"> items above it */
/* a <button> shrinks to fit, so it needs an explicit width; subtract the
   1px 2px margin it inherits from .lv-raillink so it lines up with the <a> items */
.lv-covtoggle{width:calc(100% - 4px);background:none;border:none;font:inherit;box-shadow:none}
.lv-covtoggle:hover{box-shadow:none;transform:none}
.lv-covtoggle > span{flex:1;text-align:left}
.lv-covtoggle .covchev{width:13px;height:13px;stroke:currentColor;fill:none;stroke-width:2.2;opacity:.55;flex:none;transition:transform .15s}
.lv-covtoggle.collapsed .covchev{transform:rotate(-90deg)}
.lv-raillink{display:flex;align-items:center;gap:9px;padding:8px 10px;font-size:13px;color:var(--muted);text-decoration:none;border-radius:9px;margin:1px 2px;cursor:pointer}
.lv-raillink:hover{background:var(--soft);color:var(--ink)}
.lv-raillink .ic{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:1.7;flex:none}

/* rail bottom: account */
.lv-railfoot{border-top:1px solid var(--line);padding:10px;display:flex;flex-direction:column;gap:6px}
.lv-acct{display:flex;align-items:center;gap:9px;padding:8px 10px;border-radius:10px;cursor:pointer;background:var(--soft);border:1px solid var(--line)}
.lv-acct:hover{border-color:var(--line2)}
.lv-acct .av{width:26px;height:26px;border-radius:50%;background:linear-gradient(135deg,var(--azure),var(--indigo));color:#fff;font-weight:800;font-size:12px;display:flex;align-items:center;justify-content:center;flex:none}
.lv-acct .who{flex:1;min-width:0}
.lv-acct .who .em{font-size:12px;color:var(--ink);font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.lv-acct .who .pl{font-size:10.5px;color:var(--faint)}

/* Rail quick-search */
.lv-search{display:flex;align-items:center;gap:7px;margin:2px 8px 8px;padding:7px 10px;background:var(--soft);border:1px solid var(--line);border-radius:10px}
.lv-search:focus-within{border-color:var(--blue);box-shadow:0 0 0 3px rgba(28,143,224,.12);background:#fff}
.lv-search .ic{width:15px;height:15px;fill:none;stroke:var(--faint);stroke-width:1.9;flex:none}
.lv-search input{flex:1;border:none;background:none;font-size:13px;color:var(--ink);padding:0;min-width:0}
.lv-search input:focus{outline:none;box-shadow:none}
.lv-kbd{font-size:10px;color:var(--faint);background:#fff;border:1px solid var(--line2);border-radius:5px;padding:1px 5px;font-family:inherit;flex:none}

/* Plan / credits card (Lovable-style) */
.lv-plan{background:var(--soft);border:1px solid var(--line);border-radius:10px;padding:11px 12px;display:flex;flex-direction:column;gap:8px}
.lv-plan-row{display:flex;align-items:center;justify-content:space-between}
.lv-plan-credits{font-size:14px;font-weight:800;color:var(--ink)}
.lv-plan-credits.low{color:var(--sell)}
.lv-plan-credits .u{font-size:11px;font-weight:600;color:var(--muted);margin-left:3px}
.lv-plan-buy{width:24px;height:24px;padding:0;border-radius:7px;font-size:17px;line-height:1;display:inline-flex;align-items:center;justify-content:center;margin:0;box-shadow:none}
.lv-plan-sub{font-size:10.5px;color:var(--muted);line-height:1.4}
.lv-plan-upg{width:100%;margin:0;padding:7px;border-radius:8px;font-size:12.5px;font-weight:700;box-shadow:none}

/* Account row */
.lv-acct{width:100%;text-align:left;box-shadow:none}
.lv-acct-gear{margin-left:auto;color:var(--faint);display:inline-flex;padding:4px;border-radius:6px;flex:none;text-decoration:none}
.lv-acct-gear:hover{background:#fff;color:var(--blue)}
.lv-acct-gear .ic{width:15px;height:15px;fill:none;stroke:currentColor;stroke-width:1.7}

/* ---------- Middle: conversation ---------- */
.lv-conv{display:flex;flex-direction:column;min-height:0;min-width:0;background:#fff;border-right:1px solid var(--line)}
.lv-conv-head{display:flex;align-items:center;gap:8px;height:47px;padding:0 16px;box-sizing:border-box;border-bottom:1px solid var(--line);font-size:13px;font-weight:700;color:var(--ink)}
.lv-conv-head .dot{width:7px;height:7px;border-radius:50%;background:var(--buy);flex:none}
.lv-conv-head .ctx{color:var(--faint);font-weight:500;font-size:12px;margin-left:auto;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:55%}

.lv-log{flex:1;overflow-y:auto;min-height:0;padding:18px 16px 8px;display:flex;flex-direction:column;gap:10px}
.lv-empty2{margin:auto;text-align:center;padding:20px;max-width:340px}
.lv-empty2 h2{font-size:22px;font-weight:800;color:var(--ink);margin:0 0 8px}
.lv-empty2 p{font-size:13.5px;color:var(--muted);line-height:1.6;margin:0 0 16px}
.lv-chips{display:flex;flex-wrap:wrap;gap:7px;justify-content:center}
.lv-chip{font-size:12px;font-weight:600;color:var(--blue);background:var(--soft);border:1px solid var(--line2);border-radius:999px;padding:6px 12px;cursor:pointer}
.lv-chip:hover{background:#fff;box-shadow:var(--shadow-sm)}

/* message bubbles (reuse chat classes) */
.lv-log .me{align-self:flex-end;background:linear-gradient(135deg,var(--azure),var(--indigo));color:#fff;padding:9px 13px;border-radius:14px 14px 3px 14px;font-size:13.5px;max-width:82%;line-height:1.5;white-space:pre-wrap}
.lv-log .ai{align-self:flex-start;background:var(--soft);color:var(--ink);padding:9px 13px;border-radius:14px 14px 14px 3px;font-size:13.5px;max-width:88%;line-height:1.6;white-space:pre-wrap}
.lv-log .sys{align-self:flex-start;color:var(--faint);font-size:12px;padding:1px 4px}
.lv-log .ok{align-self:flex-start;color:var(--buy);font-size:12.5px;font-weight:600;padding:2px 4px}
.lv-log .err{align-self:flex-start;color:var(--sell);font-size:12.5px;font-weight:600;padding:2px 4px}
#progress{display:flex;flex-direction:column}
#progress:empty{display:none}

/* composer */
.lv-composer{border-top:1px solid var(--line);padding:12px 14px 14px;background:#fff}
.lv-scope-note{margin-top:8px;text-align:center;font-size:10.5px;color:var(--faint,#9aa6b6);line-height:1.4}
.lv-cbox{border:1px solid var(--line2);border-radius:16px;padding:10px 12px;background:#fff;box-shadow:var(--shadow-sm);transition:border-color .15s,box-shadow .15s}
.lv-cbox:focus-within{border-color:var(--blue);box-shadow:0 0 0 3px rgba(28,143,224,.14)}
.lv-cbox textarea{width:100%;border:none;resize:none;font-size:14px;line-height:1.5;padding:2px;background:none;min-height:24px;max-height:150px;color:var(--ink)}
.lv-cbox textarea:focus{outline:none;box-shadow:none;border:none}
.lv-crow{display:flex;align-items:center;gap:8px;margin-top:6px}
.lv-crow select{width:auto;padding:6px 10px;font-size:12.5px;border-radius:9px;font-weight:600;color:var(--muted)}
.lv-attach{background:none;border:1px solid var(--line2);color:var(--muted);width:32px;height:32px;padding:0;border-radius:9px;display:inline-flex;align-items:center;justify-content:center;margin:0;box-shadow:none;cursor:pointer;font-size:18px}
.lv-attach:hover{background:var(--soft);color:var(--blue);transform:none;box-shadow:none}
.lv-send{width:34px;height:34px;padding:0;border-radius:10px;margin:0 0 0 auto;display:inline-flex;align-items:center;justify-content:center}
.lv-send:disabled{opacity:.45;cursor:not-allowed}
.lv-send.sending{background:#C0392B;border-color:#C0392B}
.lv-send.sending .ic{fill:#fff;stroke:none}
.lv-send .ic{width:17px;height:17px;fill:none;stroke:#fff;stroke-width:2.2}
.lv-opts{margin-top:8px}
.lv-opts summary{font-size:11.5px;color:var(--faint);cursor:pointer;list-style:none;padding:2px}
.lv-opts summary::-webkit-details-marker{display:none}
.lv-opts summary:hover{color:var(--blue)}
.lv-opts .in{padding:8px 2px 2px;display:flex;flex-direction:column;gap:6px}
.lv-opts label{margin:4px 0 2px}
#uploadList{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}

/* ---------- Right: live report preview ---------- */
.lv-preview{display:flex;flex-direction:column;min-height:0;min-width:0;background:var(--soft)}
/* position+z-index so the header (and its ⋯ dropdown) paints above the report body/iframe —
   backdrop-filter makes .lv-pv-head a stacking context that the later sibling would otherwise cover. */
.lv-pv-head{display:flex;align-items:center;gap:10px;height:47px;padding:0 16px;box-sizing:border-box;border-bottom:1px solid var(--line);background:rgba(255,255,255,.7);backdrop-filter:blur(8px);position:relative;z-index:2}
.lv-pv-back{display:none;align-items:center;justify-content:center;width:32px;height:32px;margin:0 0 0 -4px;box-shadow:none;border:none;background:none;color:var(--ink);cursor:pointer;border-radius:8px;flex:none}
.lv-pv-back:hover{background:var(--soft);box-shadow:none;transform:none}
.lv-pv-back .ic{width:22px;height:22px;flex:none;fill:none;stroke:currentColor;stroke-width:2}  /* flex:none: an SVG with no intrinsic width collapses to 0 inside a flex button */
.lv-pv-title{font-size:13.5px;font-weight:700;color:var(--ink);display:flex;align-items:center;gap:8px;min-width:0}
.lv-pv-title .tag{font-size:11px;padding:2px 8px;border-radius:999px}
.lv-pv-actwrap{display:flex;align-items:center;margin-left:auto;position:relative}
.lv-pv-more{display:none;align-items:center;justify-content:center;margin:0;box-shadow:none;border:none;background:none;padding:6px;border-radius:8px;color:var(--muted);cursor:pointer}
.lv-pv-more .ic{width:20px;height:20px;flex:none;fill:currentColor;stroke:none}
.lv-pv-actions .albl{display:none}   /* action labels: hidden on desktop (icon-only), shown in the mobile ⋯ menu */
.lv-pv-actions{display:flex;align-items:center;gap:2px}
.lv-pv-actions .iconbtn{border:none;background:none;border-radius:7px;padding:6px;cursor:pointer;color:var(--muted);display:inline-flex;align-items:center}
.lv-pv-actions .iconbtn:hover{background:var(--soft);color:var(--blue)}
.lv-pv-actions .iconbtn.danger:hover{background:#FBE9EC;color:var(--sell)}
.lv-pv-actions .iconbtn.locked{color:var(--faint)}
.lv-pv-actions .ic{width:17px;height:17px;fill:none;stroke:currentColor;stroke-width:1.7}
.lv-pv-body{flex:1;min-height:0;position:relative}
#reportFrame{width:100%;height:100%;border:none;background:#fff;display:none}
body.has-report #reportFrame{display:block}
.lv-pv-empty{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:30px;color:var(--faint)}
body.has-report .lv-pv-empty{display:none}
.lv-pv-empty .glyph{width:52px;height:52px;opacity:.5;margin-bottom:14px;fill:none;stroke:var(--faint);stroke-width:1.4}
.lv-pv-empty h3{font-size:16px;color:var(--muted);font-weight:700;margin:0 0 6px}
.lv-pv-empty p{font-size:13px;margin:0;max-width:300px;line-height:1.6}
.lv-pv-loading{position:absolute;top:0;left:0;right:0;height:2px;overflow:hidden;display:none}
body.pv-loading .lv-pv-loading{display:block}
.lv-pv-loading span{display:block;height:100%;width:40%;background:linear-gradient(90deg,var(--azure),var(--indigo));animation:lvslide 1.1s ease-in-out infinite}
@keyframes lvslide{0%{margin-left:-40%}100%{margin-left:100%}}

/* Floating "Ask about this" button shown when text is selected in the report */
.lv-quote-btn{position:fixed;z-index:90;transform:translate(-50%,0);display:none;align-items:center;gap:6px;
  background:var(--blue);color:#fff;border:none;font-size:12.5px;font-weight:700;padding:7px 13px;border-radius:999px;
  box-shadow:0 8px 22px rgba(22,70,140,.28);cursor:pointer;white-space:nowrap;margin:0}
.lv-quote-btn.show{display:inline-flex}
.lv-quote-btn:hover{background:var(--indigo);transform:translate(-50%,-1px)}
.lv-quote-btn svg{width:14px;height:14px;fill:none;stroke:#fff;stroke-width:1.8}

/* mobile toggle bar (hidden on desktop) */
.lv-mobile-bar{display:none}

@media(max-width:900px){
  body.lv-mode{overflow:auto}
  .lv{grid-template-columns:1fr;height:auto;min-height:100dvh}
  body.rail-collapsed .lv{grid-template-columns:1fr}
  .lv-rail{position:fixed;z-index:60;top:0;bottom:0;left:0;width:250px;transform:translateX(-100%)}
  body.rail-open .lv-rail{transform:translateX(0);box-shadow:var(--shadow)}
  .lv-railtoggle{display:none}
  .lv-gutter{display:none}
  .lv-conv{border-right:none;height:calc(100dvh - 46px)}
  .lv-preview{display:none}
  /* When viewing a report on mobile, the report pane becomes a full-screen overlay that
     covers the rail (z60), the conversation and its mobile bar — so nothing bleeds in from
     the side and the report header (with the back button) owns the top of the screen. */
  body.mobile-report .lv-conv{display:none}
  body.mobile-report .lv-preview{display:flex;position:fixed;inset:0;z-index:70;height:100dvh}
  .lv-mobile-bar{display:flex;align-items:center;gap:8px;height:46px;padding:0 12px;border-bottom:1px solid var(--line);background:#fff;position:sticky;top:0;z-index:40}
  .lv-mobile-bar button{margin:0;padding:7px 12px;font-size:12.5px;box-shadow:none}
  .lv-mobile-bar .seg{background:none;color:var(--muted);border:1px solid var(--line2)}
  .lv-mobile-bar .seg.on{background:var(--soft);color:var(--blue);border-color:var(--blue)}
  .lv-mobile-bar .mnu{background:none;border:none;color:var(--ink);width:34px;padding:0}
  .lv-pv-back{display:inline-flex}   /* back-to-chat button in the report header (mobile only) */
  /* iOS Safari zooms the whole page in when a focused input is < 16px — keep form controls at 16px on mobile */
  .lv-cbox textarea,.lv-search input{font-size:16px}
  /* Report actions collapse behind a ⋯ button that opens a labelled dropdown */
  .lv-pv-more{display:inline-flex}
  .lv-pv-actions{position:absolute;top:calc(100% + 6px);right:0;flex-direction:column;align-items:stretch;gap:2px;min-width:196px;padding:6px;background:#fff;border:1px solid var(--line);border-radius:12px;box-shadow:var(--shadow);display:none;z-index:80}
  .lv-pv-actwrap.open .lv-pv-actions{display:flex}
  .lv-pv-actions .iconbtn{width:100%;justify-content:flex-start;gap:11px;padding:10px 12px;border-radius:8px;color:var(--ink);font-size:14px;font-weight:600}
  .lv-pv-actions .iconbtn.danger{color:var(--sell)}
  .lv-pv-actions .iconbtn.locked{color:var(--faint)}
  .lv-pv-actions .ic{width:18px;height:18px;flex:none}
  .lv-pv-actions .albl{display:inline}
}

/* ---------- Entry gate (auth / terms / invite) — blocks the app until cleared ---------- */
body.gated{overflow:hidden}
body.gated .lv{filter:blur(5px);pointer-events:none;user-select:none;transition:filter .2s}
/* hardgate overlays cannot be dismissed by clicking the backdrop (handled in JS too) */
.modal.terms{max-width:460px}
.modal.terms .tg-note{font-size:14px;line-height:1.65;color:var(--muted);margin:0 0 16px}
.tg-check{display:flex;gap:10px;align-items:flex-start;font-size:13.5px;line-height:1.55;color:var(--ink);cursor:pointer}
.tg-check input{margin-top:2px;width:16px;height:16px;flex:0 0 auto;cursor:pointer}
.tg-check a{color:var(--blue);text-decoration:none}
.tg-check a:hover{text-decoration:underline}
.modal.terms .foot{display:flex;justify-content:space-between;gap:10px}
#tgAccept:disabled{opacity:.5;cursor:not-allowed}

/* ---------- Invite-first sign-in step ---------- */
.authmsg.err{color:#C13A4B}
.authmsg.ok{color:#0E8B5C}
.auth-haveacct{margin-top:14px;text-align:center}
.auth-haveacct a{color:var(--blue);font-size:13px;text-decoration:none;font-weight:600}
.auth-haveacct a:hover{text-decoration:underline}
#authStep0 .ig-row{display:flex;gap:8px}
#authStep0 .ig-row input{flex:1}
