/* NEXUS AI - original interface. Dark is the default; light is available. */
:root {
  --bg: #0a0b14;
  --bg-2: #0f1120;
  --surface: #151829;
  --surface-2: #1c2038;
  --surface-3: #242948;
  --line: rgba(148, 163, 255, 0.14);
  --text: #e8ebff;
  --muted: #8b93b8;
  --violet: #8b5cf6;
  --cyan: #22d3ee;
  --blue: #3b82f6;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --accent-grad: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 55%, #22d3ee 100%);
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --sidebar-w: 286px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5fb;
  --bg-2: #eceef8;
  --surface: #ffffff;
  --surface-2: #f3f4fc;
  --surface-3: #e7e9f6;
  --line: rgba(60, 66, 120, 0.14);
  --text: #171a33;
  --muted: #5d6490;
  --shadow: 0 10px 28px rgba(40, 48, 110, 0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5fb; --bg-2: #eceef8; --surface: #ffffff; --surface-2: #f3f4fc; --surface-3: #e7e9f6;
    --line: rgba(60, 66, 120, 0.14); --text: #171a33; --muted: #5d6490;
    --shadow: 0 10px 28px rgba(40, 48, 110, 0.12); color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Noto Sans Bengali", "Noto Sans", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 85% -10%, rgba(139, 92, 246, 0.16), transparent 60%),
              radial-gradient(900px 500px at -10% 110%, rgba(34, 211, 238, 0.10), transparent 60%),
              var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  overflow-x: hidden;
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
a { color: var(--cyan); }
code, pre { font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 13px; }
code { background: var(--surface-3); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 10px 12px; }
.hidden, [hidden] { display: none !important; }
.ok-text { color: var(--ok); }
.err-text { color: var(--err); }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Buttons and inputs */
.btn, .icon-btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 11px; padding: 9px 14px; display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  transition: background .18s, border-color .18s, transform .08s, opacity .18s;
}
.btn:hover, .icon-btn:hover { border-color: rgba(139, 92, 246, .55); background: var(--surface-3); }
.btn:active, .icon-btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent-grad); border-color: transparent; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent-grad); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 9px; }
.btn.danger { color: var(--err); }
.btn.wide { width: 100%; }
.icon-btn { padding: 8px; width: 40px; height: 40px; }
.icon-btn.stop { color: var(--err); }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(139, 92, 246, .22); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 12px; margin: 0; }
legend { color: var(--text); font-weight: 600; padding: 0 6px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.compact { gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.notice { border-radius: 10px; padding: 10px 12px; margin: 0; font-size: 14px; }
.notice.error { background: rgba(248, 113, 113, .12); color: var(--err); border: 1px solid rgba(248, 113, 113, .3); }
.notice.success { background: rgba(52, 211, 153, .12); color: var(--ok); border: 1px solid rgba(52, 211, 153, .3); }
.notice.warn { background: rgba(251, 191, 36, .12); color: var(--warn); border: 1px solid rgba(251, 191, 36, .3); }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 2px 12px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 24px; height: 24px; }
.brand-name { font-weight: 700; letter-spacing: .08em; font-size: 15px; }
.brand-name em { font-style: normal; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* Layout */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; height: 100dvh; transition: grid-template-columns .25s ease; }
.app.collapsed { grid-template-columns: 0 1fr; }
.app.collapsed .sidebar { visibility: hidden; padding: 0; border: 0; }
.sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg)); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; padding: 14px; gap: 10px; overflow: hidden;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
}
.sidebar-top { display: flex; flex-direction: column; gap: 10px; }
.search { position: relative; display: block; }
.search .ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 34px; font-size: 14px; }
.conv-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; margin: 0 -4px; padding: 0 4px; }
.conv { text-align: left; background: transparent; border: 1px solid transparent; color: var(--text); border-radius: 10px; padding: 9px 11px; cursor: pointer; font: inherit; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .15s; }
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--surface-2); border-color: rgba(139, 92, 246, .45); box-shadow: inset 3px 0 0 var(--violet); }
.sidebar-foot { display: flex; gap: 8px; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 10px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px);
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.topbar-title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); padding: 5px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.status-pill[data-kind="busy"] .dot { background: var(--cyan); animation: pulse 1.2s ease-in-out infinite; }
.status-pill[data-kind="warn"] .dot { background: var(--warn); }
.status-pill[data-kind="error"] .dot { background: var(--err); }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }
.scrim { display: none; }

/* Task panel */
.task-panel { margin: 12px 16px 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); max-height: 40vh; overflow: auto; }
.task-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-state { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-3); color: var(--muted); }
.task-state.running, .task-state.verifying, .task-state.queued { color: var(--cyan); }
.task-state.waiting { color: var(--warn); }
.task-state.completed { color: var(--ok); }
.task-state.failed, .task-state.cancelled { color: var(--err); }
.task-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.steps { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.step { display: grid; grid-template-columns: 14px 1fr; gap: 10px; }
.step-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; background: var(--surface-3); border: 1px solid var(--line); }
.step.running .step-dot { background: var(--cyan); box-shadow: 0 0 0 4px rgba(34, 211, 238, .18); }
.step.done .step-dot { background: var(--ok); }
.step.failed .step-dot { background: var(--err); }
.step.awaiting_approval .step-dot { background: var(--warn); }
.step-title { font-size: 14px; }
.tool { font-family: ui-monospace, monospace; font-size: 12px; color: var(--violet); margin-left: 4px; }
.step-meta { font-size: 12px; color: var(--muted); }
.step details { margin-top: 4px; font-size: 13px; }
.result { white-space: pre-wrap; word-break: break-word; background: var(--bg-2); padding: 8px; border-radius: 8px; max-height: 200px; overflow: auto; }

/* Messages */
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; max-width: 860px; width: 100%; margin: 0 auto; }
.msg.user { justify-content: flex-end; }
.bubble { padding: 12px 15px; border-radius: 16px; max-width: min(720px, 92%); overflow-wrap: anywhere; box-shadow: var(--shadow); }
.msg.user .bubble { background: linear-gradient(135deg, rgba(139, 92, 246, .26), rgba(34, 211, 238, .14)); border: 1px solid rgba(139, 92, 246, .35); border-bottom-right-radius: 6px; }
.msg.assistant .bubble, .msg.system .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.codeblock { margin: 10px 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg-2); }
.codehead { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.codeblock pre { margin: 0; padding: 12px; overflow-x: auto; white-space: pre; }
.copy { font: inherit; font-size: 12px; background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 7px; padding: 2px 8px; cursor: pointer; }
.copy:hover { color: var(--text); }
a.artifact { display: inline-block; margin-top: 6px; padding: 6px 12px; border-radius: 9px; background: var(--surface-3); border: 1px solid rgba(34, 211, 238, .4); color: var(--cyan); text-decoration: none; font-weight: 600; }
.empty { margin: auto; text-align: center; max-width: 520px; padding: 24px; }
.empty h2 { font-size: 1.6rem; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* Composer */
.composer { padding: 10px 16px 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.composer-box {
  max-width: 860px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 10px 10px 8px;
  box-shadow: var(--shadow); transition: border-color .2s, box-shadow .2s;
}
.composer-box:focus-within { border-color: rgba(139, 92, 246, .6); box-shadow: 0 0 0 4px rgba(139, 92, 246, .14), var(--shadow); }
.composer-box textarea { border: 0; background: transparent; box-shadow: none; resize: none; padding: 6px 6px; max-height: 180px; min-height: 28px; }
.composer-row { display: flex; align-items: center; gap: 8px; }
.composer-row .hint { flex: 1; font-size: 12px; color: var(--muted); padding-left: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.send { width: 42px; height: 42px; padding: 0; border-radius: 13px; }
.send .ico { stroke-width: 2.2; }
.attach-chip { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; margin: 0 4px 6px; color: var(--muted); }
.chip-x { border: 0; background: none; color: var(--err); cursor: pointer; font: inherit; }

/* Overlays */
.overlay { position: fixed; inset: 0; background: rgba(4, 5, 12, .6); display: flex; justify-content: flex-end; z-index: 50; backdrop-filter: blur(3px); }
.panel { width: min(520px, 100%); height: 100%; background: var(--bg-2); border-left: 1px solid var(--line); overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 22px; padding-top: calc(18px + env(safe-area-inset-top, 0px)); }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.list { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 9px 11px; }
.item-actions { display: flex; gap: 6px; flex: none; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--surface-3); color: var(--violet); font-family: ui-monospace, monospace; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--surface-3); color: var(--text); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  box-shadow: var(--shadow); transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 60; font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { border-color: rgba(248, 113, 113, .5); color: var(--err); }
.pad { padding: 10px; }

/* Login and installer */
.login-screen, .install-body { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card, .install-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.install-card { width: min(560px, 100%); }
.login-card .brand-mark { width: 52px; height: 52px; border-radius: 16px; }
.login-card .brand-mark svg { width: 34px; height: 34px; }
.install-card ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

/* Responsive */
@media (max-width: 860px) {
  .app, .app.collapsed { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-102%);
    transition: transform .25s ease; box-shadow: var(--shadow);
  }
  .app.nav-open .sidebar { transform: none; }
  .app.collapsed .sidebar { visibility: visible; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 30; }
  .composer-row .hint { display: none; }
  .messages { padding: 14px 10px; }
  .task-panel { margin: 10px 10px 0; }
  .topbar { padding-left: 10px; padding-right: 10px; }
}
@media (min-width: 861px) {
  .main { min-width: 0; }
}
pre { max-width: 100%; }
.messages, .task-panel, .conv-list { scrollbar-width: thin; }

/* Motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
