:root {
  --blue-50: #f5f8ff;
  --blue-100: #edf3ff;
  --blue-200: #dce8ff;
  --blue-300: #c2d6ff;
  --blue-500: #5b82f3;
  --blue-600: #456fe8;
  --blue-700: #365cc9;
  --ink: #202939;
  --ink-soft: #596579;
  --muted: #8b96a8;
  --line: #e5ebf5;
  --surface: #ffffff;
  --sidebar: #f5f7fb;
  --canvas: #fbfcff;
  --danger: #d94d52;
  --shadow-sm: 0 2px 10px rgba(46, 73, 122, .06);
  --shadow-md: 0 16px 48px rgba(46, 73, 122, .14);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; transition: .18s ease; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: inherit; text-decoration: none; }
.brand-logo { display: block; width: 52px; height: 52px; border-radius: 15px; box-shadow: 0 12px 28px rgba(30,62,150,.2); }
.brand-logo.small { width: 34px; height: 34px; border-radius: 10px; box-shadow: 0 7px 18px rgba(69,111,232,.24); }
.hero-logo { position: relative; z-index: 1; margin-bottom: 34px; }
.icon-button svg, .send svg, .header-actions .ghost svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.eyebrow {
  margin: 0 0 8px;
  color: var(--blue-600);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .16em;
}

/* Auth */
.auth-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(390px, .88fr);
  background: var(--blue-50);
}
.brand-panel {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(52px, 8vw, 128px);
  color: #fff;
  background: linear-gradient(145deg, #6f96f6 0%, #4b74e7 52%, #3c63d0 100%);
}
.brand-panel::before,
.brand-panel::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.09);
  filter: blur(1px);
}
.brand-panel::before { width: 520px; height: 520px; right: -210px; top: -190px; }
.brand-panel::after { width: 340px; height: 340px; left: -160px; bottom: -130px; }
.brand-mark {
  position: relative;
  z-index: 1;
  width: 62px;
  height: 62px;
  margin-bottom: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 18px;
  color: white;
  background: rgba(255,255,255,.16);
  box-shadow: 0 14px 34px rgba(30,62,150,.22);
  font-family: "Songti SC", serif;
  font-size: 28px;
  backdrop-filter: blur(12px);
}
.brand-mark.small {
  width: 34px;
  height: 34px;
  margin: 0;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(145deg, #6b91f3, #456fe8);
  box-shadow: 0 7px 18px rgba(69,111,232,.24);
  font-size: 16px;
}
.brand-panel .eyebrow { position: relative; z-index: 1; color: rgba(255,255,255,.74); }
.brand-panel h1 {
  position: relative;
  z-index: 1;
  max-width: 680px;
  margin: 8px 0 26px;
  font-family: "Songti SC", Georgia, serif;
  font-size: clamp(42px, 5vw, 72px);
  font-weight: 500;
  line-height: 1.16;
  letter-spacing: -.03em;
}
.brand-copy {
  position: relative;
  z-index: 1;
  max-width: 570px;
  margin: 0;
  color: rgba(255,255,255,.78);
  font-size: 16px;
  line-height: 1.85;
}
.feature-row { position: relative; z-index: 1; display: flex; gap: 9px; flex-wrap: wrap; margin-top: 36px; }
.feature-row span {
  padding: 8px 14px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  color: rgba(255,255,255,.84);
  background: rgba(255,255,255,.06);
  font-size: 12px;
}
.auth-card {
  width: min(430px, calc(100% - 54px));
  align-self: center;
  justify-self: center;
  padding: 34px 0;
}
.auth-heading h2 {
  margin: 0 0 8px;
  font-size: 32px;
  font-weight: 650;
  letter-spacing: -.03em;
}
.auth-heading > p:last-child { margin: 0 0 30px; color: var(--muted); font-size: 14px; }
.auth-card form { display: grid; gap: 17px; }
label { display: grid; gap: 7px; color: #465267; font-size: 13px; font-weight: 600; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
  background: var(--surface);
  color: var(--ink);
  padding: 13px 14px;
}
input::placeholder, textarea::placeholder { color: #aab3c2; }
input:focus, textarea:focus, select:focus { border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(91,130,243,.12); }
textarea { resize: vertical; line-height: 1.65; }
.primary, .secondary, .ghost, .danger, .wechat-button {
  min-height: 44px;
  border: 0;
  border-radius: 11px;
  padding: 11px 17px;
  font-weight: 650;
  text-align: center;
}
.primary { color: #fff; background: var(--blue-600); box-shadow: 0 7px 18px rgba(69,111,232,.18); }
.primary:hover { background: var(--blue-700); transform: translateY(-1px); }
.secondary { color: var(--blue-700); background: var(--blue-100); }
.secondary:hover { background: var(--blue-200); }
.ghost { border: 1px solid var(--line); color: var(--ink-soft); background: rgba(255,255,255,.72); }
.ghost:hover { color: var(--blue-700); border-color: var(--blue-300); background: var(--blue-50); }
.danger { color: #b63339; background: #fff0f1; }
.wide { width: 100%; }
.wechat-button { display: block; margin-top: 11px; color: #27743a; background: #eef9f1; }
.wechat-button span {
  display: inline-grid;
  place-items: center;
  width: 23px;
  height: 23px;
  margin-right: 7px;
  border-radius: 6px;
  color: white;
  background: #37ad55;
}
.social-logins { margin-top: 12px; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0 11px; color: var(--muted); font-size: 11px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.text-button { display: block; margin: 19px auto; border: 0; color: var(--blue-600); background: none; }
.legal { margin-top: 22px; color: #a6afbd; text-align: center; font-size: 11px; }
.community-link {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--blue-200);
  border-radius: 12px;
  color: var(--ink-soft);
  background: rgba(237,243,255,.72);
  padding: 10px 12px;
  text-align: left;
}
.community-link:hover { border-color: var(--blue-300); background: var(--blue-100); transform: translateY(-1px); }
.community-link > span:nth-child(2) { min-width: 0; }
.community-link small, .community-link strong { display: block; }
.community-link small { margin-bottom: 2px; color: var(--muted); font-size: 10px; font-weight: 500; }
.community-link strong { color: var(--ink); font-size: 13px; letter-spacing: .02em; }
.community-link b { color: var(--blue-600); font-size: 11px; font-weight: 650; }
.community-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: #fff;
  background: linear-gradient(145deg, #78a5ff, #4c75e6);
  font-size: 13px;
  font-weight: 750;
  box-shadow: 0 5px 12px rgba(69,111,232,.2);
}
.auth-community { margin-top: 4px; }

/* Main app */
.app-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 296px;
  overflow: hidden;
  background: var(--canvas);
}
.sidebar, .detail-panel { min-height: 0; background: var(--sidebar); }
.sidebar {
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 18px 14px 14px;
  border-right: 1px solid var(--line);
}
.sidebar-brand {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 7px;
  margin-bottom: 16px;
  font-size: 17px;
}
.sidebar-brand strong { font-weight: 700; }
.sidebar-close { display: none; margin-left: auto; }
.side-section { margin-top: 25px; }
.side-section.grow { flex: 1; min-height: 0; }
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
  padding: 0 8px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}
.section-title button { border: 0; color: var(--blue-600); background: transparent; font-size: 20px; }
.character-list, .session-list { display: grid; gap: 3px; }
.session-list { max-height: 100%; overflow: auto; overscroll-behavior: contain; }
.character-item, .session-item {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border: 0;
  border-radius: 10px;
  color: var(--ink-soft);
  background: transparent;
  text-align: left;
}
.session-item { position: relative; padding-right: 38px; }
.session-main { width: 100%; min-width: 0; display: flex; align-items: center; padding: 0; border: 0; color: inherit; background: transparent; text-align: left; }
.session-delete { position: absolute; right: 5px; top: 50%; width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 8px; color: #a1aabb; background: transparent; opacity: 0; transform: translateY(-50%); }
.session-item:hover .session-delete, .session-item:focus-within .session-delete { opacity: 1; }
.session-delete:hover { color: var(--danger); background: #fff0f1; }
.session-delete svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.character-item:hover, .session-item:hover { background: #edf1f8; }
.character-item.active, .session-item.active { color: var(--blue-700); background: var(--blue-100); }
.character-item .avatar { width: 32px; height: 32px; font-size: 13px; }
.character-item div, .session-item div { min-width: 0; }
.character-item strong, .session-item strong {
  display: block;
  overflow: hidden;
  color: inherit;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.character-item small, .session-item small {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 13px 7px 2px;
  border-top: 1px solid var(--line);
}
.sidebar-community { margin: 8px 0 10px; }
.user-card strong, .user-card small { display: block; }
.user-card strong { font-size: 13px; }
.user-card small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.user-card button { border: 0; color: var(--muted); background: transparent; }
.sidebar-backdrop { display: none; }
.avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, #84a7fb, #547ce9);
  font-weight: 700;
  box-shadow: 0 7px 18px rgba(69,111,232,.16);
}
.avatar.mini { width: 32px; height: 32px; border-radius: 9px; font-size: 11px; }
.avatar.hero { width: 92px; height: 92px; margin: 24px auto 15px; border-radius: 25px; font-size: 34px; }

.chat-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}
.chat-header {
  z-index: 5;
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(16px);
}
.chat-person { flex: 1; min-width: 0; }
.chat-person strong { display: block; overflow: hidden; font-size: 14px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.chat-person small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.chat-person i { display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: #59b977; }
.header-actions { display: flex; align-items: center; gap: 7px; margin-left: auto; }
.header-actions .ghost { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 12px; font-size: 12px; }
.icon-button { min-width: 38px; min-height: 38px; border: 0; border-radius: 10px; color: var(--ink-soft); background: transparent; font-size: 17px; }
.icon-button:hover { color: var(--blue-700); background: var(--blue-100); }
.chat-header > #mobile-menu { display: none; }
.empty-state {
  width: min(440px, calc(100% - 40px));
  margin: auto;
  padding: 42px 0 120px;
  text-align: center;
}
.empty-state .orb {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  margin: 0 auto 22px;
  border: 1px solid var(--blue-200);
  border-radius: 20px;
  color: var(--blue-600);
  background: linear-gradient(145deg, #fff, var(--blue-100));
  box-shadow: 0 14px 32px rgba(69,111,232,.12);
  font-family: "Songti SC", serif;
  font-size: 23px;
}
.empty-state .orb img { width: 100%; height: 100%; border-radius: inherit; }
.empty-state h2 { margin: 0 0 11px; font-size: 25px; font-weight: 650; letter-spacing: -.03em; }
.empty-state p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.75; }
.starter-prompts { width: min(590px, 100%); display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 25px; }
.starter-prompt { min-height: 48px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink-soft); background: rgba(255,255,255,.72); text-align: left; font-size: 12px; line-height: 1.45; }
.starter-prompt:hover { border-color: var(--blue-300); color: var(--blue-700); background: var(--blue-50); transform: translateY(-1px); }
.messages {
  width: 100%;
  flex: 1;
  overflow: auto;
  padding: 32px max(28px, calc((100% - 820px) / 2));
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.message { width: 100%; display: flex; align-items: flex-start; gap: 12px; margin: 0 0 28px; }
.message.user { justify-content: flex-start; flex-direction: row-reverse; }
.message > div:nth-child(2) { min-width: 0; max-width: min(82%, 700px); }
.bubble {
  color: #303a4a;
  background: transparent;
  font-size: 14px;
  line-height: 1.8;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.message-actions { min-height: 22px; display: flex; gap: 4px; margin-top: 5px; opacity: 0; transition: opacity .16s ease; }
.message:hover .message-actions, .message:focus-within .message-actions { opacity: 1; }
.message-action { padding: 2px 6px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 10px; }
.message-action:hover { color: var(--blue-700); background: var(--blue-100); }
.message.user .bubble {
  padding: 11px 14px;
  border: 1px solid #d8e5ff;
  border-radius: 14px 4px 14px 14px;
  color: #29456f;
  background: #edf4ff;
}
.message-meta { margin-top: 6px; color: #a4adba; font-size: 9px; }
.message.user .message-meta { text-align: right; }
.typing {
  width: min(820px, calc(100% - 56px));
  display: flex;
  gap: 4px;
  margin: 0 auto 12px;
  padding-left: 44px;
}
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--blue-500); animation: pulse 1s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 50% { opacity: .25; transform: translateY(-3px); } }
.composer {
  width: min(820px, calc(100% - 40px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 9px;
  margin: 0 auto max(18px, env(safe-area-inset-bottom));
  padding: 9px 9px 7px 15px;
  border: 1px solid #dfe6f1;
  border-radius: 17px;
  background: #fff;
  box-shadow: 0 8px 30px rgba(45,72,119,.09);
}
.composer:focus-within { border-color: var(--blue-300); box-shadow: 0 8px 32px rgba(69,111,232,.13), 0 0 0 3px rgba(91,130,243,.08); }
.composer textarea { max-height: 138px; padding: 8px 0; border: 0; box-shadow: none; resize: none; background: transparent; font-size: 14px; }
.composer .send {
  width: 39px;
  height: 39px;
  border: 0;
  border-radius: 11px;
  color: white;
  background: var(--blue-600);
  font-size: 18px;
}
.composer .send:hover { background: var(--blue-700); }
.composer .send:disabled { opacity: .35; cursor: default; }
.composer small { grid-column: 1 / -1; color: #a7b0bf; text-align: center; font-size: 8px; }

.detail-panel {
  display: flex;
  flex-direction: column;
  overflow: auto;
  padding: 24px 22px;
  border-left: 1px solid var(--line);
  text-align: center;
  background: #f9fbff;
}
.detail-panel h2 { margin: 0; font-size: 22px; font-weight: 650; }
.detail-panel > p:not(.eyebrow) { color: var(--muted); font-size: 12px; }
.detail-block { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); text-align: left; }
.detail-block span { color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.detail-block p { max-height: 200px; overflow: auto; margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.75; }
.plan-card { margin-top: auto; padding: 16px; border: 1px solid var(--blue-200); border-radius: 14px; color: #38517e; background: var(--blue-100); text-align: left; }
.plan-card > div:first-child { display: flex; justify-content: space-between; font-size: 11px; }
.progress { height: 5px; overflow: hidden; margin: 12px 0 14px; border-radius: 99px; background: #d4e0f5; }
.progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--blue-600); }
.plan-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.plan-option { min-width: 0; display: grid; gap: 5px; padding: 14px 12px; border: 1px solid var(--line); border-radius: 13px; background: var(--blue-50); text-align: center; }
.plan-option.featured { border-color: var(--blue-300); background: var(--blue-100); box-shadow: inset 0 0 0 1px rgba(91,130,243,.08); }
.plan-option strong { color: var(--blue-700); font-size: 22px; }
.plan-option span { color: var(--ink-soft); font-size: 11px; }
.plan-option b { color: var(--muted); font-size: 10px; font-weight: 600; }

/* Dialogs */
dialog {
  width: min(560px, calc(100vw - 28px));
  max-height: min(760px, calc(100dvh - 28px));
  overflow: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
dialog::backdrop { background: rgba(33,45,69,.36); backdrop-filter: blur(3px); }
dialog form { display: grid; gap: 17px; padding: 24px; }
.template-field { display: grid; gap: 8px; }
.template-field > span { color: #465267; font-size: 13px; font-weight: 600; }
.prompt-templates { display: flex; flex-wrap: wrap; gap: 7px; }
.prompt-template { padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink-soft); background: var(--surface); font-size: 11px; }
.prompt-template:hover, .prompt-template.active { color: var(--blue-700); border-color: var(--blue-300); background: var(--blue-100); }
.template-loading, .field-help { color: var(--muted); font-size: 11px; }
.field-help { margin: -9px 0 0; font-weight: 400; line-height: 1.5; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 24px 24px 0; }
dialog form .dialog-head { padding: 0; }
.dialog-head h2 { margin: 0; font-size: 21px; font-weight: 650; }
.dialog-head button { width: 36px; height: 36px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-size: 22px; }
.dialog-head button:hover { background: var(--blue-100); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; }
.dialog-actions.split { align-items: center; }
.dialog-actions.split > span { flex: 1; }
.upload-zone { position: relative; padding: 44px 20px; border: 1px dashed var(--blue-300); border-radius: 14px; color: var(--ink-soft); text-align: center; background: var(--blue-50); }
.upload-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-zone strong, .upload-zone span { display: block; }
.upload-zone span { margin-top: 7px; color: var(--muted); font-size: 11px; }
.account-actions { display: grid; gap: 9px; padding: 24px; }
.toast {
  position: fixed;
  z-index: 1000;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  border-radius: 10px;
  color: white;
  background: #27334a;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Admin */
.admin-body { background: var(--blue-50); }
.admin-header { height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 5vw; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.92); }
.admin-header .sidebar-brand { margin: 0; padding: 0; }
.admin-main { max-width: 1400px; margin: 0 auto; padding: 42px 5vw; }
.admin-main h1 { margin: 0; font-size: 36px; letter-spacing: -.03em; }
.stats-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin: 26px 0; }
.stat-card { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-sm); }
.stat-card span { color: var(--muted); font-size: 11px; }
.stat-card strong { display: block; margin-top: 10px; font-size: 26px; }
.admin-table-card { padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); }
.ai-config-card { margin-bottom: 14px; }
.ai-config-form { display: grid; grid-template-columns: minmax(280px, 1.4fr) minmax(180px, .7fr) minmax(220px, .8fr); gap: 12px; margin-top: 18px; }
.ai-config-form .api-url-field { grid-column: span 2; }
.ai-config-form .api-key-field { grid-column: span 2; }
.ai-config-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.ai-config-actions small { flex: 1; color: var(--muted); font-size: 11px; }
.ai-config-actions button { min-width: 112px; }
.admin-grid { display: grid; grid-template-columns: minmax(340px, .8fr) minmax(520px, 1.2fr); gap: 14px; margin-bottom: 14px; }
.table-head { display: flex; align-items: center; justify-content: space-between; }
.table-head h2 { margin: 0; font-size: 20px; }
.table-head input { width: 280px; }
.table-wrap { overflow: auto; margin-top: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 13px 11px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 10px; letter-spacing: .04em; }
.status { display: inline-block; padding: 5px 9px; border-radius: 999px; color: #6d7788; background: #edf0f5; }
.status.active { color: #34734a; background: #e6f5eb; }
.small-button { padding: 7px 10px; border: 0; border-radius: 8px; color: var(--blue-700); background: var(--blue-100); }
.table-tools, .code-value-cell { display: flex; align-items: center; gap: 8px; }
.code-value-cell code { color: var(--ink-soft); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
.code-value-cell .small-button { padding: 5px 7px; font-size: 10px; }
.muted-copy { margin-top: 3px; color: var(--muted); font-size: 11px; }
.code-form { display: grid; grid-template-columns: 1fr 110px; gap: 12px; margin-top: 18px; }
.code-form .full { grid-column: 1 / -1; }
.generated-codes { margin-top: 17px; padding-top: 17px; border-top: 1px solid var(--line); }
.generated-codes > div { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.generated-codes textarea { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.generated-codes small { display: block; margin-top: 7px; color: var(--muted); font-size: 10px; }
.compact-table { max-height: 390px; }
.status.redeemed { color: #596579; background: #edf0f5; }
.status.unused { color: #34734a; background: #e6f5eb; }
.admin-detail-dialog { width: min(1120px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.admin-detail-content { padding: 20px 24px 24px; }
.user-summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
.user-summary > div { min-width: 0; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--blue-50); }
.user-summary span, .user-summary strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-summary span { color: var(--muted); font-size: 9px; }
.user-summary strong { margin-top: 5px; color: var(--ink-soft); font-size: 12px; }
.conversation-browser { height: min(560px, 62vh); display: grid; grid-template-columns: 290px minmax(0, 1fr); overflow: hidden; border: 1px solid var(--line); border-radius: 14px; }
.conversation-browser h3 { height: 48px; display: flex; align-items: center; margin: 0; padding: 0 15px; border-bottom: 1px solid var(--line); font-size: 13px; }
.conversation-sessions { min-width: 0; border-right: 1px solid var(--line); background: var(--sidebar); }
#admin-session-list { height: calc(100% - 48px); overflow: auto; padding: 8px; }
.admin-session-item { width: 100%; display: grid; gap: 4px; padding: 10px; border: 0; border-radius: 9px; color: var(--ink-soft); background: transparent; text-align: left; }
.admin-session-item:hover, .admin-session-item.active { color: var(--blue-700); background: var(--blue-100); }
.admin-session-item strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.admin-session-item span { color: var(--muted); font-size: 9px; }
.conversation-messages { min-width: 0; background: #fff; }
.admin-messages { height: calc(100% - 48px); overflow: auto; padding: 16px; }
.admin-message { max-width: 82%; margin-bottom: 12px; }
.admin-message.user { margin-left: auto; }
.admin-message span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 9px; }
.admin-message.user span { text-align: right; }
.admin-message p { margin: 0; padding: 10px 12px; border-radius: 10px; color: var(--ink-soft); background: var(--blue-50); font-size: 12px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.admin-message.user p { color: #fff; background: var(--blue-600); }
.empty-copy { padding: 18px; color: var(--muted); text-align: center; font-size: 11px; }

/* iPad landscape / smaller desktop */
@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 250px minmax(0, 1fr); }
  .detail-panel { display: none; }
  .messages { padding-inline: max(30px, calc((100% - 760px) / 2)); }
  .composer, .typing { width: min(760px, calc(100% - 44px)); }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .admin-grid { grid-template-columns: 1fr; }
  .user-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ai-config-form { grid-template-columns: 1fr 1fr; }
  .ai-config-form .api-url-field, .ai-config-form .api-key-field { grid-column: span 1; }
}

/* iPad portrait and phones: drawer navigation */
@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 310px);
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    box-shadow: 18px 0 50px rgba(28,43,71,.16);
    transform: translateX(-104%);
    transition: transform .24s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-grid; place-items: center; }
  .sidebar-backdrop {
    position: fixed;
    z-index: 25;
    inset: 0;
    display: block;
    border: 0;
    background: rgba(30,42,65,.28);
    opacity: 0;
    pointer-events: none;
    backdrop-filter: blur(2px);
  }
  .sidebar.open + .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .chat-panel { height: 100vh; height: 100dvh; }
  .chat-header { padding-top: max(10px, env(safe-area-inset-top)); }
  .chat-header > #mobile-menu { display: inline-grid; place-items: center; }
  .messages { padding: 28px max(24px, calc((100% - 700px) / 2)); }
  .message > div:nth-child(2) { max-width: 86%; }
  .composer { width: min(700px, calc(100% - 30px)); }
}

/* Phones */
@media (max-width: 600px) {
  .auth-shell { display: block; background: var(--surface); }
  .brand-panel { min-height: 248px; padding: max(36px, env(safe-area-inset-top)) 26px 34px; justify-content: flex-end; }
  .hero-logo { width: 40px; height: 40px; margin-bottom: 20px; border-radius: 12px; }
  .brand-panel h1 { margin: 3px 0 0; font-size: 34px; line-height: 1.2; }
  .brand-copy, .feature-row { display: none; }
  .auth-card { width: 100%; padding: 34px 24px max(28px, env(safe-area-inset-bottom)); }
  .auth-heading h2 { font-size: 27px; }
  .chat-header { min-height: 61px; padding-inline: 10px; gap: 8px; }
  .chat-header .avatar { width: 36px; height: 36px; border-radius: 10px; }
  .header-actions .ghost { min-width: 38px; min-height: 38px; padding: 0; }
  .header-actions .ghost span { display: none; }
  .header-actions { gap: 0; }
  .empty-state { padding-bottom: 90px; }
  .empty-state h2 { font-size: 22px; }
  .starter-prompts { grid-template-columns: 1fr; gap: 7px; margin-top: 18px; }
  .starter-prompt { min-height: 43px; text-align: center; }
  .messages { padding: 22px 13px; }
  .message { gap: 9px; margin-bottom: 23px; }
  .message > div:nth-child(2) { max-width: calc(100% - 43px); }
  .bubble { font-size: 14px; line-height: 1.75; }
  .message.user .bubble { padding: 10px 12px; }
  .typing { width: calc(100% - 26px); padding-left: 41px; }
  .composer {
    width: calc(100% - 20px);
    margin-bottom: max(9px, env(safe-area-inset-bottom));
    border-radius: 15px;
    padding-left: 13px;
  }
  dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); border-radius: 16px; }
  dialog form, .account-actions { padding: 19px; }
  .dialog-head { padding: 19px 19px 0; }
  dialog form .dialog-head { padding: 0; }
  .dialog-actions > button { flex: 1; }
  .dialog-actions.split { display: grid; grid-template-columns: 1fr 1fr; }
  .dialog-actions.split > span { display: none; }
  .plan-options { grid-template-columns: 1fr; }
  .plan-option { grid-template-columns: auto 1fr auto; align-items: center; text-align: left; }
  .admin-main { padding: 28px 14px; }
  .ai-config-form { grid-template-columns: 1fr; }
  .ai-config-form .api-url-field, .ai-config-form .api-key-field { grid-column: auto; }
  .ai-config-actions { align-items: stretch; flex-direction: column; }
  .ai-config-actions small { margin-bottom: 4px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .table-head { display: block; }
  .table-head input { width: 100%; margin-top: 14px; }
  .table-head select { width: 100%; margin-top: 14px; }
  .user-summary { grid-template-columns: 1fr 1fr; }
  .conversation-browser { height: 68vh; display: block; overflow: auto; }
  .conversation-sessions { height: 220px; border-right: 0; border-bottom: 1px solid var(--line); }
  .conversation-messages { height: 480px; }
}

@media (hover: none) {
  .primary:hover, .ghost:hover { transform: none; }
  .character-item, .session-item, .icon-button { min-height: 44px; }
  .session-delete, .message-actions { opacity: 1; }
}

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