/* IP Brain: flat, light/dark. Colours are tokens; dark mode follows the system unless the user picks one. */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e2e5ea;
  --text: #1c2230; --muted: #667085; --accent: #2f5bd3; --accent-soft: #e8eefc; --accent-text: #ffffff;
  --error: #c2362b; --warn-bg: #fff6e0; --warn-text: #7a5300;
  --g-patent: #2f5bd3; --g-chart: #d9822b; --g-company: #2e9d6a; --g-tech: #9b51e0; --g-source: #98a2b3;
  --g-other: #c4c9d2;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --surface: #1a1e26; --surface-2: #222833; --border: #2d3442;
    --text: #e6e9ef; --muted: #98a2b3; --accent: #7c9cf5; --accent-soft: #24304d; --accent-text: #0f1420;
    --error: #ff8a80; --warn-bg: #3a3020; --warn-text: #f3d48a;
    --g-patent: #7c9cf5; --g-chart: #f0a456; --g-company: #4cc38a; --g-tech: #b98af0; --g-source: #6b7588;
    --g-other: #4a5263;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b; --surface: #1a1e26; --surface-2: #222833; --border: #2d3442;
  --text: #e6e9ef; --muted: #98a2b3; --accent: #7c9cf5; --accent-soft: #24304d; --accent-text: #0f1420;
  --error: #ff8a80; --warn-bg: #3a3020; --warn-text: #f3d48a;
  --g-patent: #7c9cf5; --g-chart: #f0a456; --g-company: #4cc38a; --g-tech: #b98af0; --g-source: #6b7588;
  --g-other: #4a5263;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--error); }
.missing { color: var(--muted); border-bottom: 1px dotted var(--muted); }
.icon { width: 18px; height: 18px; flex: none; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px;
  height: 56px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--text); font-size: 1.05rem;
  white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-icon { width: 24px; height: 24px; color: var(--accent); }
.portfolio { color: var(--muted); padding-left: 14px; border-left: 1px solid var(--border); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.badge { margin-left: auto; font-size: .8rem; padding: 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.user { position: relative; display: flex; align-items: center; gap: 8px; }
.who { font-size: .9rem; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn, .menu-btn {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.menu-btn { display: none; border-radius: 8px; font-size: 1.1rem; }
.user-menu {
  position: absolute; right: 0; top: 44px; width: 220px; padding: 12px; display: grid; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.user-menu[hidden] { display: none; }
.user-menu label { display: flex; justify-content: space-between; align-items: center; }
.user-menu select { background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 6px; font: inherit; }

/* layout */
.shell { display: flex; min-height: calc(100vh - 56px); }
.sidenav { width: 210px; flex: none; padding: 14px 10px; border-right: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; color: var(--text); }
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.main { flex: 1; min-width: 0; padding: 24px; max-width: 1150px; display: grid; gap: 18px; align-content: start; }

/* cards and panels */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat { display: grid; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); }
.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat-num { font-size: 1.7rem; font-weight: 650; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: .85rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.page-head { display: flex; align-items: baseline; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.notice { background: var(--warn-bg); color: var(--warn-text); padding: 8px 12px; border-radius: 8px; margin: 0; }

/* buttons and inputs */
.btn { font: inherit; border-radius: 8px; padding: 8px 16px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-primary:disabled { opacity: .55; cursor: wait; }
.btn-quiet { background: transparent; }
input, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; width: 100%; }
input:focus, textarea:focus, .btn:focus-visible, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filter { max-width: 320px; }

/* chat */
.messages { display: flex; flex-direction: column; gap: 12px; max-height: 60vh; min-height: 140px; overflow-y: auto;
  padding: 4px 2px 12px; }
.empty p { margin-top: 0; color: var(--muted); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; }
.example { font: inherit; font-size: .85rem; cursor: pointer; text-align: left; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.example:hover { border-color: var(--accent); }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; overflow-wrap: anywhere; }
.msg p { margin: 0 0 .5em; }
.msg p:last-child { margin-bottom: 0; }
.msg ul { margin: .2em 0 .5em; padding-left: 1.3em; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.msg.bot { align-self: flex-start; background: var(--surface-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; }
.chip { font-size: .8rem; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.answered { margin-top: 6px; }
.cursor { display: inline-block; width: 7px; height: 1em; vertical-align: text-bottom; background: var(--muted);
  animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.ask-form { display: flex; gap: 10px; align-items: flex-end; }
.ask-form textarea { resize: vertical; min-height: 46px; }
.queue { margin: 8px 0 0; }

/* lists and tables */
.recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recent li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.pill { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }

/* notes */
.crumbs { overflow-wrap: anywhere; }
.note { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 24px 20px;
  overflow-wrap: anywhere; }
.note h1 { margin-top: .8rem; }
.note h2 { font-size: 1.15rem; margin: 1.4rem 0 .6rem; }
.note h3 { font-size: 1rem; margin: 1.2rem 0 .5rem; }
.note pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; }
.note code { font-family: ui-monospace, Consolas, monospace; font-size: .88em; }
.note blockquote { margin: 0; padding: 4px 14px; border-left: 3px solid var(--border); color: var(--muted); }
.note .table-wrap { margin: .5rem 0 1rem; }

/* home: chat on the left, graph on the right */
.main.wide { max-width: 1500px; }
.home { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 40%); gap: 18px; align-items: start; }
.home-main { display: grid; gap: 18px; min-width: 0; }
.home-side { position: sticky; top: 74px; }

/* graph */
.graph-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.graph-tools label { display: flex; align-items: center; gap: 4px; color: var(--muted); margin-right: 4px; }
.graph-tools input { width: auto; }
.graph-legend { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-bottom: 8px; }
.legend-item { font: inherit; font-size: .8rem; display: flex; align-items: center; gap: 5px; padding: 2px 8px;
  border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; }
.legend-item.off { opacity: .4; text-decoration: line-through; }
.legend-item .dot { width: 9px; height: 9px; border-radius: 50%; }
.graph-canvas { position: relative; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  overflow: hidden; }
.graph-canvas canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.graph-small .graph-canvas { height: min(560px, calc(100vh - 260px)); min-height: 320px; }
.graph-full .graph-canvas { height: calc(100vh - 230px); min-height: 420px; }
.graph-tip { position: absolute; left: 10px; top: 8px; max-width: calc(100% - 20px); font-size: .85rem;
  padding: 3px 10px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); }
.graph-tip[hidden] { display: none; }
.graph-help { margin: 8px 0 0; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; padding: 28px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 4px; font-size: .9rem; }
.login-brand { font-size: 1.3rem; }
.login-card .show-pw { display: flex; align-items: center; gap: 6px; font-size: .85rem; margin-top: -6px; }
.show-pw input { width: auto; margin: 0; }

@media (max-width: 1100px) {
  .home { grid-template-columns: 1fr; }
  .home-side { position: static; }
}

/* phones and small windows */
@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: 1fr; }
  .menu-btn { display: grid; }
  .portfolio { display: none; }
  .sidenav { position: fixed; top: 56px; bottom: 0; left: 0; z-index: 9; transform: translateX(-100%);
    transition: transform .15s; box-shadow: 4px 0 18px rgba(0, 0, 0, .12); }
  .sidenav.open { transform: none; }
  .main { padding: 16px; }
  .msg { max-width: 100%; }
}
