/* ============================================================
   KakoChat · 基础层
   设计取向：会话即日志。等宽字体承担「频道」的标记与时间戳，
   正文使用系统无衬线；唯一高饱色为信号灯琥珀，只用于强调。
   ============================================================ */

:root {
  --font-ui: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --r-xs: 4px;
  --r-sm: 7px;
  --r-md: 11px;
  --r-lg: 16px;
  --r-full: 999px;
  --dur: .16s;
}

html[data-theme="dark"] {
  --bg: #12141b;
  --bg-tint: rgba(197, 229, 158, .05);
  --panel: #181b23;
  --panel-2: #20242e;
  --panel-3: #262b36;
  --line: #2b303c;
  --line-soft: #232732;
  --text: #e9e7e2;
  --text-dim: #b3b7c3;
  --muted: #838a9b;
  /* 主色：黄绿 #c5e59e，暗色下直接作前景与填充 */
  --accent: #c5e59e;
  --accent-fill: #c5e59e;
  --accent-fill-hover: #d3eeb4;
  --accent-ink: #17230b;
  --accent-wash: rgba(197, 229, 158, .13);
  --accent-line: rgba(197, 229, 158, .32);
  --ok: #46b3a0;
  --danger: #e2604c;
  --danger-wash: rgba(226, 96, 76, .13);
  --danger-line: rgba(226, 96, 76, .32);
  --shadow: 0 22px 48px -28px rgba(0, 0, 0, .9);
  --scrim: rgba(8, 9, 13, .62);
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #eceef2;
  --bg-tint: rgba(122, 168, 61, .06);
  --panel: #ffffff;
  --panel-2: #f4f5f8;
  --panel-3: #eceef2;
  --line: #dfe2e8;
  --line-soft: #eceef2;
  --text: #191b22;
  --text-dim: #4c515e;
  --muted: #74798a;
  /* 浅绿在白底上做文字太淡，前景用同色系的深绿，填充仍是 #c5e59e */
  --accent: #4c7020;
  --accent-fill: #c5e59e;
  --accent-fill-hover: #b5d98b;
  --accent-ink: #1a2607;
  --accent-wash: rgba(122, 168, 61, .14);
  --accent-line: rgba(90, 130, 40, .32);
  --ok: #1f8a72;
  --danger: #c8462f;
  --danger-wash: rgba(200, 70, 47, .09);
  --danger-line: rgba(200, 70, 47, .28);
  --shadow: 0 22px 44px -30px rgba(24, 28, 40, .45);
  --scrim: rgba(30, 34, 45, .38);
  color-scheme: light;
}

* { box-sizing: border-box; }

/* hidden 属性必须始终生效：class 上的 display 不能把它盖掉 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(760px 420px at 12% -8%, var(--bg-tint), transparent 70%),
    radial-gradient(620px 380px at 100% 108%, var(--bg-tint), transparent 72%);
  z-index: 0;
}

h1, h2, h3, h4, p, dl, dd, dt, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

.mono {
  font-family: var(--font-mono);
  font-size: .78em;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::selection { background: var(--accent-wash); }

/* 滚动条 */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--r-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* ---------------- 启动占位 ---------------- */
.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  background: var(--bg);
  /* 即便它因任何原因残留，也不会挡住页面点击 */
  pointer-events: none;
}
.boot-mark {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.03em;
}
.boot-line { color: var(--muted); }

/* ---------------- 头像 ---------------- */
.avatar {
  --av: var(--accent);
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  background: var(--av);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0;
  user-select: none;
  overflow: hidden;
}
.avatar-40 { width: 40px; height: 40px; }
.avatar-38 { width: 38px; height: 38px; font-size: 14px; }
.avatar-32 { width: 32px; height: 32px; font-size: 13px; }
.avatar-56 { width: 56px; height: 56px; font-size: 21px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------------- 标签 / 徽记 ---------------- */
.tag-chip {
  flex: none;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .06em;
  line-height: 1.5;
  padding: 1px 5px;
  border-radius: var(--r-xs);
  color: var(--accent);
  background: var(--accent-wash);
  border: 1px solid var(--accent-line);
  white-space: nowrap;
}
.uid-badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .08em;
  color: var(--muted);
}
.pill {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: var(--r-full);
  border: 1px solid var(--line);
  color: var(--muted);
}
.pill.is-accent { color: var(--accent); border-color: var(--accent-line); background: var(--accent-wash); }
.pill.is-danger { color: var(--danger); border-color: var(--danger-line); background: var(--danger-wash); }
.pill.is-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 560;
  color: var(--text);
  background: var(--panel-2);
  transition: background var(--dur), border-color var(--dur), color var(--dur), transform var(--dur);
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent-fill); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-fill-hover); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-danger { background: var(--danger-wash); border-color: var(--danger-line); color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.btn-quiet { background: transparent; color: var(--muted); padding: 0 8px; }
.btn-quiet:hover { color: var(--text); background: var(--panel-2); }
.btn-sm { height: 29px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  color: var(--muted);
  transition: background var(--dur), color var(--dur);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.is-on { color: var(--accent); background: var(--accent-wash); }

/* ---------------- 表单 ---------------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field > span {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.input, .textarea, .select {
  width: 100%;
  min-width: 0;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--dur), box-shadow var(--dur), background var(--dur);
}
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
.textarea { resize: vertical; line-height: 1.6; min-height: 76px; }
.select { appearance: none; padding-right: 30px; background-image: none; cursor: pointer; }
.form { display: grid; gap: 14px; }
.form-note { font-size: 12.5px; color: var(--danger); }
.form-note.is-ok { color: var(--ok); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.55; }

/* 开关 */
.switch { position: relative; display: inline-flex; flex: none; align-items: center; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
  width: 38px;
  height: 21px;
  border-radius: var(--r-full);
  background: var(--panel-3);
  border: 1px solid var(--line);
  transition: background var(--dur), border-color var(--dur);
  pointer-events: none;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform var(--dur), background var(--dur);
}
.switch input:checked + .switch-track { background: var(--accent-wash); border-color: var(--accent-line); }
.switch input:checked + .switch-track::after { transform: translateX(17px); background: var(--accent); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 分段控件 */
.seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-sm);
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.seg button {
  padding: 5px 11px;
  border-radius: var(--r-xs);
  font-size: 12.5px;
  color: var(--muted);
  transition: background var(--dur), color var(--dur);
}
.seg button:hover { color: var(--text); }
.seg button.is-active { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .18); }
.seg.is-full { display: flex; }
.seg.is-full button { flex: 1; text-align: center; }

/* 选项卡 */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
.tab { flex: 1; padding: 8px; border-radius: var(--r-xs); font-size: 13.5px; font-weight: 560; color: var(--muted); }
.tab.is-active { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .16); }

/* 自定义主题色选择 */
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.color-input {
  flex: none;
  width: 46px;
  height: 34px;
  padding: 2px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
}
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 0; border-radius: var(--r-xs); }
.color-input::-moz-color-swatch { border: 0; border-radius: var(--r-xs); }
.color-row .hint {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- 列表 ---------------- */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 14px;
  width: 100%;
  text-align: left;
  transition: background var(--dur);
}
.list-row:hover { background: var(--panel-2); }
.list-row-main { min-width: 0; flex: 1; display: grid; gap: 2px; }
.list-row-title { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 14px; font-weight: 560; }
.list-row-sub { font-size: 12.5px; color: var(--muted); }
.list-row-actions { display: flex; gap: 6px; flex: none; }
.list-head {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 14px 6px;
}
.list-sep { height: 1px; background: var(--line-soft); margin: 4px 0; }

.empty { padding: 34px 22px; text-align: center; }
.empty h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.empty p { font-size: 12.5px; color: var(--muted); }
.empty-mark {
  display: inline-block;
  margin-bottom: 10px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  border: 1px dashed var(--line);
  color: var(--muted);
}

/* ---------------- 弹层 ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  animation: fade .16s ease;
}
.modal {
  width: min(520px, 100%);
  max-height: min(86vh, 780px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise .2s cubic-bezier(.2, .8, .3, 1);
}
.modal.is-wide { width: min(880px, 100%); }
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.modal-title { font-size: 15px; font-weight: 620; flex: 1; letter-spacing: -.01em; }
.modal-body { padding: 18px; overflow: auto; flex: 1; }
.modal-body.is-flush { padding: 0; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 18px;
  border-top: 1px solid var(--line);
  flex: none;
}
.modal-close {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
}
.modal-close:hover { background: var(--panel-2); color: var(--text); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.99); } }

/* 弹出菜单：原生 <dialog>，showModal() 后位于浏览器顶层 */
.menu {
  position: fixed;
  inset: auto;
  top: 0;
  left: 0;
  margin: 0;
  z-index: auto;
  min-width: 196px;
  max-width: min(280px, calc(100vw - 16px));
  max-height: min(72vh, 560px);
  overflow: auto;
  width: fit-content;
  padding: 6px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  animation: rise .14s ease;
}
.menu::backdrop { background: transparent; }
/* showModal() 不可用时的降级形态：回到普通浮层，需要显式层级 */
.menu.is-plain { z-index: 56; }
.menu-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px 10px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 5px;
}
.menu-head-main { min-width: 0; display: grid; gap: 1px; }
.menu-head-main strong { font-size: 13.5px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--text-dim);
  text-align: left;
}
.menu-item:hover { background: var(--panel-2); color: var(--text); }
.menu-item svg { width: 16px; height: 16px; opacity: .8; }
.menu-item.is-danger { color: var(--danger); }
.menu-item.is-danger:hover { background: var(--danger-wash); }
.menu-item .menu-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--accent-fill);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  display: grid;
}

/* 提示条 */
.toast-layer {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: grid;
  gap: 8px;
  justify-items: center;
  width: min(420px, calc(100% - 32px));
  pointer-events: none;
}
.toast {
  max-width: 100%;
  padding: 9px 15px;
  border-radius: var(--r-full);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: rise .18s ease;
}
.toast.is-ok { border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.toast.is-error { border-color: var(--danger-line); color: var(--danger); }

/* ---------------- 通用排版块 ---------------- */
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: grid; gap: 14px; }
.stack-tight { display: grid; gap: 9px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.divider { height: 1px; background: var(--line); margin: 4px 0; }
.section-title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-2);
  padding: 14px;
}
.notice {
  padding: 11px 13px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.55;
}
.notice.is-danger { border-color: var(--danger-line); background: var(--danger-wash); color: var(--danger); }
.notice.is-warn { border-color: var(--accent-line); background: var(--accent-wash); color: var(--text); }

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