/* ============================================================================
   MeowChat app styles.
   The vendored UI library (public/vendor/ui/*) owns every component; this file
   only (1) pins the app's own palette onto the library's `--ui-*` tokens and
   (2) lays out the app shell + rendered markdown. No component is restyled
   from scratch here.
   Palette: 少数派 (sspai.com) greys + an emerald accent (#059669 / #10b981).
   `:root` = 日间 · `[data-theme="dark"]` = 夜间 · `[data-ui-theme="…"]` (themes.css) wins.
   ========================================================================== */

:root {
  color-scheme: light;

  /* accent — emerald; hover/active/light auto-derive from it */
  --ui-primary: #059669;
  --ui-primary-text: #ffffff;
  --ui-secondary: #6f7174;
  --ui-secondary-text: #ffffff;
  --ui-success: #3fd67e;
  --ui-danger: #fd281a;
  --ui-warning: #fc7310;

  /* surfaces */
  --ui-bg: #f7f7f9;            /* app / message column */
  --ui-bg-subtle: #f0f0f3;     /* recessed: received bubble, reasoning, code */
  --ui-surface: #ffffff;       /* header, composer, cards, sidebar */
  --ui-border: #e4e4e5;
  --ui-text: #000000;
  --ui-text-muted: #6f7174;
  --ui-text-inverse: #ffffff;
  --ui-overlay: rgb(0 0 0 / 0.4);

  /* 少数派 radii: cards 12px, media 4px */
  --ui-radius-sm: 6px;
  --ui-radius: 10px;
  --ui-radius-lg: 12px;

  /* shadows (少数派 --shadow-level-*) */
  --ui-shadow-sm: 0 1px 4px rgb(0 0 0 / 0.05), 0 1px 8px rgb(0 0 0 / 0.10);
  --ui-shadow: 0 1px 4px rgb(0 0 0 / 0.05), 0 1px 8px rgb(0 0 0 / 0.10);
  --ui-shadow-lg: 0 4px 4px rgb(0 0 0 / 0.03), 0 8px 32px rgb(0 0 0 / 0.14);
  --ui-shadow-xl: 0 4px 4px rgb(0 0 0 / 0.03), 0 8px 32px rgb(0 0 0 / 0.14);

  /* system Chinese-first fonts */
  --ui-font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
             "Microsoft YaHei", "Helvetica Neue", Helvetica, Ubuntu, Roboto, Arial, sans-serif;
  --ui-font-mono: "Source Code Pro", Consolas, "Liberation Mono", Menlo, Courier, ui-monospace, monospace;

  --lc-scrollbar: rgb(0 0 0 / 0.16);
}

[data-theme="dark"] {
  color-scheme: dark;

  /* Lighter emerald for dark mode; hover/active/light are still derived from
     --ui-primary by the library, so only the base colors change. */
  --ui-primary: #10b981;
  --ui-secondary: #ababae;
  --ui-success: #57ef96;
  --ui-danger: #f94135;
  --ui-warning: #ee6c35;

  --ui-bg: #28282a;
  --ui-bg-subtle: #1f1f22;
  --ui-surface: #39393c;
  --ui-border: #424245;
  --ui-text: #e2e2e6;
  --ui-text-muted: #ababae;
  --ui-text-inverse: #1a1d26;
  --ui-overlay: rgb(0 0 0 / 0.6);

  /* 少数派 drops shadows in dark mode */
  --ui-shadow-sm: none;
  --ui-shadow: none;
  --ui-shadow-lg: none;
  --ui-shadow-xl: none;

  --lc-scrollbar: rgb(255 255 255 / 0.20);
}

/* ------------------------------------------------------------------ base --- */

*,
*::before,
*::after { box-sizing: border-box; }

[x-cloak] { display: none !important; }

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

body {
  height: 100%;
  margin: 0;
  font-family: var(--ui-font);
  font-size: var(--ui-font-size);
  line-height: var(--ui-line-height);
  background: var(--ui-bg);
  color: var(--ui-text);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--ui-primary); outline-offset: 1px; }

.lc-scroll { scrollbar-width: thin; scrollbar-color: var(--lc-scrollbar) transparent; }
.lc-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.lc-scroll::-webkit-scrollbar-track { background: transparent; }
.lc-scroll::-webkit-scrollbar-thumb { background-color: var(--lc-scrollbar); border-radius: 9999px; }

/* ------------------------------------------------------------- boot/login --- */

.lc-boot {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--ui-bg);
  color: var(--ui-text-muted);
  font-size: 0.875rem;
}

.lc-login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--ui-bg);
}

.lc-login-card { width: 100%; max-width: 22rem; box-shadow: var(--ui-shadow-lg); }
.lc-login-head { text-align: center; }
.lc-login-mark {
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: var(--ui-radius-lg);
  background: var(--ui-primary);
  color: var(--ui-primary-text);
  font-size: 1.25rem;
}
.lc-login-title { margin: 0.75rem 0 0; font-size: 1.25rem; font-weight: 600; }
.lc-login-sub { margin: 0.25rem 0 0; font-size: 0.8125rem; color: var(--ui-text-muted); }
.lc-login-form { margin-top: 1.5rem; }
.lc-login-error { margin: 0; font-size: 0.75rem; }
.lc-login-note {
  margin: 1.25rem 0 0;
  font-size: 0.6875rem;
  line-height: 1.6;
  color: var(--ui-text-muted);
}
.lc-pwd-toggle {
  pointer-events: auto;   /* the library sets pointer-events:none on icon slots */
  display: flex;
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ui-text-muted);
  cursor: pointer;
}
.lc-pwd-toggle:hover { color: var(--ui-text); }

/* ------------------------------------------------------------ app shell --- */

.lc-app { display: flex; height: 100dvh; overflow: hidden; }

.lc-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--ui-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}
.lc-backdrop.open { opacity: 1; visibility: visible; }

.lc-sidebar {
  position: fixed;
  inset-block: 0;
  left: 0;
  z-index: 40;
  width: 18rem;
  display: flex;
  background: var(--ui-surface);
  border-right: 1px solid var(--ui-border);
  overflow: hidden;
  transform: translateX(-100%);
  transition: transform 0.2s ease, width 0.2s ease;
}
.lc-sidebar.open { transform: translateX(0); }
.lc-sidebar-inner { display: flex; flex-direction: column; width: 18rem; height: 100%; }

.lc-sidebar-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  height: 3.5rem;
  padding: 0 0.75rem;
  border-bottom: 1px solid var(--ui-border);
}
.lc-brand { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; }
.lc-brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  border-radius: var(--ui-radius);
  background: var(--ui-primary);
  color: var(--ui-primary-text);
}
.lc-brand-text { min-width: 0; }
.lc-brand-name { font-size: 0.875rem; font-weight: 600; line-height: 1.25; }
.lc-brand-sub { font-size: 0.6875rem; color: var(--ui-text-muted); }

/* `.ui-menu.borderless` zeroes padding; match its specificity to keep our inset. */
.ui-menu.lc-conv-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;   /* no horizontal scrollbar in the sidebar */
  padding: 0.5rem;
  gap: 0.25rem;
}

/* The whole row is the button: row padding moves onto `.lc-conv-pick` so a
   click anywhere in the row (including the vertical padding) selects it. */
.lc-conv { min-width: 0; padding: 0 0.25rem 0 0; gap: 0; }
.lc-conv-pick {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 0.4375rem 0.75rem;
  border: 0;
  border-radius: inherit;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.lc-conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lc-conv-del { opacity: 0; transition: opacity 0.15s ease; }
.lc-conv:hover .lc-conv-del,
.lc-conv:focus-within .lc-conv-del { opacity: 1; }
.lc-empty-list { padding: 1.5rem 0.75rem; text-align: center; font-size: 0.75rem; color: var(--ui-text-muted); }

.lc-sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--ui-border);
}

.lc-sidebar-foot-right { display: flex; align-items: center; gap: 0.25rem; }

.lc-theme-dropdown { position: relative; }
.lc-theme-dropdown .ui-dropdown-menu {
  top: auto;
  bottom: calc(100% + 6px);
  left: 0;
  right: auto;
  min-width: 12rem;
  max-height: 60vh;
  overflow-y: auto;
}

.lc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--ui-bg); }

.lc-topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  height: 3.5rem;
  padding: 0 0.5rem;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface);
}
.lc-topbar-title { flex: 1; min-width: 0; }
.lc-topbar-name { font-size: 0.875rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lc-topbar-sub { font-size: 0.6875rem; color: var(--ui-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.lc-scroller { flex: 1; min-height: 0; overflow-y: auto; }
.lc-thread { width: 100%; max-width: 48rem; margin: 0 auto; padding: 1rem; }

.lc-suggestions { display: grid; grid-template-columns: 1fr; gap: 0.5rem; width: 100%; max-width: 32rem; margin-top: 0.5rem; }
.lc-suggest {
  height: auto;
  justify-content: flex-start;
  padding: 0.625rem 0.875rem;
  font-weight: 400;
  line-height: 1.45;
  white-space: normal;
  text-align: left;
}

.lc-jump {
  position: sticky;
  bottom: 0.75rem;
  z-index: 5;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.lc-jump .ui-btn { pointer-events: auto; box-shadow: var(--ui-shadow-lg); }

/* ------------------------------------------------------------ messages --- */

.lc-msg { align-items: flex-start; }   /* avatar sits at the bubble's top corner */
.lc-msg-group { align-items: stretch; }
.lc-msg-in { animation: lc-msg-in 0.18s ease-out both; }
@keyframes lc-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.lc-bubble { max-width: 100%; }
.lc-user-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.lc-typing { display: flex; align-items: center; }

.lc-reasoning { margin-bottom: 0.25rem; }
.lc-reasoning-toggle { padding: 0.15rem 0.4rem; font-size: 0.75rem; }
.lc-reasoning-body {
  margin-top: 0.25rem;
  max-height: 14rem;
  overflow-y: auto;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  background: var(--ui-bg-subtle);
  color: var(--ui-text-muted);
  font-size: 0.8125rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.lc-msg-meta { align-items: center; flex-wrap: wrap; }
.lc-msg-actions { display: inline-flex; align-items: center; gap: 0.125rem; opacity: 0; transition: opacity 0.15s ease; }
.lc-msg:hover .lc-msg-actions,
.lc-msg:focus-within .lc-msg-actions { opacity: 1; }

.lc-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: 0;
  border-radius: var(--ui-radius-sm);
  background: none;
  color: var(--ui-text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.lc-act .ui-icon { font-size: 0.9375rem; }
.lc-act:hover { background: var(--ui-bg-subtle); color: var(--ui-text); }
.lc-act.danger { color: var(--ui-danger); }
.lc-act.danger:hover { background: var(--ui-danger-light); color: var(--ui-danger); }
.lc-act.copied { color: var(--ui-success); }
.lc-act-confirm { display: inline-flex; align-items: center; gap: 0.125rem; }

/* ------------------------------------------------------------ composer --- */

.lc-composer { flex-shrink: 0; padding: 0.75rem; border-top: 1px solid var(--ui-border); background: var(--ui-surface); }
.lc-composer-inner { width: 100%; max-width: 48rem; margin: 0 auto; }
.lc-composer-row { display: flex; align-items: flex-end; gap: 0.5rem; }
.lc-composer-field {
  flex: 1;
  min-width: 0;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-lg);
  background: var(--ui-bg);
  transition: border-color 0.15s ease;
}
.lc-composer-field:focus-within { border-color: var(--ui-primary); }
.lc-ta.ui-textarea {
  min-height: 2.125rem;   /* field (border 2px + pad 8px + 2.125rem) == button 2.75rem */
  max-height: 10rem;
  padding: 0.375rem 0.25rem;
  border: none;
  border-radius: 0;
  background: transparent;
  resize: none;
  line-height: 1.6;
}
.lc-ta.ui-textarea:hover,
.lc-ta.ui-textarea:focus { border: none; }
.lc-send { width: 2.75rem; height: 2.75rem; padding: 0; border-radius: var(--ui-radius-lg); flex-shrink: 0; }
.lc-notice { margin-bottom: 0.5rem; padding: 0.5rem 0.75rem; font-size: 0.8125rem; }
.lc-composer-note { margin: 0.5rem 0 0; text-align: center; font-size: 0.6875rem; color: var(--ui-text-muted); }

/* ------------------------------------------------------- markdown body --- */

.md { overflow-wrap: anywhere; }
.md p { margin: 0.5rem 0; white-space: pre-wrap; }
.md p:first-child { margin-top: 0; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { margin: 0.75rem 0 0.5rem; font-weight: 600; line-height: 1.35; }
.md h1:first-child, .md h2:first-child, .md h3:first-child { margin-top: 0; }
.md h1 { font-size: 1.125rem; }
.md h2 { font-size: 1rem; }
.md h3 { font-size: 0.9375rem; }
.md ul, .md ol { margin: 0.5rem 0; padding-left: 1.25rem; }
.md li { margin: 0.25rem 0; }
.md blockquote {
  margin: 0.5rem 0;
  padding-left: 0.75rem;
  border-left: 2px solid var(--ui-border);
  color: var(--ui-text-muted);
}
.md a { color: var(--ui-primary); text-decoration: underline; text-underline-offset: 2px; }
.md strong { font-weight: 600; }
.md :not(pre) > code {
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-sm);
  background: var(--ui-bg-subtle);
  color: var(--ui-primary);
  font-family: var(--ui-font-mono);
  font-size: 0.85em;
}
.md .ui-code { margin: 0.75rem 0; }
.md .ui-code-copy.copied { color: var(--ui-success); }
.md .ui-code-copy.copied:hover { color: var(--ui-success); }

/* streaming caret */
.lc-caret::after {
  content: "▍";
  margin-left: 1px;
  opacity: 0.7;
  animation: lc-caret-blink 1s steps(2, start) infinite;
}
@keyframes lc-caret-blink { 50% { opacity: 0; } }

/* ---------------------------------------------------------- responsive --- */

@media (max-width: 639px) {
  .lc-topbar-badge { display: none; }
}

@media (hover: none) {
  .lc-conv-del, .lc-msg-actions { opacity: 1; }
}

@media (min-width: 640px) {
  .lc-suggestions { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 768px) {
  .lc-backdrop { display: none; }
  .lc-sidebar {
    position: relative;
    z-index: auto;
    transform: none;
  }
  .lc-sidebar:not(.open) { width: 0; border-right-width: 0; }
}
