/* Buunix Command: presentation only. Base component contracts remain in app.css. */
:root {
  --bg: #11121b; --surface: #1b1c27; --surface2: #242530; --surface3: #2a2c39;
  --border: #30323f; --border2: #484b5c; --text: #f4f5f8; --muted: #b2b5c4; --faint: #989cad;
  --accent: #53c6f1; --accent-soft: rgba(83,198,241,.1); --accent-hi: #91e1ff;
  --action: #ff880a; --action-hover: #ff9e35; --action-soft: rgba(255,136,10,.12);
  --green: #78ddb0; --red: #ff9199; --amber: #ffce79;
  --radius: 14px; --ring: 0 0 0 3px rgba(83,198,241,.45);
  --shadow: 0 16px 48px rgba(0,0,0,.3);
  color-scheme: dark;
}
[hidden] { display: none !important; }
html, body { min-width: 0; }
body { background: var(--bg); font-size: 14px; }
button, input, select, textarea, a { -webkit-tap-highlight-color: transparent; }
button, a, input, select, textarea { touch-action: manipulation; }
button { overflow-wrap: anywhere; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; box-shadow: none; }
input, textarea, select { border-radius: 10px; border-color: var(--border2); }
input::placeholder, textarea::placeholder { color: var(--faint); opacity: 1; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: var(--ring); }
.btn { min-height: 38px; padding: 8px 16px; border-radius: 10px; box-shadow: none; }
.btn-primary { background: var(--action); color: #18120b; border: 1px solid var(--action); box-shadow: none; font-weight: 800; }
.btn-primary:hover { background: var(--action-hover); border-color: var(--action-hover); box-shadow: none; filter: none; }
.btn-primary:disabled { opacity: .55; }
.btn-sm { min-height: 32px; }
.btn-danger:hover, .copy-btn:hover { box-shadow: none; }
.skip-link { position: fixed; left: 16px; top: -80px; z-index: 200; padding: 12px 18px; background: var(--surface3); border: 2px solid var(--accent); border-radius: 10px; }
.skip-link:focus { top: 12px; }
.shell { height: 100dvh; overflow: hidden; }
.main { grid-template-columns: 232px minmax(0,1fr); }
.sidebar { background: var(--surface); padding: 24px 14px 14px; overflow-y: auto; }
.brand { padding: 0 10px 26px; }
.brand-wordmark { width: 174px; height: 28px; object-fit: contain; display: block; }
.brand .b-sub { margin-top: 8px; font-size: 11px; letter-spacing: .055em; }
.brand-mark { display: none; width: 30px; height: 30px; object-fit: contain; }
.nav { gap: 6px; }
.nav-btn { min-height: 44px; padding: 11px 14px; border: 1px solid transparent; position: relative; font-size: 13px; }
.nav-btn.active { background: var(--action-soft); color: #ffb361; border-color: rgba(255,136,10,.28); box-shadow: none; }
.nav-btn.active::before { content: ''; position: absolute; left: -1px; top: 11px; bottom: 11px; width: 3px; border-radius: 4px; background: var(--action); }
.nav-symbol { display: none; width: 20px; height: 20px; flex: 0 0 auto; }
.nav-symbol svg, .bn-icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-label { margin: 14px 14px 10px; color: var(--faint); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.userchip { background: var(--bg); padding: 12px; min-width: 0; }
.u-meta { min-width: 0; }
.u-name { overflow-wrap: anywhere; }
.avatar { box-shadow: none; }
.content { min-width: 0; overflow: hidden; }
.command-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; padding: 16px 28px; border-bottom: 1px solid var(--border); background: var(--bg); }
.command-heading { min-width: 0; }
.command-heading strong { font-size: 15px; letter-spacing: -.02em; }
.command-heading small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.command-search { display: flex; align-items: center; justify-content: space-between; gap: 24px; color: var(--muted); background: var(--surface); min-height: 40px; min-width: 190px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.command-search kbd { border: 1px solid var(--border2); border-radius: 4px; padding: 1px 5px; font-size: 10px; }
.workspace-body { display: flex; flex: 1; min-height: 0; min-width: 0; overflow: hidden; }
.view-stack { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; }
.view.active { animation: command-enter .16s ease-out; }
@keyframes command-enter { from { opacity: 0; } to { opacity: 1; } }
.view-head { padding: 26px 28px 18px; align-items: flex-start; flex-direction: column; gap: 6px; }
.view-head h1 { font-size: 24px; letter-spacing: -.045em; line-height: 1.2; }
.view-head .sub { max-width: 660px; font-size: 13px; line-height: 1.6; }
/* Ask: a calm, readable workspace, not a decorative hero. */
.ask-wrap { max-width: 1020px; padding: 0 32px; }
.thread { padding: 24px 2px; gap: 20px; scroll-behavior: auto; overflow-wrap: anywhere; }
.ask-empty { max-width: 740px; width: 100%; text-align: left; padding: 30px 0; }
.ask-empty .big { width: 58px; height: 58px; border-radius: 16px; margin: 0 0 20px; font-size: 0; background: var(--surface); border: 1px solid var(--border); box-shadow: none; display: grid; place-items: center; }
.ask-empty .big img { width: 30px; height: 30px; }
.ask-empty h2 { font-size: clamp(25px,3vw,36px); line-height: 1.2; letter-spacing: -.055em; margin-bottom: 12px; }
.ask-empty p { max-width: 600px; line-height: 1.65; font-size: 14px; margin-bottom: 24px; }
.sugg { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.sugg button { position: relative; text-align: left; padding: 17px 32px 17px 16px; min-height: 76px; border-radius: 12px; line-height: 1.5; color: var(--text); font-size: 12px; border-color: var(--border); }
.sugg button::after { content: '↗'; position: absolute; right: 14px; top: 17px; color: var(--action); font-size: 16px; }
.sugg button:hover { transform: none; border-color: var(--action); box-shadow: none; background: var(--surface2); }
.ask-inputrow { padding: 12px 0 18px; border-top: 1px solid var(--border); }
.ask-inputrow textarea { min-width: 0; background: var(--surface); font-size: 14px; }
.ask-inputrow .btn-primary, .ask-inputrow .ask-stop { height: 46px; }
.ask-limit { margin: -12px 0 12px; font-size: 12px; color: var(--muted); text-align: right; }
.ask-limit.over { color: var(--red); font-weight: 600; }
.msg-bot .m-body { max-width: 100%; background: var(--surface); border: 1px solid var(--border); padding: 20px 22px; border-radius: 14px; line-height: 1.65; }
.msg-bot > .avatar { font-size: 0; background: var(--surface) url('/img/buunix-mark.png') center/20px 20px no-repeat !important; box-shadow: none; border: 1px solid var(--border); }
.msg-user .m-body { background: #29251f; border-color: #59452d; color: var(--text); padding: 12px 16px; }
.md h3 { font-size: 16px; letter-spacing: -.01em; }
.md p { line-height: 1.7; }
.md blockquote { border-left-color: var(--accent); background: var(--accent-soft); }
.m-meta { padding-top: 12px; border-top: 1px solid var(--border); margin-top: 18px; gap: 8px; }
.src-chip { white-space: normal; text-align: left; max-width: 100%; min-height: 34px; border-radius: 8px; padding: 6px 10px; line-height: 1.45; font-size: 11px; }
.src-chip:hover { transform: none; box-shadow: none; }
.copy-btn { min-height: 36px; padding: 7px 12px; border-radius: 8px; font-size: 12px; }
.copy-btn.copied, .src-chip.copied { background: var(--green-soft) !important; color: var(--green) !important; border-color: var(--green) !important; }
/* Chips and the native-dialog reader. */
.chips { padding-left: 28px; padding-right: 28px; }
.chips { gap: 8px; }
.chip { min-height: 34px; padding: 6px 12px; font-size: 11px; border-color: var(--border); }
.chip:hover { transform: none; }
.reference-panel { display: none; position: static; flex: 0 0 min(560px,44%); width: min(560px,44%); max-width: 50%; max-height: none; min-width: 0; height: 100%; margin: 0; padding: 0; color: var(--text); background: var(--surface); border: 0; border-left: 1px solid var(--border2); }
.reference-panel[open] { display: flex; flex-direction: column; }
.reference-content { overflow-y: auto; padding: 24px; min-height: 0; width: 100%; overflow-wrap: anywhere; }
.reference-content .modal-head { position: sticky; top: -24px; background: var(--surface); margin: -1px -1px 18px; padding: 1px 1px 16px; border-bottom: 1px solid var(--border); z-index: 1; }
.reference-content .modal-head h2 { font-size: 19px; letter-spacing: -.025em; }
.reference-content .modal-head .x { flex: 0 0 auto; }
.reference-panel::backdrop { background: rgba(6,7,13,.7); }
/* Team chat. */
.chat-grid { grid-template-columns: 240px minmax(0,1fr); }
.conv-list { padding: 18px 12px; background: var(--surface); }
.conv { min-height: 40px; white-space: normal; }
.conv:hover { transform: none; }
.chat-head { min-height: 64px; padding: 16px 24px; flex-wrap: wrap; }
.chat-msgs { padding: 24px; scroll-behavior: auto; }
.cmsg { padding: 8px; }
.chat-inputrow { padding: 16px 24px 22px; border-top: 1px solid var(--border); }
.chat-inputrow input { min-width: 0; }
.typing-line { color: var(--muted); }
/* Admin uses the same system with denser, readable tables. */
.admin-main { grid-template-columns: 232px minmax(0,1fr); }
.admin-main .panel { padding: 30px 32px; }
.admin-main .sec-head { gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.admin-main .sec-head h2 { font-size: 24px; letter-spacing: -.04em; }
.admin-main .sec-head input, .admin-main .sec-head select { max-width: 100%; min-width: 0 !important; }
.stat-grid { gap: 14px; margin-bottom: 30px; }
.stat { padding: 22px; background: var(--surface); }
.stat:hover { transform: none; box-shadow: none; }
.stat .s-num { font-size: 30px; background: none !important; color: var(--text); -webkit-text-fill-color: currentColor; }
.stat.accent .s-num { color: var(--accent); }
.stat.green .s-num { color: var(--green); }
.stat.amber .s-num { color: var(--amber); }
.tbl-wrap { border: 1px solid var(--border); }
.tbl th, .tbl td { padding: 13px 16px; }
.tbl th { color: var(--muted); font-size: 10px; }
.tbl tbody tr:hover td { background: var(--surface2); }
.tab { min-height: 36px; }
/* Login: no credential, first-login, or access changes. */
.login-body { background: radial-gradient(ellipse at 15% 10%,rgba(255,136,10,.055),transparent 55%),var(--bg); padding: 28px 18px; }
.login-card { width: 430px; max-width: 100%; padding: 38px; border-radius: 20px; background: var(--surface); border-color: var(--border); box-shadow: var(--shadow); animation: none; }
.login-card .brand { padding-bottom: 28px; }
.login-card .brand-wordmark { width: 174px; height: 28px; }
.login-card h1 { font-size: 26px; color: var(--text); font-weight: 700; letter-spacing: -.04em; }
.login-card .sub { margin: 10px 0 28px; line-height: 1.6; }
.login-card label { text-transform: none; font-size: 12px; letter-spacing: 0; margin-top: 18px; color: var(--text); }
.login-card input { min-height: 46px; }
.login-card .btn-primary { height: 46px; margin-top: 24px; }
.login-foot { border-top: 1px solid var(--border); padding-top: 20px; margin-top: 20px; line-height: 1.7; color: var(--muted); }
.modal-backdrop { align-items: center; }
.pill { white-space: nowrap; }
/* Member app: toasts sit above the Ask / chat input rows so they never cover Send (on phones, below the header). */
.bottomnav ~ .toast-wrap { bottom: 104px; }
.modal { max-height: calc(100dvh - 40px); overflow-y: auto; border-radius: 16px; box-shadow: var(--shadow); animation: command-enter .16s ease-out; }
.toast { line-height: 1.5; }
@media (max-width: 1200px) {
  .main, .admin-main { grid-template-columns: 196px minmax(0,1fr); }
  .brand-wordmark { width: 150px; height: 25px; }
}
@media (max-width: 1100px) {
  .reference-panel { position: fixed; inset: 0 0 0 auto; width: min(540px,95vw); max-width: none; max-height: none; height: 100dvh; margin: 0; }
}
@media (max-width: 860px) and (min-width: 701px) {
  .main, .admin-main { grid-template-columns: 72px minmax(0,1fr); }
  .sidebar { padding: 20px 10px; }
  .sidebar .brand { padding: 0 10px 24px; }
  .sidebar .brand-wordmark, .sidebar .b-sub, .nav-label, .sidebar .u-meta { display: none; }
  .sidebar .brand-mark, .nav-symbol { display: block; }
  .nav-btn { padding: 12px; justify-content: center; }
  .userchip { justify-content: center; padding: 8px; }
  .command-header { padding-left: 22px; padding-right: 22px; }
}
@media (max-width: 700px) {
  body { font-size: 14px; }
  .main { grid-template-columns: minmax(0,1fr); }
  .sidebar { display: none; }
  .content { padding-bottom: calc(64px + env(safe-area-inset-bottom,0px)); }
  .command-header { padding: 12px 16px; min-height: 64px; gap: 10px; }
  .command-heading strong { font-size: 14px; }
  .command-heading small { font-size: 10px; }
  .command-search { min-width: 0; min-height: 40px; font-size: 11px; padding: 8px 10px; }
  .command-search kbd { display: none; }
  .ask-wrap { padding: 0 16px; }
  .thread { padding-top: 14px; gap: 14px; }
  .ask-empty { padding: 16px 0; margin-top: 0; }
  .ask-empty .big { width: 46px; height: 46px; margin-bottom: 16px; }
  .ask-empty h2 { font-size: 27px; }
  .ask-empty p { font-size: 12px; margin-bottom: 18px; }
  .sugg { grid-template-columns: 1fr; gap: 8px; }
  .sugg button { min-height: 58px; padding: 13px 30px 13px 14px; }
  /* A multiline field gets the full phone width; the action no longer crowds it. */
  .ask-inputrow { display: grid; grid-template-columns: minmax(0,1fr); gap: 8px; flex-shrink: 0; padding-bottom: 12px; }
  .ask-inputrow textarea { width: 100%; min-height: 120px; padding: 12px 14px; line-height: 1.5; resize: none; overflow-y: auto; }
  .ask-inputrow .btn-primary, .ask-inputrow .ask-stop { justify-self: end; min-width: 96px; }
  input, select, textarea, .ask-inputrow textarea { font-size: 16px; }
  .msg { gap: 6px; }
  .msg-bot > .avatar { display: none; }
  .msg-bot .m-body { padding: 16px; max-width: 100%; }
  .msg-user .m-body { max-width: 94%; }
  .view-head { padding: 20px 16px 14px; }
  .view-head h1 { font-size: 24px; }
  .chips { padding-left: 16px; padding-right: 16px; }
  .chip { min-height: 40px; }
  .bottomnav { min-height: 64px; background: var(--surface); padding: 7px 4px calc(7px + env(safe-area-inset-bottom,0px)); backdrop-filter: none; }
  .bn-icon { width: 21px; height: 21px; display: block; }
  .bn-btn { min-height: 48px; gap: 4px; }
  .bn-btn .bn-label { font-size: 10px; }
  .bn-btn.active { color: #ffb361; }
  .bn-btn.active::before { background: var(--action); box-shadow: none; top: -7px; width: 26px; }
  .reference-panel { inset: auto 0 0; width: 100%; height: 90dvh; border-radius: 18px 18px 0 0; border: 1px solid var(--border2); }
  .reference-content { padding: 20px 18px calc(20px + env(safe-area-inset-bottom,0px)); }
  .reference-content .modal-head { top: -20px; }
  .reference-content .modal-head h2 { font-size: 20px; }
  .chat-grid { grid-template-columns: minmax(0,1fr); }
  .chat-head, .chat-msgs { padding: 16px; }
  .chat-inputrow { padding: 12px 16px 16px; }
  .chat-head .sub { width: 100%; }
  .toast-wrap { bottom: calc(78px + env(safe-area-inset-bottom,0px)); right: 12px; left: 12px; align-items: flex-end; }
  .bottomnav ~ .toast-wrap { top: calc(var(--header-h, 80px) + 8px); bottom: auto; }
  .toast { max-width: 100%; }
  .modal-backdrop { padding: 12px; }
  .modal { max-height: calc(100dvh - 24px); }
  /* Admin's rail must not disappear while its grid reserves an empty column. */
  .admin-main { grid-template-columns: minmax(0,1fr); height: 100dvh; grid-template-rows: auto minmax(0,1fr); }
  .admin-main .sidebar { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 8px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .admin-main .sidebar .brand, .admin-main .sidebar .spacer, .admin-main .sidebar .userchip, .admin-main .sidebar .nav-label { display: none; }
  .admin-main .sidebar .nav { flex-direction: row; flex-shrink: 0; gap: 4px; }
  .admin-main .sidebar .nav-btn { width: auto; white-space: nowrap; min-height: 44px; font-size: 11px; padding: 8px 10px; flex-shrink: 0; margin: 0; }
  .admin-main .sidebar .nav-btn span.txt, .admin-main .sidebar .adminlink span.txt { display: inline; }
  .admin-main .panel { padding: 20px 16px; }
  .admin-main .sec-head h2 { font-size: 23px; }
  .admin-main .sec-head input, .admin-main .sec-head select { width: 100% !important; }
  .stat { padding: 16px; }
  .stat-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .tbl th, .tbl td { padding: 12px; }
  .login-card { padding: 28px 22px; }
}
/* Preserve conversation space in short viewports without returning to one line. */
@media (max-width: 700px) and (max-height: 500px) {
  .ask-inputrow { grid-template-columns: minmax(0,1fr) auto; }
  .ask-inputrow textarea { min-height: 96px; }
  .ask-inputrow .btn-primary, .ask-inputrow .ask-stop { min-width: 76px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (min-width: 701px) { #chat-back { display: none; } }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Phone Ask composer: four readable lines without sacrificing input width.
   Keep the existing JS auto-grow/reset and 140px cap; only the layout changes. */
@media (max-width: 700px) {
  .ask-inputrow {
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .ask-inputrow textarea {
    flex: 0 0 auto;
    width: 100%;
    min-height: 122px;
    max-height: 140px;
    padding: 12px 14px;
    line-height: 1.5;
    resize: none;
    overflow-y: auto;
  }
  .ask-inputrow .btn-primary, .ask-inputrow .ask-stop {
    align-self: flex-end;
    flex: 0 0 auto;
    min-width: 88px;
    height: 44px;
  }
}
/* Short viewports need a compact row so navigation stays reachable. */
@media (max-width: 700px) and (max-height: 500px) {
  .thread { padding-block: 8px; }
  .ask-inputrow { flex-direction: row; align-items: flex-end; }
  .ask-inputrow textarea { flex: 1 1 auto; width: 0; min-height: 72px; max-height: clamp(72px, calc(100dvh - 264px), 112px); }
}

/* Ask: streamed answers. The trace lists the research steps; the answer re-renders as markdown while it streams. */
.thread { overflow-x: hidden; }
.msg-bot .m-body { flex: 1 1 auto; min-width: 0; }
.ask-inputrow .ask-stop { border-radius: 12px; min-width: 96px; background: var(--surface2); border-color: var(--border2); }
.ask-inputrow .ask-stop:hover { border-color: var(--action); }
.ask-stop-icon { width: 10px; height: 10px; border-radius: 2px; background: var(--action); flex: 0 0 auto; }
.ask-trace { margin: 0 0 14px; font-size: 12px; color: var(--muted); }
.ask-trace summary { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; min-height: 30px; padding: 3px 10px 3px 8px; border-radius: 8px; cursor: pointer; list-style: none; line-height: 1.45; }
.ask-trace summary::-webkit-details-marker { display: none; }
.ask-trace summary:hover { background: var(--surface2); color: var(--text); }
.ask-trace.done summary::before { content: '✓'; color: var(--green); font-weight: 700; }
.ask-trace.done summary::after { content: '›'; color: var(--faint); transition: transform .15s; }
.ask-trace.done[open] summary::after { transform: rotate(90deg); }
.ask-trace-now { min-width: 0; overflow-wrap: anywhere; }
.ask-trace:not(.done) .ask-trace-now { color: var(--text); }
.ask-steps { list-style: none; margin: 6px 0 0 12px; padding: 2px 0 2px 14px; border-left: 1px solid var(--border2); display: grid; gap: 5px; }
.ask-steps:empty { display: none; }
.ask-steps li { position: relative; padding-left: 18px; line-height: 1.5; overflow-wrap: anywhere; }
.ask-steps li::before { content: '✓'; position: absolute; left: 0; color: var(--green); font-weight: 700; }
.ask-answer { min-width: 0; }
.ask-alert, .ask-note { margin: 12px 0 0; font-size: 13px; line-height: 1.55; }
.ask-alert { color: var(--red); }
.ask-note { color: var(--amber); }
.m-meta > * { max-width: 100%; }
.ask-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%; }
.ask-sources { width: 100%; margin-top: 6px; }
.ask-sources-h { margin: 4px 0 8px; color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.ask-sources-list { display: flex; flex-wrap: wrap; gap: 8px; }
.src-source { flex-wrap: wrap; column-gap: 8px; row-gap: 1px; max-width: min(100%, 440px); }
.src-source .src-title { min-width: 0; color: var(--text); font-weight: 600; }
.src-source .src-where { flex-basis: 100%; color: var(--faint); font-size: 10.5px; font-weight: 500; }
.src-source:hover .src-title { color: var(--accent); }
.cite-chip { color: var(--accent); border-color: rgba(83,198,241,.32); background: var(--accent-soft); }
.cite-chip:hover { background: rgba(83,198,241,.2); border-color: var(--accent); }
/* Wide tables scroll in their own box: the side with hidden columns fades out (classes set by common.js) and the
   box's scrollbar stays visible against the dark surface. */
.md-table.more-right { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 56px), rgba(0,0,0,.18)); mask-image: linear-gradient(to right, #000 calc(100% - 56px), rgba(0,0,0,.18)); }
.md-table.more-left { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 56px), rgba(0,0,0,.18)); mask-image: linear-gradient(to left, #000 calc(100% - 56px), rgba(0,0,0,.18)); }
.md-table.more-left.more-right { -webkit-mask-image: linear-gradient(to right, rgba(0,0,0,.18), #000 56px, #000 calc(100% - 56px), rgba(0,0,0,.18)); mask-image: linear-gradient(to right, rgba(0,0,0,.18), #000 56px, #000 calc(100% - 56px), rgba(0,0,0,.18)); }
.md-table::-webkit-scrollbar-thumb { background: var(--border2); background-clip: padding-box; }
.code-chip, .k-code { font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--accent); }
.code-chip { padding: 1px 8px; border-radius: 6px; background: var(--accent-soft); border: 1px solid rgba(83,198,241,.3); line-height: 1.6; }

/* Reference reader: library articles and Buunix notes. */
.reader-titles { flex: 1; min-width: 0; }
.reader-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; margin-bottom: 8px; color: var(--muted); font-size: 11.5px; line-height: 1.5; }
.reader-crumb { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; }
button.reader-crumb { color: var(--accent); cursor: pointer; }
button.reader-crumb:hover { text-decoration: underline; }
.reader-crumb-sep { color: var(--faint); }
.reader-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.reader-original { display: inline-flex; align-items: center; gap: 3px; min-height: 30px; color: var(--accent); font-weight: 700; }
.reader-original:hover { text-decoration: underline; }
.reader-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.reader-ask { color: #ffb361; border-color: rgba(255,136,10,.45); background: transparent; }
.reader-ask:hover { background: var(--action-soft); border-color: var(--action); }
.reader-toc { margin: 0 0 18px; padding: 8px 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; font-size: 12.5px; }
.reader-toc summary { display: flex; align-items: center; min-height: 32px; color: var(--text); font-weight: 700; cursor: pointer; }
.reader-toc ol { list-style: none; display: grid; gap: 1px; max-height: 300px; margin: 4px 0; padding: 0; overflow-y: auto; }
.reader-toc li.sub { padding-left: 14px; }
.reader-toc button { width: 100%; min-height: 30px; padding: 4px 0; border: 0; background: none; color: var(--muted); font: inherit; line-height: 1.45; text-align: left; cursor: pointer; }
.reader-toc button:hover { color: var(--accent); }
.reference-content h2:focus { outline: none; }
.reader-body { font-size: 13.5px; line-height: 1.7; }
.reader-body :is(h3, h4, h5, h6):focus { outline: none; }
.reader-facts { display: grid; gap: 10px; margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12.5px; }
.reader-facts dt { color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.reader-facts dd { margin: 2px 0 0; color: var(--text); }

/* Library: sources, collections, grouped article lists and search results; the reader opens beside it. */
.library-scroll { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; }
.library-head { padding-bottom: 10px; }
.library-tools { position: sticky; top: 0; z-index: 2; padding: 8px 28px 14px; background: var(--bg); }
.library-tools input { width: 100%; min-height: 46px; padding: 10px 14px 10px 40px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23989cad' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") 14px center/16px 16px no-repeat; }
.library-nav { display: grid; gap: 12px; padding: 0 28px 8px; }
.library-sources { display: flex; flex-wrap: wrap; gap: 8px; }
.library-source { display: inline-flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--muted); font: 700 12.5px var(--font); cursor: pointer; transition: color .15s, border-color .15s, background .15s; }
.library-source:hover { color: var(--text); border-color: var(--border2); }
.library-source.active { color: #ffb361; background: var(--action-soft); border-color: rgba(255,136,10,.4); }
.library-source .n { color: var(--faint); font: 600 11px var(--mono); }
.library-source.active .n { color: inherit; opacity: .8; }
.library-collections { padding: 0; }
.library-body { padding: 8px 28px 32px; }
.library-empty { padding: 40px 16px; color: var(--muted); text-align: center; }
.library-empty p { margin: 0 0 14px; line-height: 1.6; }
.library-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.library-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 12px; }
.library-card { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-height: 112px; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; text-align: left; cursor: pointer; transition: border-color .15s; }
.library-card:hover { border-color: var(--accent); }
.library-card-name { font-size: 14.5px; font-weight: 700; line-height: 1.35; }
.library-card-n { color: var(--muted); font-size: 12px; }
.library-card-secs { color: var(--faint); font-size: 11.5px; line-height: 1.5; }
.library-list-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 12px; margin: 4px 0 14px; }
.library-list-head h2 { margin: 0; font-size: 17px; letter-spacing: -.025em; line-height: 1.35; }
.library-jump { margin: 0 0 16px; }
.library-jump summary { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; }
.library-jump summary:hover { color: var(--text); }
.library-jump summary .n { color: var(--faint); font: 600 11px var(--mono); }
.library-jump .chips { padding: 6px 0 4px; }
.library-group { margin-bottom: 18px; }
.library-group-h { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; color: var(--faint); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; scroll-margin-top: 84px; }
.library-group-h:focus { outline: none; }
.library-group-h .n { font: 600 11px var(--mono); letter-spacing: 0; }
.library-rows, .library-hits { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.library-row, .library-hit { width: 100%; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; text-align: left; cursor: pointer; transition: border-color .15s, background .15s; }
.library-row:hover, .library-hit:hover { border-color: var(--accent); }
.library-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 46px; padding: 10px 14px; border-radius: 10px; }
.library-row-title { min-width: 0; font-size: 13.5px; font-weight: 600; line-height: 1.45; overflow-wrap: anywhere; }
.library-row-meta { display: flex; flex: 0 0 auto; align-items: center; gap: 10px; color: var(--faint); font-size: 11.5px; white-space: nowrap; }
.library-hit { display: flex; flex-direction: column; gap: 5px; padding: 14px 16px; border-radius: 12px; }
.library-hit-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; color: var(--faint); font-size: 11.5px; }
.library-hit-where { overflow-wrap: anywhere; }
.library-hit-title { font-size: 14px; font-weight: 700; line-height: 1.45; overflow-wrap: anywhere; }
.library-hit-snippet { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; color: var(--muted); font-size: 12.5px; line-height: 1.55; overflow-wrap: anywhere; }
.library-hits + .library-group-h { margin-top: 24px; }
/* Draft / KO badges on library articles (Buunix documents). */
.tag { display: inline-flex; align-items: center; min-height: 18px; padding: 0 7px; border-radius: 999px; font-size: 10.5px; font-weight: 700; line-height: 1.5; letter-spacing: .02em; white-space: nowrap; flex: 0 0 auto; }
.tag-draft { color: var(--amber); background: rgba(255,206,121,.08); border: 1px dashed rgba(255,206,121,.6); }
.tag-lang { color: var(--muted); background: var(--surface3); border: 1px solid var(--border2); font-family: var(--mono); }
.src-source .tag { align-self: center; }
/* Buunix's own rules (BX-) cite in the brand's warm tone; platform docs stay blue. */
.cite-chip[data-open-code^="BX-"] { color: #ffb361; background: var(--action-soft); border-color: rgba(255,136,10,.38); }
.cite-chip[data-open-code^="BX-"]:hover { background: rgba(255,136,10,.2); border-color: var(--action); }
:is(.src-chip, .library-row, .library-hit)[data-open-code^="BX-"] :is(.code, .k-code) { color: #ffb361; }

/* Language: EN ⇄ 한국어 switch in the sidebar (icon-only on the rail), two-option switch in the phone profile sheet. */
.lang-switch .lang-opts { display: inline-flex; align-items: center; gap: 4px; padding: 3px; border: 1px solid var(--border2); border-radius: 999px; }
.lang-opt { padding: 2px 10px; border-radius: 999px; color: var(--muted); font-size: 12px; font-weight: 700; line-height: 1.6; }
.lang-opt.on { background: var(--action-soft); color: #ffb361; }
.lang-sep { color: var(--faint); font-size: 12px; }
.lang-switch:hover .lang-opt:not(.on) { color: var(--text); }
.u-voice { margin-top: 2px; color: var(--faint); font-size: 10.5px; line-height: 1.3; overflow-wrap: anywhere; }
.sheet-label { margin: 16px 0 8px; color: var(--muted); font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.lang-seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 4px; background: var(--bg); border: 1px solid var(--border2); border-radius: 12px; }
.lang-seg-btn { min-height: 44px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--muted); font: 700 14px var(--font); cursor: pointer; }
.lang-seg-btn:hover { color: var(--text); }
.lang-seg-btn.on { background: var(--action-soft); border-color: rgba(255,136,10,.4); color: #ffb361; cursor: default; }
.voice-line { margin: 12px 0 0; color: var(--faint); font-size: 12px; }

/* Korean: Hangul falls back per glyph from Inter to Noto Sans KR (see --font). Korean text breaks between words, not
   inside them (overflow-wrap still rescues an over-long word), gets taller lines, and loses Inter's tight tracking. */
html:lang(ko) body, [lang="ko"] { word-break: keep-all; }
.md:lang(ko) :is(p, li), .reader-body:lang(ko), .msg-user .m-body:lang(ko), .c-text:lang(ko), .library-hit-snippet:lang(ko) { line-height: 1.8; }
:is(h1, h2, h3, h4):lang(ko), .reference-content .modal-head h2:lang(ko), .admin-main .sec-head h2:lang(ko), .library-list-head h2:lang(ko) { letter-spacing: -.01em; }
.bn-btn .bn-label:lang(ko) { letter-spacing: 0; }

@media (max-width: 700px) {
  /* A phone table too wide for the screen becomes one card per row, each value under its column name. */
  .md-table.stacked { overflow: visible; border: 0; border-radius: 0; -webkit-mask-image: none; mask-image: none; }
  .md-table.stacked :is(table, tbody, tr, td) { display: block; }
  .md-table.stacked thead { display: none; }
  .md-table.stacked tr { margin: 0 0 8px; padding: 2px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
  .md-table.stacked td { min-width: 0; max-width: none; padding: 8px 0; border: 0; border-bottom: 1px solid var(--border); background: none; }
  .md-table.stacked td:last-child { border-bottom: 0; }
  .md-table.stacked td::before { content: attr(data-label); display: block; margin-bottom: 2px; color: var(--faint); font-size: 10.5px; font-weight: 700; letter-spacing: .04em; line-height: 1.4; }
  .md-table.stacked td[data-label=""]::before { content: none; }
  .command-search { flex: 0 0 auto; white-space: nowrap; }
  .ask-trace summary { padding-left: 4px; }
  .library-head { padding-bottom: 6px; }
  .library-tools { padding: 6px 16px 10px; }
  .library-nav { gap: 10px; padding: 0 16px 6px; }
  /* Tabs and chips scroll sideways inside their own row on phones. */
  .library-sources, .library-collections { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; padding-bottom: 4px; }
  .library-sources > *, .library-collections > * { flex: 0 0 auto; white-space: nowrap; overflow-wrap: normal; }
  .library-body { padding: 6px 16px 24px; }
  .library-row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .library-row-meta { white-space: normal; }
  .library-card { min-height: 0; padding: 16px; }
  .reader-actions .btn { width: 100%; }
}
