/* shell/shell.css  -  the frame every tab sits in: colours, the main column, the chat pane,
   the sidebar, the two looks, the tab row, the pop-up, the shared buttons. Phone rules at the
   bottom. A tab's own look lives in that tab's folder. */

/* colours live in theme-studio.css (dark) and theme-forge.css (light, the default) */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; }
button { font: inherit; color: inherit; }

html, body { height: 100%; overflow: hidden; }
#app { display: grid; grid-template-columns: 1fr 280px; height: 100vh; will-change: transform; transform: translateZ(0); }
body.side-collapsed #app { grid-template-columns: 1fr 64px; }   /* the panel folds to a rail of icons and the page takes the width */

/* main */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }   /* the page never grows: only #messages scrolls (Joey, 2026-09-22) */
#topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 22px; border-bottom: 1px solid var(--line); }
.engine-title { display: flex; align-items: center; gap: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: var(--accent); font-size: 13px; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }
.status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; }
.icon-btn { background: transparent; border: 1px solid var(--line); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 18px; line-height: 1; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

#messages { flex: 1; min-height: 0; overflow-y: auto; padding: 28px 0; }
.msg { max-width: 820px; margin: 0 auto 22px; padding: 0 22px; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 6px; letter-spacing: .02em; }
.msg .body { white-space: pre-wrap; line-height: 1.55; }
.msg.you .body { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.msg .tools { margin-top: 6px; display: flex; gap: 10px; }
.msg .tools button { background: transparent; border: none; color: var(--muted); font-size: 12px; cursor: pointer; padding: 2px 0; }
.msg .tools button:hover { color: var(--accent); }
.msg.error .body { color: var(--danger); }
.empty { max-width: 820px; margin: 60px auto; padding: 0 22px; color: var(--muted); }
.empty h2 { color: var(--text); font-weight: 600; font-size: 22px; margin: 0 0 8px; }
.typing { color: var(--muted); font-size: 13px; }

#composer { display: flex; gap: 10px; align-items: flex-end; max-width: 820px; width: 100%; margin: 0 auto; padding: 10px 22px 6px; }
#input { flex: 1; resize: none; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; color: var(--text); padding: 12px 14px; font: inherit; line-height: 1.4; max-height: 200px; outline: none; }
#input:focus { border-color: var(--accent); }
.send-btn { background: var(--accent); color: #062b24; border: none; border-radius: 12px; width: 44px; height: 44px; cursor: pointer; font-size: 16px; }
.send-btn:disabled { opacity: .5; cursor: default; }
/* the + at the left of the message box, its menu, and the attachment chips above the box */
#composer.over #input { border-color: var(--accent); background: var(--accent-dim); }
.attach-wrap { position: relative; }
#attach-btn { width: 44px; height: 44px; border-radius: 12px; font-size: 22px; }
#attach-menu { position: absolute; bottom: 52px; left: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: flex; flex-direction: column; gap: 2px; min-width: 220px; box-shadow: 0 8px 30px rgba(0,0,0,.18); z-index: 20; }
#attach-menu[hidden] { display: none; }
#attach-menu button { background: transparent; border: none; text-align: left; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
#attach-menu button:hover { background: var(--panel-2); }
#attach-row { max-width: 820px; width: 100%; margin: 0 auto; padding: 6px 22px 0; display: flex; gap: 8px; flex-wrap: wrap; }
.attach-chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--panel); font-size: 13px; max-width: 100%; }
.attach-chip.bad { color: var(--danger); border-color: var(--danger); }
.attach-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-x { background: transparent; border: none; cursor: pointer; font-size: 16px; color: var(--muted); padding: 0 2px; }
.attach-x:hover { color: var(--danger); }
/* a dropped file inside a sent message: a card, not the text */
.att-cards { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.att-card { width: 150px; min-height: 96px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--panel); display: flex; flex-direction: column; justify-content: space-between; gap: 8px; }
.att-card-name { font-size: 13px; line-height: 1.3; word-break: break-word; max-height: 3.9em; overflow: hidden; }
.att-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.att-badge { font-size: 10px; font-weight: 700; letter-spacing: .06em; border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; background: var(--panel-2); }
.msg-text { white-space: pre-wrap; }

#foot-note { text-align: center; color: var(--muted); font-size: 11px; padding: 8px 0 12px; margin-top: auto; border-top: 1px solid var(--line); }

/* sidebar, on the right; collapsed, only the icons stay (desktop only; phones use the sheet) */
#side-collapse { position: absolute; top: 10px; left: 10px; width: 28px; height: 28px; font-size: 18px; line-height: 1; z-index: 2; }
#sidebar { position: relative; }
body.side-collapsed #sidebar { padding: 48px 8px 12px; align-items: center; overflow-x: hidden; }
body.side-collapsed .brand-name, body.side-collapsed #space-switch, body.side-collapsed .side-label, body.side-collapsed .nav-text, body.side-collapsed .nav-item .num,
body.side-collapsed #history-section, body.side-collapsed .side-note, body.side-collapsed .side-link, body.side-collapsed .side-user { display: none; }
body.side-collapsed .brand { padding: 0 0 12px; }
body.side-collapsed .nav-item { padding: 8px; justify-content: center; }
body.side-collapsed .nav-item .mini { width: 30px; height: 30px; font-size: 11px; }
body.side-collapsed .side-bottom { border-top: none; padding-top: 0; }
body.side-collapsed #side-collapse { left: 50%; transform: translateX(-50%); }

/* sidebar, on the right */
#sidebar { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 14px; overflow-y: auto; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 8px 16px; text-align: center; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); }
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.2; }
[data-theme="forge"] .brand-name { font-family: Georgia, "Times New Roman", serif; }
.side-label { color: var(--muted); font-size: 11px; letter-spacing: .12em; padding: 14px 8px 6px; }
.side-label .count { float: right; letter-spacing: 0; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; cursor: pointer; color: var(--text); }
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item .num { width: 18px; color: var(--muted); font-size: 12px; }
.nav-item .mini { width: 22px; height: 22px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: var(--accent); }
.side-section { margin-top: 6px; }
#history { list-style: none; margin: 0; padding: 0; }
#history li { padding: 7px 10px; border-radius: 8px; color: var(--muted); cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* a chat row: the name, and a pen that shows on hover (always on a phone); tap the pen to rename in place (Joey, 2026-09-22) */
#history li.chat-row { display: flex; align-items: center; gap: 6px; }
#history .chat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#history .chat-pen { flex: 0 0 auto; background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 6px; line-height: 0; }
#history .chat-pen:hover { color: var(--accent); background: var(--accent-dim); }
@media (hover: hover) { #history .chat-pen { opacity: 0; } #history li:hover .chat-pen, #history li.active .chat-pen, #history li.editing .chat-pen { opacity: 1; } }
#history .chat-rename { flex: 1; min-width: 0; font: inherit; font-size: 13px; color: var(--text); background: var(--bg); border: 1px solid var(--accent); border-radius: 6px; padding: 3px 6px; }
#history li:hover { background: var(--panel-2); color: var(--text); }
#history li.active { color: var(--text); background: var(--panel-2); }
.side-bottom { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.side-link { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.side-link:hover { background: var(--panel-2); color: var(--text); }
.side-user { color: var(--muted); font-size: 12px; padding: 8px 10px 0; }



/* top tab bar */
#tabbar[hidden] { display: none; }
#tabbar, #cc-tabbar { display: flex; align-items: center; gap: 4px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
#tabbar .tab, #cc-tabbar .tab { background: transparent; border: none; color: var(--muted); letter-spacing: .12em; font-size: 12px; font-weight: 700; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
#tabbar .tab:hover, #cc-tabbar .tab:hover { color: var(--text); background: var(--panel-2); }
#tabbar .tab.active, #cc-tabbar .tab.active { color: var(--accent); background: var(--accent-dim); }
.tab-spacer { flex: 1; }
#view-top:empty { display: none; }
#view-top { padding: 18px 22px 6px; overflow-y: auto; flex: 1; min-height: 0; }
#view-top:not(:empty) ~ #messages:not([hidden]) { flex: 0 0 auto; max-height: 38vh; }
#messages[hidden], #composer[hidden], #new-chat[hidden], #attach-row[hidden] { display: none; }
.panel h2 { margin: 0 0 6px; font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.err { color: var(--danger); font-size: 13px; min-height: 16px; }
.btn { background: var(--accent); color: var(--btnfg, #fff); border: none; border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.small { padding: 5px 9px; font-size: 12px; }
.side-note { color: var(--muted); font-size: 12px; padding: 6px 10px; line-height: 1.4; }

/* modal */
#modal[hidden] { display: none; }
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(960px, 100%); max-height: 90vh; overflow-y: auto; will-change: transform; contain: layout paint; transform: translateZ(0); }
#modal { will-change: opacity; }
#view-top { contain: content; }
.modal-card h3 { margin: 0 0 10px; font-size: 20px; }
.modal-card label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.modal-card textarea { width: 100%; box-sizing: border-box; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--text); padding: 10px 12px; font: inherit; resize: vertical; }
.modal-card input, .modal-card select { width: 100%; box-sizing: border-box; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--text); padding: 10px 12px; font: inherit; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ---- phones: one column, a bottom bar, the sidebar as a sheet that slides up ---- */
#mobile-bar { display: none; }
#sheet-backdrop { display: none; }
@media (max-width: 760px) {
  html, body { height: 100%; }
  #app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
  #main { flex: 1; min-height: 0; }
  #sidebar { display: none; }
  #side-collapse { display: none; }
  body.side-collapsed #app { grid-template-columns: none; }
  body.side-collapsed .brand-name, body.side-collapsed #space-switch, body.side-collapsed .side-label, body.side-collapsed .nav-text, body.side-collapsed #history-section, body.side-collapsed .side-note, body.side-collapsed .side-link, body.side-collapsed .side-user { display: revert; }
  body.side-collapsed #sidebar { padding: 18px 14px; align-items: stretch; }
  body.side-collapsed .nav-item { justify-content: flex-start; padding: 9px 10px; }
  #mobile-bar { display: flex; align-items: center; justify-content: center; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
  .sheet-btn { min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-weight: 600; cursor: pointer; width: 100%; }
  body.sheet-open #sidebar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; max-height: 72vh; max-height: 72dvh; border-left: none; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; z-index: 40; box-shadow: 0 -8px 30px rgba(0,0,0,.25); }
  body.sheet-open #sheet-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; }
  #sheet-backdrop[hidden] { display: none; }
  .side-bottom { margin-top: 12px; }

  /* the tab row */
  #tabbar, #cc-tabbar { padding: 8px 10px; gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #tabbar .tab, #cc-tabbar .tab { padding: 10px 7px; font-size: 10.5px; letter-spacing: .05em; white-space: nowrap; min-height: 40px; }
  #tabbar .status, #tabbar #theme, #cc-tabbar #cc-theme { display: none; }
  .icon-btn { width: 40px; height: 40px; flex: 0 0 auto; }

  /* the page area */
  #view-top { padding: 10px 10px 4px; max-height: none; }
  #messages { padding: 14px 0; }
  .msg { padding: 0 12px; margin-bottom: 16px; }
  #composer { padding: 8px 10px 6px; }
  #input { font-size: 16px; }             /* 16px stops iOS zooming the page on focus */
  .send-btn { width: 46px; height: 46px; }
  #attach-row { padding: 6px 10px 0; }
  #attach-menu button { min-height: 44px; font-size: 16px; }
  #foot-note { font-size: 10px; padding: 4px 0 6px; }


  /* pop-ups fill the screen */
  #modal { padding: 0; align-items: stretch; }
  .modal-card { width: 100%; max-height: none; height: 100vh; height: 100dvh; border-radius: 0; border: none; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .modal-card h3 { font-size: 19px; }
  .modal-card input, .modal-card select { font-size: 16px; min-height: 44px; }
  .modal-card textarea { font-size: 16px; }
  .btn { min-height: 44px; }
  .modal-actions { position: sticky; bottom: 0; background: var(--panel); padding-top: 10px; }
}

/* The Copy button under a message shows only while the mouse is over that message on a desktop; on a
   phone there is no hover, so the button stays visible (Joey, 2026-09-22). */
@media (hover: hover) {
  .msg .tools { opacity: 0; transition: opacity .12s ease; }
  .msg:hover .tools, .msg:focus-within .tools { opacity: 1; }
}

/* The engine's name above its message is in the brand colour; the person's own name stays as it is (Joey, 2026-09-22). */
.msg:not(.you) .who { color: var(--accent); }
/* The person's own name is the page's text colour: white in the dark look, ink in the light look (Joey, 2026-09-22). */
.msg.you .who { color: var(--text); }

/* Settings pop-up: three sections as small tabs, rows of label and value */
.settings-tabs { display: flex; gap: 6px; margin: 0 0 14px; border-bottom: 1px solid var(--line); }
.settings-tabs button { background: transparent; border: none; border-bottom: 2px solid transparent; color: var(--muted); padding: 8px 12px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.settings-tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.s-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.s-row .ok { color: var(--accent); }

/* ---- Oracle: the portal switch at the top of the sidebar (9FS, Betts Nation, + Add) ---- */
#portal-switch { display: flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 4px 0 14px; }
#portal-switch button { flex: 1; min-width: 40%; background: transparent; border: none; padding: 9px 6px; font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--muted); cursor: pointer; }
#portal-switch button.active { background: var(--accent-dim); color: var(--accent); }
#portal-switch button.add { flex: 0 0 100%; border-top: 1px solid var(--line); font-weight: 600; }
body.side-collapsed #portal-switch { display: none; }
#view-top { flex: 1; min-height: 0; overflow-y: auto; }

/* ---- Oracle: the chat pop-up, centre of the screen (Joey, 2026-09-24) ---- */
#chat-modal[hidden] { display: none; }
#chat-modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.chat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: min(900px, 100%); height: min(80vh, 760px); display: flex; flex-direction: column; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-title h3 { margin: 0; font-size: 18px; }
#chat-history { max-width: 200px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 6px 8px; font: inherit; font-size: 13px; }
.chat-card #messages { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 0; }
.chat-card #composer { border-top: 1px solid var(--line); }
.msg:not(.you) .who { color: var(--accent); }
.msg.you .who { color: var(--text); }
@media (max-width: 760px) {
  #chat-modal { padding: 0; align-items: stretch; }
  .chat-card { width: 100%; height: 100vh; height: 100dvh; border-radius: 0; border: none; }
  #chat-history { max-width: 110px; }
}

/* ---- Oracle: the charts (Joey's pick of 2026-09-26, look 3): the band colours, the range row, the tooltip ---- */
:root, [data-theme="forge"], [data-theme="studio"] { --band-great: #1a7f5a; --band-good: #7cc4a0; --band-bad: #e6b23a; --band-ugly: #d94f3d; --band-quiet: #d9d6cf; --band-thin: #d9d6cf; }
.range { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 12px; }
.range .seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); }
.range .seg button { background: transparent; border: none; padding: 8px 12px; font: inherit; font-size: 13px; font-weight: 700; color: var(--muted); cursor: pointer; min-height: 40px; }
.range .seg button.on { background: var(--accent-dim); color: var(--accent); }
.range .custom { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.range .custom[hidden] { display: none; }
.range input[type=date] { font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); min-height: 40px; }
.range .span { margin-left: auto; }
svg.chart { display: block; width: 100%; height: auto; font-family: inherit; }
svg.chart text { fill: var(--muted); font-size: 11px; }
svg.chart .grid, svg.chart .axis { stroke: var(--line); stroke-width: 1; }
svg.chart .label { fill: var(--text); font-weight: 700; font-size: 12px; }
.chart-tip { position: fixed; z-index: 80; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.4; max-width: 240px; display: none; }
.chart-tip b { font-size: 14px; }
.chart-tip .row { display: flex; gap: 8px; align-items: center; }
.chart-tip .key { display: inline-block; width: 12px; height: 3px; border-radius: 2px; }
.delta { font-size: 13px; font-weight: 700; } .delta.up { color: var(--accent); } .delta.down { color: var(--band-ugly); } .delta.flat { color: var(--muted); }
.pill { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; border-radius: 6px; padding: 2px 7px; color: #fff; }
.pill.great { background: var(--band-great); } .pill.good { background: var(--band-good); color: #0f1115; } .pill.bad { background: var(--band-bad); color: #0f1115; } .pill.ugly { background: var(--band-ugly); } .pill.quiet, .pill.thin { background: var(--band-quiet); color: #6b6f76; }
@media (max-width: 760px) { .range .span { margin-left: 0; width: 100%; } }
