/* chat.css -- page-specific styles for the springboard chat + sign-in pages.
   Builds on myai-theme.css: every colour here is a design-system token, so
   light and dark modes both work with no extra rules. */

html, body { min-height: 100%; }
body.chat-page { display: flex; flex-direction: column; min-height: 100vh; overflow-x: hidden; }

.skip-link { position: absolute; left: 12px; top: -48px; z-index: 60; padding: 8px 12px;
             background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.skip-link:focus { top: 10px; }

/* ------------------------------------------------------------- top bar --- */
.topbar { padding: 10px 16px; }
.brand-logo { width: 30px; height: 30px; border-radius: 9px; object-fit: cover; flex: none; }
.brand > span { min-width: 0; }
.brand .brand-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.usermenu { position: relative; }
.usermenu > summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer;
                      min-height: 36px; padding: 3px 10px 3px 3px; border-radius: 999px;
                      border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
                      font-size: 13px; font-weight: 600; }
.usermenu > summary::-webkit-details-marker { display: none; }
.usermenu > summary:hover { background: var(--surface-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
          background: var(--accent-2-soft); color: var(--accent-2); font-weight: 700; font-size: 13px; }
.usermenu .uname { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usermenu-panel { position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; z-index: 30;
                  padding: 12px; background: var(--surface); border: 1px solid var(--line);
                  border-radius: var(--radius); box-shadow: var(--shadow-2); }
.usermenu-panel .who { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.usermenu-panel .meta { font-size: 12px; color: var(--muted); margin: 2px 0 10px; }
.usermenu-panel .btn { width: 100%; }

/* ------------------------------------------------------------ chat area -- */
main.chat { flex: 1 0 auto; width: 100%; max-width: 860px; margin: 0 auto;
            padding: 24px 16px 0; display: flex; flex-direction: column; }
main.chat.empty { justify-content: center; }

#log { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
main.chat:not(.empty) #log { flex: 1 1 auto; }
main.chat.empty #log { display: none; }

/* empty state */
.welcome { display: none; text-align: center; margin: 0 auto 20px; max-width: 640px; }
main.chat.empty .welcome { display: block; }
.welcome-mark { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px; font-size: 24px; }
img.welcome-mark { display: block; object-fit: cover; box-shadow: var(--shadow-1); }
.welcome h1 { font-size: 1.7rem; letter-spacing: -.02em; margin-bottom: 6px; }
.welcome .lead { color: var(--muted); margin: 0 0 20px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; text-align: left; }
.suggest { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 12px 14px;
           font: 500 14px/1.4 var(--font); color: var(--ink-2); text-align: left;
           background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
           box-shadow: var(--shadow-1); cursor: pointer; transition: border-color .15s, background .15s; }
.suggest:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.suggest svg { width: 16px; height: 16px; flex: none; margin-top: 2px; color: var(--accent); }
@media (max-width: 560px) { .suggestions { grid-template-columns: 1fr; } }

/* messages */
.msg { padding: 12px 16px; border-radius: 16px; font-size: 15px; line-height: 1.6;
       min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.you { align-self: flex-end; max-width: 82%; white-space: pre-wrap;
       background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px;
       box-shadow: var(--shadow-1); }
.bot { align-self: flex-start; width: fit-content; background: var(--surface); color: var(--ink);
       border: 1px solid var(--line); border-bottom-left-radius: 6px; box-shadow: var(--shadow-1); }
.bot.err { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
@media (max-width: 480px) { .you { max-width: 92%; } .msg { padding: 10px 13px; } }

/* progress feed shown while the agent works */
.progress { display: flex; flex-direction: column; gap: 4px; }
.step { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.step .tick { color: var(--ok); font-weight: 700; }
.thinking { font-size: 14px; color: var(--ink-2); display: flex; align-items: center; gap: 10px; font-weight: 500; }
.dots { display: inline-flex; align-items: center; }

/* rendered answer formatting */
.answer > *:first-child { margin-top: 0; }
.answer > *:last-child { margin-bottom: 0; }
.answer p { margin: .6rem 0; }
.answer h3, .answer h4, .answer h5 { margin: 1rem 0 .45rem; line-height: 1.3; color: var(--ink); }
.answer h3 { font-size: 1.08rem; } .answer h4 { font-size: 1rem; } .answer h5 { font-size: .95rem; }
.answer ul, .answer ol { margin: .5rem 0; padding-left: 1.35rem; }
.answer li { margin: .25rem 0; }
.answer li::marker { color: var(--muted); }
.answer strong { color: var(--ink); }
.answer code { background: var(--surface-2); border: 1px solid var(--line); padding: .05rem .35rem;
               border-radius: 5px; font-size: .86em; }
.answer blockquote { margin: .7rem 0; padding: .5rem .9rem; border-left: 3px solid var(--accent);
                     background: var(--accent-soft); color: var(--ink-2); border-radius: 0 8px 8px 0; }
.answer hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.table-caption { font-weight: 600; margin: .8rem 0 .3rem; font-size: 14px; color: var(--ink); }
.table-note { font-size: 12px; color: var(--muted); margin: .25rem 0 .6rem; }

/* a table plus its Download buttons; wide / long tables scroll inside */
/* A bubble holding a table takes the full column, and the table never widens
   the page: it scrolls sideways INSIDE .tablescroll at every width. */
.bot:has(.tablewrap) { width: 100%; }
.answer { min-width: 0; max-width: 100%; }
.tablewrap { position: relative; margin: .8rem 0; border: 1px solid var(--line);
             border-radius: var(--radius); overflow: hidden; background: var(--surface);
             max-width: 100%; min-width: 0; }
.tablebar { display: flex; justify-content: flex-end; align-items: center; gap: 6px; padding: 6px 8px;
            background: var(--surface-2); border-bottom: 1px solid var(--line); }
.tablescroll { overflow: auto; max-width: 100%; max-height: min(70vh, 640px);
               overscroll-behavior-x: contain; scrollbar-width: auto;
               scrollbar-color: var(--line-strong) var(--surface-2); }
.tablescroll:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* always-visible scrollbar (overlay scrollbars hide the fact a table is wide) */
.tablescroll::-webkit-scrollbar { height: 12px; width: 12px; }
.tablescroll::-webkit-scrollbar-track { background: var(--surface-2); }
.tablescroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px;
                                        border: 3px solid var(--surface-2); }
.tablescroll::-webkit-scrollbar-thumb:hover { background: var(--muted); }
/* wide-table cue: a hint in the toolbar + a shadow on the edge that has more */
.tablehint { display: none; margin-right: auto; font-size: 12px; color: var(--muted); }
.tablewrap.is-wide .tablehint { display: inline; }
.tablewrap.is-wide.at-end .tablehint { visibility: hidden; }
.tablewrap::after, .tablewrap::before { content: ""; position: absolute; top: 0; bottom: 0; width: 28px;
                                        pointer-events: none; opacity: 0; transition: opacity .15s; z-index: 2; }
.tablewrap::after { right: 0; background: linear-gradient(to left, color-mix(in srgb, var(--ink) 16%, transparent), transparent); }
.tablewrap::before { left: 0; background: linear-gradient(to right, color-mix(in srgb, var(--ink) 16%, transparent), transparent); }
.tablewrap.is-wide:not(.at-end)::after { opacity: 1; }
.tablewrap.is-wide.scrolled::before { opacity: 1; }
.answer td.num, .answer th.num { text-align: right; font-variant-numeric: tabular-nums; }
.answer table { border-collapse: separate; border-spacing: 0; width: auto; min-width: 100%;
                margin: 0; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.answer thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--muted);
                   font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
                   padding: 9px 12px; white-space: nowrap; text-align: left;
                   border-bottom: 1px solid var(--line-strong); }
.answer tbody td { padding: 8px 12px; white-space: nowrap; border-bottom: 1px solid var(--line); color: var(--ink); }
.answer tbody tr:last-child td { border-bottom: 0; }
.answer tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.answer tbody tr:hover td { background: var(--accent-soft); }
.tablepager { display: flex; align-items: center; justify-content: space-between; gap: 8px;
              padding: 6px 8px; background: var(--surface-2); border-top: 1px solid var(--line); }
.tablepager .pgstatus { font-size: 12px; color: var(--muted); text-align: center; }

.dlbtn, .pgbtn { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px;
                 font: 600 12.5px/1 var(--font); color: var(--ink-2); background: var(--surface);
                 border: 1px solid var(--line-strong); border-radius: 8px; cursor: pointer;
                 text-decoration: none; transition: background .15s, border-color .15s, color .15s; }
.dlbtn:hover, .pgbtn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--ink);
                             text-decoration: none; }
.dlbtn[disabled] { opacity: .45; cursor: default; }
.dlbtn[disabled]:hover { background: var(--surface); border-color: var(--line-strong); color: var(--ink-2); }
.pgbtn { min-height: 34px; padding: 0 14px; font-size: 13px; }
.filebar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.pager { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* clickable disambiguation choices (entity resolution) */
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.choice { font: 600 13px/1.3 var(--font); padding: 7px 14px; border-radius: 999px; cursor: pointer;
          color: var(--accent); background: var(--accent-soft);
          border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.choice:hover { background: var(--accent); color: var(--accent-ink); }

/* ------------------------------------------------------------- composer -- */
.composer-dock { position: sticky; bottom: 0; z-index: 10; padding: 14px 0 16px;
                 background: linear-gradient(to bottom, transparent, var(--bg) 28%); }
main.chat.empty .composer-dock { position: static; background: none; }
.composer { display: flex; flex-direction: column; gap: 6px; padding: 8px;
            background: var(--surface); border: 1px solid var(--line-strong);
            border-radius: var(--radius-lg); box-shadow: var(--shadow-2);
            transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: var(--accent); box-shadow: var(--shadow-2), var(--focus); }
.attachbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 4px 0; }
.chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 3px 10px;
        font-size: 12px; font-weight: 600; border-radius: 999px; overflow-wrap: anywhere;
        background: var(--accent-2-soft); color: var(--accent-2);
        border: 1px solid color-mix(in srgb, var(--accent-2) 30%, transparent); }
.chip.err { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip .x { cursor: pointer; font-weight: 700; opacity: .7; }
.chip .x:hover { opacity: 1; }
.inputline { display: flex; align-items: flex-end; gap: 6px; }
.inputline .icon-btn { width: 40px; min-height: 40px; flex: none; color: var(--muted); }
.inputline .icon-btn:hover { color: var(--ink); }
.inputline svg { width: 18px; height: 18px; }
#q { flex: 1; min-width: 0; min-height: 40px; max-height: 168px; padding: 9px 6px;
     resize: none; overflow-y: auto; line-height: 1.45; font: 15px/1.45 var(--font);
     border: 0; background: transparent; box-shadow: none; }
#q:focus { outline: none; box-shadow: none; }
#send, #stop { flex: none; min-height: 40px; border-radius: 12px; }
#stop { background: var(--bad); border-color: var(--bad); color: #fff; }
:root[data-theme="dark"] #stop { color: #1a0606; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #stop { color: #1a0606; } }
#stop:hover { filter: brightness(1.08); }
.composer-hint { margin: 8px 4px 0; font-size: 12px; color: var(--muted); text-align: center; }
kbd { font: 600 11px/1 var(--mono); padding: 2px 5px; border-radius: 4px;
      border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink-2); }

/* -------------------------------------------- usage gate + welcome modal - */
.gate-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center;
                justify-content: center; padding: 16px; background: var(--overlay);
                backdrop-filter: blur(3px); overflow-y: auto; }
.gate-card { width: 100%; max-width: 480px; margin: auto; }
.gate-card h2 { font-size: 1.25rem; margin-bottom: 12px; }
.gate-card p { font-size: 14.5px; color: var(--ink-2); }
.gate-check { display: flex; gap: 10px; align-items: flex-start; margin: 16px 0 18px; padding: 12px;
              font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer;
              background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.gate-check input { margin-top: 3px; flex: none; width: 16px; height: 16px; accent-color: var(--accent); }
.gate-error { margin: -6px 0 12px; font-size: 13px; color: var(--danger, #b3261e); }
.gate-card { max-height: calc(100vh - 32px); overflow-y: auto; }
.btn-block { width: 100%; min-height: 42px; }
.wgreeting { min-height: 4.2rem; margin: 0 0 18px; display: flex; align-items: center;
             font-size: 15px; line-height: 1.6; color: var(--ink-2); }
.wpage2-lead { margin: 0 0 6px; color: var(--ink-2); }
.wlist { margin: 4px 0 14px; padding-left: 1.2rem; font-size: 14.5px; color: var(--ink-2); }
.wlist li { margin: 6px 0; }
.wexample { font-size: 13.5px; color: var(--muted); margin: 0 0 18px; padding: 10px 12px;
            background: var(--surface-2); border-radius: var(--radius-sm); }
.wexample b { color: var(--ink); }

/* ---------------------------------------------------------- small screens */
@media (max-width: 560px) {
  .brand small, .usermenu .uname { display: none; }
  .usermenu > summary { padding-right: 3px; }
  main.chat { padding: 16px 12px 0; }
  .welcome h1 { font-size: 1.4rem; }
  .composer-hint { display: none; }
  .gate-card.card-hero { padding: 20px; }
}

/* ------------------------------------------------------------ sign-in ---- */
body.login-page { min-height: 100vh; display: flex; flex-direction: column; }
.login-top { display: flex; justify-content: flex-end; padding: 12px 16px; }
.login-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px 16px 48px; }
.login-card { width: 100%; max-width: 400px; text-align: center; }
.login-card .brand-mark, .login-card .login-logo { width: 56px; height: 56px; border-radius: 16px;
                                                   margin: 0 auto 16px; font-size: 24px; }
.login-card .login-logo { display: block; object-fit: cover; box-shadow: var(--shadow-1); }
.login-card h1 { font-size: 1.55rem; letter-spacing: -.02em; margin-bottom: 6px; }
.login-card .sub { color: var(--muted); margin: 0 0 22px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-card label { margin-bottom: 0; }
.login-card .alert { text-align: left; margin-bottom: 16px; font-size: 14px; color: var(--bad); }
.login-card .hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 4px 0 0; text-align: center; }
.login-foot { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line);
              font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.login-foot .mode { font-size: 11.5px; }
#q::placeholder { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* -------------------------------------------------- chats + memory sidebar -- */
.top-new-chat { display: none; gap: 6px; align-items: center; }
.top-new-chat svg { width: 16px; height: 16px; }
body.has-history .top-new-chat { display: inline-flex; }
@media (max-width: 480px) { .top-new-chat span { display: none; } }

/* ------------------------------------------------- in-app confirmation -- */
.confirm-card { max-width: 420px; text-align: center; }
.confirm-icon { width: 48px; height: 48px; margin: 0 auto 12px; border-radius: 50%;
                display: flex; align-items: center; justify-content: center;
                color: var(--bad); background: var(--bad-soft); }
.confirm-icon svg { width: 24px; height: 24px; }
.confirm-card h2 { margin-bottom: 8px; }
.confirm-body { font-size: 14.5px; color: var(--ink-2); }
.confirm-body .what { margin: 0 0 4px; font-weight: 600; color: var(--ink);
                      overflow-wrap: anywhere; }
.confirm-body .meta { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.confirm-body ul { margin: 0 0 4px; padding: 10px 12px 10px 28px; text-align: left;
                   background: var(--surface-2); border: 1px solid var(--line);
                   border-radius: var(--radius-sm); font-size: 13.5px; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.confirm-actions .btn { min-width: 120px; min-height: 40px; }
.layout { display: flex; flex: 1 0 auto; min-height: 0; width: 100%; }
.layout > main.chat { min-width: 0; }
.side-toggle { display: none; }
.sidebar { width: 264px; flex: none; padding: 14px 12px; border-right: 1px solid var(--line);
           background: var(--surface); overflow-y: auto; max-height: calc(100vh - 60px);
           position: sticky; top: 0; display: flex; flex-direction: column; gap: 8px; }
.sidebar[hidden] { display: none; }
.side-h { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
          color: var(--muted); margin: 10px 4px 2px; }
.side-note { font-size: 12px; color: var(--muted); margin: 2px 4px; }
.chat-list, .memory-list { list-style: none; margin: 0; padding: 0; display: flex;
                           flex-direction: column; gap: 2px; }
.chat-item { display: flex; align-items: center; gap: 4px; border-radius: var(--radius-sm); }
.chat-item:hover, .chat-item.current { background: var(--surface-2); }
.chat-item .open { flex: 1; min-width: 0; text-align: left; background: none; border: 0;
                   padding: 7px 8px; cursor: pointer; color: var(--ink); font: inherit; }
.chat-item .open .t { display: block; font-size: 13px; white-space: nowrap; overflow: hidden;
                      text-overflow: ellipsis; }
.chat-item .open .d { display: block; font-size: 11px; color: var(--muted); }
.chat-item.working .open .d { color: var(--accent); animation: myai-pulse 1.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .chat-item.working .open .d { animation: none; } }
.chat-item .del, .memory-list .del { flex: none; border: 0; background: none; cursor: pointer;
                                     color: var(--muted); padding: 4px 8px; border-radius: 6px;
                                     font-size: 15px; line-height: 1; }
.chat-item .del:hover, .memory-list .del:hover { color: var(--bad); background: var(--bad-soft); }
.memory { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 8px; }
.memory > summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2);
                    padding: 4px; }
.memory-list li { display: flex; align-items: flex-start; gap: 4px; font-size: 12px;
                  color: var(--ink-2); padding: 4px; }
.memory-list li span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.memory #memory-clear { margin: 6px 4px 0; }
.msg.bot .history-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
@media (max-width: 900px) {
  body.has-history .side-toggle { display: inline-flex; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; max-height: none;
             box-shadow: var(--shadow-2); }
  .sidebar:not(.open) { display: none; }
}
