:root {
  --bg: #070c18;
  --bg-glow: #12244a;
  --panel: rgba(13, 22, 42, 0.92);
  --panel-2: #101c36;
  --panel-3: #16264a;
  --line: #1f3358;
  --line-2: #2c4a80;
  --text: #e8eef9;
  --muted: #8a9bbd;
  --blue: #3d7cff;
  --blue-2: #5b93ff;
  --blue-dark: #1f4fd0;
  --glow: rgba(79, 141, 255, 0.45);
  --ok: #3ddc97;
  --warn: #f0b64a;
  --err: #ff5c6c;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 50% -120px, var(--bg-glow) 0%, rgba(18, 36, 74, 0) 70%),
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,0.35) 50%, transparent 51%),
    radial-gradient(1px 1px at 33% 9%, rgba(255,255,255,0.3) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 58% 14%, rgba(255,255,255,0.35) 50%, transparent 51%),
    radial-gradient(1px 1px at 76% 6%, rgba(255,255,255,0.3) 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 21%, rgba(255,255,255,0.25) 50%, transparent 51%),
    radial-gradient(1px 1px at 44% 26%, rgba(255,255,255,0.2) 50%, transparent 51%),
    var(--bg);
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #22385f; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-3);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, background .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover { border-color: var(--blue-2); box-shadow: 0 0 10px rgba(79,141,255,0.25); }
button.active { border-color: var(--blue-2); background: #1b2f5c; }
button.primary {
  background: linear-gradient(180deg, #4a86ff 0%, #2f6bf0 100%);
  border-color: #5b93ff;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 16px var(--glow), inset 0 1px 0 rgba(255,255,255,0.2);
}
button.primary:hover { box-shadow: 0 0 22px var(--glow), inset 0 1px 0 rgba(255,255,255,0.25); }
button.danger { border-color: rgba(255,92,108,0.6); color: var(--err); }
button.danger:hover { box-shadow: 0 0 10px rgba(255,92,108,0.3); }
button.mini { padding: 2px 8px; font-size: 11px; border-radius: 6px; color: var(--muted); }
button.x { padding: 0 6px; font-size: 14px; line-height: 1; margin-left: auto; color: var(--muted); border: none; background: transparent; }
button.x:hover { color: var(--err); box-shadow: none; }
button:disabled { opacity: 0.45; cursor: default; box-shadow: none; }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: #0b1428;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--blue-2);
  box-shadow: 0 0 0 3px rgba(61,124,255,0.18), 0 0 12px rgba(79,141,255,0.25);
}
input::placeholder, textarea::placeholder { color: #5f7199; }
select.inline-select {
  width: auto; padding: 2px 6px; font-weight: 600; color: var(--blue-2);
  background: transparent; border: 1px solid transparent; border-radius: 6px; cursor: pointer;
}
select.inline-select:hover { border-color: var(--line-2); background: #0b1428; }

.muted { color: var(--muted); }
.spacer { flex: 1; }
.clickable { cursor: pointer; }
.clickable:hover { text-decoration: underline; }

/* ----- каркас ----- */
.app { display: grid; grid-template-rows: 58px 1fr; height: 100%; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 0 18px; }
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: 0.3px; }
.topbar .brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(160deg, #2c62e8, #1a3ea8);
  display: grid; place-items: center;
  box-shadow: 0 0 14px var(--glow);
}
.topbar .ctl { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.topbar .ctl select { width: auto; padding: 5px 10px; font-size: 13px; color: var(--text); }

/* лимиты */
.usage { display: flex; gap: 14px; align-items: center; font-size: 11px; margin-left: 10px; }
.meter { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.meter .mlabel { min-width: 26px; }
.meter .mbar { width: 90px; height: 6px; border-radius: 4px; background: #14203c; border: 1px solid var(--line); overflow: hidden; }
.meter .mfill { display: block; height: 100%; background: linear-gradient(90deg, #2f6bf0, #5b93ff); box-shadow: 0 0 8px var(--glow); }
.meter.warn .mfill { background: linear-gradient(90deg, #c98d2a, var(--warn)); box-shadow: 0 0 8px rgba(240,182,74,0.5); }
.meter.bad .mfill { background: linear-gradient(90deg, #c23a48, var(--err)); box-shadow: 0 0 8px rgba(255,92,108,0.5); }
.meter .mval { color: var(--text); font-weight: 600; min-width: 34px; }
.meter .mreset { color: var(--muted); }

.columns { display: grid; grid-template-columns: 270px 1fr 340px; gap: 12px; min-height: 0; padding: 0 14px 14px; }
.columns.no-panel { grid-template-columns: 270px 1fr; }
.col {
  min-height: 0; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 0 0 1px rgba(79,141,255,0.05), 0 8px 30px rgba(0,0,0,0.35);
  overflow: hidden;
}
.col-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); min-height: 48px;
  font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: 1.2px;
}
.col-head.tabs { justify-content: flex-start; padding: 6px 10px; }
.tab { text-transform: uppercase; font-size: 11px; letter-spacing: 1px; color: var(--muted); border-color: transparent; background: transparent; padding: 6px 10px; }
.tab.active { color: var(--text); background: var(--panel-3); border-color: var(--line-2); }
.scroll { overflow-y: auto; min-height: 0; flex: 1; }

.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--err); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.badge.blue { background: var(--blue); }

/* ----- команда ----- */
.model-line { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 12px; }
.agent-list { padding: 6px 10px; display: flex; flex-direction: column; gap: 4px; }
.agent-item {
  display: flex; gap: 11px; align-items: center; padding: 10px 12px; cursor: pointer;
  border-radius: 10px; border: 1px solid transparent; transition: background .15s, border-color .15s;
}
.agent-item:hover { background: rgba(22, 38, 74, 0.7); border-color: var(--line); }
.agent-item.active {
  background: linear-gradient(90deg, #2f6ff0 0%, #1f4fd0 100%);
  border-color: #5b93ff; color: #fff;
  box-shadow: 0 0 18px rgba(61,124,255,0.35);
}
.agent-item.active .role, .agent-item.active .deputy-badge { color: rgba(255,255,255,0.8); border-color: rgba(255,255,255,0.45); }
.agent-item .dot { width: 9px; height: 9px; border-radius: 50%; background: #3a4d75; flex-shrink: 0; }
.agent-item .dot.working { background: var(--warn); box-shadow: 0 0 10px var(--warn); animation: pulse 1.2s infinite; }
.agent-item .dot.error { background: var(--err); box-shadow: 0 0 8px var(--err); }
.agent-item .name { font-weight: 600; }
.agent-item .role { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-item .meta { min-width: 0; flex: 1; }
.agent-item .deputy-badge { font-size: 10px; color: var(--blue-2); border: 1px solid var(--blue-2); border-radius: 5px; padding: 1px 5px; margin-left: 4px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ----- кадрирование ----- */
.modal-back.top { z-index: 30; }
.modal.cropper { width: 400px; align-items: center; }
.crop-stage { position: relative; width: 320px; height: 320px; border-radius: 12px; overflow: hidden; background: #050913; cursor: grab; }
.crop-stage:active { cursor: grabbing; }
.crop-stage canvas { display: block; touch-action: none; }
.crop-mask {
  position: absolute; inset: 0; pointer-events: none; border-radius: 12px;
  background: radial-gradient(circle at center, transparent 0 159px, rgba(5, 9, 19, 0.78) 160px);
}
.crop-mask::after { content: ''; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--blue-2); box-shadow: 0 0 18px var(--glow); }
.crop-controls { display: flex; align-items: center; gap: 10px; width: 100%; }
.crop-controls input[type="range"] { flex: 1; accent-color: var(--blue); padding: 0; background: transparent; border: none; }

/* ----- аватарки ----- */
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff;
  background: linear-gradient(160deg, #2c62e8, #1a3ea8); border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 0 10px rgba(61,124,255,0.25);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }
.avatar.clickable { cursor: pointer; }
.avatar.clickable:hover { box-shadow: 0 0 14px var(--glow); }
.agent-item .avatar-wrap { position: relative; }
.agent-item .avatar-wrap .dot { position: absolute; right: -2px; bottom: -2px; width: 11px; height: 11px; border: 2px solid var(--panel); }
.line.assistant .avatar { margin-top: 2px; }
.persona-row { display: flex; align-items: center; gap: 14px; }
.persona-row .hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
.chat-head a { color: var(--blue-2); text-decoration: none; }
.chat-head a:hover { text-decoration: underline; }

.sys-block { margin: 8px 12px 12px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.sys-block .check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.sys-block input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--blue); }

/* ----- чат ----- */
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--line); min-height: 48px; }
.chat-head .title { font-weight: 700; font-size: 15px; }
.chat-head .sub { color: var(--muted); font-size: 12px; }
.messages { padding: 16px 22px; display: flex; flex-direction: column; gap: 6px; }
.line { display: flex; gap: 10px; align-items: flex-start; line-height: 1.55; }
.line .ts { display: block; font-size: 10px; color: var(--muted); margin-top: 3px; }

.line.user { justify-content: flex-end; flex-direction: column; align-items: flex-end; margin: 10px 0 6px; }
.line.user .bubble {
  max-width: 78%; padding: 9px 14px; border-radius: 12px; white-space: pre-wrap; word-break: break-word;
  background: linear-gradient(180deg, #2f6bf0, #1f4fd0); color: #fff; box-shadow: 0 0 14px rgba(61,124,255,0.3);
}

.line.incoming { margin: 8px 0; }
.line.incoming .card {
  max-width: 82%; padding: 10px 14px; border-radius: 12px; font-size: 13px;
  background: rgba(61,220,151,0.06); border: 1px solid rgba(61,220,151,0.35); border-left: 3px solid var(--ok);
}
.line.incoming .head { color: var(--ok); font-weight: 600; margin-bottom: 4px; }

.line.assistant { margin: 8px 0; }
.line.assistant .mark { color: var(--blue-2); font-size: 11px; margin-top: 5px; text-shadow: 0 0 8px var(--glow); }
.line.assistant .content { max-width: 92%; word-break: break-word; }

.line.system { justify-content: center; color: var(--muted); font-size: 12px; margin: 4px 0; }
.line.system.error { color: var(--err); }

.line.tool { flex-direction: column; gap: 4px; padding-left: 4px; font-size: 13px; color: var(--muted); }
.line.tool .trow { display: flex; align-items: center; gap: 8px; min-height: 22px; }
.line.tool .tdot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: #3a4d75; }
.line.tool .tdot.pending { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: pulse 1s infinite; }
.line.tool .tdot.ok { background: var(--ok); }
.line.tool .tdot.err { background: var(--err); box-shadow: 0 0 6px var(--err); }
.line.tool .ticon { width: 18px; text-align: center; font-size: 13px; }
.line.tool .tlabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line.tool.delegate .tlabel { color: var(--ok); }
.line.tool.error .tlabel { color: var(--err); }
.line.tool .tresult {
  margin: 2px 0 6px 33px; padding: 10px 14px; border-radius: 10px; color: var(--text); font-size: 13px;
  background: rgba(11, 20, 40, 0.8); border: 1px solid var(--line); border-left: 3px solid var(--ok);
  max-height: 360px; overflow: auto;
}
.line.tool.error .tresult { border-left-color: var(--err); }

.activity { display: flex; align-items: center; gap: 8px; color: var(--blue-2); font-size: 13px; margin: 6px 0 4px 2px; }
.activity .spin { display: inline-block; width: 14px; text-align: center; text-shadow: 0 0 8px var(--glow); }
.activity .dots span { animation: blink 1.2s infinite; }
.activity .dots span:nth-child(2) { animation-delay: .2s; }
.activity .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }

.composer { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px 8px; border-top: 1px solid var(--line); background: rgba(11, 20, 40, 0.6); }
.composer-main { display: flex; gap: 10px; }
.composer textarea { flex: 1; min-height: 46px; max-height: 220px; }
.statusrow { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); min-height: 24px; }
.statusrow select.mode { color: var(--muted); font-weight: 500; padding: 2px 4px; }
.statusrow select.mode:hover { color: var(--text); }

/* кружок лимита */
.ring-wrap { position: relative; display: flex; align-items: center; }
.ring { padding: 2px; border: none; background: transparent; border-radius: 50%; line-height: 0; }
.ring:hover { box-shadow: 0 0 10px var(--glow); }
.ring-bg { fill: none; stroke: #22385f; stroke-width: 3; }
.ring-fg { fill: none; stroke: var(--blue-2); stroke-width: 3; stroke-linecap: round; transition: stroke-dasharray .6s ease; filter: drop-shadow(0 0 3px var(--glow)); }
.ring.warn .ring-fg { stroke: var(--warn); filter: drop-shadow(0 0 3px rgba(240,182,74,0.6)); }
.ring.bad .ring-fg { stroke: var(--err); filter: drop-shadow(0 0 3px rgba(255,92,108,0.6)); }
.usage-pop {
  position: absolute; right: 0; bottom: 30px; width: 400px; padding: 14px 16px; z-index: 15;
  background: #0f182e; border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: 0 0 30px rgba(61,124,255,0.18), 0 14px 40px rgba(0,0,0,0.55);
  display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text);
  animation: slide-in .15s ease-out;
}
.usage-pop .row { display: flex; align-items: center; gap: 10px; }
.usage-pop .row.head { color: var(--muted); font-size: 12px; }
.usage-pop .row.sep { margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.usage-pop .row .val { margin-left: auto; color: var(--text); font-weight: 600; }
.usage-pop .row .name { font-weight: 600; }
.usage-pop .row .reset { color: var(--muted); font-size: 12px; margin-left: auto; }
.usage-pop .row .reset + .val { margin-left: 0; min-width: 40px; text-align: right; }
.usage-pop .limit { margin-top: 6px; }
.usage-pop .bar { height: 5px; border-radius: 4px; background: #16213d; overflow: hidden; margin-top: 4px; }
.usage-pop .bar .fill { display: block; height: 100%; background: linear-gradient(90deg, #2f6bf0, #5b93ff); }
.usage-pop .bar.warn .fill { background: linear-gradient(90deg, #c98d2a, var(--warn)); }
.usage-pop .bar.bad .fill { background: linear-gradient(90deg, #c23a48, var(--err)); }
.usage-pop .small { font-size: 12px; }
.composer-buttons { display: flex; flex-direction: column; gap: 6px; }
.composer-buttons button { justify-content: center; }
.composer-buttons .mic { font-size: 15px; padding: 5px 10px; user-select: none; }
.composer-buttons .mic.rec { border-color: var(--err); color: var(--err); box-shadow: 0 0 14px rgba(255,92,108,0.45); animation: pulse 1s infinite; font-size: 12px; }
.chat.dragging { outline: 2px dashed var(--blue-2); outline-offset: -6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.right { justify-content: flex-end; margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 8px; font-size: 12px; background: var(--panel-3); border: 1px solid var(--line-2); color: var(--text); }
.chip .x { margin-left: 2px; }

/* ----- панель ----- */
.feed-list { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.feed-item { padding: 10px 12px; font-size: 13px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); border-left-width: 3px; }
.feed-item .kind { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.feed-item .title { font-weight: 600; margin: 3px 0; }
.feed-item .body { color: var(--muted); white-space: pre-wrap; max-height: 80px; overflow: hidden; cursor: pointer; position: relative; }
.feed-item .body.open { max-height: none; color: var(--text); }
.feed-item .body:not(.open)::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 30px; background: linear-gradient(transparent, var(--panel-2)); }
.feed-item.high { border-left-color: var(--err); box-shadow: 0 0 12px rgba(255,92,108,0.15); }
.feed-item.report { border-left-color: var(--ok); }
.feed-item.hire { border-left-color: var(--blue-2); }
.feed-item.delegate { border-left-color: var(--blue-2); }
.feed-item.memory { border-left-color: #8b6cff; }
.feed-item.error { border-left-color: var(--err); }
.feed-item.permission { border-left-color: var(--warn); }
.feed-item .ts { color: var(--muted); font-size: 10px; }

/* ----- MCP ----- */
.mcp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 6px; }
.feed-item.mcp { border-left-color: var(--line-2); }
.feed-item.mcp .row { display: flex; align-items: center; gap: 8px; }
.feed-item.mcp .dot { width: 8px; height: 8px; border-radius: 50%; background: #3a4d75; flex-shrink: 0; }
.feed-item.mcp .dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.feed-item.mcp .dot.error { background: var(--err); box-shadow: 0 0 6px var(--err); }
.feed-item.mcp .actions { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.keyrow { display: flex; gap: 6px; flex: 1; min-width: 200px; }
.keyrow input { padding: 4px 8px; font-size: 12px; }
.feed-item.info { border-left-color: var(--blue-2); color: var(--muted); }
.small { font-size: 12px; }
.ok { color: var(--ok); }
.err { color: var(--err); }

/* ----- всплывающие запросы ----- */
.toasts { position: fixed; top: 66px; right: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 20; width: 380px; }
.toast {
  padding: 12px 14px; border-radius: 12px; font-size: 13px;
  background: #1a1f38; border: 1px solid rgba(240,182,74,0.55); border-left: 3px solid var(--warn);
  box-shadow: 0 0 22px rgba(240,182,74,0.2), 0 10px 30px rgba(0,0,0,0.5);
  animation: slide-in .18s ease-out;
}
.toast .kind { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--warn); }
.toast .title { font-weight: 700; margin: 3px 0; }
.toast .body { color: var(--muted); white-space: pre-wrap; max-height: 120px; overflow: auto; font-family: Consolas, monospace; font-size: 12px; }
.toast .actions { display: flex; gap: 8px; margin-top: 10px; }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ----- вход и доступ с телефона ----- */
.login { height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; padding: 24px; border-radius: 16px; background: var(--panel-2); border: 1px solid var(--line-2); box-shadow: 0 0 40px rgba(61,124,255,0.2); }
.login-card .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; margin-bottom: 6px; }
.login-card .brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(160deg, #2c62e8, #1a3ea8); display: grid; place-items: center; }
.login-card label { font-size: 12px; color: var(--muted); }
.access-pop { width: 380px; top: 42px; bottom: auto; }
.access-pop code { flex: 1; font-family: Consolas, monospace; font-size: 12px; color: var(--text); word-break: break-all; }
.feed-item.alert { border-left-color: var(--err); background: rgba(255,92,108,0.06); }
body.offline .topbar::after { content: 'нет связи со Штабом, переподключаюсь…'; color: var(--warn); font-size: 12px; margin-left: 10px; }
.tabbar { display: none; }

/* ----- телефон ----- */
@media (max-width: 900px) {
  .app { grid-template-rows: 52px 1fr 56px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .brand { font-size: 16px; }
  .desktop-only { display: none !important; }
  .columns { display: block; padding: 0 8px; min-height: 0; overflow: hidden; }
  .columns .col { display: none; height: 100%; border-radius: 12px; }
  .app.m-team .col-team, .app.m-chat .chat, .app.m-panel .col-panel { display: flex; }
  .tabbar {
    display: flex; gap: 6px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line); background: var(--panel-2);
  }
  .tabbar button { flex: 1; justify-content: center; padding: 8px 4px; font-size: 13px; border-color: transparent; background: transparent; }
  .tabbar button.active { background: var(--panel-3); border-color: var(--line-2); color: var(--blue-2); }
  .chat-head { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .chat-head .cost { display: none; }
  .messages { padding: 12px; }
  .line.user .bubble, .line.assistant .content, .line.incoming .card { max-width: 100%; }
  .composer { padding: 8px 10px 6px; }
  .composer-main { flex-direction: column; }
  .composer-buttons { flex-direction: row; }
  .composer-buttons button { flex: 1; }
  .composer textarea { min-height: 42px; }
  .statusrow { flex-wrap: wrap; }
  .toasts { left: 10px; right: 10px; width: auto; top: 60px; }
  .usage-pop { width: min(400px, calc(100vw - 24px)); }
  .access-pop { width: min(360px, calc(100vw - 24px)); }
  .modal { width: calc(100vw - 20px); padding: 16px; }
  .modal .row { grid-template-columns: 1fr; }
  .modal.cropper { width: calc(100vw - 20px); }
  .crop-stage, .crop-stage canvas { width: min(320px, calc(100vw - 60px)); height: min(320px, calc(100vw - 60px)); }
}

/* ----- модальное окно ----- */
.modal-back { position: fixed; inset: 0; background: rgba(3, 7, 18, 0.7); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 10; }
.modal {
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 16px; padding: 22px; width: 580px; max-height: 90vh; overflow: auto;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 0 40px rgba(61,124,255,0.2);
}
.modal h3 { margin: 0 0 6px; }
.modal label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
.modal .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal .footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.empty { color: var(--muted); padding: 30px; text-align: center; line-height: 1.6; }
.cost { color: var(--muted); font-size: 11px; }

/* ----- разметка ----- */
.md { white-space: normal; }
.md ul { margin: 4px 0; padding-left: 20px; }
.md li { margin: 2px 0; }
.md .md-h { font-weight: 700; margin: 8px 0 4px; }
.md .md-gap { height: 8px; }
.md code { background: rgba(61,124,255,0.15); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-family: Consolas, monospace; font-size: 12.5px; }
