:root {
  --bg: #0f1720; --panel: #17212b; --line: #243240; --text: #e8eef4; --muted: #8b9bab;
  --me: #7a3d14; --bot: #1e2c3a; --accent: #f47c2c; --ok: #2fb36b; --warn: #e0a72e; --off: #6b7785; --err: #e5534b;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #eef2f6; --panel: #ffffff; --line: #d8e0e8; --text: #15202b; --muted: #5d6b79; --me: #fde3cf; --bot: #ffffff; color-scheme: light; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, select, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--err); min-height: 1.4em; margin: 0; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: grid; gap: 14px; }
.card .logo { width: 220px; height: auto; margin: 0 auto 4px; display: block; }
@media (prefers-color-scheme: dark) { .card .logo { background: #f6f7f9; border-radius: 14px; padding: 10px 14px; } }
.card p { margin: 0; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input, textarea, select { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.primary { background: var(--accent); color: #1a1006; border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 600; }
.primary:disabled { opacity: .5; cursor: default; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; cursor: pointer; }

.chat { height: 100%; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; }
.top { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.name { font-weight: 600; }
.state { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.avatar { position: relative; width: 34px; height: 34px; flex: none; }
.avatar img { width: 34px; height: 34px; display: block; }
.dot { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--off); border: 2px solid var(--panel); }
.dot.online { background: var(--ok); }
.dot.working { background: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.actions { display: flex; gap: 8px; align-items: center; }
.actions select { padding: 6px 10px; }
.menu { position: absolute; right: 12px; top: 100%; z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: grid; min-width: 200px; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.menu button { text-align: left; background: none; border: 0; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--bg); }

.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 82%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.owner { align-self: flex-end; background: var(--me); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bot); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .time { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; text-align: right; }
.msg a { color: var(--accent); }
.msg.pending { opacity: .6; }
.approval { align-self: flex-start; max-width: 82%; background: var(--panel); border: 1px solid var(--warn); border-radius: 14px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.approval .btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.approval .btns button { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.approval .answered { margin-top: 8px; color: var(--muted); font-size: 14px; }
.empty { margin: auto; text-align: center; color: var(--muted); }

.composer { display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 160px; }
@media (max-width: 520px) { .msg, .approval { max-width: 92%; } .log { padding: 12px; } }

.botpick { padding: 2px 6px; font-weight: 600; border-radius: 8px; max-width: 46vw; }
.iconbtn { display: grid; place-items: center; width: 42px; flex: none; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer; font-size: 18px; }
.iconbtn.on { border-color: var(--err); }
.rec { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--panel); border-top: 1px solid var(--line); }
.rec .primary { margin-left: auto; }
.recdot { width: 10px; height: 10px; border-radius: 50%; background: var(--err); animation: pulse 1s infinite; }
.msg img.media, .msg video.media { display: block; max-width: 100%; max-height: 360px; border-radius: 10px; margin: 2px 0 4px; }
.msg audio { display: block; width: 240px; max-width: 100%; margin: 2px 0 4px; }
.msg .filelink { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; margin: 2px 0 4px; }
.msg code { font-size: 14px; }
@media (max-width: 520px) { .composer { gap: 6px; padding-left: 10px; padding-right: 10px; } .iconbtn { width: 38px; } .composer .primary { padding: 10px 12px; } }
.voicelabel { font-size: 13px; color: var(--muted); margin-bottom: 2px; }

/* ---------- phase 3: main menu, live view, bots, team tasks, editor ---------- */
.menu-toggle { position: relative; border: 0; background: none; padding: 0; cursor: pointer; width: 38px; height: 38px; color: inherit; }
.menu-toggle .face { display: grid; place-items: center; width: 34px; height: 34px; }
.menu-toggle .burger { position: absolute; left: -4px; bottom: -3px; font-size: 11px; line-height: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 1px 3px; color: var(--muted); }
.menu-toggle:focus-visible { outline: 2px solid var(--accent); border-radius: 10px; }
.emoji-face { display: inline-grid; place-items: center; line-height: 1; }
.dot.hidden { display: none; }
.titles { min-width: 0; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); z-index: 21; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 10px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 2px; box-shadow: 8px 0 30px rgba(0,0,0,.35); animation: slidein .16s ease-out; }
@keyframes slidein { from { transform: translateX(-24px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 6px 8px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.drawer-sec { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 10px 4px; }
.drawer-item { display: grid; grid-template-columns: 30px 1fr auto; grid-template-rows: auto auto; align-items: center; column-gap: 8px; text-align: left; background: none; border: 0; border-radius: 10px; padding: 8px 10px; cursor: pointer; width: 100%; }
.drawer-item .ic { grid-row: 1 / span 2; position: relative; font-size: 18px; display: grid; place-items: center; }
.drawer-item .sub { grid-column: 2; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-item:hover, .drawer-item.active { background: var(--bg); }
.drawer-item.active { box-shadow: inset 3px 0 0 var(--accent); }
.drawer-item.soon { cursor: default; opacity: .55; grid-template-rows: auto; }
.drawer-item .badge { grid-column: 3; grid-row: 1; font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.face-sm { width: 26px; height: 26px; }
.face-sm .dot, .face-md .dot { position: absolute; right: -3px; bottom: -3px; width: 10px; height: 10px; border: 2px solid var(--panel); }
.face-md { position: relative; width: 34px; height: 34px; display: grid; place-items: center; flex: none; }
.small { font-size: 13px; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.page { overflow-y: auto; padding: 16px; gap: 12px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.page h2, .page h3 { margin: 0; }
.page h3 { font-size: 16px; margin-top: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.bot-card { display: grid; gap: 4px; }
.bot-card.working { border-color: var(--warn); }
.bc-head { display: flex; align-items: center; gap: 10px; }
.bc-name { display: grid; min-width: 0; }
.bc-state { font-size: 14px; overflow-wrap: anywhere; }
.bc-actions { display: flex; gap: 6px; margin-top: 6px; }
.ghost.small { padding: 4px 10px; font-size: 13px; }
.botlist { display: grid; gap: 8px; }
.bot-row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.tasks { display: grid; gap: 6px; }
.task { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.task summary { display: flex; gap: 8px; align-items: baseline; cursor: pointer; list-style: none; }
.task summary::-webkit-details-marker { display: none; }
.task.doing { border-color: var(--warn); }
.task.problem { border-color: var(--err); }
.tk-body { margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; display: grid; gap: 4px; }
.msg .from { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; display: flex; align-items: center; gap: 4px; }
.editor { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); padding: 0; }
.editor::backdrop { background: rgba(0,0,0,.5); }
.editor form { display: grid; gap: 12px; padding: 18px; }
.editor h2 { margin: 0; font-size: 20px; }
.editor textarea { resize: vertical; }
.row2 { display: flex; gap: 10px; }
.row2 .emoji { width: 84px; }
.row2 .emoji input { text-align: center; font-size: 22px; padding: 6px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 12px; margin: 0; }
legend { color: var(--muted); font-size: 14px; padding: 0 4px; }
.toolgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
label.check { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: start; color: var(--text); font-size: 15px; }
label.check input { margin-top: 3px; }
label.check .muted { grid-column: 2; }
.editor-actions { display: flex; gap: 8px; align-items: center; }
.danger { background: none; border: 1px solid var(--err); color: var(--err); border-radius: 10px; padding: 10px 14px; cursor: pointer; }
@media (max-width: 520px) { .page { padding: 12px; } .grid { grid-template-columns: 1fr; } }
.editor { overflow-x: hidden; }
.row2 > label { min-width: 0; }
.row2 .grow { flex: 1; }
.row2 .emoji input, .row2 .grow input { width: 100%; min-width: 0; box-sizing: border-box; }
label input, label textarea, label select { color: var(--text); width: 100%; box-sizing: border-box; }
label.check input { width: auto; }

/* ---------- phase 4 ---------- */
.workbar { display: flex; gap: 10px; align-items: flex-start; padding: 8px 16px; background: var(--panel); border-top: 1px solid var(--warn); }
.recdot.warn { background: var(--warn); margin-top: 5px; }
.steps { margin: 4px 0 0; padding-left: 18px; display: grid; gap: 1px; }
.steps .t { opacity: .7; font-size: 11px; }
.job { font-style: italic; overflow-wrap: anywhere; }
.harder { align-self: flex-start; margin: -2px 0 4px 4px; }
.sched-form { display: grid; gap: 10px; }
.sched { display: flex; gap: 10px; align-items: center; }
.dept-row { margin-top: 8px; }
.filegrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.file { cursor: pointer; display: grid; gap: 4px; padding: 8px; }
.file .thumb { height: 110px; border-radius: 10px; background: var(--bg); display: grid; place-items: center; overflow: hidden; font-size: 34px; }
.file .thumb img { width: 100%; height: 100%; object-fit: cover; }
.fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conns { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 4px; font-size: 14px; }
.conns .off { opacity: .6; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 12px; }
