:root {
  --accent: #2563eb;
  --accent-deep: #1d4ed8;
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --bg-soft: #0f172a;
  --bg-elev2: #1e293b;
  --ink: #e2e8f0;
  --muted: #64748b;
  --line: #334155;
  --accent-soft: color-mix(in srgb, #2563eb 16%, transparent);
  --chat: 420px;
  --chrome: 48px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --display: var(--font);
  --mono: "SF Mono", "Cascadia Code", "Fira Code", Menlo, monospace;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

*::-webkit-scrollbar { display: none; }
.chat-panel, .canvas-area, .md pre, .md-table-wrap { scrollbar-width: none; }

body { overflow: hidden; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.err { color: #ef4444; font-size: 12px; }
.ok { color: #22c55e; font-size: 12px; padding: 8px 0; }

/* ---- Landing ---- */

.landing-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.landing {
  text-align: center; max-width: 420px; padding: 40px 24px;
}
.landing-mark {
  width: 64px; height: 64px; color: var(--accent); margin-bottom: 24px;
}
.landing-brand {
  font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 12px;
}
.landing-line {
  color: var(--muted); font-size: 15px; margin-bottom: 28px; line-height: 1.6;
}
.landing-actions {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
}
.btn-primary {
  display: inline-block; padding: 10px 20px;
  background: var(--accent); color: #fff;
  border: 0; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn-primary:hover { background: var(--accent-deep); text-decoration: none; }
.btn-ghost {
  display: inline-block; padding: 10px 20px;
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 14px; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn-ghost:hover { border-color: var(--accent); text-decoration: none; }

/* ---- Auth ---- */

.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.auth-card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 12px; padding: 36px 32px; max-width: 380px; width: 100%;
  text-align: center;
}
.auth-logo { width: 48px; height: 48px; color: var(--accent); margin-bottom: 16px; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: 6px; }
.subtitle { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.form-error {
  background: rgba(239,68,68,.1); color: #ef4444;
  padding: 8px 12px; border-radius: var(--radius);
  font-size: 13px; margin-bottom: 16px;
}
.field { margin-bottom: 16px; text-align: left; }
.field label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--muted); margin-bottom: 6px;
}
.field input {
  width: 100%; padding: 10px 12px;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 14px; font-family: var(--font);
}
.field input:focus { outline: none; border-color: var(--accent); }
.auth-card .btn-primary { width: 100%; margin-top: 8px; }
.auth-switch { margin-top: 20px; font-size: 13px; color: var(--muted); }

/* ---- App shell ---- */

.app-shell {
  display: flex; height: 100vh; width: 100vw; overflow: hidden;
}
.canvas-pane {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  border-right: 0;
  background: var(--bg);
}
.topbar { display: none; }
.canvas-area {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 0;
  background: var(--bg);
}
.canvas-empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%; min-height: 300px;
}
.canvas-logo {
  width: 80px; height: 80px; color: var(--muted); opacity: 0.3;
}
.canvas-view {
  min-height: 100%; padding: 24px;
}
.canvas-view[data-title=""] { padding: 0; }

/* ---- Chat pane ---- */

.chat-pane {
  width: var(--chat); flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  position: relative;
  border-left: 1px solid var(--line);
}
.chat-resize {
  position: absolute; left: -3px; top: 0; bottom: 0;
  width: 6px; cursor: col-resize; z-index: 10;
}
.chat-resize:hover, .chat-resize.is-dragging {
  background: transparent;
}
.chat-panel {
  flex: 1; overflow-y: auto; overflow-x: hidden;
}
.chat-view { min-height: 100%; display: flex; flex-direction: column; }
.messages {
  display: flex; flex-direction: column; gap: 0;
  padding: 0; width: 100%;
  border-top: 1px solid var(--line);
}
.chat-empty { text-align: center; padding: 60px 16px; }
.chat-empty-title {
  font-family: var(--display); font-size: 1.15rem;
  margin-bottom: 6px; color: var(--ink);
}

.msg {
  display: block; width: 100%;
  border-bottom: 1px solid var(--line);
}
.bubble {
  width: 100%; max-width: none;
  padding: 12px 14px; border-radius: 0; font-size: 13px; line-height: 1.5;
  word-wrap: break-word; overflow-wrap: anywhere;
  box-sizing: border-box;
}
.user-bubble {
  background: var(--accent-soft);
  color: var(--ink);
  white-space: pre-wrap;
  border: 0;
  position: relative;
  overflow: hidden;
}
.user-bubble:has(.turn-meta) { padding-right: 7.5rem; }
.user-bubble .bubble-text { position: relative; z-index: 1; }
.user-bubble.working::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; z-index: 0;
  width: 55%;
  background: linear-gradient(90deg, transparent 0%,
    color-mix(in srgb, var(--bg-elev) 55%, transparent) 45%,
    color-mix(in srgb, var(--bg-elev) 70%, transparent) 50%,
    color-mix(in srgb, var(--bg-elev) 55%, transparent) 55%,
    transparent 100%);
  animation: sheen 1.7s linear infinite;
  pointer-events: none;
}
@keyframes sheen {
  from { transform: translateX(-120%); }
  to { transform: translateX(220%); }
}
.turn-meta {
  position: absolute; top: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: flex-end;
  padding: 0 12px 0 28px;
  pointer-events: none; z-index: 2;
  background: linear-gradient(to right,
    transparent 0%,
    color-mix(in srgb, var(--accent-soft) 88%, var(--bg-elev)) 28%,
    color-mix(in srgb, var(--accent-soft) 96%, var(--bg-elev)) 100%);
}
.turn-meta-text {
  font-size: 11px; font-weight: 650;
  letter-spacing: .01em; color: var(--muted);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.draft-bubble { opacity: 0.72; border-top: 1px dashed var(--line); }
.assistant-bubble { background: transparent; border: 0; color: var(--ink); }
.chat-run {
  width: 8px; height: 8px; border-radius: 50%;
  border: 1.5px solid var(--accent); border-top-color: transparent;
  animation: spin .7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Markdown ---- */

.md { font-size: 13px; line-height: 1.65; }
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { margin: 18px 0 10px; font-weight: 650; }
.md h1 { font-size: 1.35rem; }
.md h2 { font-size: 1.15rem; }
.md h3 { font-size: 1rem; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin-bottom: 5px; }
.md li > ul, .md li > ol { margin-top: 4px; margin-bottom: 4px; }
.md code {
  font-family: var(--mono); font-size: 12px;
  background: var(--bg-elev); padding: 2px 6px; border-radius: 4px;
  border: 1px solid var(--line);
}
.md pre {
  background: var(--bg-elev); padding: 12px; border-radius: var(--radius);
  overflow-x: auto; margin: 0 0 12px;
  border: 1px solid var(--line);
}
.md pre code { background: none; padding: 0; border: 0; }
.md blockquote {
  margin: 0 0 12px; padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: var(--bg-elev); color: var(--ink);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.md blockquote p:last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md a:hover { color: var(--accent-deep); }
.md-table-wrap { overflow-x: auto; margin: 0 0 12px; }
.md-table-wrap table, .data-table {
  border-collapse: collapse; width: 100%; font-size: 12px;
}
.md-table-wrap th, .md-table-wrap td,
.data-table th, .data-table td {
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid var(--line);
}
.md-table-wrap th, .data-table th {
  font-weight: 650; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.data-table { margin: 12px 0; }

/* ---- Canvas content ---- */

.card-list { display: flex; flex-direction: column; gap: 8px; }
.card-item {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.card-item-title { font-weight: 650; font-size: 14px; margin-bottom: 4px; }
.card-item-meta { font-size: 12px; color: var(--muted); }
.empty-state {
  text-align: center; padding: 40px 16px;
  color: var(--muted); font-size: 13px;
}
.empty-state strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* canvas forms */
form.minios-form, .canvas-view form {
  display: flex; flex-direction: column; gap: 10px; max-width: 480px; margin-bottom: 20px;
}
.canvas-view input[type="text"],
.canvas-view input[type="number"],
.canvas-view input[type="date"],
.canvas-view select,
.canvas-view textarea {
  width: 100%; padding: 8px 10px;
  background: var(--bg-elev); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13px; font-family: var(--font);
}
.canvas-view input:focus, .canvas-view select:focus, .canvas-view textarea:focus {
  outline: none; border-color: var(--accent);
}
.canvas-view button[type="submit"] {
  align-self: flex-start; padding: 8px 16px;
  background: var(--accent); color: #fff;
  border: 0; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.canvas-view button[type="submit"]:hover { background: var(--accent-deep); }
.canvas-view h1, .canvas-view h2, .canvas-view h3 {
  margin-bottom: 12px; color: var(--ink);
}
.canvas-view h1 { font-size: 1.4rem; }
.canvas-view h2 { font-size: 1.15rem; }

/* ---- Composer ---- */

.composer-wrap {
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
  padding: 0;
  flex-shrink: 0;
  display: flex; gap: 0; align-items: stretch;
}
#composer-form {
  flex: 1;
  display: flex; gap: 0; align-items: stretch;
}
#msg {
  flex: 1; resize: none;
  background: var(--bg); color: var(--ink);
  border: 0; border-radius: 0;
  padding: 13px 12px; font-size: 13px; font-family: var(--font);
  line-height: 1.35; min-height: 44px;
}
#msg:focus { outline: none; }
.composer-btn {
  width: 44px; min-height: 44px;
  border: 0; border-radius: 0;
  cursor: pointer; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.model-btn {
  background: var(--bg-elev2); color: var(--muted);
}
.model-btn:hover { background: var(--bg); color: var(--ink); }
.send-btn {
  background: var(--accent); color: #fff;
}
.send-btn:hover { background: var(--accent-deep); }
.send-btn .ico { width: 16px; height: 16px; }

/* ---- Ask bar ---- */

.ask-bar {
  border-top: 1px solid var(--line);
  background: var(--bg-elev2);
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.ask-bar[hidden] { display: none !important; }
.ask-bar.is-danger {
  background: rgba(239,68,68,.06);
  border-top-color: color-mix(in srgb, #ef4444 35%, var(--line));
}
.ask-q { font-size: 13px; font-weight: 650; color: var(--ink); white-space: pre-wrap; line-height: 1.4; }
.ask-opts { display: flex; gap: 8px; flex-wrap: wrap; }
.ask-opt {
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--ink);
  padding: 8px 12px; font-size: 12px; font-weight: 650;
  cursor: pointer; font-family: var(--font); border-radius: var(--radius);
}
.ask-opt:hover { border-color: var(--accent); }
.ask-opt.danger { border-color: #ef4444; color: #ef4444; }
.ask-opt.danger:hover { background: rgba(239,68,68,.1); }

/* ---- Responsive ---- */

@media (max-width: 900px) {
  .app-shell { flex-direction: column-reverse; }
  .canvas-pane { flex: 1; border-right: 0; border-top: 0; background: var(--bg); }
  .chat-pane { width: 100%; height: 50vh; background: var(--bg-elev); }
  .chat-resize { display: none; }
}
