/* ==========================================================================
   Code service — design system
   Polished, professional. CSS vars, dark (default) + light themes.
   ========================================================================== */

* { box-sizing: border-box; }

:root {
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --nav-h: 56px;
  --max-w: 1240px;
  --ease: cubic-bezier(.4, 0, .2, 1);
}

[data-theme="dark"] {
  --bg: #081418;
  --bg-grad:
    radial-gradient(900px 420px at 82% -8%, rgba(87, 214, 242, .12), transparent 62%),
    radial-gradient(760px 380px at 6% 0%, rgba(127, 230, 210, .08), transparent 60%),
    radial-gradient(700px 500px at 50% 108%, rgba(87, 214, 242, .05), transparent 65%),
    var(--bg);
  --panel: #0b1d23;
  --panel-2: #0e2329;
  --panel-3: #12303a;
  --panel-4: #173c47;
  --border: #1b3a44;
  --border-soft: #122a32;
  --text: #eef6f7;
  --text-dim: #a9c3c9;
  --text-faint: #7f9aa1;
  --accent: #57d6f2;
  --accent-2: #7fe6d2;
  --accent-grad: linear-gradient(135deg, #57d6f2 0%, #7fe6d2 100%);
  --accent-soft: rgba(87, 214, 242, .16);
  --accent-line: rgba(87, 214, 242, .34);
  --on-accent: #06232b;
  --ok: #7fe6b0; --ok-soft: rgba(127, 230, 176, .14);
  --warn: #f6c969; --warn-soft: rgba(246, 201, 105, .14);
  --err: #ff8080; --err-soft: rgba(255, 128, 128, .13);
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 10px 30px -12px rgba(0, 0, 0, .6);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .4), 0 32px 64px -24px rgba(0, 0, 0, .75);
  --code-bg: #061417;
  --user-bubble: linear-gradient(140deg, rgba(87, 214, 242, .22), rgba(127, 230, 210, .14));
  --scroll-thumb: #1e4250;
  --glass: rgba(8, 20, 24, .78);
  --ans0:#7c8496; --ans1:#f87171; --ans2:#34d399; --ans3:#fbbf24; --ans4:#60a5fa; --ans5:#c084fc; --ans6:#22d3ee; --ans7:#d1d5db;
  --ans0b:#9ca3af; --ans1b:#fca5a5; --ans2b:#6ee7b7; --ans3b:#fcd34d; --ans4b:#93c5fd; --ans5b:#d8b4fe; --ans6b:#67e8f9; --ans7b:#f3f4f6;
  --ansbg0:rgba(17,24,39,.55); --ansbg1:rgba(248,113,113,.16); --ansbg2:rgba(52,211,153,.14); --ansbg3:rgba(251,191,36,.14);
  --ansbg4:rgba(96,165,250,.14); --ansbg5:rgba(192,132,252,.14); --ansbg6:rgba(34,211,238,.14); --ansbg7:rgba(209,213,219,.12);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #eef4f5;
  --bg-grad:
    radial-gradient(900px 420px at 84% -10%, rgba(87, 214, 242, .20), transparent 62%),
    radial-gradient(700px 380px at 4% -6%, rgba(127, 230, 210, .16), transparent 60%),
    var(--bg);
  --panel: #ffffff;
  --panel-2: #f4f9fa;
  --panel-3: #e8f1f3;
  --panel-4: #dce8ea;
  --border: #d3e2e5;
  --border-soft: #e5eef0;
  --text: #08222a;
  --text-dim: #3d5b63;
  --text-faint: #6f8b92;
  --accent: #148aa4;
  --accent-2: #12a189;
  --accent-grad: linear-gradient(135deg, #57d6f2 0%, #7fe6d2 100%);
  --accent-soft: rgba(87, 214, 242, .18);
  --accent-line: rgba(20, 138, 164, .28);
  --on-accent: #06232b;
  --ok: #0f8a63; --ok-soft: rgba(15, 138, 99, .1);
  --warn: #a15c00; --warn-soft: rgba(161, 92, 0, .12);
  --err: #c62828; --err-soft: rgba(198, 40, 40, .08);
  --shadow: 0 1px 2px rgba(8, 34, 42, .05), 0 10px 24px -14px rgba(8, 34, 42, .22);
  --shadow-lg: 0 2px 8px rgba(8, 34, 42, .06), 0 28px 56px -26px rgba(8, 34, 42, .3);
  --code-bg: #f1f7f8;
  --user-bubble: linear-gradient(140deg, rgba(87, 214, 242, .22), rgba(127, 230, 210, .18));
  --scroll-thumb: #c3d6da;
  --glass: rgba(255, 255, 255, .82);
  --hair: rgba(8, 34, 42, .06);
  color-scheme: light;
}

/* EMBED-THEMES: 8 extra embed themes (same variable set as dark/light). */
[data-theme="ocean"] {
  --bg: #071a24;
  --bg-grad: radial-gradient(1200px 500px at 70% -10%, rgba(56, 189, 248, 0.09), transparent 60%),
             radial-gradient(900px 400px at 10% -10%, rgba(45, 212, 191, 0.07), transparent 60%),
             var(--bg);
  --panel: #0d2431;
  --panel-2: #12303f;
  --panel-3: #12303f;
  --border: #1d4a5e;
  --border-soft: #16394a;
  --text: #e6f2f7;
  --text-dim: #9fc3d1;
  --text-faint: #5f8fa3;
  --accent: #38bdf8;
  --accent-2: #2dd4bf;
  --accent-grad: linear-gradient(135deg, #38bdf8, #2dd4bf);
  --accent-soft: rgba(56, 189, 248, 0.14);
  --ok: #34d399; --ok-soft: rgba(52, 211, 153, .14);
  --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
  --err: #f87171; --err-soft: rgba(248, 113, 113, .14);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.45), 0 24px 48px rgba(0,0,0,.4);
  --user-bubble: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(45, 212, 191, 0.20));
  --code-bg: #0a1f2b;
  --scroll-thumb: #1f4a5e;
  --ans0:#7c8496; --ans1:#f87171; --ans2:#34d399; --ans3:#fbbf24; --ans4:#60a5fa; --ans5:#c084fc; --ans6:#22d3ee; --ans7:#d1d5db;
  --ans0b:#9ca3af; --ans1b:#fca5a5; --ans2b:#6ee7b7; --ans3b:#fcd34d; --ans4b:#93c5fd; --ans5b:#d8b4fe; --ans6b:#67e8f9; --ans7b:#f3f4f6;
}

[data-theme="forest"] {
  --bg: #0a140d;
  --bg-grad: radial-gradient(1200px 500px at 70% -10%, rgba(74, 222, 128, 0.09), transparent 60%),
             radial-gradient(900px 400px at 10% -10%, rgba(163, 230, 53, 0.07), transparent 60%),
             var(--bg);
  --panel: #102015;
  --panel-2: #16291c;
  --panel-3: #16291c;
  --border: #24452e;
  --border-soft: #1c3626;
  --text: #e7f3ea;
  --text-dim: #a3c4ab;
  --text-faint: #678a6f;
  --accent: #4ade80;
  --accent-2: #a3e635;
  --accent-grad: linear-gradient(135deg, #4ade80, #a3e635);
  --accent-soft: rgba(74, 222, 128, 0.14);
  --ok: #34d399; --ok-soft: rgba(52, 211, 153, .14);
  --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
  --err: #f87171; --err-soft: rgba(248, 113, 113, .14);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.45), 0 24px 48px rgba(0,0,0,.4);
  --user-bubble: linear-gradient(135deg, rgba(74, 222, 128, 0.22), rgba(163, 230, 53, 0.20));
  --code-bg: #0c1a10;
  --scroll-thumb: #24452e;
  --ans0:#7c8496; --ans1:#f87171; --ans2:#34d399; --ans3:#fbbf24; --ans4:#60a5fa; --ans5:#c084fc; --ans6:#22d3ee; --ans7:#d1d5db;
  --ans0b:#9ca3af; --ans1b:#fca5a5; --ans2b:#6ee7b7; --ans3b:#fcd34d; --ans4b:#93c5fd; --ans5b:#d8b4fe; --ans6b:#67e8f9; --ans7b:#f3f4f6;
}

[data-theme="sunset"] {
  --bg: #1a0e12;
  --bg-grad: radial-gradient(1200px 500px at 70% -10%, rgba(251, 113, 113, 0.09), transparent 60%),
             radial-gradient(900px 400px at 10% -10%, rgba(245, 158, 11, 0.07), transparent 60%),
             var(--bg);
  --panel: #241318;
  --panel-2: #2e1a20;
  --panel-3: #2e1a20;
  --border: #4a2c36;
  --border-soft: #3a222b;
  --text: #f8ecef;
  --text-dim: #d4aab5;
  --text-faint: #96687a;
  --accent: #fb7171;
  --accent-2: #f59e0b;
  --accent-grad: linear-gradient(135deg, #fb7171, #f59e0b);
  --accent-soft: rgba(251, 113, 113, 0.14);
  --ok: #34d399; --ok-soft: rgba(52, 211, 153, .14);
  --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
  --err: #f87171; --err-soft: rgba(248, 113, 113, .14);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.45), 0 24px 48px rgba(0,0,0,.4);
  --user-bubble: linear-gradient(135deg, rgba(251, 113, 113, 0.22), rgba(245, 158, 11, 0.20));
  --code-bg: #1f1116;
  --scroll-thumb: #4a2c36;
  --ans0:#7c8496; --ans1:#f87171; --ans2:#34d399; --ans3:#fbbf24; --ans4:#60a5fa; --ans5:#c084fc; --ans6:#22d3ee; --ans7:#d1d5db;
  --ans0b:#9ca3af; --ans1b:#fca5a5; --ans2b:#6ee7b7; --ans3b:#fcd34d; --ans4b:#93c5fd; --ans5b:#d8b4fe; --ans6b:#67e8f9; --ans7b:#f3f4f6;
}

[data-theme="midnight"] {
  --bg: #05070f;
  --bg-grad: radial-gradient(1200px 500px at 70% -10%, rgba(129, 140, 248, 0.09), transparent 60%),
             radial-gradient(900px 400px at 10% -10%, rgba(56, 189, 248, 0.07), transparent 60%),
             var(--bg);
  --panel: #0a0e1a;
  --panel-2: #0f1526;
  --panel-3: #0f1526;
  --border: #1d2742;
  --border-soft: #161e36;
  --text: #dbe2f5;
  --text-dim: #97a3c8;
  --text-faint: #5a6790;
  --accent: #818cf8;
  --accent-2: #38bdf8;
  --accent-grad: linear-gradient(135deg, #818cf8, #38bdf8);
  --accent-soft: rgba(129, 140, 248, 0.14);
  --ok: #34d399; --ok-soft: rgba(52, 211, 153, .14);
  --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
  --err: #f87171; --err-soft: rgba(248, 113, 113, .14);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.45), 0 24px 48px rgba(0,0,0,.4);
  --user-bubble: linear-gradient(135deg, rgba(129, 140, 248, 0.22), rgba(56, 189, 248, 0.20));
  --code-bg: #080c18;
  --scroll-thumb: #1d2742;
  --ans0:#7c8496; --ans1:#f87171; --ans2:#34d399; --ans3:#fbbf24; --ans4:#60a5fa; --ans5:#c084fc; --ans6:#22d3ee; --ans7:#d1d5db;
  --ans0b:#9ca3af; --ans1b:#fca5a5; --ans2b:#6ee7b7; --ans3b:#fcd34d; --ans4b:#93c5fd; --ans5b:#d8b4fe; --ans6b:#67e8f9; --ans7b:#f3f4f6;
}

[data-theme="paper"] {
  --bg: #f7f4ee;
  --bg-grad: radial-gradient(1200px 500px at 70% -10%, rgba(180, 83, 9, 0.08), transparent 60%), var(--bg);
  --panel: #fffdf9;
  --panel-2: #f8f5ef;
  --panel-3: #efeae0;
  --border: #e0d8c8;
  --border-soft: #e8e1d4;
  --text: #2a2620;
  --text-dim: #5c554a;
  --text-faint: #8a8172;
  --accent: #b45309;
  --accent-2: #92400e;
  --accent-grad: linear-gradient(135deg, #b45309, #92400e);
  --accent-soft: rgba(180, 83, 9, 0.10);
  --ok: #059669; --ok-soft: rgba(5, 150, 105, .10);
  --warn: #b45309; --warn-soft: rgba(217, 119, 6, .12);
  --err: #dc2626; --err-soft: rgba(220, 38, 38, .08);
  --shadow: 0 1px 2px rgba(23,32,63,.06), 0 6px 20px rgba(23,32,63,.07);
  --shadow-lg: 0 4px 12px rgba(23,32,63,.1), 0 24px 48px rgba(23,32,63,.14);
  --user-bubble: linear-gradient(135deg, rgba(180, 83, 9, 0.14), rgba(146, 64, 14, 0.12));
  --code-bg: #f2ede3;
  --scroll-thumb: #d6cbb6;
  --ans0:#6b7280; --ans1:#dc2626; --ans2:#047857; --ans3:#b45309; --ans4:#1d4ed8; --ans5:#6d28d9; --ans6:#155e75; --ans7:#1f2937;
  --ans0b:#4b5563; --ans1b:#b91c1c; --ans2b:#065f46; --ans3b:#92400e; --ans4b:#1e40af; --ans5b:#5b21b6; --ans6b:#164e63; --ans7b:#111827;
}

[data-theme="terminal"] {
  --bg: #050805;
  --bg-grad: radial-gradient(1200px 500px at 70% -10%, rgba(34, 197, 94, 0.09), transparent 60%),
             radial-gradient(900px 400px at 10% -10%, rgba(74, 222, 128, 0.07), transparent 60%),
             var(--bg);
  --panel: #0a100b;
  --panel-2: #0e160f;
  --panel-3: #0e160f;
  --border: #1d2c1e;
  --border-soft: #152016;
  --text: #d3f5d9;
  --text-dim: #86b891;
  --text-faint: #55805e;
  --accent: #22c55e;
  --accent-2: #4ade80;
  --accent-grad: linear-gradient(135deg, #22c55e, #4ade80);
  --accent-soft: rgba(34, 197, 94, 0.14);
  --ok: #34d399; --ok-soft: rgba(52, 211, 153, .14);
  --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
  --err: #f87171; --err-soft: rgba(248, 113, 113, .14);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.45), 0 24px 48px rgba(0,0,0,.4);
  --user-bubble: linear-gradient(135deg, rgba(34, 197, 94, 0.22), rgba(74, 222, 128, 0.20));
  --code-bg: #070d08;
  --scroll-thumb: #1d2c1e;
  --ans0:#7c8496; --ans1:#f87171; --ans2:#34d399; --ans3:#fbbf24; --ans4:#60a5fa; --ans5:#c084fc; --ans6:#22d3ee; --ans7:#d1d5db;
  --ans0b:#9ca3af; --ans1b:#fca5a5; --ans2b:#6ee7b7; --ans3b:#fcd34d; --ans4b:#93c5fd; --ans5b:#d8b4fe; --ans6b:#67e8f9; --ans7b:#f3f4f6;
}

[data-theme="rose"] {
  --bg: #faf4f6;
  --bg-grad: radial-gradient(1200px 500px at 70% -10%, rgba(219, 39, 119, 0.08), transparent 60%), var(--bg);
  --panel: #ffffff;
  --panel-2: #fbf4f6;
  --panel-3: #f5e8ec;
  --border: #ecd9e0;
  --border-soft: #f2e4e9;
  --text: #33222a;
  --text-dim: #6b4a56;
  --text-faint: #9c7f8b;
  --accent: #db2777;
  --accent-2: #9d174d;
  --accent-grad: linear-gradient(135deg, #db2777, #9d174d);
  --accent-soft: rgba(219, 39, 119, 0.10);
  --ok: #059669; --ok-soft: rgba(5, 150, 105, .10);
  --warn: #b45309; --warn-soft: rgba(217, 119, 6, .12);
  --err: #dc2626; --err-soft: rgba(220, 38, 38, .08);
  --shadow: 0 1px 2px rgba(23,32,63,.06), 0 6px 20px rgba(23,32,63,.07);
  --shadow-lg: 0 4px 12px rgba(23,32,63,.1), 0 24px 48px rgba(23,32,63,.14);
  --user-bubble: linear-gradient(135deg, rgba(219, 39, 119, 0.14), rgba(157, 23, 77, 0.12));
  --code-bg: #f7eef1;
  --scroll-thumb: #e5cdd6;
  --ans0:#6b7280; --ans1:#dc2626; --ans2:#047857; --ans3:#b45309; --ans4:#1d4ed8; --ans5:#6d28d9; --ans6:#155e75; --ans7:#1f2937;
  --ans0b:#4b5563; --ans1b:#b91c1c; --ans2b:#065f46; --ans3b:#92400e; --ans4b:#1e40af; --ans5b:#5b21b6; --ans6b:#164e63; --ans7b:#111827;
}

[data-theme="slate"] {
  --bg: #0e1116;
  --bg-grad: radial-gradient(1200px 500px at 70% -10%, rgba(56, 189, 248, 0.09), transparent 60%),
             radial-gradient(900px 400px at 10% -10%, rgba(96, 165, 250, 0.07), transparent 60%),
             var(--bg);
  --panel: #151a21;
  --panel-2: #1b222b;
  --panel-3: #1b222b;
  --border: #2c3642;
  --border-soft: #232c37;
  --text: #e2e8f0;
  --text-dim: #9aa7b8;
  --text-faint: #64748b;
  --accent: #38bdf8;
  --accent-2: #60a5fa;
  --accent-grad: linear-gradient(135deg, #38bdf8, #60a5fa);
  --accent-soft: rgba(56, 189, 248, 0.14);
  --ok: #34d399; --ok-soft: rgba(52, 211, 153, .14);
  --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
  --err: #f87171; --err-soft: rgba(248, 113, 113, .14);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.45), 0 24px 48px rgba(0,0,0,.4);
  --user-bubble: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(96, 165, 250, 0.20));
  --code-bg: #10151c;
  --scroll-thumb: #2c3642;
  --ans0:#7c8496; --ans1:#f87171; --ans2:#34d399; --ans3:#fbbf24; --ans4:#60a5fa; --ans5:#c084fc; --ans6:#22d3ee; --ans7:#d1d5db;
  --ans0b:#9ca3af; --ans1b:#fca5a5; --ans2b:#6ee7b7; --ans3b:#fcd34d; --ans4b:#93c5fd; --ans5b:#d8b4fe; --ans6b:#67e8f9; --ans7b:#f3f4f6;
}

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg-grad) fixed;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; }
::selection { background: var(--accent-soft); }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

.mono { font-family: var(--mono); font-size: .92em; }
.dim { color: var(--text-dim); }
.hint { color: var(--text-faint); font-size: .84em; margin: 6px 0 0; }
.hidden { display: none !important; }
.grow { flex: 1 1 160px; }
.grow2 { flex: 2 1 240px; }
.inline { display: inline; margin: 0; }

/* ---------------- top nav ---------------- */
.topnav {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-h);
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent-grad); color: #fff;
  font-family: var(--mono); font-size: 13px; font-weight: 700;
  box-shadow: 0 2px 10px rgba(108, 140, 255, .35);
}
.brand-mark.big { width: 52px; height: 52px; font-size: 22px; border-radius: 15px; }
.nav-links { display: flex; gap: 4px; }
.nav-links a {
  padding: 7px 13px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 500; font-size: 14px;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.nav-links a:hover { color: var(--text); background: var(--panel-3); text-decoration: none; }
.nav-links a.active { color: var(--text); background: var(--accent-soft); }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer; font-size: 15px;
  transition: all .15s var(--ease);
}
.iconbtn:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.iconbtn.danger:hover { color: var(--err); border-color: var(--err); background: var(--err-soft); }
.iconbtn.attach { width: 40px; height: 40px; border-radius: 10px; }
[data-theme="dark"] .ic-sun { display: none; }
[data-theme="light"] .ic-moon { display: none; }

.langbtn {
  padding: 6px 11px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); font-weight: 700; font-size: 12.5px; letter-spacing: .05em;
  cursor: pointer; transition: all .15s var(--ease);
}
.langbtn:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

.usermenu { position: relative; }
.userbtn {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text); cursor: pointer; font-size: 14px; font-weight: 500;
  transition: all .15s var(--ease);
}
.userbtn:hover { border-color: var(--accent); background: var(--accent-soft); }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-grad); color: #fff;
  font-weight: 700; font-size: 13px; flex: none;
}
.avatar.sm { width: 22px; height: 22px; font-size: 11px; }

.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 200px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: none; z-index: 60;
}
.dropdown.open { display: block; animation: pop .14s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
.dropdown-head { padding: 10px 12px 8px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.dropdown-name { font-weight: 600; }
.dropdown-item {
  display: block; padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 14px;
}
.dropdown-item:hover { background: var(--panel-3); color: var(--text); text-decoration: none; }
.dropdown-item.danger:hover { background: var(--err-soft); color: var(--err); }

/* ---------------- layout ---------------- */
.page { max-width: var(--max-w); margin: 0 auto; padding: 28px 20px 60px; }
.page-title { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.page-sub { color: var(--text-faint); margin: 4px 0 0; font-size: 13.5px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.dash-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 14px; font-weight: 600;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: all .15s var(--ease);
}
.btn:hover { border-color: var(--accent); background: var(--panel-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary {
  background: var(--accent-grad); border: none; color: #fff;
  box-shadow: 0 2px 12px rgba(108, 140, 255, .35);
}
.btn-primary:hover { filter: brightness(1.08); background: var(--accent-grad); border: none; }
.btn-danger { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 40%, transparent); color: var(--err); }
.btn-danger:hover { background: var(--err); border-color: var(--err); color: #fff; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; }

.spinner {
  display: inline-block; width: 15px; height: 15px; flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- forms ---------------- */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px;
  font-family: var(--font); font-size: 14px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder { color: var(--text-faint); }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%), linear-gradient(135deg, var(--text-faint) 50%, transparent 50%); background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.select-sm { padding: 5px 26px 5px 9px; font-size: 13px; border-radius: 7px; width: auto; }
.row-form { display: flex; gap: 8px; align-items: center; }
.row-form .input { flex: 1; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.form-err {
  padding: 10px 12px; margin-bottom: 14px;
  background: var(--err-soft); color: var(--err);
  border: 1px solid color-mix(in srgb, var(--err) 30%, transparent);
  border-radius: var(--radius-sm); font-size: 13.5px;
}
.prefix-input { display: flex; align-items: center; flex: 1; }
.prefix {
  font-family: var(--mono); font-size: 13px; color: var(--text-faint);
  padding: 9px 10px; border: 1px solid var(--border); border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--panel-3);
  white-space: nowrap;
}
.prefix-input .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.suffix {
  font-family: var(--mono); font-size: 13px; color: var(--text-faint);
  padding: 9px 10px; border: 1px solid var(--border); border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--panel-3);
  white-space: nowrap;
}
.prefix-input.suffix-input .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); flex: 1; }
.subdomain-row .row-form { margin-top: 6px; }

/* ---------------- badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .02em;
  border: 1px solid transparent;
}
.badge-online, .badge-active { background: var(--ok-soft); color: var(--ok); }
.badge-offline, .badge-retired { background: var(--err-soft); color: var(--err); }
.badge-public { background: var(--ok-soft); color: var(--ok); }
.badge-private { background: var(--warn-soft); color: var(--warn); }
.badge-env { background: var(--accent-soft); color: var(--accent); }
.badge-admin, .badge-default, .badge-owner { background: var(--accent-soft); color: var(--accent); }
.badge-member { background: var(--panel-3); color: var(--text-dim); }
.badge-new { background: var(--accent-grad); color: #fff; }

/* ---------------- auth ---------------- */
.auth-wrap { min-height: calc(100vh - var(--nav-h) - 56px); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px 0; }
.auth-card { width: 100%; max-width: 400px; padding: 34px 32px 26px; }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand h1 { margin: 12px 0 2px; font-size: 26px; letter-spacing: -.02em; }
.auth-tagline { color: var(--text-faint); margin: 0; font-size: 14px; }
.auth-form .btn { margin-top: 6px; }
.auth-alt { text-align: center; color: var(--text-faint); font-size: 13.5px; margin: 16px 0 0; }
.auth-foot { color: var(--text-faint); font-size: 12.5px; margin-top: 18px; }

/* ---------------- dashboard / app grid ---------------- */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 16px;
}
.app-card {
  display: block; padding: 18px;
  color: var(--text); position: relative; overflow: hidden;
  transition: transform .18s var(--ease), border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.app-card:hover { text-decoration: none; transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow-lg); }
.app-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.app-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--panel-3); color: var(--accent);
  font-weight: 800; font-size: 18px;
}
.app-icon.plus { background: var(--accent-grad); color: #fff; font-size: 22px; font-weight: 600; }
/* agent-synced app icon (2026-11-12): real image instead of first letter */
.app-icon-img { overflow: hidden; background: var(--panel-3); }
.app-icon-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.app-card-title { font-weight: 700; font-size: 16px; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-card-meta { display: flex; gap: 8px; color: var(--text-faint); font-size: 12.5px; }
.app-card-link { margin-top: 10px; font-family: var(--mono); font-size: 12px; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-app-card { display: block; }
.new-app-form { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; }
.new-app-card .app-card-top { margin-bottom: 4px; }

/* ---------------- app page layout ---------------- */
.app-page { display: flex; flex-direction: column; gap: 16px; }
.page:has(> .app-page) { max-width: none; padding: 16px 16px; }
.app-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 20px; flex-wrap: wrap;
}
.app-head-left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.crumb { font-size: 12.5px; color: var(--text-faint); }
.app-head-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.app-head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.app-layout {
  display: grid;
  grid-template-columns: 312px minmax(0, 1fr) 384px;
  gap: 16px;
  align-items: stretch;
  height: calc(100vh - var(--nav-h) - 32px);
}
/* right sidebar */
.app-side {
  display: flex; flex-direction: column; gap: 16px;
  height: 100%; max-height: 100%;
  overflow-y: auto;
}
.app-side-mobhead { display: none; }
.app-side-card { padding: 16px 18px; }
.app-side-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 700; margin: 0 0 10px; }
.app-side-readme .app-side-title, .readme-head .app-side-title { margin-bottom: 0; }
.app-info-name { font-size: 18px; font-weight: 700; margin: 0 0 8px; letter-spacing: -.01em; }
.app-info-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.app-info-sub { display: inline-block; font-family: var(--mono); font-size: 12px; color: var(--accent); word-break: break-all; margin-bottom: 6px; }
.app-info-meta { font-size: 11.5px; color: var(--text-faint); }
.app-side-actions { display: flex; flex-direction: column; gap: 8px; }
.app-side-actions .btn { width: 100%; }
.app-side-actions form { margin: 0; }
.app-side-members { margin-bottom: 0; }

/* right sidebar: user prompts list (task6) */
.app-side-prompts { display: flex; flex-direction: column; flex: 1 1 240px; min-height: 240px; }
.uprompt-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 3px;
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
}
.uprompt-item {
  display: flex; align-items: baseline; gap: 7px;
  padding: 5px 8px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--border-soft);
  cursor: pointer;
}
.uprompt-item:hover, .uprompt-item:focus-visible { border-color: var(--accent); background: var(--panel-3); outline: none; }
.uprompt-no { flex: none; font-size: 10.5px; color: var(--text-faint); min-width: 16px; text-align: right; }
.uprompt-text {
  flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.uprompt-item:hover .uprompt-text { color: var(--text); }
@keyframes upromptFlash { from { box-shadow: 0 0 0 2px var(--accent); } to { box-shadow: 0 0 0 2px transparent; } }
.msg.user.uprompt-target { border-radius: 10px; animation: upromptFlash 1.8s var(--ease) 1; }
.readme-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.readme-head .btn-sm { padding: 3px 8px; }
.readme-body { min-height: 20px; overflow-x: auto; }
.readme-md { font-size: 13px; }
.readme-md pre { max-height: 320px; }
.readme-empty { color: var(--text-faint); font-size: 13px; padding: 14px 12px; border: 1px dashed var(--border); border-radius: var(--radius-sm); text-align: center; }

/* sidebar */
.sidebar { padding: 14px; display: flex; flex-direction: column; gap: 10px; height: 100%; max-height: 100%; overflow: hidden; }
.sidebar-head { display: flex; flex-direction: column; gap: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--border-soft); }
.sidebar-title { font-weight: 700; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.newchat-form { display: flex; gap: 8px; }
.newchat-form .select { flex: 1; min-width: 0; }
.newchat-form .btn { flex: none; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 0; }
.chat-item { position: relative; }
.chat-item .ci-link {
  display: block; padding: 9px 30px 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); transition: background .13s var(--ease);
}
.chat-item .ci-link:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }
.chat-item.active .ci-link { background: var(--accent-soft); color: var(--text); }
.ci-title { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-meta { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }
/* chat-list run-state indicator (item: running vs idle at a glance) */
.ci-status { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; background: var(--text-faint); opacity: .5; }
.ci-status.running { background: var(--ok); opacity: 1; animation: ci-pulse 1.2s ease-in-out infinite; }
.ci-status.queued { background: #f2c852; opacity: 1; }
@keyframes ci-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(62, 207, 142, .45); } 50% { box-shadow: 0 0 0 4px rgba(62, 207, 142, 0); } }
.chat-item.running .ci-title { color: var(--ok); }
.chat-item.queued .ci-title { color: #f2c852; }
.ci-del { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); margin: 0; opacity: 0; transition: opacity .13s; }
.chat-item:hover .ci-del { opacity: 1; }
.ci-del button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 6px;
  background: transparent; border: none; color: var(--text-faint); cursor: pointer;
}
.ci-del button:hover { background: var(--err-soft); color: var(--err); }
.empty-sm { color: var(--text-faint); font-size: 13px; padding: 8px 6px; }
/* bookmark toggle (2026-11-12): sidebar 'important' chats */
.ci-bmk { position: absolute; right: 34px; top: 50%; transform: translateY(-50%); margin: 0; opacity: 0; transition: opacity .13s; }
.chat-item:hover .ci-bmk { opacity: 1; }
.chat-item.bookmarked .ci-bmk { opacity: 1; }
.ci-bmk button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 6px;
  background: transparent; border: none; color: var(--text-faint); cursor: pointer;
}
.ci-bmk button:hover { background: var(--panel-2); color: var(--text); }
.chat-item.bookmarked .ci-bmk button { color: #f2c852; }
.chat-item.bookmarked:not(.active) .ci-link {
  background: rgba(242, 200, 82, .06);
  box-shadow: inset 2px 0 0 rgba(242, 200, 82, .8);
}
/* embed card, not-yet-activated state (2026-11-12) */
.embed-card-off { border-style: dashed; }
.embed-card-off .btn { margin-top: 8px; }

/* chat panel */
.chat-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; }
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border-soft);
}
.chat-head-title { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-pick { display: flex; align-items: center; gap: 8px; }
.model-pick-label { font-size: 11.5px; color: var(--text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.chat-head-right { display: flex; align-items: center; gap: 10px; }
.chat-toggle { display: none; }
.sidebar-close { display: none; }
.sidebar-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 20px 18px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}
.chat-loading { color: var(--text-faint); display: flex; align-items: center; gap: 8px; justify-content: center; padding: 30px; }
.chat-messages > * { flex-shrink: 0; }

/* messages */
.msg { display: flex; flex-direction: column; max-width: 88%; animation: msgIn .18s var(--ease); }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; align-items: flex-end; position: relative; min-width: 0; }
.msg .bubble {
  padding: 11px 15px; border-radius: 14px;
  font-size: 14.5px; overflow-wrap: break-word; min-width: 0;
}
.msg.user .bubble {
  background: var(--user-bubble);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  max-width: 100%; overflow-wrap: anywhere;
  border-bottom-right-radius: 5px;
}
.msg.assistant .bubble {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-top-left-radius: 5px;
}
.msg .files { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; justify-content: flex-end; min-width: 0; max-width: 100%; }
.msg .file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 11.5px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--panel-3); color: var(--text-dim);
  border: 1px solid var(--border);
  max-width: 100%; min-width: 0;
  text-decoration: none; cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.msg .file-chip:hover { color: var(--text); border-color: var(--accent); background: var(--panel-2); }
.msg .file-chip .fc-ico { flex: none; font-size: 12px; }
.msg .file-chip .fc-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .img-chip { display: inline-flex; max-width: 100%; }
.msg .u-img {
  display: block; width: auto; height: auto;
  max-width: 280px; max-height: 220px; object-fit: contain;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); cursor: zoom-in;
  transition: border-color .15s, transform .15s;
}
.msg .img-chip:hover .u-img { border-color: var(--accent); transform: scale(1.02); }
.msg.streaming .bubble::after {
  content: ""; display: inline-block; width: 7px; height: 15px; margin-left: 3px;
  background: var(--accent); border-radius: 2px; vertical-align: text-bottom;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* markdown */
.md { white-space: normal; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 8px 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 8px; }
.md h1 { font-size: 1.25em; } .md h2 { font-size: 1.15em; } .md h3 { font-size: 1.05em; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 3px 0; }
.md code {
  font-family: var(--mono); font-size: .88em;
  background: var(--code-bg); border: 1px solid var(--border-soft);
  padding: 1.5px 5px; border-radius: 5px;
}
.md pre {
  background: var(--code-bg); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px; overflow-x: auto; margin: 10px 0;
}
.md pre code { background: none; border: none; padding: 0; font-size: 12.8px; line-height: 1.5; }
.md blockquote { margin: 10px 0; padding: 6px 14px; border-left: 3px solid var(--accent); background: var(--panel-3); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-dim); }
.md table { border-collapse: collapse; margin: 10px 0; font-size: .92em; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 10px; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* tool cards */
.toolcard {
  align-self: flex-start; width: 100%; max-width: 96%;
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-faint);
  border-radius: var(--radius-sm);
  background: var(--panel-2); overflow: hidden;
  animation: msgIn .18s var(--ease);
}
.toolcard:has(.tool-state.running) { border-left-color: var(--warn); }
.toolcard:has(.tool-state.ok) { border-left-color: var(--ok); }
.toolcard:has(.tool-state.err) { border-left-color: var(--err); }
.toolcard summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px 9px 13px; font-size: 13px; user-select: none;
  background: var(--panel-2);
  transition: background .13s var(--ease);
}
.toolcard summary::-webkit-details-marker { display: none; }
.toolcard summary::before {
  content: "▸"; color: var(--text-faint); font-size: 11px;
  transition: transform .15s var(--ease);
}
.toolcard[open] summary::before { transform: rotate(90deg); }
.toolcard[open] summary, .toolcard summary:hover { background: var(--panel-3); }
.tool-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px;
}
.tool-name { font-family: var(--mono); font-weight: 700; font-size: 12.8px; color: var(--text); }
.tool-args { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tool-state {
  font-size: 11px; font-weight: 700; flex: none;
  padding: 2px 8px; border-radius: 999px;
}
.tool-state.running { color: var(--warn); background: var(--warn-soft); }
.tool-state.ok { color: var(--ok); background: var(--ok-soft); }
.tool-state.err { color: var(--err); background: var(--err-soft); }
.tool-body { border-top: 1px solid var(--border-soft); padding: 12px 14px; max-height: min(68vh, 680px); overflow: auto; display: flex; flex-direction: column; gap: 13px; }
.t-imgwrap { display: flex; justify-content: center; background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 8px; padding: 8px; }
.t-img { max-width: 100%; max-height: 440px; border-radius: 6px; display: block; }
.t-filename { font-size: 12px; color: var(--text-dim); font-family: var(--mono); word-break: break-all; }
.t-fn-size { color: var(--text-faint); font-size: 11px; font-family: var(--mono); }
.t-media { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 8px; padding: 8px; }
.t-media video, .t-media .t-video { max-width: 100%; max-height: 440px; border-radius: 6px; display: block; background: #000; width: 100%; }
.t-media audio, .t-media .t-audio { width: 100%; display: block; }
.t-media iframe, .t-media .t-pdf, .t-media .t-html { width: 100%; height: 440px; border: 0; border-radius: 6px; background: #fff; display: block; }
.t-dl { align-self: center; }
.t-sec { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.t-h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); }
.t-h .t-badge { font-family: var(--mono); font-size: 10.5px; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text-dim); background: var(--panel-3); border: 1px solid var(--border-soft); padding: 1px 8px; border-radius: 999px; max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-badge.b-ok { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.t-badge.b-warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.t-note { font-size: 12px; color: var(--text-dim); }
.t-empty { color: var(--text-faint); font-size: 11.5px; font-style: italic; }
.t-block { margin: 0; background: var(--code-bg); border: 1px solid var(--border-soft); border-radius: 8px; padding: 9px 11px; font-family: var(--mono); font-size: 11.8px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; color: var(--text-dim); max-height: 46vh; overflow: auto; }
.t-block.t-cmd { color: var(--text); background: var(--panel-3); }
.t-block.t-err { color: var(--err); background: var(--err-soft); border-color: var(--border-soft); }
.t-line { display: flex; gap: 9px; align-items: baseline; font-family: var(--mono); font-size: 11.8px; line-height: 1.55; }
.t-line b { flex: none; font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; padding: 1.5px 7px; border-radius: 5px; font-weight: 700; }
.t-line.b-user b { color: var(--accent); background: var(--accent-soft); }
.t-line.b-assistant b { color: var(--ok); background: var(--ok-soft); }
.t-line span { color: var(--text-dim); white-space: pre-wrap; word-break: break-word; }
.a-b { font-weight: 700; }
.a-u { text-decoration: underline; }

/* thinking */
.think {
  align-self: flex-start; width: 100%; max-width: 96%;
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
  background: transparent; overflow: hidden;
  animation: msgIn .18s var(--ease);
}
.think summary {
  list-style: none; cursor: pointer; padding: 6px 12px;
  font-size: 12px; color: var(--text-faint); font-style: italic;
  display: flex; align-items: center; gap: 7px; user-select: none;
}
.think summary::-webkit-details-marker { display: none; }
.think summary::before { content: "◌"; font-size: 13px; }
.think[open] summary::before { content: "◉"; }
.think-body { padding: 0 12px 10px; }
.think-body pre {
  margin: 0; font-family: var(--mono); font-size: 11.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; color: var(--text-faint);
  max-height: 260px; overflow: auto;
}

/* prism + copy button integration */
.md pre, .t-block { position: relative; }
.md pre code[class*="language-"], .t-block code[class*="language-"] {
  display: block; padding: 0; margin: 0; background: transparent; overflow: visible;
  font-family: var(--mono);
}
.code-copy { position: absolute; top: 6px; right: 6px; z-index: 2; font-size: 11px; line-height: 1;
  padding: 3px 7px; border-radius: 6px; border: 1px solid var(--border-soft);
  background: var(--panel-2); color: var(--text-dim); cursor: pointer; opacity: 0; transition: opacity .12s; }
.md pre:hover .code-copy, .t-block:hover .code-copy, .code-copy:focus-visible, .code-copy.ok { opacity: 1; }
.code-copy.ok { color: var(--ok); border-color: var(--ok); }
@media (hover: none) { .code-copy { opacity: .75; } }
.think-sink { font-family: var(--mono); font-size: 11.5px; line-height: 1.5; white-space: pre-wrap;
  word-break: break-word; color: var(--text-faint); max-height: 260px; overflow: auto; }
.think-sink.md { white-space: normal; font-family: inherit; font-size: 12px; }

/* status bar */
.statusbar {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 18px;
  border-top: 1px solid var(--border-soft);
  background: var(--panel-2);
  font-size: 12.5px; color: var(--text-dim);
  min-height: 38px;
}
.status-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-elapsed { color: var(--text-faint); font-size: 11.5px; }
.status-tokens {
  color: var(--text-faint); font-size: 11.5px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 4px; flex: none;
}
.status-tokens .tok-ico { opacity: .85; font-size: 12px; }
.status-tokens .tok-num { font-weight: 600; }
.status-tokens .tok-word { opacity: .8; }

/* task 8: "show details" off (default) -> hide think blocks + tool cards */
#chatMessages.hide-details details.think,
#chatMessages.hide-details details.toolcard { display: none; }

/* task 8: shared chat-options sidebar card (nice + show details) */
.chat-options-card .chat-opt-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
.chat-options-card .chat-opt-label { font-size: 13px; opacity: .85; cursor: default; }
.chat-options-card .chat-opt-chk { width: 16px; height: 16px; cursor: pointer; }
.chat-options-card .chat-opt-row + .chat-opt-row { border-top: 1px solid var(--border-soft); }
/* task 8: parent-chat link in the chat head */
.parent-link { color: var(--accent); }

/* composer */
.composer { border-top: 1px solid var(--border-soft); padding: 12px 14px 14px; background: var(--panel); }
.composer-row { display: flex; align-items: flex-end; gap: 9px; }
.composer-input {
  flex: 1; resize: none; min-height: 42px; max-height: 180px;
  border-radius: 10px; font-size: 14.5px; padding: 10px 12px;
  line-height: 1.45;
}
.composer-send { height: 42px; flex: none; padding: 0 18px; }
.file-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.file-chips:empty { display: none; margin: 0; }
.file-chips .chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 11.5px;
  padding: 4px 6px 4px 10px; border-radius: 999px;
  background: var(--panel-3); border: 1px solid var(--border); color: var(--text-dim);
}
.file-chips .chip button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%;
  background: transparent; border: none; color: var(--text-faint);
  cursor: pointer; font-size: 13px; line-height: 1;
}
.file-chips .chip button:hover { background: var(--err-soft); color: var(--err); }

/* empty state */
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px 24px; gap: 8px;
}
.empty-icon { color: var(--text-faint); opacity: .8; margin-bottom: 8px; }
.empty-state h2 { margin: 0; font-size: 19px; }
.empty-sub { color: var(--text-faint); max-width: 460px; margin: 0 0 14px; font-size: 14px; }
.empty-start { display: flex; gap: 10px; }

/* ---------------- settings drawer ---------------- */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(5, 8, 15, .55);
  backdrop-filter: blur(2px);
  animation: fadeIn .18s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 95;
  width: min(440px, 100vw);
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(102%);
  transition: transform .24s var(--ease);
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid var(--border-soft);
}
.drawer-head h2 { margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { padding: 8px 20px 30px; overflow-y: auto; flex: 1; }
.settings-sec { padding: 18px 0; border-bottom: 1px solid var(--border-soft); }
.settings-sec:last-child { border-bottom: none; }
.settings-sec h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
.subhead { margin: 16px 0 8px; font-size: 12.5px; font-weight: 700; color: var(--text-dim); }
.danger-zone { background: linear-gradient(180deg, var(--err-soft), transparent 140%); border-radius: var(--radius); padding-left: 14px; padding-right: 14px; margin: 0 -14px; }
.danger-zone h3 { color: var(--err); }

.member-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.member-list li {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--border-soft);
  font-size: 13.5px;
}
.member-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-list .inline { margin: 0; }

/* ---------------- tables (admin) ---------------- */
.page:has(> .admin) { max-width: calc(var(--max-w) * 1.25); }
.table-card { padding: 18px 20px 20px; margin-bottom: 18px; }
.table-title { font-size: 16px; font-weight: 700; margin: 0 0 12px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 8px 10px;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--panel-2); }
.row-retired td { opacity: .55; }
.cell-name { font-weight: 600; display: inline; margin-left: 8px; }
.cell-actions { white-space: nowrap; text-align: right; }
.cell-actions form { display: inline-block; margin-left: 6px; }
.cell-url { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.add-model-form { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border-soft); }
.add-model-form .row-form { flex-wrap: wrap; }

/* ---------------- toasts ---------------- */
.toasts {
  position: fixed; top: calc(var(--nav-h) + 14px); right: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(380px, calc(100vw - 36px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 16px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px; font-weight: 500;
  display: flex; align-items: flex-start; gap: 10px;
  animation: toastIn .22s var(--ease);
  word-break: break-word;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--accent); }
.toast-err { border-color: color-mix(in srgb, var(--err) 45%, transparent); }
.toast-err::before { background: var(--err); }
.toast-ok::before { background: var(--ok); }
.toast.out { animation: toastOut .3s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(24px); } }

/* ---------------- responsive ---------------- */
@media (max-width: 1100px) {
  .app-layout { grid-template-columns: 288px minmax(0, 1fr); }
  .app-side {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 95;
    width: min(456px, 92vw); height: 100vh;
    background: var(--panel); border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 16px;
    transform: translateX(103%);
    transition: transform .24s var(--ease);
  }
  .app-side.open { transform: none; }
  .app-side-mobhead { display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: 14px; padding: 2px 2px 10px; }
  #toggleSide { display: inline-flex; }
}
@media (max-width: 768px) {
  .app-layout { grid-template-columns: minmax(0, 1fr); height: calc(100vh - var(--nav-h) - 24px); }
  /* composer: icon-only action buttons + tighter padding + 16px input
     (prevents iOS Safari focus-zoom) */
  .composer { padding: 9px 10px calc(9px + env(safe-area-inset-bottom)); }
  .composer-row { gap: 7px; }
  .composer-input { font-size: 16px; min-height: 40px; padding: 9px 11px; }
  .composer-send { width: 40px; min-width: 40px; height: 40px; padding: 0; }
  .composer-send .btn-txt { display: none; }
  .page:has(> .app-page) { padding: 12px 12px; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 95;
    width: min(384px, 86vw); height: 100vh;
    background: var(--panel); border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(-103%);
    transition: transform .24s var(--ease);
  }
  .sidebar.open { transform: none; }
  .sidebar-close { display: inline-flex; }
  #toggleChats { display: inline-flex; }
  .chat-panel { height: 100%; min-height: 0; }
  .page { padding: 18px 12px 50px; }
  .topnav { gap: 12px; padding: 0 12px; }
  .userbtn-name { display: none; }
}
@media (max-width: 620px) {
  .nav-links { display: none; }
  .msg { max-width: 100%; }
  .empty-start { flex-direction: column; width: 100%; }
  .dash-head { flex-direction: column; align-items: flex-start; }
}

/* ================= task2: queue / snapshots / terminal / fleet / ntfy ================= */

/* left sidebar sections (queue + snapshots) */
.side-sec { border-top: 1px solid var(--border-soft); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.side-sec-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.side-sec-cnt { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 8px; font-size: 11px; }
.side-sec-btn { width: 22px; height: 22px; }
.side-queue { max-height: 34%; }
.queue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; min-height: 0; }
.queue-item { display: flex; align-items: center; gap: 6px; background: var(--panel-2); border-radius: var(--radius-sm); padding: 6px 8px; }
.queue-text { flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-cancel { flex: none; width: 20px; height: 20px; border: none; border-radius: 5px; background: transparent; color: var(--text-faint); cursor: pointer; font-size: 14px; line-height: 1; }
.queue-cancel:hover { background: var(--err-soft); color: var(--err); }
.side-snap { max-height: 38%; }
.snap-body { overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.snap-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.snap-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.snap-item { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: var(--radius-sm); padding: 7px 9px; }
.snap-item.head { outline: 1px solid var(--accent); }
.btn-ghost.snap-perm { color: var(--err); font-weight: 600; }
.btn-ghost.snap-perm:hover { background: var(--err-soft); }
.snap-info { flex: 1; min-width: 0; }
.snap-btns { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; }
.snap-date { color: var(--text-faint); font-size: 11px; }
.snap-subject { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* -------- commit diff modal (GitHub-style) -------- */
.snap-hash { cursor: pointer; color: var(--accent); }
.snap-hash:hover { text-decoration: underline; }
.snap-headtag { color: var(--text-faint); font-size: 11px; }
.commit-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(3, 5, 9, .55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
  animation: fadeIn .16s var(--ease);
}
.commit-modal {
  width: min(1100px, 100%); height: min(86vh, 900px);
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden;
}
.commit-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--border-soft); flex: none;
}
.commit-title { min-width: 0; }
.commit-loadline { display: flex; align-items: center; gap: 9px; color: var(--text-faint); font-size: 13px; }
.commit-hashline { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-faint); flex-wrap: wrap; }
.commit-hashline .mono { color: var(--text-dim); word-break: break-all; }
.commit-badge {
  background: var(--panel-2); border: 1px solid var(--border-soft); color: var(--text-dim);
  font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px;
}
.commit-root-tag { color: var(--text-faint); font-size: 11px; }
.commit-msg {
  margin: 7px 0 5px; font-size: 14.5px; font-weight: 600; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word; max-height: 96px; overflow: auto;
}
.commit-meta { font-size: 12px; color: var(--text-dim); }
.commit-close { flex: none; }
.commit-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.commit-summary {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 9px 16px; border-bottom: 1px solid var(--border-soft);
  font-size: 12.5px; color: var(--text-dim); flex: none;
}
.commit-summary .pos { color: var(--ok); font-weight: 700; }
.commit-summary .neg { color: var(--err); font-weight: 700; }
.commit-main { flex: 1; display: flex; min-height: 0; }
.commit-files {
  width: 252px; flex: none; border-right: 1px solid var(--border-soft);
  overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 3px;
}
.commit-file {
  display: flex; align-items: center; gap: 7px; padding: 6px 8px;
  border-radius: 8px; cursor: pointer; border: 1px solid transparent; min-width: 0;
  user-select: none;
}
.commit-file:hover { background: var(--panel-2); }
.commit-file.active { background: var(--panel-2); border-color: var(--border-soft); }
.commit-file .fpath { flex: 1; min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.commit-file .fstats { font-size: 11px; white-space: nowrap; }
.commit-file .fstats .pos { color: var(--ok); }
.commit-file .fstats .neg { color: var(--err); }
.commit-st {
  font-size: 10px; font-weight: 800; width: 17px; height: 17px; flex: none;
  border-radius: 5px; display: inline-flex; align-items: center; justify-content: center;
}
.commit-st.A, .commit-st.C { background: var(--ok-soft); color: var(--ok); }
.commit-st.D { background: var(--err-soft); color: var(--err); }
.commit-st.R { background: rgba(242, 200, 82, .14); color: #f2c852; }
.commit-st.M, .commit-st.T, .commit-st.U { background: var(--panel-2); color: var(--text-dim); }
.commit-diff { flex: 1; min-width: 0; overflow: auto; }
.dfile-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border-bottom: 1px solid var(--border-soft);
  padding: 8px 12px; font-size: 12px; font-weight: 600;
}
.dfile-head .dpath { word-break: break-all; }
.dbin-badge {
  background: var(--panel); border: 1px solid var(--border-soft); color: var(--text-faint);
  font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
}
.dline { display: flex; font-family: var(--mono); font-size: 12px; line-height: 1.55; }
.dline .dn {
  width: 44px; flex: none; text-align: right; padding: 0 8px;
  color: var(--text-faint); user-select: none; border-right: 1px solid var(--border-soft);
}
.dline .dt { flex: 1; min-width: 0; padding: 0 12px; white-space: pre-wrap; word-break: break-word; }
/* prism tokens must not override diff row backgrounds/padding */
.dline .dt .token { background: transparent; padding: 0; }
.dline.add .dt { background: var(--ok-soft); }
.dline.add .dn { color: color-mix(in srgb, var(--ok) 55%, var(--text-faint)); }
.dline.del .dt { background: var(--err-soft); }
.dline.del .dn { color: color-mix(in srgb, var(--err) 55%, var(--text-faint)); }
.dline.hunk {
  background: var(--panel-2); color: var(--text-dim); padding: 3px 12px;
  border-top: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft);
  white-space: pre-wrap; word-break: break-word;
}
.dline.note .dt { color: var(--text-faint); font-style: italic; }
.dnote { padding: 14px 16px; color: var(--text-faint); font-size: 12.5px; }
.commit-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: var(--text-faint); padding: 30px 18px; text-align: center; font-size: 13px;
  min-height: 0;
}
.commit-err-icon { font-size: 22px; }
.commit-state.err > div:last-child { color: var(--err); max-width: 420px; word-break: break-word; }
@media (max-width: 700px) {
  .commit-backdrop { padding: 0; }
  .commit-modal { width: 100%; height: 100%; border-radius: 0; border: none; }
  .commit-main { flex-direction: column; }
  .commit-files {
    width: 100%; max-height: 34vh; border-right: none;
    border-bottom: 1px solid var(--border-soft);
  }
  .dline .dn { width: 38px; }
}


/* center column + terminal (VSCode-like) */
.center-col { display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0; }
.term-area { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.term-grabber { flex: none; height: 12px; cursor: row-resize; position: relative; margin: 2px 8px; }
.term-grabber::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 3px; transform: translateY(-50%); border-radius: 2px; background: var(--border); transition: background .13s; }
.term-grabber:hover::after, body.term-dragging .term-grabber::after { background: var(--accent); }
.term-panel { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; overflow: hidden; margin-bottom: 8px; }
.term-head { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--border-soft); }
.term-head-title { font-size: 13px; font-weight: 700; }
.term-hint { flex: 1; text-align: right; margin: 0; font-size: 11.5px; }
.term-body { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 14px; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; background: var(--panel-2); }
.term-line { white-space: pre-wrap; word-break: break-word; }
.term-line.t-err { color: var(--err); }
.term-ps1 { color: var(--accent); font-weight: 600; }
.term-inputline { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--border-soft); }
.term-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-family: var(--mono); font-size: 12.5px; padding: 0; }

/* rename chat */
.rename-btn { flex: none; }
.chat-title-input { width: min(260px, 40vw); flex: none; }

/* fleet page */
.fleet-sub { margin: 0; }
.fleet-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.fleet-item { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 10px 12px; }
.fleet-item.fleet-prod { border-color: var(--err); }
.fleet-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.fleet-name { font-weight: 700; font-size: 14px; }
.fleet-descr { color: var(--text-dim); font-size: 12.5px; margin-top: 3px; }
.fleet-addr { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }

/* dashboard: new app card + ntfy note */
.new-app-card { border-style: dashed; border-color: var(--border); text-align: center; padding: 26px 18px 18px; }
.new-app-card:hover { transform: none; }
.nac-plus { width: 54px; height: 54px; margin: 0 auto 10px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 300; }
.nac-title { font-weight: 700; font-size: 16px; margin-bottom: 12px; }
.new-app-card .new-app-form { text-align: left; margin-top: 0; }
.ntfy-note { padding: 18px 20px; margin-top: 16px; }
.ntfy-note-title { font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.ntfy-topic { display: inline-block; background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 6px; padding: 1px 7px; margin: 0 4px; }

@media (max-width: 768px) {
  .term-hint { display: none; }
  .chat-title-input { width: min(180px, 32vw); }
}

/* web search / fetch tool cards */
.t-webitem { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; }
.t-webitem + .t-webitem { margin-top: 6px; }
.t-webtitle { font-weight: 700; font-size: 12.5px; color: var(--text); }
.t-webhref { font-size: 11px; color: var(--text-faint); word-break: break-all; }
.t-snippet { font-size: 11.5px; color: var(--text-dim); line-height: 1.5; white-space: pre-wrap; word-break: break-word; max-height: 130px; overflow: auto; }
.t-fetchitem { display: flex; flex-direction: column; gap: 6px; }
.t-fetchitem + .t-fetchitem { margin-top: 8px; }
.t-fetchurl { font-size: 11px; color: var(--text-faint); word-break: break-all; }
.t-link { color: var(--accent); text-decoration: none; }
.t-link:hover { text-decoration: underline; }

/* ---------------- task 10: continue + edit-message buttons ---------------- */
/* edit button — sits to the LEFT of each user prompt bubble */
.msg-edit {
  position: absolute; right: 100%; top: 1px; margin-right: 7px;
  width: 24px; height: 24px; border-radius: 7px;
  opacity: .4;
}
.msg .bubble .md { min-width: 0; max-width: 100%; }
.msg .bubble .md pre { max-width: 100%; }
.msg.user:hover .msg-edit, .msg-edit:focus-visible { opacity: 1; }
.chat-messages.running .msg-edit { display: none; }
/* continue button in the composer (ghost, hidden while running) */
.composer-send#continueBtn { color: var(--text-dim); }
.composer-send#continueBtn:hover { color: var(--text); }

/* ---- model semaphore panel (admin) ---- */
.sems-panel .sem-block { padding: 10px 12px; border: 1px solid var(--border, #333); border-radius: 8px; margin-bottom: 12px; }
.sems-panel .sem-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sems-panel .sem-col { margin-top: 6px; }
.sems-panel .sem-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim, #888); margin-bottom: 4px; }
.sems-panel .sem-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.sems-panel .sem-row.running .cell-name { color: var(--ok, #4caf7d); }
.sems-panel .sem-elapsed { margin-left: auto; }
.sems-panel .sem-btns { margin-left: 8px; display: inline-flex; gap: 4px; }
.sems-panel .sem-btns .btn-sm { padding: 0 6px; line-height: 22px; }


/* ============ Generation error records (T17) ============
   Inserted into the conversation history when a run errors out, so the
   user can see exactly what went wrong and fix/continue. */
.msg.error { align-self: flex-start; align-items: flex-start; }
.msg.error .err-bubble {
  background: var(--err-soft);
  border: 1px solid color-mix(in srgb, var(--err) 45%, transparent);
  border-left: 3px solid var(--err);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

/* T5b: admin backdoor impersonation banner */
.imp-banner { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 6px 14px; background: rgba(255, 193, 7, 0.12); border-bottom: 1px solid rgba(255, 193, 7, 0.35);
  color: var(--text); font-size: 13px; }
.imp-banner .btn { padding: 2px 10px; font-size: 12px; }

/* ---------------- task 7 ---------------- */
/* dashboard: give the "Servers" section header room after the apps grid */
.apps-grid + .dash-head { margin-top: 36px; }

/* admin users table: presence dot (green = online now, dim = offline) */
.online-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin: 0 7px 0 8px; vertical-align: middle;
  background: var(--text-faint); opacity: .35;
}
.online-dot.on { background: var(--ok); opacity: 1; box-shadow: 0 0 7px color-mix(in srgb, var(--ok) 55%, transparent); }

/* dashboard: ntfy app-store buttons */
.ntfy-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* server page: 2-column "server address" form (label | input) */
.srv-addr-table { width: 100%; border-collapse: collapse; }
.srv-addr-table th, .srv-addr-table td { padding: 4px 0; text-align: left; vertical-align: middle; }
.srv-addr-label {
  width: 40%; color: var(--text-dim); font-weight: 600; font-size: 12.5px;
  padding-right: 12px; white-space: nowrap;
}
.srv-addr-table td { width: 60%; }
.srv-addr-actions { display: flex; gap: 8px; margin-top: 10px; }

/* server page: public key block — long hex key scrolls horizontally instead of wrapping */
.srv-pubkey {
  display: block; background: var(--code-bg); border: 1px solid var(--border-soft);
  border-radius: 6px; padding: 8px 10px; font-size: 12px; line-height: 1.5;
  overflow-x: auto; white-space: nowrap; margin: 0 0 10px;
}
.srv-pubkey-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }

/* ==========================================================================
   task 9: show-details toggle switch (replaces the raw checkbox)
   ========================================================================== */
.switch { position: relative; display: inline-block; width: 38px; height: 21px; flex: 0 0 auto; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch-track { position: absolute; inset: 0; border-radius: 999px; background: var(--panel-3); border: 1px solid var(--border); transition: background .18s, border-color .18s; pointer-events: none; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #8a93a6; transition: transform .18s, background .18s; }
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(17px); background: #fff; }
/* override the task-8 .chat-opt-chk size rule (higher specificity) */
.chat-options-card .switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.chat-options-card .chat-opt-row .switch { margin-left: auto; }

/* ==========================================================================
   task 9: embed page (/embed/app/<id>) — left sidebar + chat only
   ========================================================================== */
.embed-page { padding: 0; margin: 0; }
.app-layout.embed-layout { grid-template-columns: 312px minmax(0, 1fr); height: 100vh; margin: 0; padding: 12px; gap: 12px; }
@media (max-width: 1100px) {
  .app-layout.embed-layout { grid-template-columns: 288px minmax(0, 1fr); }
}
@media (max-width: 768px) {
  .app-layout.embed-layout { grid-template-columns: 1fr; height: 100vh; }
}
.embed-det { display: none !important; }

/* ==========================================================================
   task 9: embed card in the app right sidebar
   ========================================================================== */
.embed-card .embed-desc { margin: 0 0 10px; line-height: 1.45; }
.embed-label { display: block; font-size: 12px; color: var(--text-dim); margin: 10px 0 4px; }
.embed-url-input { width: 100%; font-size: 11px; }
.embed-iframe-input { width: 100%; font-size: 11px; line-height: 1.45; resize: vertical; min-height: 58px; }
.embed-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* Web terminal (auth-gated gotty relay iframe) — terminal task 2026-10-25 */
.term-web-wrap { flex: 1; min-height: 0; display: flex; }
.term-web-frame { flex: 1; width: 100%; height: 100%; border: 0; background: #111; }
.term-mode-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }


/* ==========================================================================
   TOKEN-MAX: out-of-tokens handoff banners
   (agent.py role=system chunks flagged tokenLimitWarn1/2, rendered by
   addTokenWarn() in static/chat.js)
   ========================================================================== */
.msg.token-warn { align-self: center; max-width: 92%; }
.bubble.token-warn-bubble {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  font-size: 13.5px; line-height: 1.45;
}
.msg.token-warn-critical .bubble.token-warn-bubble {
  background: var(--err-soft);
  border-color: color-mix(in srgb, var(--err) 50%, transparent);
}
.token-warn-icon { flex: none; font-size: 15px; }
.token-warn-text { flex: 1 1 auto; min-width: 0; }
.token-warn-count { margin-left: auto; padding-left: 10px; flex: none; font-size: 12px; color: var(--text-dim); }
@media (max-width: 620px) {
  .msg.token-warn { max-width: 96%; }
  .token-warn-count { margin-left: 0; width: 100%; text-align: left; }
}

/* ==========================================================================
   EMBED-THEMES: swatch picker (app sidebar embed card, templates/app.html)
   Each swatch previews its theme via --sw-bg/--sw-fg/--sw-ac set inline.
   ========================================================================== */
.theme-swatches {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px; margin: 4px 0 12px;
}
.theme-swatch {
  --sw-bg: #0b0e14; --sw-fg: #e8ebf4; --sw-ac: #6c8cff;
  background: var(--sw-bg); color: var(--sw-fg);
  border: 1px solid color-mix(in srgb, var(--sw-ac) 55%, var(--border));
  border-radius: var(--radius-sm);
  padding: 12px 6px 9px;
  font-family: var(--font); font-size: 11.5px; font-weight: 600;
  cursor: pointer; text-align: center;
  transition: transform .12s var(--ease), box-shadow .12s var(--ease), border-color .12s var(--ease);
}
.theme-swatch::before {
  content: ""; display: block; width: 18px; height: 18px; border-radius: 6px;
  background: var(--sw-ac); margin: 0 auto 7px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
.theme-swatch:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0, 0, 0, .22); border-color: var(--sw-ac); }
.theme-swatch:active { transform: translateY(0); box-shadow: none; }

/* ================= admin: embed tokens + user modal (C-4, 2026-11-12) ================= */

/* clickable user rows (admin users table) */
tr.user-row { cursor: pointer; }
tr.user-row .chev { display: inline-flex; color: var(--text-faint); transition: color .12s; }
tr.user-row:hover .chev { color: var(--accent); }

/* summary cards */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat-card { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.stat-card b { display: block; font-size: 20px; font-weight: 700; margin-bottom: 2px; }
.stat-card span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); line-height: 1.35; display: block; }
.stat-card.warn { border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.stat-card.warn span { color: var(--warn); }
.stat-card.warn b { color: var(--warn); }

/* app cell in the embed tokens table */
.et-app { line-height: 1.55; }

/* admin modals (user detail + token audit) */
.amodal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(3, 10, 13, .62);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.amodal-overlay.hidden { display: none; }
.amodal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: min(780px, 100%); max-height: 88vh;
  display: flex; flex-direction: column;
}
.amodal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 18px; border-bottom: 1px solid var(--border-soft);
}
.amodal-head h3 { margin: 0; font-size: 15px; }
.amodal-body { padding: 16px 18px; overflow-y: auto; min-height: 0; }
.amodal .table td { padding: 7px 10px; }
.amodal .table td.dim { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* user detail modal layout */
.umd-section { margin-bottom: 18px; }
.umd-section:last-child { margin-bottom: 4px; }
.umd-section > h4 {
  margin: 0 0 8px; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-faint);
}
.umd-id { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 14px; }
.umd-id > div { font-size: 13.5px; min-width: 0; }
.umd-id .k { display: block; font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.umd-actions { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 640px) {
  .amodal { max-height: 92vh; }
  .umd-actions { gap: 6px; }
}

/* ================= admin: capped (scrollable) long tables + API keys (2026-11-12) ================= */
.table-wrap.tbl-capped { max-height: 420px; overflow-y: auto; }
.table-wrap.tbl-capped .table thead th { position: sticky; top: 0;
  background: var(--panel); z-index: 1; }
/* admin: one-time API key value box */
.apikey-box { background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; font-size: 13px;
  word-break: break-all; user-select: all; }

/* admin: stale app cleanup rows */
.stale-results { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.stale-app-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 8px 12px; font-size: 13px; }
