/* MagnoPilot — Phase 0 UI. Small, dependency-free, dark-neutral. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1c2330;
  --muted: #68707f;
  --primary: #2f5cff;
  --primary-hover: #244ae0;
  --danger: #c93b3b;
  --green: #167a4a;
  --green-bg: #e4f4ec;
  --red-bg: #fbe9e9;
  --blue-bg: #e8eeff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  font-size: 15px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef0f4; border-radius: 4px; padding: 1px 5px; font-size: .9em; }
h1 { font-size: 1.5rem; margin: 0 0 .8rem; }
h2 { font-size: 1.1rem; margin: 0 0 .7rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }

/* layout */
.topbar { background: #101623; color: #fff; }
.topbar-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 1.2rem; padding: .6rem 1rem; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; letter-spacing: .3px; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; }
.nav a { color: #c6cddc; }
.nav a.active, .nav a:hover { color: #fff; text-decoration: none; }
.nav .admin-link { color: #8fb0ff; }
.nav-disabled { color: #5a6478; cursor: not-allowed; }
.nav-sep { width: 1px; height: 18px; background: #2b3550; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .7rem; }
.topbar-right .muted { color: #9aa4b8; }
.container { max-width: 1100px; margin: 1.4rem auto 3rem; padding: 0 1rem; }
.footer { max-width: 1100px; margin: 0 auto 2rem; padding: 0 1rem; font-size: .85rem; }

/* cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1.1rem; }
.card.highlight { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 92, 255, .12); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.1rem; align-items: start; }
.grid .card { margin-bottom: 0; }
.section-title { margin-top: 1.6rem; }
.page-head { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .9rem; }
.page-head h1 { margin: 0; }

/* forms */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .1rem; }
label input, label select { font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=search], select {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); font: inherit; margin-top: .25rem;
}
input:focus, select:focus { outline: 2px solid rgba(47, 92, 255, .35); border-color: var(--primary); }
input:disabled { background: #f0f2f5; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: .85rem; align-items: flex-start; }
.stack label, .stack input, .stack select { width: 100%; }
.stack .btn { width: auto; }
.row-form { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row-form input, .row-form select { width: auto; flex: 1 1 180px; margin-top: 0; }
.checkbox { display: flex; align-items: center; gap: .4rem; font-weight: 400; white-space: nowrap; }
.inline { display: inline-flex; align-items: center; gap: .5rem; }
.copyable { width: 100%; font-family: ui-monospace, monospace; font-size: .85rem; background: #fffbe8; }

/* buttons */
.btn {
  display: inline-block; padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: #f0f2f6; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--red-bg); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn-sm { padding: .25rem .6rem; font-size: .85rem; }

/* tables */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.table-plain th { width: 38%; color: var(--muted); font-weight: 600; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* badges & flash */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; background: #eef0f4; color: var(--muted); font-size: .78rem; font-weight: 600; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--danger); }
.badge-blue { background: var(--blue-bg); color: var(--primary); }
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: .9rem; border: 1px solid; }
.flash-success { background: var(--green-bg); border-color: #bfe4d0; color: var(--green); }
.flash-error { background: var(--red-bg); border-color: #efc4c4; color: var(--danger); }
.flash-info { background: var(--blue-bg); border-color: #c9d7ff; color: var(--primary); }

/* auth / minimal layout */
.centered-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 2rem; width: 100%; max-width: 420px; }
.brand-large { font-size: 1.3rem; font-weight: 700; margin-bottom: 1.2rem; }

/* misc */
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error-page { text-align: center; padding: 3rem 0; }
.error-page h1 { font-size: 2.4rem; }
.debug { text-align: left; background: #101623; color: #d7e0f0; padding: 1rem; border-radius: 8px; overflow: auto; font-size: .8rem; }

/* ---- Phase 1: connections & chat ---- */
.badge-amber { background: #fff3d6; color: #8a5a00; }
.narrow { max-width: 480px; margin: 2rem auto; }
.container-wide { max-width: 1400px; }
.btn-block { display: block; text-align: center; width: 100%; }
.chat-layout { display: grid; grid-template-columns: 260px 1fr; gap: 1rem; height: calc(100vh - 140px); min-height: 480px; }
.chat-sidebar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; overflow-y: auto; }
.conv-list { list-style: none; margin: .8rem 0 0; padding: 0; }
.conv-list li { padding: .45rem .5rem; border-radius: 8px; display: flex; flex-direction: column; }
.conv-list li.active { background: var(--blue-bg); }
.conv-list li a { color: var(--text); font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-main { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 0; }
.chat-messages { flex: 1 1 auto; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .9rem; }
.chat-empty { margin: auto; }
.msg { max-width: 82%; padding: .6rem .9rem; border-radius: 12px; line-height: 1.5; }
.msg-user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-assistant { align-self: flex-start; background: #f0f2f6; border-bottom-left-radius: 4px; }
.msg-body { white-space: pre-wrap; word-wrap: break-word; }
.msg-status-streaming .msg-body::after { content: '▍'; animation: blink 1s steps(2) infinite; color: var(--muted); }
.msg-status-failed, .msg-status-interrupted { border: 1px solid #efc4c4; }
.msg-meta { margin-top: .35rem; font-size: .78rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.msg-error { color: var(--danger); font-weight: 600; }
.composer { border-top: 1px solid var(--border); padding: .7rem .9rem; display: flex; flex-direction: column; gap: .5rem; }
.composer textarea { width: 100%; resize: vertical; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
.composer-row { display: flex; align-items: center; gap: .6rem; justify-content: space-between; }
.composer-row select { width: auto; max-width: 70%; margin: 0; }
@keyframes blink { 50% { opacity: 0; } }
@media (max-width: 800px) { .chat-layout { grid-template-columns: 1fr; height: auto; } .chat-sidebar { max-height: 160px; } .msg { max-width: 95%; } }

/* ---- Phase 2: routing ---- */
.fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .9rem; display: flex; flex-wrap: wrap; gap: .8rem; }
.fieldset legend { font-weight: 600; font-size: .9rem; padding: 0 .3rem; }
.route-list { margin: .3rem 0 .5rem 1.2rem; padding: 0; }
.route-panel { font-size: .78rem; margin-top: .3rem; }
.route-panel summary { cursor: pointer; color: var(--primary); }
.route-body { margin-top: .3rem; padding: .5rem .7rem; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.route-body ol { margin: .3rem 0 .3rem 1.2rem; padding: 0; }
.route-body p { margin: .25rem 0; }
.route-body .ok { color: var(--green); font-weight: 600; }

/* ---- Phase 7: projects ---- */
textarea { width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; margin-top: .25rem; background: #fff; color: var(--text); }
textarea:focus { outline: 2px solid rgba(47, 92, 255, .35); border-color: var(--primary); }
.stack textarea { width: 100%; }
.pre-wrap { white-space: pre-wrap; word-wrap: break-word; background: #f7f8fb; border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; font: inherit; }
.project-bar { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; padding: .45rem .9rem; border-bottom: 1px solid var(--border); background: #f7f8fb; font-size: .85rem; }
.project-bar input[type=file] { font-size: .8rem; max-width: 220px; }
.chat-sidebar label.small { margin-top: .6rem; font-weight: 600; }
.chat-sidebar label.small select { margin-top: .2rem; font-size: .85rem; }
.doc-status { white-space: nowrap; }
input[type=file] { font: inherit; font-size: .9rem; }

/* ---- Phase 8: plans, usage, signup ---- */
.hp { position: absolute; left: -9999px; top: -9999px; height: 0; overflow: hidden; }
.card.highlight h2 { color: var(--primary); }

/* ---- checkboxes and radios: never stretched by the form layout rules above ---- */
input[type=checkbox], input[type=radio] { width: auto; margin: 0; flex: 0 0 auto; }
.stack input[type=checkbox], .stack input[type=radio], .row-form input[type=checkbox], .row-form input[type=radio] { width: auto; flex: 0 0 auto; margin-top: 0; }
.checkbox { justify-content: flex-start; text-align: left; }
.fieldset .checkbox, .row-form .checkbox { width: auto; }

/* ---- dashboard activity table ---- */
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table.stats th:first-child { color: var(--muted); font-weight: 600; white-space: nowrap; }

/* Chat: rendered Markdown replies, ChatGPT/Claude-like layout (2026-09-05) */
.chat-main { position: relative; }
.chat-messages { gap: 1.1rem; }
.msg-assistant { background: transparent; max-width: 100%; padding: .1rem .2rem; border-radius: 0; }
.msg-assistant.msg-status-failed, .msg-assistant.msg-status-interrupted { background: #fdf4f4; padding: .6rem .9rem; border-radius: 12px; }
.msg-assistant .msg-body:not(.md-rendered) { white-space: pre-wrap; }
.msg-assistant .msg-body.md-rendered { white-space: normal; line-height: 1.6; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7rem; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1rem 0 .45rem; line-height: 1.3; font-weight: 650; }
.md h1 { font-size: 1.25rem; } .md h2 { font-size: 1.15rem; } .md h3 { font-size: 1.05rem; } .md h4, .md h5, .md h6 { font-size: 1rem; }
.md ul, .md ol { margin: .2rem 0 .7rem; padding-left: 1.5rem; }
.md li { margin: .2rem 0; }
.md li > p { margin: 0 0 .35rem; }
.md li > ul, .md li > ol { margin: .2rem 0 .2rem; }
.md blockquote { margin: .4rem 0 .7rem; padding: .25rem .9rem; border-left: 3px solid var(--border); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: .9rem 0; }
.md a { text-decoration: underline; }
.md strong { font-weight: 650; }
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; background: rgba(28, 35, 48, .07); padding: .1em .35em; border-radius: 4px; }
.md .code-block { margin: .5rem 0 .8rem; border-radius: 8px; overflow: hidden; border: 1px solid #2a3140; }
.md .code-head { display: flex; justify-content: space-between; align-items: center; background: #2a3140; color: #c8cfdb; font-size: .74rem; padding: .28rem .75rem; }
.md .code-copy { background: transparent; border: 1px solid #4a5468; color: inherit; border-radius: 5px; padding: .1rem .55rem; font-size: .72rem; cursor: pointer; }
.md .code-copy:hover { background: #3a4356; }
.md pre { margin: 0; padding: .75rem .9rem; overflow-x: auto; background: #1e2430; color: #e8ecf3; font-size: .85rem; line-height: 1.5; }
.md pre code { background: none; padding: 0; font-size: inherit; color: inherit; }
.md .table-wrap { overflow-x: auto; margin: .4rem 0 .8rem; }
.md table { border-collapse: collapse; font-size: .92em; }
.md th, .md td { border: 1px solid var(--border); padding: .35rem .6rem; text-align: left; vertical-align: top; }
.md th { background: rgba(28, 35, 48, .04); font-weight: 600; }
.jump-latest { position: absolute; left: 50%; transform: translateX(-50%); bottom: 9.5rem; z-index: 2; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: .35rem .9rem; font-size: .82rem; box-shadow: 0 4px 14px rgba(0, 0, 0, .12); cursor: pointer; }
.jump-latest:hover { background: #f4f6fa; }
