/* ================================================================
   NoraX Design System — 全局基础样式
   所有页面共享：变量、reset、header、sidebar、scrollbar、
   button、input、modal、toast
   ================================================================ */

:root {
  --bg-body:       #0b0b10;
  --bg-header:     #0e0e15;
  --bg-sidebar:    #0e0e15;
  --bg-chat:       #0b0b10;
  --bg-card:       #111118;
  --bg-hover:      #15151e;
  --bg-active:     rgba(124, 58, 237, 0.07);
  --bg-input:      #0e0e15;

  --border-subtle: #181820;
  --border-card:   #1c1c26;

  --brand:         #8b5cf6;
  --brand-hover:   #7c3aed;
  --brand-soft:    rgba(139, 92, 246, 0.10);
  --danger:        #ef4444;
  --danger-soft:   rgba(239, 68, 68, 0.10);

  --t1: #f5f5f6;
  --t2: #a1a1aa;
  --t3: #71717a;
  --t4: #52525b;

  --header-h: 48px;
  --sidebar-w: 252px;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --transition: 0.12s ease;
}

/* 亮色模式 */
body.light {
  --bg-body:       #dce0e4;
  --bg-header:     #e6e8eb;
  --bg-sidebar:    #e3e5e8;
  --bg-chat:       #dce0e4;
  --bg-card:       #e6e8eb;
  --bg-hover:      #d0d4d8;
  --bg-active:     rgba(124, 58, 237, 0.09);
  --bg-input:      #e3e5e8;

  --border-subtle: #c8ccd0;
  --border-card:   #b8bcc0;

  --t1: #1e1e2a;
  --t2: #444452;
  --t3: #636370;
  --t4: #8e8e9a;

  --brand:         #7c3aed;
  --brand-hover:   #6d28d9;
  --brand-soft:    rgba(124, 58, 237, 0.15);
}

/* 主题切换按钮 — 仅 home 页 */
.home-only .theme-toggle { display: flex; }
.theme-toggle {
  position: fixed; left: 8px; bottom: 160px; z-index: 100;
  width: 38px; height: 38px; display: none; align-items: center; justify-content: center;
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: var(--r-sm); color: var(--t3); font-size: 16px;
  cursor: pointer; transition: all var(--transition);
}
.theme-toggle:hover { border-color: var(--brand); color: var(--brand); }

/* 字体缩放 — 仅 home 页 */
.home-only .font-scale-group { display: flex; }
.font-scale-group {
  position: fixed; left: 8px; bottom: 240px; z-index: 100;
  display: none; flex-direction: column; align-items: center; gap: 2px;
}
.fs-btn, .fs-val {
  width: 38px; height: 28px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: var(--r-sm); color: var(--t3); font-size: 13px;
  cursor: pointer; transition: all var(--transition); font-family: inherit;
}
.fs-btn:hover { border-color: var(--brand); color: var(--brand); }
.fs-val { cursor: default; font-size: 11px; font-weight: 500; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-body); color: var(--t1);
  height: 100vh; overflow: hidden;
  font-size: 13px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* =================================================================
   HEADER
   ================================================================= */
.header {
  height: var(--header-h); background: var(--bg-header);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; color: var(--t1);
  cursor: pointer; user-select: none; flex-shrink: 0;
}
.header-logo .mark { color: var(--brand); font-size: 19px; line-height: 1; }
.header-divider { color: var(--t4); font-size: 12px; flex-shrink: 0; }
.header-agent { color: var(--brand); font-weight: 600; font-size: 13px; flex-shrink: 0; }
.header-chat {
  color: var(--t3); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-info {
  display: flex; align-items: center; gap: 18px;
  font-size: 12px; color: var(--t3); flex-shrink: 0;
}
.header-info .credits { color: var(--brand); font-weight: 600; }

/* =================================================================
   MAIN LAYOUT
   ================================================================= */
.main { display: flex; flex: 1; overflow: hidden; }

/* =================================================================
   SIDEBAR
   ================================================================= */
.sidebar {
  width: var(--sidebar-w); background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-top { padding: 16px 16px 0; }
.sidebar-section { padding: 14px 16px; }
.sidebar-label {
  font-size: 10px; color: var(--t4); text-transform: uppercase;
  letter-spacing: 1px; margin-bottom: 10px;
}
.sidebar-foot { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot .row { display: flex; gap: 6px; }

/* =================================================================
   BUTTONS
   ================================================================= */
.btn-back {
  display: block; width: 100%; padding: 7px 0; text-align: center;
  background: var(--bg-hover); border-radius: var(--r-sm);
  color: var(--t3); font-size: 12px; cursor: pointer;
  border: 1px solid transparent; transition: all var(--transition);
}
.btn-back:hover { color: var(--t2); border-color: var(--border-card); }

.btn-side {
  flex: 1; padding: 7px 0; text-align: center; font-size: 11px;
  border-radius: var(--r-sm); cursor: pointer; color: var(--t3);
  background: transparent; border: 1px solid var(--border-card);
  transition: all var(--transition);
}
.btn-side:hover { border-color: var(--brand); color: var(--brand); }
.btn-side.full { flex: none; }

.btn-primary {
  padding: 8px 20px; background: var(--brand); border: none;
  border-radius: var(--r-sm); color: #fff; font-size: 12px;
  font-weight: 500; cursor: pointer; transition: background var(--transition);
}
.btn-primary:hover { background: var(--brand-hover); }

.btn-ghost {
  padding: 6px 13px; font-size: 11px; color: var(--t3);
  background: transparent; border: 1px solid var(--border-card);
  border-radius: var(--r-sm); cursor: pointer; transition: all var(--transition);
}
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-ghost.on {
  background: var(--brand-soft); border-color: var(--brand); color: var(--brand);
}

.btn-export {
  padding: 4px 12px; font-size: 11px; color: var(--t3);
  background: transparent; border: 1px solid var(--border-card);
  border-radius: var(--r-sm); cursor: pointer; transition: all var(--transition);
}
.btn-export:hover { border-color: var(--brand); color: var(--brand); }

/* =================================================================
   INPUT
   ================================================================= */
.input-field {
  padding: 8px 14px; font-size: 12px; color: var(--t1);
  background: var(--bg-input); border: 1px solid var(--border-card);
  border-radius: var(--r-sm); outline: none; font-family: inherit;
  transition: border-color var(--transition);
}
.input-field:focus { border-color: var(--brand); }
.input-field::placeholder { color: var(--t4); }

/* =================================================================
   MODAL
   ================================================================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: var(--r-lg); max-width: 92vw; max-height: 82vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 600; color: var(--t1); }
.modal-close {
  font-size: 18px; color: var(--t4); cursor: pointer;
  padding: 2px 6px; border-radius: var(--r-sm); transition: all var(--transition);
}
.modal-close:hover { color: var(--t1); background: var(--bg-hover); }
.modal-body {
  flex: 1; overflow-y: auto; padding: 16px 20px;
}

/* =================================================================
   TOAST
   ================================================================= */
.toast-container {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column;
  align-items: center; gap: 10px; pointer-events: none;
}
.toast {
  min-width: 200px; max-width: 350px;
  padding: 12px 20px; border-radius: var(--r-sm);
  background: var(--bg-card); color: var(--t1);
  font-size: 13px; text-align: center;
  border-left: 3px solid var(--brand);
  opacity: 0; transform: translateY(-16px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-left-color: #22c55e; }
.toast.error   { border-left-color: #ef4444; }
.toast.warning { border-left-color: #f59e0b; }
.toast.info    { border-left-color: #3b82f6; }

/* =================================================================
   SCROLLBARS
   ================================================================= */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a3a50; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #4e4e66; }

body.light ::-webkit-scrollbar-thumb { background: #c0c0cc; }
body.light ::-webkit-scrollbar-thumb:hover { background: #a0a0b0; }

/* =================================================================
   移动端适配（≤768px）
   ================================================================= */
#mobileMenuBtn { display: none; }

@media (max-width: 768px) {
  #mobileMenuBtn {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; font-size: 18px; color: var(--t2);
    cursor: pointer; flex-shrink: 0; border-radius: var(--r-sm);
  }
  #mobileMenuBtn:hover { background: var(--bg-hover); }

  .header { padding: 0 12px; padding-top: env(safe-area-inset-top, 0px); }
  .header-info { gap: 10px; font-size: 11px; }
  .header-logo { font-size: 13px; }
  .header-agent { font-size: 11px; }
  .header-chat { display: none; }
  .header-divider { display: none; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 9999;
    width: 260px; transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .sidebar.open { transform: translateX(0); }

  /* 侧栏遮罩 */
  .sidebar-overlay {
    position: fixed; inset: 0; z-index: 9998;
    background: rgba(0,0,0,0.5); display: none;
  }
  .sidebar-overlay.show { display: block; }

  .main { flex-direction: column; }
  .chat-area { width: 100%; }
  .messages { padding: 16px 12px; gap: 16px; }
  .msg { max-width: 88% !important; }
  .msg-body { font-size: 13px !important; padding: 10px 12px !important; }

  .input-zone { padding: 0 8px 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .input-card .text-zone { padding: 10px 12px; }
  .input-card textarea { font-size: 13px; min-height: 40px; }
  .input-card .ctrls { padding: 0 10px 10px; gap: 6px; flex-wrap: wrap; }
  .ctrls .spacer { display: none; }

  .pipeline-bar { padding: 8px 12px; overflow-x: auto; }
  .templates-bar { padding: 8px 12px 0; }

  /* Hub 卡片竖排 */
  .hub-grid { grid-template-columns: 1fr !important; }
  .category-section { padding: 0 12px; }

  /* Admin 表格横向滚 */
  .admin-table-wrap { overflow-x: auto; }

  /* Credits 卡片 */
  .credits-cards { flex-direction: column; gap: 12px; padding: 0 12px; }
}
