/* 轻酒馆 · 基础样式：设计变量、布局骨架、通用控件。
   聊天区在 chat.css，各管理面板在 panels.css。 */

:root {
  /* 深色（默认）：炭黑底 + 灯火琥珀色 */
  --bg: #101216;
  --bg-raised: #171a20;
  --bg-panel: #1c2028;
  --bg-input: #12151a;
  --bg-hover: #252a34;
  --border: #2b313c;
  --border-strong: #3b4350;
  --text: #dfe3ea;
  --text-dim: #9aa3b2;
  --text-faint: #6b7483;
  --accent: #e8a33d;
  --accent-hover: #f2b556;
  --accent-text: #1a1305;
  --accent-soft: rgba(232, 163, 61, 0.14);
  --danger: #e5646a;
  --danger-soft: rgba(229, 100, 106, 0.14);
  --ok: #5fba7d;
  --quote: #e8a33d; /* 对白引号内的文字 */
  --emph: #a9b4c6; /* 斜体（动作、心理） */
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);

  --radius: 10px;
  --radius-sm: 6px;
  --topbar-h: 46px;
  --chat-width: 880px;
  --font: system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  --chat-font-size: 16px;
  color-scheme: dark;
}

:root[data-theme='light'] {
  --bg: #f3f1ec;
  --bg-raised: #fbfaf7;
  --bg-panel: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #efece5;
  --border: #dedad0;
  --border-strong: #c7c2b5;
  --text: #23262b;
  --text-dim: #5d6470;
  --text-faint: #8a909b;
  --accent: #b9741a;
  --accent-hover: #a36414;
  --accent-text: #ffffff;
  --accent-soft: rgba(185, 116, 26, 0.12);
  --danger: #c4424a;
  --danger-soft: rgba(196, 66, 74, 0.1);
  --ok: #2f8f55;
  --quote: #a8600c;
  --emph: #5d6470;
  --shadow: 0 10px 30px rgba(60, 50, 30, 0.18);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

#app {
  height: 100dvh;
}

.boot {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  letter-spacing: 0.3em;
}

a {
  color: var(--accent);
}

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

/* 细滚动条 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

/* ---------- 布局骨架 ---------- */

.shell {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: none;
  height: var(--topbar-h);
  padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 8px;
  height: 34px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.topbar-title:hover {
  background: var(--bg-hover);
}

.topbar-title .sub {
  color: var(--text-faint);
  font-weight: 400;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-title .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ---------- 抽屉（顶栏图标打开的面板） ---------- */

.drawer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.35);
}

.drawer {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 21;
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: drawer-in-left 0.16s ease-out;
}

.drawer.right {
  right: 0;
  border-right: 0;
  border-left: 1px solid var(--border);
  animation-name: drawer-in-right;
}

.drawer.wide {
  width: min(760px, 100%);
}

@keyframes drawer-in-left {
  from {
    transform: translateX(-16px);
    opacity: 0;
  }
}

@keyframes drawer-in-right {
  from {
    transform: translateX(16px);
    opacity: 0;
  }
}

.drawer-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-head h2 {
  flex: 1;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
}

/* ---------- 通用控件 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.btn:hover {
  background: var(--bg-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

.btn.danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn.ghost {
  border-color: transparent;
  background: none;
}

.btn.ghost:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn.small {
  height: 28px;
  padding: 0 9px;
  font-size: 13px;
}

.btn.block {
  width: 100%;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-dim);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.icon-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.icon-btn.small {
  width: 28px;
  height: 28px;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn.small .icon,
.btn.small .icon {
  width: 16px;
  height: 16px;
}

.btn .icon {
  width: 17px;
  height: 17px;
}

:is(button, a, input, textarea, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.input,
.textarea,
.select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.input,
.select {
  height: 34px;
}

.textarea {
  min-height: 84px;
  line-height: 1.5;
  resize: vertical;
}

.textarea.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}

.input:disabled,
.textarea:disabled,
.select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 触屏设备：输入框字号不小于 16px，否则 iOS Safari 聚焦时会自动放大页面 */
@media (pointer: coarse) {
  .input,
  .textarea,
  .select {
    font-size: 16px;
  }
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field > .label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--text-dim);
}

.field > .hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-faint);
}

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

.row.wrap {
  flex-wrap: wrap;
}

.row > .grow {
  flex: 1;
  min-width: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

.spacer {
  flex: 1;
}

.muted {
  color: var(--text-dim);
}

.faint {
  color: var(--text-faint);
}

.small {
  font-size: 13px;
}

.danger-text {
  color: var(--danger);
}

.section-title {
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.section-title:first-child {
  margin-top: 0;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  padding: 12px;
}

.divider {
  height: 1px;
  margin: 14px 0;
  background: var(--border);
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 10px;
  background: var(--bg-hover);
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}

.chip.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

/* 开关 */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 14px;
}

.toggle input {
  appearance: none;
  flex: none;
  width: 34px;
  height: 20px;
  margin: 0;
  border-radius: 10px;
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}

.toggle input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}

.toggle input:checked {
  background: var(--accent);
}

.toggle input:checked::after {
  transform: translateX(14px);
}

/* 列表项 */
.list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-width: 0;
}

.list-item:hover {
  background: var(--bg-hover);
}

.list-item.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.list-item .main {
  flex: 1;
  min-width: 0;
}

.list-item .title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item .desc {
  font-size: 12px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  background: var(--bg-hover);
  display: grid;
  place-items: center;
  color: var(--text-dim);
  font-weight: 600;
  overflow: hidden;
}

.empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--text-faint);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- 弹窗、菜单、提示 ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  /* 列宽不随内容撑开，否则一行被截断的长文字会把弹窗顶出屏幕 */
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.5);
}

.modal {
  width: min(520px, 100%);
  max-height: min(86dvh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal.wide {
  width: min(860px, 100%);
}

.modal-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 12px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  flex: 1;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.modal-foot {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.menu {
  position: fixed;
  z-index: 120;
  min-width: 180px;
  max-width: min(320px, calc(100vw - 16px));
  max-height: min(70dvh, 520px);
  overflow-y: auto;
  padding: 5px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--bg-hover);
}

.menu-item.danger {
  color: var(--danger);
}

.menu-item:disabled {
  opacity: 0.45;
  cursor: default;
}

.menu-sep {
  height: 1px;
  margin: 5px 4px;
  background: var(--border);
}

.toasts {
  position: fixed;
  left: 50%;
  /* 放在顶栏下方：底部是输入框和「重试」这类马上要点的东西，不能挡 */
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 10px);
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(480px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  max-width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  font-size: 14px;
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
  overflow-wrap: anywhere;
}

.toast.error {
  border-color: var(--danger);
  color: var(--danger);
}

.toast.ok {
  border-color: var(--ok);
}

@keyframes toast-in {
  from {
    transform: translateY(-8px);
    opacity: 0;
  }
}

/* ---------- 登录页 ---------- */

.login {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
}

.login-card {
  width: min(360px, 100%);
  padding: 28px 24px 22px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.login-brand img {
  width: 44px;
  height: 44px;
}

.login-brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.04em;
}

.login-brand p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-faint);
}

.login-error {
  min-height: 20px;
  margin: 2px 0 10px;
  font-size: 13px;
  color: var(--danger);
}

.login-foot {
  margin-top: 16px;
  display: flex;
  justify-content: center;
}

.login-foot .select {
  width: auto;
  height: 28px;
  padding: 0 6px;
  font-size: 12px;
  color: var(--text-dim);
  background: none;
  border-color: transparent;
}

@media (max-width: 640px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .drawer,
  .drawer.wide {
    width: 100%;
    border: 0;
  }

  .modal-backdrop {
    padding: 0;
    place-items: end stretch;
  }

  .modal,
  .modal.wide {
    width: 100%;
    max-height: 92dvh;
    border-radius: 14px 14px 0 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
}
