:root {
  --bg: #07090f;
  --panel: #0d121c;
  --panel-2: #121a28;
  --line: #1e293b;
  --line-soft: #16202f;
  --text: #e5e7eb;
  --muted: #8b95a7;
  --faint: #5b6678;
  --accent: #60a5fa;
  --accent-2: #f472b6;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(900px 500px at 10% -10%, #12203a 0%, transparent 55%),
    radial-gradient(800px 500px at 105% 0%, #1a1025 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font: 14.5px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hint { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }

.app {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) 300px;
  height: 100vh;
}

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: rgba(10, 14, 22, 0.72);
  padding: 16px 12px 12px;
  gap: 10px;
}
.brand-row { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 8px; }
.brand { font-size: 20px; font-weight: 750; letter-spacing: -0.03em; }
.brand span { color: var(--accent); }

.icon {
  width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); font-size: 19px; line-height: 1;
}
.icon:hover { color: var(--text); border-color: #334155; }

.side-label {
  display: flex; align-items: center; justify-content: space-between;
  color: var(--faint); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 8px 8px 2px;
}
.mini {
  border: 0; background: transparent; color: var(--muted);
  font-size: 11.5px; padding: 2px 5px; border-radius: 6px;
}
.mini:hover { background: var(--panel-2); color: var(--text); }

.bots { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 4px; }
.bot-chip {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 4px 9px 4px 6px; font-size: 12.5px; color: var(--muted);
}
.bot-chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.bot-chip.active { color: var(--text); border-color: #3b4b63; background: var(--panel-2); }

.sessions { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; padding: 2px; min-height: 60px; }
.session {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 8px 9px; color: var(--muted); text-align: left; background: transparent;
}
.session:hover { background: var(--panel); color: var(--text); }
.session.active { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.session .emoji { flex: none; }
.session .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.session .del { opacity: 0; border: 0; background: transparent; color: var(--faint); padding: 0 3px; font-size: 15px; }
.session:hover .del { opacity: 1; }
.session .del:hover { color: var(--danger); }

.side-bottom { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line-soft); padding-top: 8px; }
.side-bottom button {
  border: 0; background: transparent; color: var(--muted);
  text-align: left; font-size: 12.5px; padding: 7px 9px; border-radius: 8px;
}
.side-bottom button:hover { background: var(--panel); color: var(--text); }

.device-chip {
  margin-top: 4px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 9px; padding: 7px 9px; font-size: 11.5px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.device-chip.mock { border-color: #4a3a12; color: var(--warn); }

/* ------------------------------------------------------------------- chat */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 17px 26px; border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 15, 0.55); backdrop-filter: blur(6px);
}
.chat-title-wrap { min-width: 0; }
.chat-head h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.head-actions { display: flex; gap: 8px; }

.messages {
  flex: 1; overflow-y: auto; padding: 26px max(26px, calc((100% - 820px) / 2)) 10px;
  scroll-behavior: smooth;
}
.empty {
  height: 100%; min-height: 300px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 10px; color: var(--muted);
}
.empty .big { font-size: 42px; }
.empty h2 { color: var(--text); margin: 4px 0 0; font-size: 22px; letter-spacing: -0.02em; }
.empty p { max-width: 440px; margin: 0; font-size: 13.5px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.suggestion { border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 999px; padding: 7px 12px; font-size: 12.5px; }
.suggestion:hover { color: var(--text); border-color: #334155; }

.msg { display: flex; gap: 10px; margin: 0 0 16px; animation: rise 0.18s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
.msg.user { justify-content: flex-end; }
.msg .avatar {
  flex: none; width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line);
  font-size: 15px;
}
.bubble {
  max-width: min(720px, 80%); border: 1px solid var(--line); background: var(--panel);
  border-radius: 14px; padding: 10px 13px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.user .bubble { background: #16233a; border-color: #243b5c; border-bottom-right-radius: 5px; }
.msg.assistant .bubble { border-bottom-left-radius: 5px; }
.msg .meta { color: var(--faint); font-size: 10.5px; margin-top: 5px; }

.msg.tool { display: block; margin-left: 40px; margin-bottom: 12px; }
.tool-card {
  border: 1px solid var(--line); background: rgba(13, 18, 28, 0.8);
  border-radius: 11px; overflow: hidden;
}
.tool-card summary {
  cursor: pointer; padding: 8px 11px; color: var(--muted); font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  display: flex; gap: 8px; align-items: center;
}
.tool-card summary:hover { color: var(--text); }
.tool-card .tool-name { color: var(--accent); }
.tool-card .tool-status { margin-left: auto; color: var(--faint); }
.tool-body { border-top: 1px solid var(--line-soft); padding: 10px 11px; }
.tool-body pre {
  margin: 0; max-height: 220px; overflow: auto; color: #9fb0c7; font-size: 11.5px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.tool-shot { margin-top: 8px; border-radius: 8px; border: 1px solid var(--line); max-width: 150px; max-height: 240px; width: auto; height: auto; display: block; }
.msg.tool a { display: inline-block; }

/* --------------------------------------------------------------- composer */
.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px max(26px, calc((100% - 820px) / 2)) 18px;
}
.composer textarea {
  flex: 1; resize: none; min-height: 46px; max-height: 190px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 13px;
  padding: 12px 14px; outline: none;
}
.composer textarea:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.13); }

button.primary { background: #1d4ed8; border: 1px solid #2563eb; color: #fff; }
button.primary:hover:not(:disabled) { background: #2563eb; }
button.danger { background: #3f1d1d; border: 1px solid #5b2626; color: #fecaca; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
button.ghost:hover:not(:disabled) { color: var(--text); border-color: #334155; }
.composer button, .row button, .dlg-actions button {
  border-radius: 10px; padding: 9px 13px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
}
.composer button:disabled { opacity: 0.45; cursor: not-allowed; }

/* -------------------------------------------------------------- approvals */
.approval {
  margin: 0 max(26px, calc((100% - 820px) / 2)) 8px;
  border: 1px solid #5b4a1f; background: linear-gradient(180deg, #2a2413, #1d1a10);
  border-radius: 13px; padding: 12px 14px;
}
.approval-head { color: var(--warn); font-size: 11.5px; letter-spacing: 0.09em; text-transform: uppercase; margin-bottom: 6px; }
.approval-body { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; color: #e7d8ae; overflow-wrap: anywhere; }
.approval-actions { display: flex; gap: 8px; margin-top: 10px; }
.approval-actions button {
  border-radius: 10px; padding: 8px 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
}
.approval-actions button.primary { background: #1d4ed8; border-color: #2563eb; color: #fff; }
.approval-actions button.danger { background: #3f1d1d; border-color: #5b2626; color: #fecaca; }

/* ------------------------------------------------------------------ phone */
.phone {
  border-left: 1px solid var(--line); padding: 16px; display: flex;
  flex-direction: column; gap: 10px; min-height: 0; background: rgba(10, 14, 22, 0.55);
}
.phone-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.screen-wrap {
  position: relative; border-radius: 18px; overflow: hidden; background: #05070c;
  border: 1px solid #263041; box-shadow: 0 18px 50px rgba(0,0,0,0.45);
  aspect-ratio: 9 / 20; flex: none;
}
#screen { width: 100%; height: 100%; object-fit: contain; display: block; cursor: crosshair; }
.screen-meta {
  position: absolute; right: 8px; bottom: 8px; font-size: 10.5px; color: #a8b3c4;
  background: rgba(7,9,15,0.75); border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 8px; pointer-events: none;
}
.phone input {
  flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; outline: none;
}
.phone input:focus { border-color: #3b82f6; }
.phone .keys { flex-wrap: wrap; }
.phone .keys button { font-size: 11.5px; padding: 6px 8px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.phone .keys button:hover { color: var(--text); }
.phone-note { color: var(--faint); font-size: 11px; line-height: 1.35; margin-top: auto; }

/* ---------------------------------------------------------------- dialogs */
dialog {
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel);
  color: var(--text); padding: 0; width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 40px); overflow: auto;
  box-shadow: 0 40px 120px rgba(0,0,0,0.65);
}
dialog.wide-dialog { width: min(860px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(3, 5, 9, 0.66); backdrop-filter: blur(3px); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dlg.wide { width: auto; }
.dlg h2 { margin: 0 0 2px; font-size: 18px; letter-spacing: -0.02em; }
.dlg label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12px; }
.dlg input, .dlg textarea, .dlg select {
  width: 100%; background: #0b111c; border: 1px solid #233044; border-radius: 9px;
  padding: 9px 11px; outline: none; color: var(--text); resize: vertical;
}
.dlg input:focus, .dlg textarea:focus, .dlg select:focus { border-color: #3b82f6; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlg-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dlg-actions .hint { margin-right: auto; }

.routine-list, .device-list { display: flex; flex-direction: column; gap: 7px; max-height: 300px; overflow-y: auto; }
.memory-list { display: flex; flex-direction: column; gap: 6px; max-height: 150px; overflow-y: auto; }
.memory-list .hint { font-size: 11.5px; line-height: 1.45; }
.memory {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  font-size: 12px; line-height: 1.4; padding: 7px 9px;
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: 8px;
}
.memory span { min-width: 0; overflow-wrap: anywhere; }
.memory button { flex: none; font-size: 11px; padding: 4px 7px; border-radius: 6px;
  background: transparent; border: 1px solid var(--line); color: var(--muted); }
.memory button:hover { color: var(--text); }
.routine, .device {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 9px 11px;
}
.routine .grow, .device .grow { flex: 1; min-width: 0; }
.routine .name, .device .name { font-size: 13px; }
.routine .sched, .device .sub { color: var(--muted); font-size: 11.5px; }
.routine button, .device button { font-size: 11px; padding: 5px 8px; border-radius: 7px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.routine button:hover, .device button:hover { color: var(--text); }
.routine-form { display: flex; flex-direction: column; gap: 9px; border-top: 1px solid var(--line-soft); padding-top: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #111827; border: 1px solid #2a3648; color: var(--text);
  border-radius: 10px; padding: 9px 14px; font-size: 13px; z-index: 100;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
}

/* ------------------------------------------------------------- responsive */
@media (max-width: 1040px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  .phone { display: none; }
}
@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .messages, .composer, .approval { padding-left: 16px; padding-right: 16px; margin-left: 0; margin-right: 0; }
  .chat-head { padding: 14px 16px; }
}

.ws-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.ws-grid button { justify-content: flex-start; }

.welcome { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 20; }
.welcome[hidden] { display: none; }
.welcome-card { text-align: center; max-width: 520px; padding: 32px; }
.welcome-card h1 { font-size: 44px; margin: 0 0 8px; letter-spacing: -0.02em; }
.welcome-card p { color: var(--muted); font-size: 17px; line-height: 1.5; margin: 0 0 22px; }
.welcome-terms { font-size: 12px !important; margin-top: 26px !important; opacity: .6; }

#btn-signin {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border-radius: 999px; border: 0;
  background: #0b0b0f; color: #fff; font-size: 15px; font-weight: 500;
  cursor: pointer;
}
#btn-signin:hover { background: #1a1a22; }
body.dark #btn-signin, html[data-theme="dark"] #btn-signin { background: #f5f5f5; color: #0b0b0f; }

.auth-form { display: grid; gap: 10px; max-width: 360px; margin: 0 auto; text-align: left; }
.auth-form label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.auth-form input { padding: 10px 12px; border-radius: 8px; }
.auth-form .row { display: flex; gap: 8px; margin-top: 6px; }
.auth-status { color: #f87171; font-size: 12px; min-height: 16px; }

.options { display: grid; gap: 8px; margin-top: 10px; }
.options .option { display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 10px 12px; border-radius: 10px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); font-size: 14px; }
.options .option:hover { background: #17233a; border-color: #2b3a55; }
.options .option-key { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 5px; background: var(--panel); font-size: 11px; }
.msg.system { justify-content: center; }
.system-line { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 0; }

.account-menu { position: fixed; left: 12px; bottom: 52px; z-index: 40; min-width: 220px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
  display: grid; gap: 2px; box-shadow: 0 18px 40px rgba(0,0,0,.45); }
.account-menu[hidden] { display: none; }
.account-menu .acct-head { padding: 8px 10px; color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; }
.account-menu button { justify-content: flex-start; padding: 8px 10px; border-radius: 8px; }

.account-chip { position: fixed; left: 12px; bottom: 10px; z-index: 30; width: 34px; height: 34px; border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); font-size: 11px; }
.attach { width: 34px; height: 34px; border-radius: 50%; background: var(--panel-2);
  border: 1px solid var(--line); color: var(--text); font-size: 16px; }

.botpage-head { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.avatar.big { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); font-size: 20px; }
.botpage-id { display: flex; align-items: center; gap: 8px; flex: 1; }
.botpage-id strong { font-size: 15px; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tabs .tab { background: transparent; border: 0; color: var(--muted); padding: 8px 2px; margin-right: 12px; }
.tabs .tab.active { color: var(--text); border-bottom: 2px solid var(--text); }
.pane-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin: 10px 0 6px; }
.computer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.computer-thumb { width: 44px; height: 30px; border-radius: 6px; object-fit: cover; background: #0a0e16; }
.voice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.voice-row label { display: grid; gap: 4px; font-size: 11px; color: var(--muted); }
.watch-pill { position: absolute; left: 50%; transform: translateX(-50%); bottom: 8px; display: flex; align-items: center; gap: 8px;
  background: rgba(10,14,22,.85); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 12px; }

/* The environment window is 1280x800; keep the composer inside it. */
.composer-fits .messages { padding-bottom: 4px; }
.chat { display: flex; flex-direction: column; min-height: 0; }
.composer { margin: 6px 18px 10px; }
.phone { overflow-y: auto; }
.phone .screen-wrap { flex: 0 0 auto; max-height: 46vh; }

/* Upcoming rows: name and schedule stacked, toggle pinned right. */
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 6px;
  background: var(--panel-2); }
.list-item .li-main { display: grid; gap: 2px; min-width: 0; }
.list-item .li-main strong { font-size: 13px; font-weight: 500; }
.list-item .li-main .li-sub { font-size: 11px; color: var(--muted); }
.list-item .mini { flex: 0 0 auto; }

.device-chip { margin-bottom: 44px; }

/* Dialogs must fit an 800px-tall window: scroll the body, pin the actions. */
dialog { max-height: 92vh; }
dialog .dlg { max-height: 90vh; overflow-y: auto; }
dialog .dlg-actions { position: sticky; bottom: -1px; background: var(--panel);
  padding-top: 8px; border-top: 1px solid var(--line); }
