/* AI Hub - dark theme */
:root {
  --bg: #0f1117;
  --bg2: #171a23;
  --bg3: #1e2230;
  --line: #2a2f3f;
  --txt: #e6e9f2;
  --dim: #8b93a7;
  --acc: #5b8cff;
  --acc2: #7c5bff;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --rad: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--txt);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
}
.hidden { display: none !important; }
button {
  background: var(--bg3); color: var(--txt); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 14px; cursor: pointer; font-size: 13px;
  transition: all .15s;
}
button:hover { border-color: var(--acc); }
button.primary { background: linear-gradient(135deg, var(--acc), var(--acc2)); border: none; color: #fff; }
button.primary:hover { filter: brightness(1.15); }
button.ghost { background: transparent; }
button.tiny { padding: 3px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, textarea, select {
  background: var(--bg2); color: var(--txt); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; font-family: inherit;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--acc); }
.badge { background: var(--bg3); border: 1px solid var(--line); border-radius: 20px; padding: 3px 12px; font-size: 12px; color: var(--dim); }

/* gate */
.gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 100; }
.gate-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 40px; width: 340px; text-align: center; }
.gate-card h1 { margin-bottom: 8px; }
.gate-card p { color: var(--dim); margin-bottom: 16px; }
.gate-card input { width: 100%; margin-bottom: 12px; text-align: center; }
.gate-card button { width: 100%; }
.err { color: var(--err); }

/* app layout */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 20px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { font-size: 16px; white-space: nowrap; }
.brand .sub { color: var(--dim); font-size: 12px; margin-left: 8px; }
.tabs { display: flex; gap: 6px; flex: 1; }
.tab { border: none; background: transparent; padding: 8px 16px; border-radius: 8px; color: var(--dim); font-size: 14px; }
.tab.active { background: var(--bg3); color: var(--txt); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.tab-panel { flex: 1; overflow: hidden; display: none; }
.tab-panel.active { display: flex; }

/* ===== CHAT ===== */
.chat-layout { display: flex; flex: 1; overflow: hidden; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.empty-hint { text-align: center; color: var(--dim); margin: 80px auto; font-size: 15px; }
.empty-hint small { color: var(--dim); opacity: .7; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, #2b4a9e, #4a2d9e); }
.msg.ai { align-self: flex-start; background: var(--bg3); border: 1px solid var(--line); }
.msg.err { align-self: flex-start; background: rgba(248,113,113,.12); border: 1px solid var(--err); color: var(--err); }
.msg .role-tag { display: block; font-size: 11px; color: var(--dim); margin-bottom: 4px; }
.msg.ai .role-tag { color: var(--acc); }
.chat-input-row { display: flex; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--bg2); }
.chat-input-row textarea { flex: 1; resize: none; max-height: 140px; }
.chat-meta { display: flex; gap: 14px; align-items: center; padding: 8px 20px; color: var(--dim); font-size: 12px; border-top: 1px solid var(--line); }
.chat-meta label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* memory panel */
.mem-panel { width: 280px; border-left: 1px solid var(--line); background: var(--bg2); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.mem-panel h3 { font-size: 14px; }
.mem-panel .hint { color: var(--dim); font-size: 12px; }
.mem-facts { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.mem-fact { background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; position: relative; line-height: 1.5; }
.mem-fact .x { position: absolute; top: 4px; right: 8px; color: var(--dim); cursor: pointer; font-size: 11px; background: none; border: none; padding: 0; }
.mem-fact .x:hover { color: var(--err); }
.mem-add-row { display: flex; gap: 6px; }
.mem-add-row input { flex: 1; padding: 6px 10px; font-size: 12px; }
.mem-foot { border-top: 1px solid var(--line); padding-top: 8px; text-align: right; }

/* ===== HISTORY ===== */
.hist-layout { display: flex; flex: 1; overflow: hidden; }
.hist-side { width: 380px; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--bg2); }
.hist-search-row { display: flex; gap: 8px; padding: 12px; }
.hist-search-row input { flex: 1; }
.hist-filters { display: flex; gap: 6px; padding: 0 12px 10px; flex-wrap: wrap; }
.chip { border-radius: 20px; padding: 4px 12px; font-size: 12px; background: var(--bg3); color: var(--dim); border: 1px solid var(--line); }
.chip.active { color: #fff; background: var(--acc); border-color: var(--acc); }
.hist-list { flex: 1; overflow-y: auto; }
.hist-item { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.hist-item:hover { background: var(--bg3); }
.hist-item.active { background: var(--bg3); border-left: 3px solid var(--acc); }
.hist-item .t { font-size: 13px; margin-bottom: 3px; word-break: break-all; }
.hist-item .m { font-size: 11px; color: var(--dim); display: flex; gap: 8px; }
.hist-item .m .src { color: var(--acc); }
.hist-foot { padding: 10px 12px; border-top: 1px solid var(--line); text-align: right; }
.hist-detail { flex: 1; overflow: hidden; background: var(--bg); display: flex; flex-direction: column; }
.hist-msgs { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.hist-chat { border-top: 1px solid var(--line); background: var(--bg2); }
.hist-msgs .msg { max-width: 92%; }
.hist-msgs .msg.ai { background: var(--bg3); }
.hist-msgs .msg.user { background: #22315e; }

/* ===== MAIL ===== */
#tab-mail { flex-direction: column; }
.mail-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--bg2); gap: 10px; flex-wrap: wrap; }
.mail-filters { display: flex; gap: 6px; }
.mail-tools { display: flex; gap: 8px; align-items: center; }
.mail-status { padding: 8px 20px; color: var(--dim); font-size: 12px; }
.mail-list { flex: 1; overflow-y: auto; padding: 10px 20px 30px; }
.mail-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin-bottom: 10px; cursor: pointer; transition: border-color .15s; }
.mail-card:hover { border-color: var(--acc); }
.mail-card .row1 { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.acc-tag { font-size: 11px; padding: 1px 8px; border-radius: 10px; }
.acc-tag.gmail { background: rgba(234,67,53,.18); color: #ff8a80; }
.acc-tag.outlook { background: rgba(0,120,212,.18); color: #6ec3ff; }
.mail-card .from { font-weight: 600; font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-card .date { color: var(--dim); font-size: 12px; white-space: nowrap; }
.mail-card .subject { font-size: 13px; margin-bottom: 4px; }
.mail-card .preview { color: var(--dim); font-size: 12px; line-height: 1.5; max-height: 3.2em; overflow: hidden; }
.mail-card .actions { margin-top: 8px; display: flex; gap: 8px; align-items: center; }
.mail-summary { background: rgba(52,211,153,.08); border: 1px solid rgba(52,211,153,.3); border-radius: 8px; padding: 10px; margin-top: 8px; font-size: 12px; line-height: 1.7; white-space: pre-wrap; }
.mail-full { margin-top: 10px; background: var(--bg3); border-radius: 8px; padding: 12px; font-size: 12px; white-space: pre-wrap; line-height: 1.7; max-height: 400px; overflow-y: auto; }

/* toast */
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--line); padding: 10px 20px; border-radius: 10px; z-index: 200; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.toast.err { border-color: var(--err); color: var(--err); }
.toast.ok { border-color: var(--ok); color: var(--ok); }

/* mail batch summary */
.mail-toolbar2 { display: flex; align-items: center; gap: 10px; padding: 8px 20px; border-bottom: 1px solid var(--line); background: var(--bg2); }
.mail-toolbar2 .hint { color: var(--dim); font-size: 12px; }
.mail-summary-row { background: rgba(52,211,153,.06); border-bottom: 1px solid rgba(52,211,153,.25); padding: 12px 20px; }
.mail-summary-row .mail-summary { font-size: 13px; line-height: 1.8; white-space: pre-wrap; max-height: 320px; overflow-y: auto; }
.mail-summary-actions { display: flex; gap: 8px; margin-top: 10px; }

/* email iframe */
.mail-iframe-wrap { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.mail-iframe-wrap iframe { display: block; width: 100%; border: none; background: #fff; }

/* mem fact edit */
.mem-fact textarea { width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; color: var(--txt); font-size: 12px; padding: 6px; resize: vertical; min-height: 40px; font-family: inherit; }
.mem-fact .save-row { display: flex; gap: 6px; margin-top: 6px; }

/* ===== RESPONSIVE (mobile) ===== */
@media (max-width: 900px) {
  .topbar { padding: 8px 12px; gap: 10px; flex-wrap: wrap; }
  .brand .sub { display: none; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; text-align: center; padding: 8px 4px; font-size: 13px; }
  .mem-panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: 82vw; max-width: 320px;
    z-index: 150; box-shadow: -8px 0 30px rgba(0,0,0,.5);
    transform: translateX(100%); transition: transform .25s ease;
  }
  .mem-panel.open { transform: translateX(0); }
  .mem-close { display: block !important; }
  .hist-layout { flex-direction: column; }
  .hist-side { width: 100%; border-right: none; border-bottom: 1px solid var(--line); max-height: 42vh; }
  .hist-detail { flex: 1; min-height: 0; }
  .chat-layout { flex-direction: column; }
  .msg { max-width: 92%; }
  .mail-toolbar, .mail-toolbar2 { flex-wrap: wrap; padding: 8px 12px; }
  .mail-tools { flex: 1; justify-content: flex-end; }
}

@media (max-width: 480px) {
  .chat-meta { flex-wrap: wrap; gap: 8px; }
  .chat-meta label { width: 100%; }
  .chat-input-row { padding: 8px 10px; }
  .gate-card { width: 90vw; padding: 30px 24px; }
  .mail-card .row1 { flex-wrap: wrap; }
  .mail-card .date { width: 100%; }
}
