/* ATLAS maintenance assistant — shop-floor UI: dark, high contrast, big targets. */

:root {
  --bg:        #0e1116;
  --bg-2:      #151a21;
  --bg-3:      #1c232c;
  --line:      #2a3441;
  --fg:        #e6ecf3;
  --fg-dim:    #93a1b2;
  --accent:    #d62b1f;   /* brand red: buttons, active markers */
  --accent-2:  #ff9086;   /* light red: links and headings on dark */
  --brand:     #f4392c;   /* wordmark red — brighter than --accent so it
                             clears 4.5:1 as text on the dark background */
  --on-accent: #ffffff;   /* text on an --accent fill */
  --user:      #1e3a5f;
  --err:       #ff6b6b;
  --ok:        #4ade80;
  --radius:    12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent-2); }

/* ------------------------------------------------------------- login */
.login-page {
  display: grid; place-items: center; min-height: 100vh; padding: 20px;
}
.login-box {
  width: 100%; max-width: 440px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 28px;
}
/* Scales with the viewport so the lockup stays on one line; if a very narrow
   screen forces a break it falls to wordmark-over-tagline, which still reads. */
.login-box h1 {
  margin: 0 0 22px; font-size: clamp(14px, 4.2vw, 21px); font-weight: 400;
  display: flex; align-items: baseline; gap: .45em; flex-wrap: wrap;
}
.login-box .wordmark { font-size: 1.2em; }
.login-box .tagline { color: var(--fg-dim); }
.login-box label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--fg-dim); }
.login-box input {
  width: 100%; margin-top: 6px; padding: 14px; font-size: 17px;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--line); border-radius: 8px;
}
.login-box button {
  width: 100%; padding: 15px; font-size: 17px; font-weight: 600;
  background: var(--accent); color: var(--on-accent); border: 0;
  border-radius: 8px; cursor: pointer;
}
.login-box .hint { margin: 14px 0 0; font-size: 12px; color: var(--fg-dim); text-align: center; }
@media (max-width: 420px) {
  .login-page { padding: 14px; }
  .login-box { padding: 24px 18px; }
}
.err { color: var(--err); }

/* --------------------------------------------------------------- shell */
.app { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 270px; flex: 0 0 270px; background: var(--bg-2);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.side-head { padding: 14px; border-bottom: 1px solid var(--line); }
.newchat {
  display: block; text-align: center; padding: 12px; border-radius: 8px;
  background: var(--bg-3); color: var(--fg); text-decoration: none; font-weight: 600;
}
.chatlist { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item {
  display: block; padding: 11px 12px; border-radius: 8px;
  color: var(--fg); text-decoration: none; margin-bottom: 3px;
}
.chat-item:hover { background: var(--bg-3); }
.chat-item.active { background: var(--bg-3); border-left: 3px solid var(--accent); }
.ci-title {
  display: block; font-size: 14px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.ci-meta {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 11px; color: var(--fg-dim); margin-top: 2px;
}
/* Name is truncated, timestamp never is — the date must stay readable. */
.ci-user {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ci-user::before { content: "· "; }
.empty { color: var(--fg-dim); font-size: 14px; padding: 12px; }
.side-foot {
  padding: 12px 14px; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; font-size: 13px; color: var(--fg-dim);
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.topbar .brand {
  flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 9px;
}
.wordmark { color: var(--brand); font-weight: 800; letter-spacing: .09em; }
.topbar .wordmark { font-size: 20px; line-height: 1; }
.topbar .tagline {
  color: var(--fg-dim); font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  display: inline-grid; place-items: center; min-width: 44px; height: 44px;
  border-radius: 10px; background: var(--bg-3); border: 1px solid var(--line);
  color: var(--fg); font-size: 19px; cursor: pointer; text-decoration: none;
}
#menuBtn { display: none; }

/* ------------------------------------------------------------ messages */
.messages { flex: 1; overflow-y: auto; padding: 20px 16px 8px; scroll-behavior: smooth; }
.turn { max-width: 860px; margin: 0 auto 26px; }

.msg.user {
  background: var(--user); border-radius: var(--radius);
  padding: 12px 15px; margin-left: auto; max-width: 85%; width: fit-content;
}
.msg.user p { margin: 0 0 6px; white-space: pre-wrap; }
.msg.user p:last-child { margin-bottom: 0; }
.msg.bot { margin-top: 16px; }

.thumb {
  max-width: 220px; max-height: 220px; border-radius: 8px;
  margin-top: 8px; display: block; border: 1px solid var(--line);
}
.filechip {
  display: inline-block; margin-top: 8px; padding: 6px 11px;
  background: var(--bg-3); border-radius: 6px; font-size: 13px; text-decoration: none;
}
.upload-warn { color: var(--accent-2); font-size: 13px; margin: 8px 0 0; }

.thinking { display: flex; align-items: center; gap: 10px; color: var(--fg-dim); font-size: 14px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

.answer.stream { white-space: pre-wrap; }

/* --------------------------------------------------------- answer body */
.answer { font-size: 16px; }
.answer h1 { font-size: 21px; margin: 20px 0 10px; }
.answer h2 { font-size: 18px; margin: 22px 0 8px; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.answer h3 { font-size: 16px; margin: 18px 0 6px; color: var(--accent-2); }
.answer p { margin: 0 0 12px; }
.answer ul, .answer ol { margin: 0 0 12px; padding-left: 22px; }
.answer li { margin-bottom: 6px; }
.answer code {
  background: var(--bg-3); padding: 2px 6px; border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9em;
}
.answer pre {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 13px; overflow-x: auto; margin: 0 0 14px;
}
.answer pre code { background: none; padding: 0; }
.answer blockquote {
  margin: 0 0 12px; padding: 8px 14px;
  border-left: 3px solid var(--accent); background: var(--bg-2); color: var(--fg-dim);
}
.answer table {
  border-collapse: collapse; width: 100%; margin: 0 0 14px;
  font-size: 14px; display: block; overflow-x: auto;
}
.answer th, .answer td { border: 1px solid var(--line); padding: 8px 11px; text-align: left; }
.answer th { background: var(--bg-3); }

/* ------------------------------------------------- document references */
.ref {
  margin: 14px 0; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.ref-doc { padding: 0; }
.ref-doc img {
  display: block; width: 100%; background: #fff; cursor: zoom-in;
}
.ref-doc figcaption {
  padding: 11px 14px; display: flex; flex-wrap: wrap;
  align-items: center; gap: 8px 12px;
}
.ref-cap { font-size: 14px; flex: 1 1 220px; }
.ref-meta { font-size: 12px; color: var(--fg-dim); flex: 1 1 100%; }
.ref-btn {
  padding: 9px 14px; background: var(--accent); color: var(--on-accent);
  border-radius: 8px; font-size: 13px; font-weight: 600; text-decoration: none;
  white-space: nowrap;
}
.ref-trace, .ref-block {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 13px 15px;
}
.ref-ico { font-size: 20px; }
.ref-bad {
  padding: 11px 14px; color: var(--accent-2);
  background: var(--bg-2); border-color: var(--accent); font-size: 14px;
}

/* -------------------------------------------------------------- welcome */
.welcome { max-width: 640px; margin: 8vh auto 0; text-align: center; }
.welcome h1 { font-size: 26px; margin: 0 0 12px; }
.welcome p { color: var(--fg-dim); margin: 0 0 26px; }
.examples { display: flex; flex-direction: column; gap: 10px; }
.ex {
  padding: 14px 16px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; color: var(--fg); font-size: 15px; text-align: left; cursor: pointer;
}
.ex:hover { border-color: var(--accent); }

/* ------------------------------------------------------------- composer */
.composer {
  border-top: 1px solid var(--line); background: var(--bg-2);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; max-width: 860px; margin: 0 auto; }
#input {
  flex: 1; resize: none; padding: 13px 14px; font: inherit; line-height: 1.45;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--line); border-radius: 10px; max-height: 200px;
}
#input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.send {
  flex: 0 0 auto; width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  cursor: pointer; display: grid; place-items: center;
}
/* The plane points up-right, so its mass sits low-left; nudge to optical centre. */
.send svg {
  width: 20px; height: 20px; display: block;
  fill: currentColor; transform: translate(1px, -1px);
}
.send:disabled { opacity: .45; cursor: default; }
.previews { display: none; gap: 8px; flex-wrap: wrap; max-width: 860px; margin: 0 auto 10px; }
.previews.has { display: flex; }
.preview {
  position: relative; background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px; font-size: 12px;
}
.preview img { display: block; max-width: 84px; max-height: 84px; border-radius: 4px; }
.preview-x {
  position: absolute; top: -8px; right: -8px; width: 24px; height: 24px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--bg);
  color: var(--fg); cursor: pointer; line-height: 1;
}
.disclaimer {
  max-width: 860px; margin: 9px auto 0; font-size: 11.5px;
  color: var(--fg-dim); text-align: center;
}

/* ------------------------------------------------------- doc/trace page */
.doc-page { padding: 0 0 60px; }
.doc-head {
  display: flex; align-items: center; gap: 16px; padding: 14px 18px;
  border-bottom: 1px solid var(--line); background: var(--bg-2);
  position: sticky; top: 0;
}
.doc-title { color: var(--fg-dim); font-size: 14px; }
.back { text-decoration: none; font-weight: 600; }
.doc-page .answer { max-width: 900px; margin: 24px auto; padding: 0 18px; }
.block-dump {
  max-width: 1000px; margin: 24px auto; padding: 16px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 8px; overflow-x: auto;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5;
}

/* ---------------------------------------------------------------- phone */
@media (max-width: 880px) {
  #menuBtn { display: inline-grid; }
  .topbar .tagline { display: none; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .messages { padding: 14px 12px 4px; }
  .msg.user { max-width: 92%; }
  .welcome { margin-top: 4vh; }
  .answer { font-size: 15.5px; }
}

/* ------------------------------------------------- save as a trace card */
.save-trace {
  padding: 10px 14px; border-radius: 10px; cursor: pointer;
  background: var(--bg-3); border: 1px solid var(--line);
  color: var(--fg); font-size: 13.5px; font-weight: 600; white-space: nowrap;
}
.save-trace:hover:not(:disabled) { border-color: var(--accent); }
.save-trace:disabled { opacity: .5; cursor: default; }
.save-trace.saved { color: var(--ok); border-color: var(--ok); }

.msg.note {
  background: transparent; border: 1px dashed var(--line);
  border-radius: var(--radius); padding: 10px 14px;
  color: var(--fg-dim); font-size: 14px; text-align: center;
}
.msg.note p { margin: 0; }
.turn-trace .msg.bot { margin-top: 12px; }

.ref-field { border-left: 3px solid var(--ok); }

/* front matter strip on a saved analysis */
.front {
  max-width: 900px; margin: 20px auto -6px; padding: 14px 18px;
  display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13.5px;
}
.front dt { color: var(--fg-dim); }
.front dd { margin: 0; }

@media (max-width: 880px) {
  .save-trace { font-size: 0; padding: 12px; }
  .save-trace::before { content: '💾'; font-size: 18px; }
  .save-trace.saved::before { content: '✓'; }
  .front { margin: 14px 12px -6px; }
}
