/* Neyu Bot Studio - giao diện đồng bộ với các ứng dụng Neyu Space (Kế toán, Autopost, Ads Dashboard) */
:root {
  --green-950: #0b231c; --green-900: #0f2e25; --green-800: #14392e; --green-700: #1b4d3e; --green-600: #24614e; --green-100: #e3efe9; --green-50: #f1f7f4;
  --gold: #e3a83b; --gold-600: #c48b1f; --gold-700: #9a6a10; --gold-100: #fbf0d6; --cream: #f4ecc9;
  --bg: #f6f4ee; --panel: #ffffff; --ink: #16271f; --muted: #62716a; --line: #e7e2d4; --line-2: #efebe0;
  --warn: #9a6a10; --warn-soft: #fbf0d6; --bad: #b4372d; --bad-soft: #fbe9e6; --ok: #1f7a4f; --ok-soft: #e3f3ea;
  --radius: 14px; --shadow: 0 1px 2px rgba(15, 46, 37, .06), 0 4px 16px rgba(15, 46, 37, .05);
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55; }
a { color: var(--green-700); text-underline-offset: 3px; }
a:hover { color: var(--gold-700); }
h1 { font-size: 22px; margin: 0; color: var(--green-900); letter-spacing: -.01em; line-height: 1.3; }
h2, h3 { margin: 0; color: var(--green-900); letter-spacing: -.01em; line-height: 1.3; }
p { margin: 0; }
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline: 3px solid rgba(227, 168, 59, .55); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.caption { font-size: 13px; line-height: 18px; color: var(--muted); }
.note { color: var(--muted); font-size: 13.5px; }

/* ===== Thanh trên cùng (giống Kế toán) ===== */
.topbar { position: sticky; top: 0; z-index: 20; background: linear-gradient(180deg, var(--green-900), var(--green-950)); color: var(--cream);
  display: flex; align-items: center; gap: 20px; padding: 10px 20px; padding-top: calc(10px + env(safe-area-inset-top)); box-shadow: 0 2px 12px rgba(0, 0, 0, .18); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--cream); text-decoration: none; flex: none; }
.brand:hover { color: var(--cream); }
.brand img { display: block; width: 36px; height: 36px; flex: none; }
.brand-text { line-height: 1.1; }
.brand-text b { display: block; font-size: 16px; font-weight: 800; letter-spacing: .06em; }
.brand-text b span { color: var(--gold); }
.brand-text small { display: block; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: rgba(244, 236, 201, .65); margin-top: 2px; }
.topnav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; align-items: center; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { white-space: nowrap; text-decoration: none; color: rgba(244, 236, 201, .82); padding: 7px 12px; border-radius: 8px; font-weight: 500;
  transition: background .15s, color .15s; display: inline-flex; align-items: center; gap: 6px; }
.topnav a:hover { background: rgba(244, 236, 201, .08); color: var(--cream); }
.topnav a[aria-current="page"] { background: var(--gold); color: var(--green-950); font-weight: 600; }
.topnav .sep { width: 1px; height: 22px; background: rgba(244, 236, 201, .2); margin: 0 6px; flex: none; }
.topnav .bot-name { color: var(--cream); font-weight: 700; font-size: 14px; padding: 0 6px; white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.count { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 600; padding: 1px 7px; }
.topnav a[aria-current="page"] .count { background: var(--green-900); color: var(--cream); }
.ny-user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: rgba(244, 236, 201, .75); flex: none; }
.ny-user img { width: 28px; height: 28px; border-radius: 50%; }

/* ===== Nút ===== */
.ny-btn { font: inherit; font-weight: 500; font-size: 14px; line-height: 1.3; border: 1px solid var(--line); background: var(--panel); color: var(--green-900);
  border-radius: 10px; padding: 8px 15px; cursor: pointer; text-decoration: none; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .15s, border-color .15s, transform .05s, box-shadow .15s; }
.ny-btn:hover:not(:disabled) { border-color: var(--green-600); background: var(--green-50); color: var(--green-900); }
.ny-btn:active { transform: translateY(1px); }
.ny-btn:disabled { opacity: .5; cursor: default; }
.ny-btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.ny-btn-primary { background: var(--green-700); color: #fff; border-color: var(--green-700); box-shadow: 0 2px 6px rgba(27, 77, 62, .25); }
.ny-btn-primary:hover:not(:disabled) { background: var(--green-800); border-color: var(--green-800); color: #fff; }
.ny-btn-line { }
.ny-btn-ghost { background: transparent; color: var(--cream); border-color: rgba(244, 236, 201, .35); }
.ny-btn-ghost:hover:not(:disabled) { background: rgba(244, 236, 201, .08); border-color: rgba(244, 236, 201, .7); color: var(--cream); }
.ny-btn-danger { color: var(--bad); }
.ny-btn-danger:hover:not(:disabled) { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.ny-btn-text { background: none; border: 0; padding: 2px 4px; color: var(--green-700); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none; }
.ny-btn-text:hover { color: var(--gold-700); text-decoration: underline; }
.icon { width: 17px; height: 17px; flex: none; }

/* ===== Nhãn trạng thái (pill như Kế toán) ===== */
.ny-badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 99px; background: var(--line-2); color: var(--muted); white-space: nowrap; line-height: 1.5; }
.ny-badge-ok { background: var(--ok-soft); color: var(--ok); }
.ny-badge-warn { background: var(--warn-soft); color: var(--warn); }
.ny-badge-bad { background: var(--bad-soft); color: var(--bad); }
.kind-info { background: var(--green-50); color: var(--green-700); }
.kind-faq { background: var(--gold-100); color: var(--gold-700); }
.kind-example { background: #eef0f6; color: #4a5378; }

/* ===== Ô nhập ===== */
.ny-field { display: grid; gap: 4px; min-width: 0; }
.ny-field > label { font-size: 13px; color: var(--muted); font-weight: 500; }
.ny-field input, .ny-field select, .ny-field textarea, .input {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; width: 100%; min-width: 0;
  transition: border-color .15s, box-shadow .15s; }
:where(.ny-field input, .ny-field select, .ny-field textarea, .input, td select):focus { border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(36, 97, 78, .12); outline: none; }
.ny-field textarea, textarea.input { resize: vertical; min-height: 90px; line-height: 1.55; }
.ny-field textarea.tall { min-height: 320px; }
.ny-field .hint { font-size: 12.5px; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; color: var(--ink); }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--green-700); flex: none; }
.check b { display: block; font-weight: 600; }
input[type="color"] { padding: 3px; height: 40px; width: 64px; cursor: pointer; }

/* ===== Khung trang ===== */
main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; display: grid; gap: 16px; }
main > * { min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 4px; }
.page-head .grow { flex: 1; min-width: 220px; display: grid; gap: 2px; }
.page-head .note { margin: 0; }
.page-head code { font-size: 13px; background: var(--green-50); color: var(--green-800); padding: 1px 6px; border-radius: 6px; }
.crumb { font-size: 13px; font-weight: 600; text-decoration: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 14px; }
.card h2 { font-size: 17px; font-weight: 700; }
.stack { display: grid; gap: 14px; min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.notice { border-radius: 12px; padding: 11px 15px; font-size: 14px; border: 1px solid var(--green-100); background: var(--green-50); color: var(--green-800); }
.notice-warn { background: var(--warn-soft); border-color: #f0dcaa; color: var(--gold-700); }
.notice-bad { background: var(--bad-soft); border-color: #f2cbc5; color: var(--bad); }
.notice a { color: inherit; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; font-size: 14px; }

/* Lọc dạng chip */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font: inherit; font-size: 13px; font-weight: 500; padding: 4px 12px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--green-900); transition: background .15s, border-color .15s; }
.chips button:hover { border-color: var(--green-600); background: var(--green-50); }
.chips button[aria-pressed="true"] { background: var(--green-700); border-color: var(--green-700); color: #fff; }

/* ===== Danh sách bot ===== */
.bots { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.bot-card { position: relative; overflow: hidden; display: grid; gap: 14px; text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s, transform .15s; }
.bot-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--gold); }
.bot-card:hover { color: inherit; border-color: var(--green-600); box-shadow: 0 8px 24px rgba(15, 46, 37, .1); transform: translateY(-2px); }
.bot-card .top { display: flex; gap: 12px; align-items: center; }
.bot-card .name { font-weight: 700; font-size: 16px; color: var(--green-900); }
.bot-card code { font-size: 12.5px; color: var(--muted); }
.avatar { width: 42px; height: 42px; border-radius: 12px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 800;
  font-size: 18px; overflow: hidden; background: var(--green-700); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page-head .avatar { width: 52px; height: 52px; border-radius: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--green-50); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--green-700); line-height: 1.2; }
.stat span { font-size: 12px; color: var(--muted); }
.new-bot { border: 2px dashed var(--line); background: transparent; display: grid; place-items: center; align-content: center; gap: 8px; cursor: pointer;
  font: inherit; color: var(--green-700); font-weight: 600; min-height: 190px; border-radius: var(--radius); transition: border-color .15s, background .15s; }
.new-bot:hover { border-color: var(--green-600); background: var(--panel); }
.new-bot .icon { width: 24px; height: 24px; }

/* ===== Huấn luyện: kiến thức + chat thử ===== */
.train { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
.train .chat-col { position: sticky; top: 76px; }
@media (max-width: 980px) { .train { grid-template-columns: minmax(0, 1fr); } .train .chat-col { position: static; } }

.k-list { display: grid; gap: 8px; }
.k-item { border: 1px solid var(--line-2); border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; background: var(--panel); transition: border-color .15s; }
.k-item:hover { border-color: var(--line); background: #fbfaf6; }
.k-item.off { opacity: .6; }
.k-item .k-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.k-item .k-title { font-weight: 700; flex: 1; min-width: 160px; color: var(--green-900); }
.k-item .k-body { white-space: pre-wrap; font-size: 14px; max-height: 4.8em; overflow: hidden; cursor: pointer; }
.k-item.open .k-body { max-height: none; }
.k-item .k-actions { display: flex; gap: 4px; align-items: center; }
.k-form { border: 1px solid var(--green-600); box-shadow: 0 0 0 3px rgba(36, 97, 78, .1); border-radius: 12px; padding: 14px; display: grid; gap: 12px; background: var(--panel); }

.prompt-view { white-space: pre-wrap; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--bg);
  border-radius: 10px; padding: 14px; max-height: 480px; overflow: auto; border: 1px solid var(--line); }
pre.code { white-space: pre-wrap; word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: 13px; margin: 0;
  background: var(--green-900); color: var(--cream); border-radius: 10px; padding: 14px 16px; }

/* Khung chat (chat thử và xem lại hội thoại) */
.chat { display: flex; flex-direction: column; height: min(640px, calc(100vh - 120px)); padding: 0; overflow: hidden; }
.chat-head { display: flex; gap: 10px; align-items: center; padding: 12px 14px; background: linear-gradient(180deg, var(--green-800), var(--green-900)); color: var(--cream); }
.chat-head .avatar { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }
.chat-head b { display: block; font-size: 14px; color: #fff; }
.chat-head span { font-size: 12px; color: rgba(244, 236, 201, .7); }
.chat-head .ny-btn { margin-left: auto; }
.log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 4px; background: var(--panel); }
.msg { max-width: 86%; padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; font-size: 14.5px; }
.msg.bot { align-self: flex-start; background: var(--green-50); border: 1px solid var(--green-100); border-bottom-left-radius: 5px; }
.msg.user { align-self: flex-end; background: var(--green-700); color: #fff; border-bottom-right-radius: 5px; }
.msg.user + .bot-wrap, .bot-wrap + .msg.user { margin-top: 8px; }
.bot-wrap { display: grid; gap: 3px; justify-items: start; }
.msg-tools { display: flex; gap: 6px; align-items: center; padding-left: 6px; font-size: 12px; color: var(--muted); }
.msg.error { background: var(--bad-soft); border-color: #f2cbc5; color: var(--bad); }
.typing { align-self: flex-start; background: var(--green-50); padding: 11px 13px; border-radius: 16px; display: flex; gap: 4px; margin-top: 8px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--green-600); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line-2); background: var(--panel); align-items: flex-end; }
.chat-form textarea { flex: 1; resize: none; min-height: 42px; max-height: 120px; }
.chat-meta { padding: 6px 14px 10px; font-size: 12px; color: var(--muted); background: var(--panel); }
.fix-form { border: 1px solid #f0dcaa; background: var(--gold-100); border-radius: 12px; padding: 12px; display: grid; gap: 10px; margin: 6px 0 8px; width: 100%; }
.fix-form .ny-field textarea { min-height: 70px; font-size: 14px; }

/* ===== Hội thoại ===== */
.convo { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .convo { grid-template-columns: minmax(0, 1fr); } }
.c-list { display: grid; max-height: calc(100vh - 250px); overflow-y: auto; padding: 0; }
.c-item { display: grid; gap: 2px; text-align: left; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line-2); background: var(--panel);
  font: inherit; color: inherit; cursor: pointer; width: 100%; }
.c-item:hover { background: #fbfaf6; }
.c-item[aria-current="true"] { background: var(--gold-100); box-shadow: inset 4px 0 0 var(--gold); }
.c-item .first { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--green-900); }
.c-item .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.c-detail .log { max-height: calc(100vh - 330px); min-height: 300px; border-radius: 10px; border: 1px solid var(--line-2); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 13.5px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

/* ===== Bảng ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfaf6; }
td.wrap { min-width: 200px; white-space: pre-wrap; }
td select { font: inherit; font-size: 13px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); }

/* ===== Đăng nhập ===== */
.login { min-height: calc(100vh - 140px); display: grid; place-items: center; padding: 24px 0; }
.login-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.login-card .head { padding: 26px 24px; background: linear-gradient(180deg, var(--green-900), var(--green-950)); color: var(--cream); display: grid; gap: 6px; }
.login-card .head .brand { margin-bottom: 10px; }
.login-card .head h1 { color: #fff; }
.login-card .head p { color: rgba(244, 236, 201, .75); font-size: 14px; }
.login-card .body { padding: 24px; display: grid; gap: 14px; justify-items: center; text-align: center; }
#google-btn { min-height: 44px; display: flex; justify-content: center; }

/* Thông báo nổi */
#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; justify-items: center; }
.toast { background: var(--green-900); color: var(--cream); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.toast.bad { background: var(--bad); color: #fff; }

dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(11, 35, 28, .35); }
dialog::backdrop { background: rgba(11, 35, 28, .5); }
dialog form { padding: 20px; display: grid; gap: 12px; }
dialog h2 { font-size: 19px; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
  .brand { flex: 1; }
  .topnav { order: 3; flex: 1 1 100%; margin: 0 -4px; }
  .ny-user span { display: none; }
}
@media (max-width: 600px) {
  main { padding: 14px 12px 50px; }
  .card { padding: 14px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
