/* ==========================================================================
   S.U.N.D.E.Y — UI v2 layer
   Loaded AFTER style.css. Redefines the design tokens and the core surfaces
   (nav, dashboard, auth, app/chat workspace). Component names from v1 are
   kept so every page keeps working; only the skin + layout changes.
   ========================================================================== */

/* ---------------------------------------------------------------- tokens -- */
:root {
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --font: "Inter", -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: 60px;
  --max-w: 1200px;
  --ease: cubic-bezier(.32, .72, 0, 1);
  --ring: 0 0 0 3px var(--accent-soft);
  --hair: rgba(255, 255, 255, .06);
}

[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;
}

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

body {
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  letter-spacing: -.003em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { letter-spacing: -.021em; line-height: 1.22; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: none; }

::selection { background: var(--accent-soft); color: var(--text); }

*:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }

.mono { font-family: var(--mono); font-size: .925em; letter-spacing: -.01em; }
.hint { color: var(--text-faint); font-size: 12.5px; line-height: 1.5; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* ------------------------------------------------------------------- nav -- */
.topnav {
  height: var(--nav-h);
  padding: 0 22px;
  gap: 18px;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--hair);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 80;
}

.brand { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent-grad);
  box-shadow: 0 6px 16px -8px var(--accent), inset 0 1px 0 rgba(255, 255, 255, .35);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 12.5px; font-weight: 700; color: #fff;
  letter-spacing: -.06em;
}
.brand-mark.big { width: 52px; height: 52px; border-radius: 15px; font-size: 20px; }

/* S.U.N.D.E.Y vector mark (static/logo.svg) — transparent, no tile background */
img.brand-mark {
  display: inline-block; padding: 0; border: 0; border-radius: 0;
  background: none; object-fit: contain; flex: none;
  box-shadow: none;
}
img.brand-mark.big { width: 52px; height: 52px; border-radius: 0; }
.brand-name { font-weight: 700; font-size: 15.5px; letter-spacing: -.02em; }
/* icon + wordmark lockup above the auth headline */
.auth-hero-brand .brand-mark { width: 42px; height: 42px; }
.auth-hero-brand .brand-wordmark { font-weight: 700; font-size: 17px; letter-spacing: -.025em; }
.auth-hero-brand .brand-by {
  font-weight: 500; font-size: 13.5px; letter-spacing: -.01em;
  color: var(--text-dim); margin-left: 2px;
}
.auth-brand .brand-mark.big { width: 54px; height: 54px; }

.nav-links {
  display: flex; align-items: center; gap: 2px;
  padding: 3px; border-radius: 999px;
  background: color-mix(in srgb, var(--panel-2) 65%, transparent);
  border: 1px solid var(--border-soft);
}
.nav-links a {
  position: relative;
  padding: 6px 14px; border-radius: 999px;
  color: var(--text-dim); font-size: 13.5px; font-weight: 550;
  transition: color .14s var(--ease), background .14s var(--ease);
  white-space: nowrap;
}
.nav-links a:hover { color: var(--text); background: var(--panel-3); text-decoration: none; }
.nav-links a.active {
  color: var(--text); background: var(--panel-4);
  box-shadow: inset 0 0 0 1px var(--hair), 0 1px 2px rgba(0, 0, 0, .18);
}

.nav-right { display: flex; align-items: center; gap: 8px; }

.iconbtn {
  width: 34px; height: 34px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent;
  color: var(--text-dim); cursor: pointer; transition: all .14s var(--ease);
  flex: none;
}
.iconbtn:hover { background: var(--panel-3); color: var(--text); border-color: var(--border-soft); }
.iconbtn.danger:hover { background: var(--err-soft); color: var(--err); border-color: transparent; }

.langbtn {
  height: 34px; padding: 0 11px; border-radius: 10px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
  font-size: 11.5px; font-weight: 700; letter-spacing: .06em;
  transition: all .14s var(--ease);
}
.langbtn:hover { color: var(--text); border-color: var(--accent-line); background: var(--panel-3); }

.usermenu { position: relative; }
.userbtn {
  display: inline-flex; align-items: center; gap: 9px;
  height: 38px; padding: 0 10px 0 4px; border-radius: 999px;
  background: transparent; border: 1px solid transparent;
  color: var(--text); cursor: pointer; transition: all .14s var(--ease);
}
.userbtn:hover { background: var(--panel-3); border-color: var(--border-soft); }
.userbtn-name { font-size: 13.5px; font-weight: 550; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 30px; height: 30px; border-radius: 999px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-grad); color: var(--on-accent);
  font-size: 12.5px; font-weight: 700; letter-spacing: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3);
}
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }

.dropdown {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 120;
  min-width: 232px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  opacity: 0; visibility: hidden; transform: translateY(-6px) scale(.98);
  transform-origin: top right;
  transition: opacity .16s var(--ease), transform .16s var(--ease), visibility .16s;
}
.dropdown.open { opacity: 1; visibility: visible; transform: none; }
.dropdown-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.dropdown-name { font-weight: 650; font-size: 13.5px; margin-bottom: 6px; }
.dropdown-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; border-radius: 9px;
  color: var(--text-dim); font-size: 13.5px; font-weight: 500;
}
.dropdown-item:hover { background: var(--panel-3); color: var(--text); text-decoration: none; }
.dropdown-item.danger { color: var(--err); }
.dropdown-item.danger:hover { background: var(--err-soft); }

.imp-banner {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  padding: 8px 16px; font-size: 12.5px;
  background: var(--warn-soft); color: var(--warn);
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
}

/* -------------------------------------------------------------- surfaces -- */
.page { max-width: var(--max-w); margin: 0 auto; padding: 30px 24px 72px; }

.card {
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.page-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.03em; }
.page-sub { margin: 4px 0 0; color: var(--text-faint); font-size: 13px; }

/* ---------------------------------------------------------------- buttons -- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 15px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
  font-family: inherit; font-size: 13.5px; font-weight: 550; letter-spacing: -.005em;
  cursor: pointer; white-space: nowrap;
  transition: transform .1s var(--ease), background .14s var(--ease), border-color .14s var(--ease), box-shadow .14s var(--ease);
}
.btn:hover { background: var(--panel-3); border-color: var(--border); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent-grad); border-color: transparent; color: var(--on-accent);
  font-weight: 600;
  box-shadow: 0 8px 20px -12px var(--accent), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.btn-primary:hover { filter: brightness(1.06); background: var(--accent-grad); border-color: transparent; }

.btn-ghost { background: transparent; border-color: var(--border-soft); color: var(--text-dim); }
.btn-ghost:hover { background: var(--panel-3); color: var(--text); border-color: var(--border); }

.btn-danger { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 38%, transparent); color: var(--err); }
.btn-danger:hover { background: color-mix(in srgb, var(--err) 20%, transparent); border-color: var(--err); color: var(--err); }

.btn-sm { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-label { display: inline-flex; align-items: center; gap: 7px; }
.inline { display: inline; }

/* ----------------------------------------------------------------- inputs -- */
.input, .select, textarea.input {
  width: 100%; height: 38px; padding: 0 12px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: inherit; font-size: 13.5px;
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease), background .14s var(--ease);
}
.input::placeholder, textarea.input::placeholder { color: var(--text-faint); }
.input:hover, .select:hover { border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--panel);
}
.input-sm, .select-sm { height: 32px; font-size: 12.5px; border-radius: 8px; padding: 0 10px; }
.select {
  appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236c7689' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.select option { background: var(--panel); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); letter-spacing: -.005em; }
.form-err {
  padding: 10px 13px; border-radius: 10px; font-size: 13px;
  background: var(--err-soft); color: var(--err);
  border: 1px solid color-mix(in srgb, var(--err) 30%, transparent);
}
.row-form { display: flex; gap: 8px; align-items: center; }

.prefix-input { position: relative; display: flex; align-items: center; }
.prefix-input .input { padding-right: 108px; }
.prefix-input .suffix {
  position: absolute; right: 12px; font-family: var(--mono); font-size: 11.5px;
  color: var(--text-faint); pointer-events: none;
}

/* ----------------------------------------------------------------- badges -- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 7px;
  font-size: 11px; font-weight: 650; letter-spacing: .01em;
  background: var(--panel-3); color: var(--text-dim);
  border: 1px solid var(--border-soft); white-space: nowrap;
}
.badge-public { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 26%, transparent); }
.badge-private { background: var(--panel-3); color: var(--text-faint); }
.badge-admin { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.badge-owner { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.badge-member { background: transparent; color: var(--text-faint); }
.badge-default { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 26%, transparent); }
.badge-env { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0; }
/* task 12: env type badge (base / dind / gui / bio / gpu) */
.badge-evtype { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0; padding: 0 7px; }
.badge-evtype.dind { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.badge-evtype.gui { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 26%, transparent); }
.badge-evtype.bio { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 26%, transparent); }
.badge-evtype.gpu { background: color-mix(in srgb, var(--ans5, #8b5cf6) 14%, transparent); color: var(--ans5, #8b5cf6); border-color: color-mix(in srgb, var(--ans5, #8b5cf6) 32%, transparent); }
.badge-online { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 26%, transparent); }
.badge-online::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.badge-offline { background: var(--panel-3); color: var(--text-faint); }
.badge-active { background: var(--ok-soft); color: var(--ok); }
.badge-retired { background: var(--panel-3); color: var(--text-faint); }

.online-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.online-dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }

/* dashboard app-card run-state (which apps have active chats) */
.app-run-state { display: inline-flex; align-items: center; gap: 6px; }
.online-dot.off { background: var(--text-faint); opacity: .55; }
/* dashboard app-card: webapp-online dot (env port 80) — red = offline */
.online-dot.apdot { opacity: 1; margin: 0; } /* style.css's admin-table .online-dot (opacity .35, 8px left margin) must not leak into the dashboard dot */
.app-card .online-dot.on.apdot { animation: none; } /* stable dot: the run-state dot's pulse halo reads as 'blinking' on a 7px indicator */
.ap-wrap { display: inline-flex; align-items: center; height: 22px; } /* badge height: vertically centers the dot (the row itself is flex-start) */
.online-dot.ap-off { background: var(--err); opacity: .85; box-shadow: 0 0 0 3px color-mix(in srgb, var(--err) 20%, transparent); }
.badge-idle { background: transparent; color: var(--text-faint); }
.app-card .online-dot.on { animation: dot-pulse 1.6s ease-in-out infinite; }
@keyframes dot-pulse {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ok) 0%, transparent); }
}

/* ------------------------------------------------------------- dashboard -- */
.dash { display: flex; flex-direction: column; gap: 26px; }

.dash-hero {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 20px;
  flex-wrap: wrap; padding-top: 6px;
}
.dash-hero h1 {
  margin: 0; font-size: clamp(24px, 3.2vw, 32px); font-weight: 720;
  letter-spacing: -.035em;
  background: linear-gradient(120deg, var(--text) 20%, var(--text-dim) 120%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.dash-hero p { margin: 7px 0 0; color: var(--text-faint); font-size: 14px; }
.dash-hero-actions { display: flex; gap: 9px; align-items: center; }
.dash-hero-actions .btn-primary { height: 40px; padding: 0 18px; border-radius: 11px; }

.stat-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 9px 14px 9px 11px; border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  border: 1px solid var(--border-soft);
}
.stat-ico {
  width: 28px; height: 28px; border-radius: 9px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
}
.stat-ico.ok { background: var(--ok-soft); color: var(--ok); }
.stat-ico.warn { background: var(--warn-soft); color: var(--warn); }
.stat-val { font-size: 15px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.stat-lbl { font-size: 11.5px; color: var(--text-faint); }

.section-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: -8px;
}
.section-head h2 {
  margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.02em;
  color: var(--text);
}
.section-count {
  font-family: var(--mono); font-size: 11px; color: var(--text-faint);
  padding: 1px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border-soft);
}
.section-head .spacer { flex: 1; }

.search {
  position: relative; display: flex; align-items: center;
  width: 230px; max-width: 100%;
}
.search svg { position: absolute; left: 11px; color: var(--text-faint); pointer-events: none; }
.search .input { height: 34px; padding-left: 33px; font-size: 13px; border-radius: 9px; }

.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
}

.app-card {
  position: relative;
  display: flex; flex-direction: column; gap: 0;
  padding: 16px 16px 14px;
  color: var(--text);
  min-height: 156px;
  overflow: hidden;
  transition: transform .18s var(--ease), border-color .18s var(--ease), box-shadow .18s var(--ease), background .18s var(--ease);
}
.app-card::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(420px 180px at 100% 0%, var(--accent-soft), transparent 70%);
  opacity: 0; transition: opacity .2s var(--ease);
}
.app-card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 36%, var(--border));
  box-shadow: var(--shadow-lg);
}
.app-card:hover::after { opacity: 1; }

.app-card-top { display: block; position: relative; padding-right: 16px; margin-bottom: 13px; line-height: 1; } /* non-flex row: explicit display:block OVERRIDES style.css's legacy .app-card-top flex rule (space-between spread + center-aligned badges). Badges flow inline (top-aligned), web dot pinned top-right, space reserved via padding-right */
.app-card-top .app-icon { vertical-align: top; margin-right: 10px; }
.app-card-top > .badge { vertical-align: top; margin-right: 6px; }
.app-card-top .ap-wrap { position: absolute; top: 0; right: 0; }
.app-icon {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: var(--text);
  background: var(--panel-3);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 var(--hair);
}
.app-card:hover .app-icon {
  background: var(--accent-grad); border-color: transparent; color: var(--on-accent);
}
.app-card-title {
  font-size: 15px; font-weight: 650; letter-spacing: -.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.app-card-domain {
  margin-top: 3px; font-family: var(--mono); font-size: 11.5px;
  color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.app-card:hover .app-card-domain { color: var(--accent); }
.app-card-foot {
  display: flex; align-items: center; gap: 6px; flex-wrap: nowrap;
  margin-top: auto; padding-top: 14px; min-width: 0;
  font-size: 11.5px; color: var(--text-faint); white-space: nowrap;
}
.app-card-foot > span:not(.dot):not(.app-card-go) { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.app-card-foot .dot { opacity: .5; flex: none; }
.app-card-go {
  margin-left: auto; width: 24px; height: 24px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-faint); opacity: 0; transform: translateX(-4px);
  transition: all .18s var(--ease);
}
.app-card:hover .app-card-go { opacity: 1; transform: none; color: var(--accent); background: var(--panel-3); }

.apps-grid .empty-card {
  grid-column: 1 / -1;
  padding: 40px 20px; text-align: center; color: var(--text-faint);
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 50%, transparent);
}

/* create-app card */
.new-app-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 18px;
  border: 1px dashed var(--border);
  background: color-mix(in srgb, var(--panel) 45%, transparent);
  box-shadow: none;
  min-height: 156px;
  text-align: center;
}
.new-app-card:hover { border-color: var(--accent-line); background: color-mix(in srgb, var(--panel) 75%, transparent); }
.nac-plus {
  width: 38px; height: 38px; border-radius: 11px; margin-bottom: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 400; line-height: 1;
  color: var(--accent); background: var(--accent-soft);
  border: 1px solid var(--accent-line);
}
.nac-title { font-size: 14px; font-weight: 620; color: var(--text); }
.new-app-form { display: flex; flex-direction: column; gap: 8px; width: 100%; margin-top: 12px; }
.new-app-form .input { height: 34px; font-size: 13px; text-align: center; }
.new-app-form .btn { height: 34px; border-radius: 9px; font-size: 13px; }
.new-app-card .nac-plus { transition: transform .18s var(--ease); }
.new-app-card:hover .nac-plus { transform: scale(1.06) rotate(90deg); }

/* servers list on dashboard */
.srv-list { display: flex; flex-direction: column; gap: 8px; }
.srv-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  border: 1px solid var(--border-soft);
  color: var(--text); transition: all .14s var(--ease);
}
.srv-row:hover { border-color: var(--accent-line); background: var(--panel-2); text-decoration: none; }
.srv-row .srv-name { font-weight: 600; font-size: 13.5px; }
.srv-row .srv-meta { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }
.srv-row .srv-ping { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }

.ntfy-note { position: relative; padding: 18px 20px; }
.ntfy-note-title { font-size: 13.5px; font-weight: 650; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.ntfy-note p { margin: 0 0 12px; }
.ntfy-topic {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--border-soft); color: var(--text-dim);
}
.ntfy-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.ntfy-close { position: absolute; top: 12px; right: 12px; }

/* ------------------------------------------------------------------ auth -- */
.auth-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 1fr;
  place-items: center; padding: 32px 20px;
}
.auth-card {
  width: 100%; max-width: 400px; padding: 32px 30px 26px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand h1 { margin: 14px 0 4px; font-size: 23px; letter-spacing: -.03em; }
.auth-tagline { margin: 0; color: var(--text-faint); font-size: 13.5px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .btn { height: 42px; border-radius: 11px; font-size: 14px; margin-top: 4px; }
.auth-alt { text-align: center; margin: 18px 0 0; font-size: 13px; color: var(--text-faint); }
.auth-alt a { font-weight: 600; }
.auth-foot { text-align: center; margin: 20px 0 0; font-size: 12px; color: var(--text-faint); font-family: var(--mono); }

/* split-screen variant: marketing panel + form */
@media (min-width: 980px) {
  .auth-wrap.split {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
    place-items: stretch; padding: 0; gap: 0;
    min-height: 100vh;
  }
  .auth-wrap.split .auth-hero {
    display: flex; flex-direction: column; justify-content: space-between;
    padding: 44px 52px; margin: 0;
    border-right: 1px solid var(--hair);
    background:
      radial-gradient(700px 420px at 10% 0%, rgba(87, 214, 242, .14), transparent 62%),
      radial-gradient(600px 420px at 90% 100%, rgba(127, 230, 210, .12), transparent 60%),
      color-mix(in srgb, var(--panel) 55%, transparent);
  }
  .auth-wrap.split .auth-form-col {
    display: flex; align-items: center; justify-content: center;
    padding: 40px; min-width: 0;
  }
  .auth-wrap.split .auth-card { box-shadow: none; background: transparent; border-color: transparent; padding: 0; }
  .auth-wrap.split .auth-foot { margin-top: 26px; }
}
.auth-hero { display: none; }
.auth-hero-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.auth-hero h2 {
  margin: 0 0 14px; font-size: clamp(27px, 3vw, 38px); font-weight: 730; letter-spacing: -.04em; line-height: 1.12;
}
.auth-hero h2 em {
  font-style: normal;
  background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-hero p.lead { margin: 0; color: var(--text-dim); font-size: 15px; max-width: 42ch; line-height: 1.6; }
.auth-feats { display: flex; flex-direction: column; gap: 14px; margin: 32px 0 0; padding: 0; list-style: none; }
.auth-feats li { display: flex; gap: 12px; align-items: flex-start; font-size: 13.5px; color: var(--text-dim); }
.auth-feats .fi {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--accent);
}
.auth-feats b { color: var(--text); font-weight: 600; display: block; margin-bottom: 1px; }
.auth-quote { font-size: 12.5px; color: var(--text-faint); font-family: var(--mono); }

/* ---------------------------------------------------------- app workspace -- */
.page:has(> .app-page) { max-width: none; padding: 14px 16px 16px; }
.app-page { display: flex; flex-direction: column; gap: 12px; }

.app-layout {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr) 344px;
  gap: 12px;
  height: calc(100vh - var(--nav-h) - 30px);
  align-items: stretch;
}
body.rail-hidden .app-layout { grid-template-columns: 296px minmax(0, 1fr); }
body.rail-hidden .app-side { display: none; }
body.side-hidden .app-layout { grid-template-columns: minmax(0, 1fr) 344px; }
body.side-hidden .sidebar { display: none; }
body.side-hidden.rail-hidden .app-layout { grid-template-columns: minmax(0, 1fr); }

/* chat panel */
.chat-panel {
  display: flex; flex-direction: column; height: 100%; min-height: 0;
  overflow: hidden; border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}

.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  backdrop-filter: blur(8px);
}
.chat-head-title {
  font-weight: 620; font-size: 14px; letter-spacing: -.015em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0; flex: 0 1 auto;
}
.chat-head-right { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }
.model-pick { display: flex; align-items: center; gap: 7px; }
.model-pick-label {
  font-size: 10.5px; color: var(--text-faint); font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; white-space: nowrap;
}
.chat-head .model-pick .select {
  height: 30px; font-size: 12px; border-radius: 8px; padding: 0 26px 0 9px;
  font-family: var(--mono); max-width: 168px;
}

/* app context strip (mobile / narrow) */
.chat-ctx {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--panel-2) 55%, transparent);
  font-size: 12px; color: var(--text-faint); min-height: 36px;
}
.chat-ctx .ctx-name { font-weight: 600; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-ctx .ctx-sep { opacity: .45; }
.chat-ctx a { color: var(--text-dim); font-family: var(--mono); font-size: 11.5px; }
.chat-ctx a:hover { color: var(--accent); }
.chat-ctx .ctx-actions { margin-left: auto; display: flex; gap: 4px; }
.chat-ctx .iconbtn { width: 26px; height: 26px; border-radius: 7px; }

/* sidebar */
.sidebar {
  padding: 12px; gap: 10px; height: 100%; max-height: 100%; overflow: hidden;
  display: flex; flex-direction: column;
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}
.sidebar-head { display: flex; flex-direction: column; gap: 9px; padding: 2px 2px 11px; border-bottom: 1px solid var(--border-soft); }
.sidebar-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-title {
  font-weight: 700; font-size: 11.5px; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-faint);
  display: inline-flex; align-items: center; gap: 7px;
}
.newchat-form { display: flex; gap: 7px; }
.newchat-form .select { flex: 1; min-width: 0; height: 32px; font-size: 12px; border-radius: 8px; }
.newchat-form .btn { height: 32px; border-radius: 8px; font-size: 12.5px; padding: 0 11px; flex: none; }

.chat-search { position: relative; display: flex; align-items: center; }
.chat-search svg { position: absolute; left: 9px; color: var(--text-faint); pointer-events: none; }
.chat-search .input { height: 31px; padding-left: 29px; font-size: 12.5px; border-radius: 8px; background: var(--panel-2); }

.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; }
.chat-list::-webkit-scrollbar, .chat-messages::-webkit-scrollbar, .app-side::-webkit-scrollbar { width: 8px; height: 8px; }
.chat-list::-webkit-scrollbar-thumb, .chat-messages::-webkit-scrollbar-thumb, .app-side::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb); border-radius: 99px; border: 2px solid transparent; background-clip: content-box;
}

.chat-item { position: relative; }
.chat-item .ci-link {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 30px 8px 10px; border-radius: 10px;
  color: var(--text-dim);
  border: 1px solid transparent;
  transition: background .12s var(--ease), border-color .12s var(--ease), color .12s var(--ease);
}
.chat-item .ci-link:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.chat-item.active .ci-link {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--text);
}
.chat-item.active .ci-link::before {
  content: ""; position: absolute; left: -12px; top: 12px; bottom: 12px; width: 2px;
  border-radius: 2px; background: var(--accent);
}
.ci-title { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -.01em; }
.ci-meta { font-size: 10.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-del { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); margin: 0; opacity: 0; transition: opacity .13s; }
.chat-item:hover .ci-del, .chat-item:focus-within .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: 12.5px; padding: 10px 6px; text-align: center; }

.side-sec { border-top: 1px solid var(--border-soft); padding-top: 9px; }
.side-sec-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); margin-bottom: 6px;
}
.side-sec-cnt { font-size: 10px; padding: 0 5px; border-radius: 5px; background: var(--panel-3); }

/* messages */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 22px 20px 12px;
  display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
  overflow-anchor: none;
}
.chat-messages > * { flex-shrink: 0; }

.msg { display: flex; flex-direction: column; gap: 6px; max-width: 88%; animation: msgIn .2s var(--ease); }
@keyframes msgIn { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }

.msg.user { align-self: flex-end; align-items: flex-end; position: relative; max-width: min(80%, 680px); }
.msg .bubble { padding: 11px 15px; border-radius: 14px; font-size: 14.5px; line-height: 1.6; overflow-wrap: break-word; min-width: 0; }
.msg.user .bubble {
  background: var(--user-bubble);
  border: 1px solid var(--accent-line);
  border-bottom-right-radius: 5px;
  box-shadow: 0 6px 18px -14px var(--accent);
}
.msg.assistant { align-self: stretch; max-width: 100%; align-items: stretch; }
.msg.assistant .bubble {
  background: transparent;
  border: none;
  border-left: 2px solid var(--border);
  border-radius: 0;
  padding: 2px 4px 2px 16px;
  font-size: 14.5px;
}
.msg.assistant .bubble > :first-child { margin-top: 0; }
.msg.assistant .bubble > :last-child { margin-bottom: 0; }

.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;
  max-width: 240px; padding: 5px 9px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border-soft);
  font-size: 11.5px; color: var(--text-dim);
}
.msg .file-chip:hover { color: var(--text); border-color: var(--accent); background: var(--panel-3); text-decoration: none; }
.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 { max-width: 260px; max-height: 220px; border-radius: 10px; border: 1px solid var(--border); transition: transform .14s var(--ease), border-color .14s var(--ease); }
.msg .img-chip:hover .u-img { border-color: var(--accent); transform: scale(1.01); }

.msg.streaming .bubble::after {
  content: ""; display: inline-block; width: 7px; height: 15px; margin-left: 3px;
  vertical-align: -2px; background: var(--accent); border-radius: 2px;
  animation: caret 1s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

.msg-edit {
  position: absolute; left: -34px; bottom: 4px;
  opacity: 0; transition: opacity .14s; width: 26px; height: 26px; border-radius: 7px;
}
.msg.user:hover .msg-edit, .msg-edit:focus-visible { opacity: 1; }
.chat-messages.running .msg-edit { display: none; }
.msg.user.uprompt-target .bubble { animation: upromptFlash 1.6s var(--ease) 1; }
@keyframes upromptFlash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 3px transparent; } }

/* tool cards + thinking */
.toolcard {
  border: 1px solid var(--border-soft); border-left: 2px solid var(--border);
  border-radius: 10px; background: color-mix(in srgb, var(--panel-2) 70%, transparent);
  overflow: hidden; margin: 2px 0;
}
.toolcard:has(.tool-state.running) { border-left-color: var(--warn); }
.toolcard:has(.tool-state.ok) { border-left-color: color-mix(in srgb, var(--ok) 60%, transparent); }
.toolcard:has(.tool-state.err) { border-left-color: var(--err); }
.toolcard summary {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px; cursor: pointer; list-style: none;
  font-size: 12.5px; color: var(--text-dim);
}
.toolcard summary::-webkit-details-marker { display: none; }
.toolcard summary::before { content: "›"; color: var(--text-faint); transition: transform .15s var(--ease); display: inline-block; font-size: 14px; }
.toolcard[open] summary::before { transform: rotate(90deg); }
.toolcard[open] summary, .toolcard summary:hover { background: var(--panel-3); }
.tool-name { font-family: var(--mono); font-size: 12px; color: var(--text); font-weight: 550; }
.tool-args { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.tool-state { margin-left: auto; font-size: 12px; color: var(--text-faint); }
.tool-state.ok { color: var(--ok); }
.tool-state.err { color: var(--err); }
.tool-state.running { color: var(--warn); }
.tool-body { padding: 11px 13px; border-top: 1px solid var(--border-soft); font-size: 12.5px; }

.think { border: 1px dashed var(--border); border-radius: 10px; background: color-mix(in srgb, var(--panel-2) 45%, transparent); }
.think summary {
  list-style: none; cursor: pointer; padding: 7px 12px;
  font-size: 12px; color: var(--text-faint); display: flex; align-items: center; gap: 8px;
}
.think summary::-webkit-details-marker { display: none; }
.think summary::before { content: "◌"; font-size: 12px; }
.think[open] summary::before { content: "◉"; color: var(--accent); }
.think-body { padding: 0 13px 11px; color: var(--text-dim); font-size: 13px; }
.think-sink { font-family: var(--mono); font-size: 11.5px; line-height: 1.55; white-space: pre-wrap; color: var(--text-faint); }
.think-sink.md { white-space: normal; font-family: inherit; font-size: 12.5px; }

.chat-loading { color: var(--text-faint); display: flex; align-items: center; gap: 9px; justify-content: center; padding: 34px; font-size: 13px; }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 8px; font-weight: 680; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15.5px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md code {
  font-family: var(--mono); font-size: 12.5px;
  padding: 1.5px 5px; border-radius: 5px;
  background: var(--panel-3); border: 1px solid var(--border-soft); color: var(--text);
}
.md pre {
  position: relative; margin: 10px 0; padding: 12px 14px;
  background: var(--code-bg); border: 1px solid var(--border-soft);
  border-radius: 10px; overflow-x: auto; font-size: 12.5px; line-height: 1.6;
}
.md pre code { background: none; border: none; padding: 0; font-size: 12.5px; }
.md blockquote { margin: 10px 0; padding: 4px 0 4px 14px; border-left: 2px solid var(--accent-line); color: var(--text-dim); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.md table { border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border-soft); padding: 6px 10px; text-align: left; }
.md th { background: var(--panel-2); font-weight: 600; }
.md img { max-width: 100%; border-radius: 8px; }
.md a { text-decoration: underline; text-decoration-color: var(--accent-line); text-underline-offset: 2px; }
.md a:hover { text-decoration-color: var(--accent); }
.code-copy { position: absolute; top: 7px; right: 7px; }

/* statusbar + composer */
.statusbar {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 16px; min-height: 32px;
  font-size: 12px; color: var(--text-faint);
  border-top: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--panel-2) 40%, transparent);
}
.status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-elapsed { color: var(--text-faint); font-size: 11px; }
.status-tokens { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-faint); }
.statusbar #stopBtn { margin-left: 8px; }

.composer {
  border-top: 1px solid var(--border-soft);
  padding: 11px 13px 13px;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-input {
  min-height: 42px; max-height: 210px; padding: 10px 13px;
  font-size: 14.5px; line-height: 1.55; border-radius: 12px;
  resize: none; overflow-y: auto;
  background: var(--panel-2);
}
.composer-input:focus { background: var(--panel); }
.composer .attach { width: 38px; height: 42px; border-radius: 11px; border: 1px solid var(--border); }
.composer .attach:hover { border-color: var(--accent-line); color: var(--accent); }
.composer-send { height: 42px; border-radius: 12px; padding: 0 16px; flex: none; }
.composer-send .btn-txt { display: inline; }
.composer-foot {
  display: flex; align-items: center; gap: 10px;
  margin-top: 7px; padding: 0 2px;
  font-size: 11px; color: var(--text-faint);
}
.composer-foot kbd {
  font-family: var(--mono); font-size: 10px; padding: 1px 5px;
  border-radius: 4px; background: var(--panel-3); border: 1px solid var(--border);
  color: var(--text-dim);
}
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.file-chips:not(:empty) { margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 7px; font-size: 11.5px;
  background: var(--panel-3); border: 1px solid var(--border); color: var(--text-dim);
}

/* right rail */
.app-side {
  display: flex; flex-direction: column; gap: 10px;
  height: 100%; max-height: 100%; overflow-y: auto;
  padding-right: 2px;
}
.app-side-card {
  padding: 14px 15px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}
.app-side-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  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-side-mobhead { display: none; }

.app-info-name { font-size: 16.5px; font-weight: 680; margin: 0 0 8px; letter-spacing: -.025em; }
.app-info-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.app-info-sub {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 11.5px; color: var(--text-dim);
  word-break: break-all; padding: 6px 9px; margin-bottom: 8px;
  background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 8px;
}
.app-info-sub:hover { color: var(--accent); border-color: var(--accent-line); text-decoration: none; }
.app-info-meta { font-size: 11px; color: var(--text-faint); }

.app-side-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.app-side-actions .btn { width: 100%; height: 34px; font-size: 12.5px; padding: 0 8px; border-radius: 9px; }
.app-side-actions .btn-primary { grid-column: 1 / -1; height: 38px; font-size: 13px; }
.app-side-actions form { margin: 0; display: flex; }
.app-side-actions form .btn { width: 100%; }

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

.app-side-prompts { display: flex; flex-direction: column; flex: 1 1 200px; min-height: 180px; }
.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: 8px;
  background: var(--panel-2); border: 1px solid var(--border-soft); cursor: pointer;
}
.uprompt-item:hover, .uprompt-item:focus-visible { border-color: var(--accent-line); background: var(--panel-3); outline: none; }
.uprompt-no { flex: none; font-size: 10px; color: var(--text-faint); min-width: 15px; text-align: right; }
.uprompt-text { flex: 1; min-width: 0; font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uprompt-item:hover .uprompt-text { color: var(--text); }

.readme-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.readme-head .btn-sm { padding: 2px 8px; }
.readme-body { min-height: 20px; overflow-x: auto; }
.readme-md { font-size: 12.5px; }
.readme-md pre { max-height: 300px; }
.readme-empty {
  color: var(--text-faint); font-size: 12.5px; padding: 16px 12px;
  border: 1px dashed var(--border); border-radius: 9px; text-align: center;
}

.chat-opt-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
.chat-opt-label { font-size: 12.5px; color: var(--text-dim); }
.chat-opt-row .select { width: auto; min-width: 70px; }

/* ------------------------------------------------------------- empty state -- */
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 40px 24px; text-align: center; }
.empty-icon {
  width: 62px; height: 62px; border-radius: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent-line);
}
.empty-state h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.empty-sub { margin: 0; color: var(--text-faint); font-size: 13.5px; max-width: 46ch; line-height: 1.6; }
.empty-start { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.empty-start .select { width: auto; }

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

/* ----------------------------------------------------------------- toasts -- */
.toasts { position: fixed; top: calc(var(--nav-h) + 14px); right: 18px; z-index: 300; display: flex; flex-direction: column; gap: 9px; max-width: min(400px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; padding: 11px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 13px; font-weight: 500;
  display: flex; align-items: flex-start; gap: 9px;
  animation: toastIn .22s var(--ease); word-break: break-word;
  backdrop-filter: blur(10px);
}
.toast::before { content: ""; width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--accent); }
.toast-err { border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.toast-err::before { background: var(--err); }
.toast-ok::before { background: var(--ok); }
.toast.out { animation: toastOut .28s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* ---------------------------------------------------------------- spinner -- */
.spinner {
  width: 15px; height: 15px; border-radius: 50%; flex: none;
  border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
  display: inline-block;
}
.spinner.hidden { display: none !important; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- switches -- */
.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-4); 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; }

/* ----------------------------------------------------------------- tables -- */
.table-card { padding: 18px 20px 20px; margin-bottom: 18px; }
.table-title { font-size: 15px; font-weight: 680; margin: 0 0 12px; letter-spacing: -.02em; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; padding: 8px 10px; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint);
  border-bottom: 1px solid var(--border); white-space: nowrap; font-weight: 700;
}
.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: color-mix(in srgb, var(--panel-2) 70%, transparent); }
.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); }

/* --------------------------------------------------------------- terminal -- */
.term-panel { display: flex; flex-direction: column; min-height: 0; border-radius: var(--radius); overflow: hidden; }
.term-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border-soft); background: var(--panel-2); font-size: 12px; }
.term-head-title { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); }
.term-hint { margin-left: 6px; }
.term-body { flex: 1; min-height: 60px; overflow-y: auto; padding: 10px 12px; background: var(--code-bg); font-family: var(--mono); font-size: 12px; line-height: 1.55; }
.term-line { white-space: pre-wrap; word-break: break-word; }
.term-inputline { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--border-soft); background: var(--code-bg); }
.term-ps1 { font-family: var(--mono); font-size: 11.5px; color: var(--ok); white-space: nowrap; }
.term-input { flex: 1; background: transparent; border: none; color: var(--text); font-family: var(--mono); font-size: 12.5px; outline: none; }
.term-grabber { height: 6px; cursor: ns-resize; border-radius: 3px; }
.term-grabber:hover { background: var(--accent-soft); }

/* ============================================================ v2.1 polish -- */
/* admin tables: keep dates / ids on one line */
.table td.mono { white-space: nowrap; }
.table th { white-space: nowrap; }

/* auth pages own the whole viewport (no page padding / no scrollbar) */
.page:has(> .auth-wrap) { padding: 0; max-width: none; }
@media (min-width: 980px) {
  .auth-wrap.split { min-height: calc(100vh - var(--nav-h)); }
}


/* assistant prose should read at full contrast; only meta text stays dim */
.msg.assistant .bubble { color: var(--text); }
.msg.assistant .bubble .md p,
.msg.assistant .bubble .md li { color: var(--text); }
.msg.assistant .bubble .md h1,
.msg.assistant .bubble .md h2,
.msg.assistant .bubble .md h3,
.msg.assistant .bubble .md h4 { color: var(--text); }
.msg.user .bubble { color: var(--text); }

/* merged info / actions card in the right rail */
.app-side-actions {
  margin-top: 14px; padding-top: 13px;
  border-top: 1px solid var(--border-soft);
}
.app-side-actions .btn { justify-content: center; }
.app-side-card .app-info-meta { display: flex; gap: 10px; flex-wrap: wrap; }

/* composer hint row */
.composer-foot .cf-dot { opacity: .45; }
.composer-foot kbd + kbd { margin-left: 1px; }

/* chat filter */
.chat-search .input::-webkit-search-cancel-button { -webkit-appearance: none; }
.chat-item.filtered-out { display: none; }

/* ------------------------------------------------------- auth split v2.1 -- */
.auth-kicker {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em;
  color: var(--accent); margin: 0 0 8px;
}

/* product name under the mark on small screens (login card) */
.auth-brand-name { display: none; }
@media (max-width: 979px) {
  .auth-brand-name { display: block; margin: 12px 0 0; font-size: 21px; font-weight: 700; letter-spacing: -.03em; }
  .auth-brand .auth-kicker { margin-top: 9px; }
}
.auth-h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.03em; font-weight: 700; }
.auth-sub { margin: 0 0 22px; color: var(--text-faint); font-size: 13.5px; }
.auth-hero-mid { margin: auto 0; }
.auth-pw-wrap { position: relative; display: flex; }
.auth-pw-wrap .input { padding-right: 42px; width: 100%; }
.auth-pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 30px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--text-faint); cursor: pointer;
  transition: color .14s, background .14s;
}
.auth-pw-toggle:hover { color: var(--text); background: var(--panel-3); }
.auth-pw-toggle.on { color: var(--accent); }
.field-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }
.field-hint.err { color: var(--err); }
.field-hint.ok { color: var(--ok); }
.input.invalid { border-color: var(--err) !important; box-shadow: 0 0 0 3px var(--err-soft) !important; }
.pw-meter { display: flex; gap: 4px; margin-top: 7px; }
.pw-meter i {
  flex: 1; height: 3px; border-radius: 2px; background: var(--panel-3);
  transition: background .18s var(--ease);
}
.pw-meter.s1 i:nth-child(-n+1) { background: var(--err); }
.pw-meter.s2 i:nth-child(-n+2) { background: var(--warn); }
.pw-meter.s3 i { background: var(--ok); }
.auth-or {
  display: flex; align-items: center; gap: 10px; margin: 2px 0 0;
  font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .08em;
}
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--border-soft); }
.auth-form .btn[type="submit"] { position: relative; }
.auth-form .btn[type="submit"].busy { color: transparent; }
.auth-form .btn[type="submit"].busy::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 15px; height: 15px;
  margin: -8px 0 0 -8px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@media (min-width: 980px) {
  .auth-wrap.split .auth-brand-mobile { display: none; }
  .auth-wrap.split .auth-brand { text-align: left; margin-bottom: 4px; }
  .auth-wrap.split .auth-kicker { margin-top: 0; }
}
.auth-wrap.split .auth-brand h1 { margin: 0; }
@media (max-width: 979px) {
  .auth-wrap { place-items: center; }
  .auth-card { max-width: 420px; }
}

/* ------------------------------------------------------------- responsive -- */
@media (max-width: 1280px) {
  .app-layout { grid-template-columns: 272px minmax(0, 1fr) 320px; }
  body.rail-hidden .app-layout { grid-template-columns: 272px minmax(0, 1fr); }
  body.side-hidden .app-layout { grid-template-columns: minmax(0, 1fr) 320px; }
}

@media (max-width: 1100px) {
  .app-layout { grid-template-columns: 272px minmax(0, 1fr); }
  body.rail-hidden .app-layout { grid-template-columns: 272px minmax(0, 1fr); }
  body.side-hidden .app-layout { grid-template-columns: minmax(0, 1fr); }
  .app-side {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 96;
    width: min(460px, 92vw); height: 100vh;
    background: var(--panel); border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg); padding: 16px;
    transform: translateX(103%); transition: transform .26s var(--ease);
    display: flex !important;
  }
  .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; color: var(--text-dim);
  }
  #toggleSide { display: inline-flex; }
  #toggleRail { display: none; }
}

@media (max-width: 860px) {
  .nav-links { display: none; }
}

@media (max-width: 768px) {
  .page { padding: 20px 14px 60px; }
  .page:has(> .app-page) { padding: 8px 8px 8px; }
  .topnav { padding: 0 12px; gap: 10px; }
  .userbtn-name { display: none; }
  .userbtn { padding: 0 4px; }

  .app-layout { grid-template-columns: minmax(0, 1fr); height: calc(100vh - var(--nav-h) - 16px); gap: 8px; }
  .chat-panel { border-radius: 16px; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 96;
    width: min(360px, 88vw); height: 100vh;
    background: var(--panel); border-right: 1px solid var(--border); border-radius: 0;
    box-shadow: var(--shadow-lg); transform: translateX(-103%);
    transition: transform .26s var(--ease);
  }
  .sidebar.open { transform: none; }
  .sidebar-close { display: inline-flex; }
  #toggleChats { display: inline-flex; }

  .chat-head { padding: 8px 10px; gap: 6px; }
  .chat-head-title { font-size: 13px; }
  .model-pick-label { display: none; }
  .chat-head .model-pick .select { max-width: 116px; font-size: 11px; height: 28px; padding: 0 22px 0 7px; }
  .chat-messages { padding: 14px 12px 8px; gap: 12px; }
  .msg { max-width: 100%; }
  .msg.user { max-width: 88%; }
  .msg.assistant .bubble { padding-left: 12px; font-size: 14px; }
  .msg .bubble { font-size: 14px; }
  .msg-edit { display: none; }

  .composer { padding: 8px 9px calc(8px + env(safe-area-inset-bottom)); }
  .composer-row { gap: 6px; }
  .composer-input { font-size: 16px; min-height: 40px; padding: 9px 11px; border-radius: 11px; }
  .composer .attach { width: 36px; height: 40px; border-radius: 10px; }
  .composer-send { height: 40px; width: 40px; min-width: 40px; padding: 0; border-radius: 10px; }
  .composer-send .btn-txt { display: none; }
  .composer-foot { display: none; }

  .statusbar { padding: 6px 12px; font-size: 11.5px; }

  .dash-hero { align-items: flex-start; }
  .dash-hero h1 { font-size: 24px; }
  .apps-grid { grid-template-columns: 1fr; gap: 10px; }
  .app-card { min-height: 0; padding: 14px; }
  .search { width: 100%; }
  .section-head { gap: 8px; }
  .auth-card { padding: 26px 20px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---- v2.4 auth: "by AIGU" + floating theme toggle ---- */
.auth-brand-by { display: none; margin: 3px 0 0; font-size: 12.5px; font-weight: 500; letter-spacing: .06em; color: var(--text-dim); }
.auth-brand-by b { color: var(--accent); font-weight: 700; letter-spacing: .09em; }
@media (max-width: 979px) { .auth-brand-by { display: block; } }
.auth-theme-toggle { position: fixed; top: 12px; right: 12px; z-index: 90; background: var(--panel); border: 1px solid var(--border); color: var(--text-dim); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.auth-theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.auth-theme-toggle.pulse { animation: authThemePulse .35s var(--ease); }
@keyframes authThemePulse { 0% { transform: scale(1); } 40% { transform: scale(1.16); } 100% { transform: scale(1); } }

/* ---- v2.5 dotted wordmark S.U.N.D.E.Y ---- */
.brand-name { letter-spacing: .045em; font-size: 14px; }
.auth-hero-brand .brand-wordmark { letter-spacing: .045em; font-size: 15px; }
.auth-brand-name { letter-spacing: .05em; font-size: 20px; }

/* ---- v2.6 brand tail "CODE" ---- */
.brand-tail { font-size: .58em; font-weight: 700; letter-spacing: .18em; color: var(--text-dim); margin-left: .4em; }
