/* ===================================================================
   AI 大模型采购成本表管理系统 — 样式
   主题：靛蓝(indigo #4f46e5) 浅色、留白、克制动效
   布局：ChatGPT 式 —— 对话为主，成本表为可展开右侧栏/手机抽屉
   =================================================================== */

:root {
  --indigo: #4f46e5;
  --indigo-600: #4338ca;
  --indigo-50: #eef2ff;
  --indigo-100: #e0e7ff;
  --ink: #1e1b2e;
  --ink-soft: #5b5770;
  --ink-faint: #8b87a0;
  --line: #eceaf3;
  --line-strong: #ddd9ec;
  --surface: #ffffff;
  --surface-2: #fafaff;
  --bg: #f6f5fb;
  --ok: #0d9488;
  --danger: #e11d48;
  --warn: #b45309;
  --warn-bg: #fff7ed;
  --warn-line: #fed7aa;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow-sm: 0 1px 2px rgba(30, 27, 75, .06), 0 2px 6px rgba(30, 27, 75, .05);
  --shadow-md: 0 6px 24px rgba(49, 46, 129, .10);
  --shadow-lg: 0 18px 50px rgba(49, 46, 129, .16);
  --font-display: "Sora", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-body: "Manrope", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

/* 关键：确保 hidden 属性能真正隐藏元素。
   否则 .modal / .app-view / .login-view 等设置了 display 的作者样式会覆盖
   浏览器默认的 [hidden]{display:none}，导致弹窗一直显示、关不掉。 */
[hidden] { display: none !important; }

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

/* ---------- 背景装饰 ---------- */
.bg-decor { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .5; }
.blob-1 { width: 420px; height: 420px; top: -140px; right: -100px;
  background: radial-gradient(circle at 30% 30%, #c7d2fe, #a5b4fc); }
.blob-2 { width: 360px; height: 360px; bottom: -120px; left: -80px;
  background: radial-gradient(circle at 60% 40%, #ddd6fe, #c4b5fd); opacity: .4; }
.grid-lines {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(79,70,229,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79,70,229,.04) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 30%, #000, transparent 75%);
}

/* ---------- 通用按钮 ---------- */
.btn {
  font-family: var(--font-body);
  font-weight: 600; font-size: 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary { background: var(--indigo); color: #fff; box-shadow: 0 4px 14px rgba(79,70,229,.32); }
.btn-primary:hover { background: var(--indigo-600); box-shadow: 0 8px 22px rgba(79,70,229,.40); transform: translateY(-1px); }
.btn-soft { background: var(--indigo-50); color: var(--indigo-600); }
.btn-soft:hover { background: var(--indigo-100); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line-strong); }
.btn-ghost:hover { background: #f3f1fb; color: var(--ink); }
.btn-block { width: 100%; padding: 13px; font-size: 15px; letter-spacing: .12em; }

/* ---------- 登录视图 ---------- */
.login-view {
  position: relative; z-index: 1;
  min-height: 100%; display: grid; place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 34px 32px 26px;
  box-shadow: var(--shadow-lg);
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-mark {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--indigo), #7c6cf0);
  color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 22px;
  border-radius: 13px; box-shadow: 0 6px 16px rgba(79,70,229,.35);
}
.brand-mark.sm { width: 34px; height: 34px; font-size: 16px; border-radius: 10px; }
.brand-text h1 { margin: 0; font-family: var(--font-display); font-size: 19px; letter-spacing: .01em; }
.brand-text p { margin: 3px 0 0; font-size: 12.5px; color: var(--ink-faint); }

.login-form { display: grid; gap: 16px; }
.field { display: grid; gap: 7px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.field input, .field select, .item-form input, .item-form select {
  font-family: var(--font-body); font-size: 14.5px; color: var(--ink);
  padding: 11px 13px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); transition: border-color .15s, box-shadow .15s, background .15s;
  width: 100%;
}
.field input::placeholder { color: var(--ink-faint); }
.field input:focus, .field select:focus,
.item-form input:focus, .item-form select:focus {
  outline: none; border-color: var(--indigo);
  background: #fff; box-shadow: 0 0 0 4px rgba(79,70,229,.13);
}
.form-error { color: var(--danger); font-size: 13px; margin: 2px 0 0; font-weight: 600; }
.login-foot { margin: 20px 0 0; text-align: center; font-size: 11.5px; color: var(--ink-faint); }

/* ---------- 主视图 ---------- */
.app-view { position: relative; z-index: 1; display: flex; flex-direction: column; height: 100%; }

.topbar {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: rgba(255,255,255,.82);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); z-index: 30;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title strong { font-family: var(--font-display); font-size: 15.5px; }
.topbar-sub { font-size: 11.5px; color: var(--ink-faint); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip {
  font-size: 12.5px; font-weight: 600; color: var(--indigo-600);
  background: var(--indigo-50); border: 1px solid var(--indigo-100);
  padding: 6px 11px; border-radius: 999px;
}
.model-select { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-soft); font-weight: 600; }
.model-select select {
  font-family: var(--font-body); font-size: 13px; font-weight: 600; color: var(--ink);
  padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--surface-2); max-width: 190px;
}
.model-select select:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(79,70,229,.13); }

/* ---------- 布局：对话为主 + 成本表面板 ---------- */
.app-layout {
  flex: 1; min-height: 0;
  display: flex; gap: 0;
}
.chat-pane {
  flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--line);
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
/* 收起成本表时，对话占满整行 */
.app-view:not(.table-open) .table-panel { display: none; }

/* 成本表面板（PC 右侧栏） */
.table-panel {
  flex: none; width: 460px; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface-2); border-left: 1px solid var(--line);
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}

/* ---------- 对话区 ---------- */
.chat-log {
  flex: 1; min-height: 0; overflow-y: auto;
  width: 100%; max-width: 880px; margin: 0 auto;
  padding: 22px 20px; display: flex; flex-direction: column; gap: 14px;
}
.chat-empty { margin: auto; text-align: center; color: var(--ink-faint); max-width: 420px; }
.chat-empty-ico { font-size: 30px; color: var(--indigo); opacity: .6; }
.chat-empty p { font-size: 13.5px; line-height: 1.7; margin: 10px 0 0; }
.chat-empty .eg { color: var(--indigo-600); font-weight: 600; }
.chat-empty .hint { color: var(--ink-soft); }

.msg { max-width: 88%; padding: 12px 15px; border-radius: 15px; font-size: 14.5px; line-height: 1.65; animation: pop .3s ease both; }
.msg-user { align-self: flex-end; background: var(--indigo); color: #fff; border-bottom-right-radius: 4px; }
.msg-ai { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-ai .ai-reply { color: var(--ink); white-space: normal; }
.msg-ai .ai-reply.ai-loading { color: var(--ink-faint); }
.msg-ai .ai-summary {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line-strong);
  font-size: 12.5px; color: var(--ink-soft);
}
.msg-ai .ai-label { font-weight: 700; color: var(--indigo-600); margin-right: 4px; }
.msg-clarify { background: var(--warn-bg); border: 1px solid var(--warn-line); }
.msg-clarify .ai-reply { color: #7c2d12; }
.msg-clarify .ai-tag {
  margin-top: 10px; font-size: 12px; font-weight: 700; color: var(--warn);
}

/* 输入区（ChatGPT 式 composer） */
.chat-form { flex: none; padding: 12px 20px 18px; }
.composer {
  max-width: 880px; margin: 0 auto;
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 18px; padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--indigo); box-shadow: 0 0 0 4px rgba(79,70,229,.12); }
.composer textarea {
  flex: 1; font-family: var(--font-body); font-size: 14.5px; color: var(--ink);
  resize: none; max-height: 140px; padding: 8px 0; border: none; background: transparent; line-height: 1.5;
}
.composer textarea:focus { outline: none; }
.composer-hint { max-width: 880px; margin: 8px auto 0; text-align: right; font-size: 11px; color: var(--ink-faint); }
.send-btn { width: 44px; height: 44px; flex: none; padding: 0; justify-content: center; border-radius: 13px; font-size: 19px; }
.send-ico { line-height: 1; }

/* ---------- 成本表面板 ---------- */
.pane-head {
  flex: none; display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px; padding: 18px 18px 14px; border-bottom: 1px solid var(--line);
}
.pane-title h2 { margin: 0; font-family: var(--font-display); font-size: 16.5px; }
.pane-title p { margin: 4px 0 0; font-size: 12.5px; color: var(--ink-faint); }
.muted { color: var(--ink-faint); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.table-wrap { flex: 1; min-height: 0; overflow: auto; padding: 6px 6px 14px; }

.cost-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 920px; }
.cost-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface); color: var(--ink-soft);
  font-weight: 700; text-align: left; white-space: nowrap;
  padding: 12px 14px; border-bottom: 1px solid var(--line-strong);
}
.cost-table tbody td {
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  white-space: nowrap; color: var(--ink); vertical-align: middle;
}
.cost-table tbody tr { transition: background .15s; }
.cost-table tbody tr:hover { background: var(--indigo-50); }
.cost-table .col-ops { text-align: right; position: sticky; right: 0; background: var(--surface); }
.cost-table tbody tr:hover td.col-ops { background: var(--indigo-50); }

.cell-tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.tag-region-海外 { background: #e0f2fe; color: #0369a1; }
.tag-region-国内 { background: #dcfce7; color: #15803d; }
.tag-signed-是 { background: #dcfce7; color: #15803d; }
.tag-signed-否 { background: #fee2e2; color: #b91c1c; }
.discount-val { font-weight: 700; color: var(--indigo-600); }
.discount-val::after { content: "%"; font-size: 11px; margin-left: 1px; opacity: .7; }

.row-ops { display: inline-flex; gap: 6px; }
.row-ops button {
  font-family: var(--font-body); font-size: 12px; font-weight: 600;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink-soft);
  padding: 5px 10px; border-radius: 8px; cursor: pointer; transition: all .15s;
}
.row-ops .op-edit:hover { border-color: var(--indigo); color: var(--indigo-600); }
.row-ops .op-del:hover { border-color: var(--danger); color: var(--danger); }

.table-empty { padding: 40px; text-align: center; color: var(--ink-faint); font-size: 13.5px; }

/* 手机抽屉遮罩 */
.table-scrim {
  display: block;
  position: fixed; inset: 0; z-index: 55;
  background: rgba(30,27,75,.42); opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}

/* ---------- 模态（移动端可滚动，保存按钮常驻底部） ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(30,27,75,.42); backdrop-filter: blur(3px); animation: fade .2s ease; }
.modal-card {
  position: relative; width: min(560px, 100%); max-height: calc(100vh - 32px);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg);
  animation: pop .25s cubic-bezier(.2,.7,.2,1) both;
}
.modal-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 12px; }
.modal-head h3 { margin: 0; font-family: var(--font-display); font-size: 17px; }
.modal-x { border: none; background: transparent; font-size: 24px; line-height: 1; color: var(--ink-faint); cursor: pointer; }
.modal-x:hover { color: var(--ink); }
.item-form { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 6px 20px 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-wide { grid-column: 1 / -1; }
.modal-foot { position: sticky; bottom: 0; flex: none; background: var(--surface); padding: 12px 20px 18px; border-top: 1px solid var(--line); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(12px);
  z-index: 80; background: var(--ink); color: #fff; font-size: 13.5px; font-weight: 600;
  padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow-md);
  opacity: 0; transition: opacity .25s, transform .25s; max-width: 88vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.toast.warn { background: var(--warn); }

/* ---------- 动效 ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: scale(1); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 响应式：≤720px 改为抽屉 ---------- */
@media (max-width: 720px) {
  body { overflow: auto; }
  .app-view { height: auto; min-height: 100%; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-right { flex-wrap: wrap; }

  .app-layout { flex-direction: column; }
  .chat-pane { border-right: none; min-height: 70vh; }
  .chat-log { padding: 16px 14px; }
  .composer, .composer-hint, .chat-log { max-width: 100%; }
  .chat-form { padding: 12px 14px 16px; }

  /* 成本表：全屏抽屉，从右滑入 */
  .table-panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: 100%;
    z-index: 60; transform: translateX(100%);
    transition: transform .28s cubic-bezier(.2,.7,.2,1);
    box-shadow: var(--shadow-lg); border-left: none;
  }
  .app-view.table-open .table-panel { transform: translateX(0); }
  .app-view:not(.table-open) .table-panel { display: flex; transform: translateX(100%); }

  .table-scrim { display: block; }
  .app-view.table-open .table-scrim { opacity: 1; pointer-events: auto; }

  .table-close { display: inline-flex; }
  .toolbar { justify-content: stretch; }
  .toolbar .btn { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
}
.table-close { display: none; }

@media (min-width: 721px) {
  .table-close { display: inline-flex; }
}

/* 极窄屏微调 */
@media (max-width: 420px) {
  .login-card { padding: 26px 20px 20px; }
  .brand-text h1 { font-size: 17px; }
}
