/* Co-Mac staff parts finder. Co-Mac brand colours (comac.nz): navy #374261, green #8dbf42,
   blue #0f73c2, gold #ffd700, Open Sans. Product codes are drawn as gold parts tags. */

@font-face { font-family: 'Open Sans'; font-weight: 400; font-display: swap; src: url('fonts/open-sans-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Open Sans'; font-weight: 600; font-display: swap; src: url('fonts/open-sans-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Open Sans'; font-weight: 700; font-display: swap; src: url('fonts/open-sans-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-display: swap; src: url('fonts/barlow-condensed-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 700; font-display: swap; src: url('fonts/barlow-condensed-latin-700-normal.woff2') format('woff2'); }

:root {
  --navy-900: #232b42;
  --navy-800: #2e3856;
  --navy: #374261;
  --ink: #1f2638;
  --muted: #5d6680;
  --paper: #f2f4f7;
  --surface: #ffffff;
  --line: #dde2ea;
  --green: #8dbf42;
  --green-600: #7cad35;
  --blue: #0f73c2;
  --gold: #ffd700;
  --gold-hover: #ffe14a;
  --warn-bg: #fff4d1;
  --warn-line: #e9c65a;
  --warn-ink: #634800;
  --danger: #a8261e;
  --font-body: 'Open Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-tag: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', sans-serif;
  --sidebar-w: 280px;
  --thread-w: 46rem;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

/* Parts tag: every product code. A punched hole sits on the left. */
.tag {
  position: relative;
  display: inline-block;
  font-family: var(--font-tag);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--navy-900);
  background: var(--gold);
  border: 0;
  border-radius: 3px 7px 7px 3px;
  line-height: 1.2;
}
.tag::before {
  content: '';
  position: absolute;
  top: 50%;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: inset 0 0 0 1.5px rgba(35, 43, 66, 0.45);
  transform: translateY(-50%);
}
.tag {
  font-size: 1.08rem;
  padding: 0.05em 0.5em 0.05em 1.15em;
  margin-right: 0.35em;
  cursor: copy;
  vertical-align: baseline;
}
.tag::before { left: 0.42em; width: 0.36em; height: 0.36em; }
.tag:hover { background: var(--gold-hover); }
.tag.copied::after {
  content: 'Copied';
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0;
  color: #fff;
  background: var(--navy-900);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
}

/* Buttons */
.btn-primary, .btn-new {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 0;
  border-radius: 999px;
  background: var(--green);
  color: var(--navy-900);
  font-weight: 700;
  padding: 0.7rem 1.3rem;
}
.btn-primary:hover, .btn-new:hover { background: var(--green-600); }
.btn-quiet { background: none; border: 0; color: inherit; text-decoration: underline; text-underline-offset: 3px; padding: 0.25rem 0; }
.btn-small { border: 1px solid var(--navy); background: var(--surface); color: var(--navy); border-radius: 999px; padding: 0.3rem 0.9rem; font-weight: 600; font-size: 0.85rem; }

/* ---------- Sign in ---------- */
.login-wrap { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.login-brand {
  background: var(--navy-900);
  color: #fff;
  padding: clamp(2rem, 6vw, 5rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.5rem;
}
.login-logo { width: 220px; height: auto; }
.login-lede { margin: 0; max-width: 26rem; font-size: 1.15rem; line-height: 1.5; color: rgba(255, 255, 255, 0.82); }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; }
.login-form { width: 100%; max-width: 22rem; display: flex; flex-direction: column; }
.login-form h1 { font-size: 1.6rem; margin: 0 0 1.25rem; color: var(--navy-900); }
.login-form label { font-weight: 600; margin-top: 1rem; margin-bottom: 0.35rem; }
.login-form input {
  border: 1px solid #c7cedb;
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  background: var(--surface);
}
.login-form input:focus { border-color: var(--blue); outline: 3px solid rgba(15, 115, 194, 0.25); outline-offset: 0; }
.login-form .btn-primary { margin-top: 1.5rem; padding: 0.8rem 1.3rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.35rem 0 0; font-weight: 400; }
.login-error { margin: 0 0 0.25rem; padding: 0.65rem 0.8rem; border-radius: 8px; background: #fdecea; color: var(--danger); font-weight: 600; }

/* ---------- App layout ---------- */
/* Browser extensions (password managers, Hudu, Grammarly) add their own elements to <body>.
   The sidebar and chat are pinned to the first row and any extra rows get no height,
   so those elements can't take a slice of the screen or push the layout around. */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  grid-auto-rows: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  grid-area: 1 / 1;
  background: var(--navy-900);
  color: rgba(255, 255, 255, 0.88);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.1rem 0.85rem 0.9rem;
  gap: 1rem;
}
.sidebar :focus-visible { outline-color: var(--gold); }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 0.7rem; padding: 0.2rem 0.35rem 0.4rem; }
.brand-logo { width: 130px; height: auto; }
.btn-new { width: 100%; justify-content: flex-start; padding: 0.65rem 1rem; }
.history { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -0.35rem; padding: 0 0.35rem; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.history h3 { font-size: 0.78rem; font-weight: 600; color: rgba(255, 255, 255, 0.55); margin: 1rem 0.6rem 0.35rem; }
.history ul { list-style: none; margin: 0; padding: 0; }
.chat-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  color: rgba(255, 255, 255, 0.86);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9rem;
}
.chat-link:hover { background: var(--navy-800); color: #fff; }
.chat-link[aria-current='true'] { background: var(--navy-800); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.history-empty { font-size: 0.85rem; color: rgba(255, 255, 255, 0.55); margin: 1rem 0.6rem; }
.me { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.75rem 0.4rem 0; border-top: 1px solid rgba(255, 255, 255, 0.12); font-size: 0.88rem; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me form { margin: 0; }

.main { grid-area: 1 / 2; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 0.5rem; padding: 0.85rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--paper); }
.btn-menu { display: none; border: 0; background: none; padding: 0.35rem; margin-left: -0.35rem; border-radius: 8px; color: var(--navy-900); }
.chat-title { margin: 0; font-size: 1rem; font-weight: 600; color: var(--navy-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.thread { flex: 1; min-height: 0; overflow-y: auto; padding: 1.5rem 1.25rem 1rem; scroll-behavior: smooth; }
.thread > * { max-width: var(--thread-w); margin-left: auto; margin-right: auto; }

/* Empty state */
.empty { padding: clamp(1.5rem, 8vh, 5rem) 0 1rem; }
.empty h2 {
  font-family: var(--font-tag);
  font-weight: 700;
  font-size: clamp(2.1rem, 4.5vw, 2.9rem);
  line-height: 1.05;
  color: var(--navy-900);
  margin: 0 0 0.6rem;
}
.empty p { margin: 0 0 1.5rem; max-width: 36rem; color: var(--muted); font-size: 1.02rem; }
.examples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
.example {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  color: var(--navy);
  line-height: 1.4;
}
.example:hover { border-color: var(--navy); color: var(--navy-900); }

/* Messages */
.msg { margin-top: 1.4rem; margin-bottom: 0; }
.msg:first-child { margin-top: 0; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user p {
  margin: 0;
  max-width: min(85%, 34rem);
  background: var(--navy);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
  padding: 0.6rem 0.95rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.answer { color: var(--ink); overflow-wrap: anywhere; }
.answer p { margin: 0 0 0.75rem; max-width: 42rem; }
.answer p:last-child { margin-bottom: 0; }
.answer ul, .answer ol { margin: 0 0 0.75rem; padding-left: 1.3rem; }
.answer strong { font-weight: 700; color: var(--navy-900); }
.answer a.lnk-text { color: var(--blue); }
.parts {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0 0 0.85rem;
}
.part {
  display: grid;
  grid-template-columns: minmax(4.5rem, max-content) minmax(0, 1fr);
  align-items: baseline;
  column-gap: 0.4rem;
  padding: 0.7rem 0.9rem;
  line-height: 1.5;
}
.part + .part { border-top: 1px solid var(--line); }
.part .tag { justify-self: start; }
.part-text { min-width: 0; }
.lnk-view, .lnk-admin {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.05rem 0.6rem;
  margin-left: 0.15rem;
  white-space: nowrap;
  border: 1.5px solid currentColor;
}
.lnk-view { color: var(--blue); }
.lnk-admin { color: var(--navy); }
.lnk-view:hover { background: var(--blue); border-color: var(--blue); color: #fff; }
.lnk-admin:hover { background: var(--navy); border-color: var(--navy); color: #fff; }
.badge-draft {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 600;
  color: #7a5200;
  background: #fff0c4;
  border-radius: 999px;
  padding: 0 0.5rem;
  white-space: nowrap;
}
.answer p.warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn-ink);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-weight: 600;
}

.msg-meta { display: flex; align-items: center; gap: 0.25rem; margin-top: 0.45rem; color: var(--muted); font-size: 0.8rem; }
.fb {
  border: 0;
  background: none;
  padding: 0.3rem;
  border-radius: 6px;
  color: var(--muted);
  line-height: 0;
}
.fb svg { width: 1.05rem; height: 1.05rem; }
.fb:hover { background: #e6eaf0; color: var(--navy-900); }
.fb[aria-pressed='true'].fb-up { color: #4f7f17; background: #e8f3da; }
.fb[aria-pressed='true'].fb-down { color: var(--danger); background: #fdecea; }
.took { margin-left: 0.4rem; }
.fb-note { display: flex; align-items: flex-end; gap: 0.5rem; margin-top: 0.5rem; max-width: 34rem; }
.fb-note label { flex: 1; display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; font-weight: 600; color: var(--navy); }
.fb-note input { border: 1px solid #c7cedb; border-radius: 8px; padding: 0.45rem 0.6rem; font-weight: 400; background: var(--surface); }
.fb-note input:focus-visible, .login-form input:focus-visible { outline: 3px solid rgba(15, 115, 194, 0.28); outline-offset: 0; border-color: var(--blue); }
.nowrap { white-space: nowrap; }
.fb-thanks { color: var(--muted); font-size: 0.8rem; margin: 0.4rem 0 0; }

.searching { display: inline-flex; align-items: center; gap: 0.6rem; color: var(--muted); font-size: 0.92rem; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 2px; background: var(--gold); box-shadow: inset 0 0 0 1px rgba(35, 43, 66, 0.25); animation: bob 1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bob { 0%, 80%, 100% { transform: translateY(0); opacity: 0.6; } 40% { transform: translateY(-4px); opacity: 1; } }

.msg-error p { margin: 0 0 0.5rem; color: var(--danger); font-weight: 600; }

/* Composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin: 0 auto;
  width: calc(100% - 2.5rem);
  max-width: var(--thread-w);
  background: var(--surface);
  border: 1px solid #c7cedb;
  border-radius: 26px;
  padding: 0.35rem 0.35rem 0.35rem 1.1rem;
  box-shadow: 0 6px 20px -12px rgba(35, 43, 66, 0.35);
}
.composer:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(15, 115, 194, 0.18); }
.composer textarea {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  background: none;
  padding: 0.55rem 0;
  max-height: 12rem;
  line-height: 1.45;
}
.btn-send {
  flex: none;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 0;
  background: var(--green);
  color: var(--navy-900);
  display: grid;
  place-items: center;
}
.btn-send:hover { background: var(--green-600); }
.btn-send:disabled { background: #d7dce5; color: #8a93a8; cursor: not-allowed; }
.composer-note { text-align: center; font-size: 0.78rem; color: var(--muted); margin: 0.45rem 1rem 0.8rem; }

.scrim { display: none; }

/* ---------- Phones and small tablets ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .main { grid-column: 1; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, 300px);
    z-index: 20;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, 0.35); }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(20, 25, 40, 0.45); z-index: 10; }
  .btn-menu { display: inline-flex; }
  .topbar { padding: 0.7rem 1rem; }
  .thread { padding: 1.1rem 1rem 0.75rem; }
  .composer { width: calc(100% - 1.5rem); }
  .examples { grid-template-columns: minmax(0, 1fr); }
  .login-wrap { grid-template-columns: minmax(0, 1fr); }
  .login-brand { padding: 2rem 1.25rem; gap: 1rem; }
  .login-lede { font-size: 1rem; }
}

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