:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --panel-2: #16213a;
  --line: #22304d;
  --text: #e6ecf7;
  --muted: #8b9bb8;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --code-bg: #0d1526;
  --radius: 12px;
  --mono: "Cascadia Code", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, sans-serif;
  display: grid; grid-template-columns: 210px 1fr 300px; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* sidebar */
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 10px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 600; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #3b82f6, #6366f1); display: grid; place-items: center; font-size: 15px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; border: 0; background: none; color: var(--muted); cursor: pointer; text-align: left; width: 100%; }
.nav:hover { background: var(--panel-2); color: var(--text); }
.nav.active { background: #1d2c4d; color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav .ico { width: 18px; text-align: center; }
.sidebar .spacer { flex: 1; }

/* main */
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.topbar .grow { flex: 1; }
.page { flex: 1; overflow: auto; padding: 18px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
label.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #33466e; background: #1b2846; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.btn.ghost { background: none; }
.btn:disabled { opacity: .5; cursor: default; }
.stop-btn { background: var(--bad); color: #fff; border: 0; border-radius: 10px; padding: 9px 18px; font-weight: 700; cursor: pointer; letter-spacing: .5px; }
.stop-btn:hover { background: #dc2626; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.pill.ok { color: var(--ok); border-color: #1f5136; background: #0f2a1d; }
.pill.bad { color: var(--bad); border-color: #5a2323; background: #2a1212; }
.pill.warn { color: var(--warn); border-color: #5a4316; background: #2a200d; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* chat */
.chat { display: flex; flex-direction: column; height: 100%; }
.messages { flex: 1; overflow: auto; padding-right: 4px; }
.hello { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.hello .logo { width: 40px; height: 40px; font-size: 20px; }
.msg-user { margin: 0 0 14px auto; max-width: 75%; background: #1d2c4d; border: 1px solid #2a3d66; border-radius: 12px 12px 4px 12px; padding: 10px 14px; width: fit-content; }
.msg-bot { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.code-wrap { display: grid; grid-template-columns: 1fr 120px; gap: 12px; margin: 10px 0; }
.code-actions { display: flex; flex-direction: column; gap: 8px; }
pre.code { margin: 0; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 0; overflow: auto; font: 13px/1.6 var(--mono); counter-reset: ln; }
pre.code span.l { display: block; padding: 0 12px 0 0; white-space: pre; }
pre.code span.l::before { counter-increment: ln; content: counter(ln); display: inline-block; width: 34px; padding-right: 10px; text-align: right; color: #4b5b7a; }
.kw { color: #c084fc; } .str { color: #86efac; } .com { color: #64748b; font-style: italic; } .num { color: #fbbf24; } .fn { color: #60a5fa; }
.explanation { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; margin-top: 8px; }
.problems { color: var(--warn); white-space: pre-wrap; font-size: 12px; margin-top: 8px; }
.composer { display: flex; gap: 8px; margin-top: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.composer input { flex: 1; background: transparent; border: 0; }
.round { width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center; font-size: 16px; }
.round.send { background: var(--accent); color: #fff; }
.round.mic { background: var(--panel-2); border: 1px solid var(--line); }
.round.mic.rec { background: var(--bad); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.thinking { color: var(--muted); font-style: italic; margin-bottom: 14px; }

/* editor */
.editor { display: grid; grid-template-columns: 44px 1fr; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; height: 360px; }
.gutter { padding: 10px 6px; color: #4b5b7a; text-align: right; font: 13px/1.6 var(--mono); overflow: hidden; user-select: none; white-space: pre; }
.editor textarea { border: 0; border-radius: 0; resize: none; font: 13px/1.6 var(--mono); padding: 10px; white-space: pre; tab-size: 4; background: transparent; }
.log { background: #070c17; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font: 12px/1.5 var(--mono); height: 180px; overflow: auto; white-space: pre-wrap; }

/* robot */
.device { display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.device.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pad { display: grid; grid-template-columns: repeat(3, 64px); gap: 8px; justify-content: start; }
.pad button { height: 56px; font-size: 20px; }
.sensor-big { font-size: 26px; font-weight: 600; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13px; }
.kv div:nth-child(odd) { color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }

/* right panel */
.right { background: var(--bg); border-left: 1px solid var(--line); padding: 16px; overflow: auto; }
.balance { font-size: 30px; font-weight: 700; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1d2c4d; border: 1px solid #2a3d66; padding: 10px 16px; border-radius: 10px; max-width: 70%; white-space: pre-wrap; z-index: 10; }
.toast.err { background: #2a1212; border-color: #5a2323; }
/* confirmation dialog: centred, same theme but brighter so it stands out */
.modal-back { position: fixed; inset: 0; background: rgba(3, 7, 15, .65); display: grid; place-items: center; z-index: 20; backdrop-filter: blur(2px); }
.modal { width: min(460px, calc(100vw - 32px)); background: #1e2d50; border: 1px solid #4d6aa8; border-radius: 14px; padding: 22px;
         box-shadow: 0 0 0 1px rgba(96, 165, 250, .25), 0 20px 60px rgba(0, 0, 0, .55); color: #f3f6fc; }
#modalText { white-space: pre-wrap; line-height: 1.55; }
.modal h3 { font-size: 17px; color: #fff; }
.modal .btn:not(.primary) { background: #273a66; border-color: #4d6aa8; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: none; color: var(--muted); cursor: pointer; }
.tab.active { background: #1d2c4d; color: var(--text); border-color: #2a3d66; }

/* web app additions */
.code-panel { margin-top: 14px; }
.pair-input { font: 700 28px/1.2 var(--mono); letter-spacing: 6px; text-align: center; width: 100%; }
.price-table td:last-child, .price-table th:last-child { text-align: right; }
.banner { background: #2a200d; border: 1px solid #5a4316; color: #fcd34d; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; }
.lang { width: auto; }
