/* ============================================================
   口播生产台 · 设计系统
   深色专业工具风格，克制、高效、低饱和
   ============================================================ */

:root {
  --bg: #0c0f15;
  --bg-elev: #10141c;
  --surface: #151a24;
  --surface-2: #1b2230;
  --surface-3: #232b3b;
  --border: #262f40;
  --border-strong: #33405a;

  --text: #e9edf4;
  --text-dim: #9aa5b8;
  --text-faint: #6a7588;

  --primary: #4f6ef2;
  --primary-hover: #3f5ce0;
  --primary-active: #354fc7;
  --primary-soft: rgba(79, 110, 242, 0.14);
  --primary-ring: rgba(79, 110, 242, 0.35);

  --success: #3fb96a;
  --success-soft: rgba(63, 185, 106, 0.14);
  --warning: #dfa53c;
  --warning-soft: rgba(223, 165, 60, 0.14);
  --danger: #ef5350;
  --danger-soft: rgba(239, 83, 80, 0.14);
  --info: #4db6e8;
  --info-soft: rgba(77, 182, 232, 0.14);

  --radius: 12px;
  --radius-sm: 9px;
  --radius-xs: 6px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px -4px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 18px 50px -12px rgba(0, 0, 0, 0.65);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Cascadia Code", Consolas, monospace;

  --sidebar-w: 236px;
  --topbar-h: 60px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #3c4a63; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================ 布局 ============================ */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 48px;
}

/* ============================ 品牌 ============================ */
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 18px;
}
.brand-mark {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f6ef2, #7a5cf0);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 4px 14px rgba(79, 110, 242, 0.4);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: 0.5px; }
.brand-sub { font-size: 11px; color: var(--text-faint); letter-spacing: 0.4px; }

/* ============================ 导航 ============================ */
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
  user-select: none;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--text); }
.nav-item.active .nav-icon { color: var(--primary); }
.nav-icon { width: 18px; height: 18px; display: grid; place-items: center; color: var(--text-faint); }
.nav-badge {
  margin-left: auto;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-dim);
}

/* ============================ 侧边栏底部 ============================ */
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s var(--ease);
}
.user-chip:hover { background: var(--surface); }
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2f3b56, #38475f);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  flex: 0 0 auto;
}
.user-name { font-size: 13px; font-weight: 550; }
.user-role { font-size: 11px; color: var(--text-faint); }

/* ============================ 顶栏 ============================ */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(8px);
}
.page-title { font-size: 17px; font-weight: 650; margin: 0; letter-spacing: 0.3px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ============================ 按钮 ============================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: all 0.15s var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .btn-icon { width: 15px; height: 15px; }

.btn-primary {
  background: linear-gradient(135deg, #4f6ef2, #5b62f0);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px rgba(79, 110, 242, 0.35);
}
.btn-primary:hover { background: linear-gradient(135deg, #4463ea, #4f56e8); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; }

.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: var(--radius-xs);
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn .btn-icon { width: 15px; height: 15px; }

/* ============================ 卡片 ============================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 600; margin: 0; }
.card-body { padding: 16px; }

/* ============================ 统计卡 ============================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s var(--ease), transform 0.15s var(--ease);
}
.stat-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.stat-label { font-size: 12.5px; color: var(--text-dim); }
.stat-value { font-size: 26px; font-weight: 680; letter-spacing: -0.5px; }
.stat-value .unit { font-size: 13px; font-weight: 500; color: var(--text-faint); margin-left: 3px; }
.stat-delta { font-size: 12px; color: var(--text-faint); }
.stat-delta.up { color: var(--success); }

/* ============================ 表单 ============================ */
.field { margin-bottom: 14px; }
.field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 7px;
}
.field-label .req { color: var(--danger); }
.hint { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }

.input, .textarea, .select {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  padding: 9px 12px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.textarea { resize: vertical; min-height: 96px; line-height: 1.7; }
.select { appearance: none; 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='%239aa5b8' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; padding-right: 32px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.14s var(--ease);
  user-select: none;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--text); }

/* 模式切换 */
.seg {
  display: inline-flex;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}
.seg-item {
  padding: 5px 14px;
  border-radius: var(--radius-xs);
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.14s var(--ease);
  border: none;
  background: transparent;
}
.seg-item.on { background: var(--surface-3); color: var(--text); }

/* ============================ 生成页 ============================ */
.gen-layout { display: grid; grid-template-columns: minmax(360px, 5fr) minmax(440px, 6fr); gap: 18px; align-items: start; }
.gen-col { display: flex; flex-direction: column; gap: 14px; }
.gen-sticky { position: sticky; top: 0; }

.prompt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s var(--ease);
}
.prompt-card:hover { border-color: var(--border-strong); }
.prompt-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.prompt-index {
  font-size: 12px;
  font-weight: 650;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 9px;
  border-radius: 999px;
}
.prompt-tools { margin-left: auto; display: flex; gap: 2px; }
.prompt-body {
  padding: 13px 15px;
  font-size: 13px;
  line-height: 1.75;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  font-family: var(--font);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 54px 24px;
  color: var(--text-faint);
  gap: 10px;
}
.empty-icon { width: 44px; height: 44px; color: var(--border-strong); }
.empty-title { font-size: 14.5px; font-weight: 600; color: var(--text-dim); }
.empty-desc { font-size: 12.5px; max-width: 300px; }

/* ============================ 看板 ============================ */
.kanban { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: 12px; align-items: start; }
.kanban-col {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
}
.kanban-col.drag-over { border-color: var(--primary); background: var(--primary-soft); }
.kanban-col-head {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 6px 10px;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text-dim);
}
.kanban-dot { width: 8px; height: 8px; border-radius: 50%; }
.kanban-count { margin-left: auto; font-size: 11.5px; color: var(--text-faint); font-weight: 500; }
.kanban-list { display: flex; flex-direction: column; gap: 8px; flex: 1; }

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  cursor: grab;
  transition: border-color 0.14s var(--ease), transform 0.14s var(--ease);
}
.task-card:hover { border-color: var(--border-strong); }
.task-card:active { cursor: grabbing; }
.task-card.dragging { opacity: 0.4; }
.task-script {
  font-size: 12.5px;
  color: var(--text);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}
.task-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-faint);
  flex-wrap: wrap;
}
.task-meta .tag {
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text-dim);
}
.task-meta .plays { color: var(--warning); font-weight: 600; }

/* ============================ 模板 ============================ */
.tpl-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.tpl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tpl-kind {
  font-size: 11px;
  font-weight: 650;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tpl-title { font-size: 14px; font-weight: 600; }
.tpl-content {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tpl-actions { display: flex; gap: 4px; margin-left: auto; }

/* ============================ 弹窗 ============================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.6);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 50;
  animation: fadeIn 0.15s var(--ease);
}
.modal {
  width: min(480px, calc(100vw - 40px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: popIn 0.18s var(--ease);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 650; margin: 0; }
.modal-body { padding: 18px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.96) translateY(6px); } to { opacity: 1; transform: none; } }

/* ============================ Toast ============================ */
.toast-root {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 550;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.2s var(--ease);
}
.toast.success { border-color: rgba(63, 185, 106, 0.5); }
.toast.error { border-color: rgba(239, 83, 80, 0.5); }
.toast .toast-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.toast.error .toast-dot { background: var(--danger); }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ============================ 加载骨架 ============================ */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 30px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ============================ 任务行（工作台列表） ============================ */
.task-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.task-row:last-child { border-bottom: none; }
.task-row-main { flex: 1; min-width: 0; }
.task-row-script {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.task-row-time { font-size: 12px; color: var(--text-faint); flex: 0 0 auto; }

/* ============================ 模板选择弹窗 ============================ */
.tpl-pick {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 8px;
  transition: border-color 0.14s var(--ease), background 0.14s var(--ease);
}
.tpl-pick:hover { border-color: var(--primary); background: var(--primary-soft); }
.tpl-pick .tpl-content { font-size: 12px; color: var(--text-dim); line-height: 1.55; margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ============================ v2 鉴权 / 工作区 / 套餐 ============================ */
body:not(.authed) .app { display: none; }

.auth-screen {
  position: fixed; inset: 0;
  display: none;
  place-items: center;
  background: radial-gradient(1200px 800px at 50% -10%, #171d2b, var(--bg));
  z-index: 90;
}
.auth-screen.show { display: grid; }
.auth-card {
  width: min(380px, calc(100vw - 40px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 26px;
  box-shadow: var(--shadow-lg);
}
.auth-subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 16px;
}
.auth-error {
  background: var(--danger-soft);
  border: 1px solid rgba(239, 83, 80, 0.4);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

.ws-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 11px; margin: 2px 0 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer;
  transition: border-color 0.14s var(--ease);
}
.ws-chip:hover { border-color: var(--border-strong); }
.ws-chip-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ws-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-switch { color: var(--text-faint); flex: 0 0 auto; }

.plan-badge {
  font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 999px;
  width: fit-content; letter-spacing: 0.3px;
}
.plan-free { background: var(--surface-3); color: var(--text-dim); }
.plan-personal { background: var(--primary-soft); color: var(--primary); }
.plan-team { background: var(--success-soft); color: var(--success); }

.user-chip { display: flex; align-items: center; gap: 9px; padding: 8px 6px; }
.user-chip-info { flex: 1; min-width: 0; }
.user-chip-info .user-name { font-size: 13px; font-weight: 550; }
.user-chip-info .user-role { font-size: 11px; color: var(--text-faint); }
.user-chip .icon-btn { flex: 0 0 auto; }

.quota-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 14px; margin-bottom: 16px;
  background: var(--warning-soft); border: 1px solid rgba(223,165,60,0.4);
  border-radius: var(--radius); font-size: 13px;
}

.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.plan-grid .card:first-child { grid-column: 1 / -1; }
.plan-rows { display: flex; flex-direction: column; gap: 8px; }
.plan-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.plan-row:last-child { border-bottom: none; }
.plan-row-k { color: var(--text-dim); }
.plan-row-v { font-weight: 600; }

.plans-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.plan-mini { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elev); }
.plan-mini-name { font-size: 13px; font-weight: 650; margin-bottom: 3px; }
.plan-mini-price { font-size: 15px; font-weight: 700; color: var(--primary); margin-bottom: 3px; }

.code-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; margin-bottom: 6px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 13px;
}

@media (max-width: 760px) {
  .plan-grid { grid-template-columns: 1fr; }
  .plans-preview { grid-template-columns: 1fr; }
}

/* ============================ 响应式 ============================ */
@media (max-width: 1080px) {
  .gen-layout { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: repeat(5, 1fr); overflow-x: auto; }
  .kanban-col { min-width: 200px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .sidebar { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
  .tpl-grid { grid-template-columns: 1fr; }
}
