/* Project Knowledge Agent PoC — "engineering ledger" look: warm paper, TCS navy ink, amber mark, blueprint grid */
:root {
  --paper: #F4F0E8; --paper-2: #FBF9F4; --ink: #0B2E59; --ink-2: #1F2933; --muted: #6B7280; --rule: #D9D2C3; --rule-2: #EAE4D7;
  --amber: #E39B00; --amber-2: #FFF1CF; --teal: #0E8C7F; --teal-2: #DDF3EF; --red: #B23A2E; --red-2: #FBE3DF; --blue: #1F6FB2; --blue-2: #E1ECF8;
  --display: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  --mono: "IBM Plex Mono", "Consolas", monospace;
  --rail: 248px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--body); color: var(--ink-2); background: var(--paper); font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .55;
  background-image: linear-gradient(rgba(11,46,89,.045) 1px, transparent 1px), linear-gradient(90deg, rgba(11,46,89,.045) 1px, transparent 1px);
  background-size: 32px 32px; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

/* ---------- shell */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; position: relative; z-index: 1; }
.rail { background: var(--ink); color: #E6EDF7; padding: 28px 22px; display: flex; flex-direction: column; gap: 28px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { font-family: var(--display); font-weight: 800; font-size: 20px; letter-spacing: .04em; color: var(--ink); background: var(--amber); width: 46px; height: 46px; display: grid; place-items: center; border-radius: 4px; }
.brand-title { font-family: var(--display); font-size: 15px; font-weight: 700; line-height: 1.25; }
.brand-sub { font-family: var(--mono); font-size: 10.5px; color: #9FB3D1; letter-spacing: .06em; margin-top: 3px; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { color: #C9D6EA; padding: 9px 10px; border-radius: 4px; display: flex; gap: 12px; align-items: baseline; font-size: 13.5px; border-left: 2px solid transparent; }
nav a .n { font-family: var(--mono); font-size: 11px; color: #7E95BA; width: 20px; }
nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
nav a.active { background: rgba(227,155,0,.14); color: #fff; border-left-color: var(--amber); }
nav a.active .n { color: var(--amber); }
.rail-foot { margin-top: auto; font-size: 11.5px; color: #9FB3D1; display: flex; flex-direction: column; gap: 10px; }
.rail-status { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; }
.rail-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #F0A500; box-shadow: 0 0 0 4px rgba(240,165,0,.18); }
.rail-status.ok .dot { background: #2BD4A4; box-shadow: 0 0 0 4px rgba(43,212,164,.18); }
.rail-status.bad .dot { background: #FF6B6B; }
.rail-tcs { font-family: var(--mono); letter-spacing: .18em; font-size: 9.5px; color: #7E95BA; }

.main { padding: 36px 44px 64px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--ink); padding-bottom: 14px; margin-bottom: 24px; }
.kicker { font-family: var(--mono); font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--amber); font-weight: 600; }
h1 { font-family: var(--display); font-size: 30px; font-weight: 700; color: var(--ink); margin: 6px 0 4px; letter-spacing: .01em; line-height: 1.25; }
.lede { color: var(--muted); max-width: 760px; margin: 0; }
h2 { font-family: var(--display); font-size: 18px; color: var(--ink); margin: 0 0 10px; font-weight: 700; }
h3 { font-size: 13.5px; margin: 0 0 6px; color: var(--ink); font-weight: 700; }

/* ---------- reveal */
.reveal > * { animation: rise .55s cubic-bezier(.2,.7,.2,1) both; }
.reveal > *:nth-child(1) { animation-delay: .02s } .reveal > *:nth-child(2) { animation-delay: .08s } .reveal > *:nth-child(3) { animation-delay: .14s }
.reveal > *:nth-child(4) { animation-delay: .20s } .reveal > *:nth-child(5) { animation-delay: .26s } .reveal > *:nth-child(6) { animation-delay: .32s }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- cards & grid */
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); } .g5 { grid-template-columns: repeat(5, 1fr); }
.card { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 6px; padding: 18px 20px; position: relative; box-shadow: 0 1px 0 rgba(11,46,89,.04); }
.card.ink { background: var(--ink); color: #E6EDF7; border-color: var(--ink); }
.card.ink h2, .card.ink h3 { color: #fff; }
.card::before, .card::after { content: ""; position: absolute; width: 10px; height: 10px; border-color: var(--ink); border-style: solid; opacity: .35; }
.card::before { top: -1px; left: -1px; border-width: 1px 0 0 1px; } .card::after { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }
.card.ink::before, .card.ink::after { border-color: var(--amber); opacity: .9; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.card-head .sub { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.card.ink .sub { color: #9FB3D1; }

/* ---------- KPI */
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .v { font-family: var(--mono); font-size: 34px; font-weight: 600; color: var(--ink); line-height: 1; letter-spacing: -.02em; }
.kpi .v small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi.amber .v { color: var(--amber); }
.kpi.teal .v { color: var(--teal); }

/* ---------- funnel */
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel .row { display: grid; grid-template-columns: 34px 1fr 70px; align-items: center; gap: 10px; }
.funnel .row .s { font-family: var(--mono); font-weight: 600; color: var(--ink); }
.funnel .bar { height: 22px; background: var(--rule-2); border-radius: 3px; overflow: hidden; position: relative; }
.funnel .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ink), var(--blue)); border-radius: 3px; transform-origin: left; animation: grow .9s cubic-bezier(.2,.7,.2,1) both; }
.funnel .row.z .bar i { background: linear-gradient(90deg, var(--amber), #F6C453); }
.funnel .n { font-family: var(--mono); text-align: right; font-size: 12.5px; }
.funnel .d { font-size: 11.5px; color: var(--muted); grid-column: 2 / 4; margin-top: -4px; }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---------- tables */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--ink); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--rule-2); vertical-align: top; }
tr:hover td { background: rgba(11,46,89,.03); }
td.mono, .code { font-family: var(--mono); font-size: 12px; }
.tbl-wrap { overflow: auto; max-height: 520px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper-2); }
.tbl-wrap table th { position: sticky; top: 0; background: var(--paper-2); z-index: 1; }

/* ---------- badges */
.badge { display: inline-block; font-family: var(--mono); font-size: 10.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.b-ok { background: var(--teal-2); color: var(--teal); border-color: #A9DED4; }
.b-warn { background: var(--amber-2); color: #8A5A00; border-color: #F1D68B; }
.b-bad { background: var(--red-2); color: var(--red); border-color: #F0B8AF; }
.b-info { background: var(--blue-2); color: var(--blue); border-color: #B9D2EE; }
.b-mute { background: var(--rule-2); color: var(--muted); border-color: var(--rule); }
.chip { display: inline-block; padding: 3px 10px; border: 1px solid var(--rule); border-radius: 999px; font-size: 12px; margin: 2px 4px 2px 0; background: var(--paper-2); cursor: pointer; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- forms & buttons */
.form { display: grid; gap: 12px; grid-template-columns: repeat(4, 1fr); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); font-family: var(--mono); letter-spacing: .04em; }
input, select, textarea { font: inherit; font-family: var(--body); padding: 9px 11px; border: 1px solid var(--rule); border-radius: 4px; background: #fff; color: var(--ink-2); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(11,46,89,.10); }
button, .btn { font: inherit; font-family: var(--body); font-weight: 700; padding: 9px 16px; border-radius: 4px; border: 1px solid var(--ink); background: var(--ink); color: #fff; cursor: pointer; letter-spacing: .02em; transition: transform .08s ease, background .15s; }
button:hover { background: #12406F; } button:active { transform: translateY(1px); }
button.ghost { background: transparent; color: var(--ink); } button.ghost:hover { background: rgba(11,46,89,.06); }
button.amber { background: var(--amber); border-color: var(--amber); color: var(--ink); } button.amber:hover { background: #F5AE1C; }
button.sm { padding: 5px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { padding: 7px 10px; font-size: 13px; }

/* ---------- tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); margin-bottom: 18px; }
.tabs button { background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 14px; font-weight: 600; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--amber); }

/* ---------- tree */
.tree ul { list-style: none; margin: 0; padding-left: 18px; border-left: 1px dashed var(--rule); }
.tree > ul { padding-left: 0; border: none; }
.tree li { padding: 3px 0; }
.tree .node { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.tree .node .name { font-weight: 600; color: var(--ink); }
.tree .node .cnt { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.tree .tw { width: 14px; display: inline-block; color: var(--muted); font-family: var(--mono); }

/* ---------- misc */
.progress { height: 8px; background: var(--rule-2); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--amber); transition: width .3s ease; }
.list { display: flex; flex-direction: column; gap: 10px; }
.item { border: 1px solid var(--rule); border-radius: 6px; padding: 12px 14px; background: var(--paper-2); }
.item .t { font-weight: 700; color: var(--ink); }
.item .s { font-size: 12px; color: var(--muted); }
.sim { display: grid; grid-template-columns: 56px 1fr; gap: 14px; align-items: start; }
.sim .score { font-family: var(--mono); font-size: 26px; font-weight: 600; color: var(--ink); line-height: 1; }
.sim .score small { display: block; font-size: 10px; color: var(--muted); letter-spacing: .1em; margin-top: 3px; }
.meter { height: 6px; background: var(--rule-2); border-radius: 3px; overflow: hidden; margin: 6px 0; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--ink), var(--amber)); }
.riskgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.risk { border: 1px solid var(--rule); border-radius: 6px; padding: 10px 12px; background: var(--paper-2); }
.risk .c { font-family: var(--mono); font-size: 22px; color: var(--ink); font-weight: 600; }
.risk .k { font-size: 12px; font-weight: 700; color: var(--ink); }
.risk ul { margin: 6px 0 0; padding-left: 14px; font-size: 11.5px; color: var(--ink-2); }
.spark { width: 100%; height: 120px; }
.q { border-left: 3px solid var(--amber); background: var(--amber-2); padding: 12px 14px; border-radius: 0 6px 6px 0; }
.q.done { border-left-color: var(--teal); background: var(--teal-2); }
.q .qt { font-weight: 700; color: var(--ink); }
.ev { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl { display: grid; grid-template-columns: 96px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--rule-2); }
.tl .d { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.note { font-size: 12.5px; color: var(--muted); border-top: 1px dashed var(--rule); padding-top: 10px; margin-top: 12px; }
.endpoint { display: grid; grid-template-columns: 70px 1fr 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--rule-2); font-size: 12.5px; align-items: baseline; }
.endpoint .m { font-family: var(--mono); font-weight: 600; color: var(--teal); }
.endpoint .p { font-family: var(--mono); color: var(--ink); }
.empty { color: var(--muted); font-style: italic; padding: 14px; }
.toast { position: fixed; right: 24px; bottom: 24px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px; font-size: 13px; opacity: 0; transform: translateY(8px); transition: all .25s; pointer-events: none; z-index: 50; border-left: 3px solid var(--amber); }
.toast.show { opacity: 1; transform: none; }

/* ---------- gate */
.gate { position: fixed; inset: 0; background: var(--ink); display: grid; place-items: center; z-index: 100; }
.gate::before { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px); background-size: 40px 40px; }
.gate-card { position: relative; background: var(--paper-2); padding: 36px 40px; border-radius: 8px; width: 420px; display: flex; flex-direction: column; gap: 12px; border-top: 6px solid var(--amber); }
.gate-card h1 { font-size: 24px; margin: 0; }
.gate-card p { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.gate-card .err { color: var(--red); font-size: 12.5px; min-height: 18px; }

@media (max-width: 1100px) { .g4, .g5 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: 1fr 1fr; } .form { grid-template-columns: 1fr 1fr; } .riskgrid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 800px) { .shell { grid-template-columns: 1fr; } .rail { position: static; height: auto; } .main { padding: 20px; } .g2, .g3, .g4, .g5 { grid-template-columns: 1fr; } }

/* ---------- language switch */
.lang-switch { display: inline-flex; border: 1px solid rgba(255,255,255,.25); border-radius: 4px; overflow: hidden; align-self: flex-start; }
.lang-switch button { background: transparent; border: none; border-radius: 0; color: #9FB3D1; padding: 5px 12px; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; }
.lang-switch button:hover { background: rgba(255,255,255,.08); color: #fff; }
.lang-switch button.on { background: var(--amber); color: var(--ink); }
.gate-lang { position: absolute; top: -34px; right: 0; border-color: rgba(255,255,255,.25); }
.gate-card { position: relative; }

/* ---------- extended nav groups + scroll */
.rail { overflow: hidden; }
nav { overflow-y: auto; flex: 1; padding-right: 4px; }
nav::-webkit-scrollbar { width: 6px; } nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }
.nav-grp { font-family: var(--mono); font-size: 9.5px; letter-spacing: .16em; text-transform: uppercase; color: #6E86AD; margin: 14px 10px 4px; }
.nav-grp:first-child { margin-top: 0; }
.rail { gap: 18px; }

/* ---------- search page (faceted + NL) */
.fbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.fsel { display: flex; align-items: center; gap: 6px; border: 1px solid var(--rule); border-radius: 6px; background: #fff; padding: 0 8px 0 10px; min-width: 0; }
.fsel .ic { font-size: 13px; opacity: .8; }
.fsel select { border: none; background: transparent; flex: 1; min-width: 0; padding: 8px 4px; font-size: 12.5px; }
.fsel select:focus { box-shadow: none; }
.fpanel { border: 1px solid var(--rule); border-radius: 6px; background: var(--paper-2); padding: 8px 10px; }
.fpanel .ttl { font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.fpanel select, .fpanel input { width: 100%; padding: 7px 8px; font-size: 12.5px; }
.frow { display: flex; gap: 8px; align-items: center; }
.frow input { width: 90px; }
.chip.tag { font-size: 11.5px; border-color: #A9DED4; background: #F1FAF8; color: var(--teal); padding: 2px 9px; }
.chip.tag.on { background: var(--teal); color: #fff; border-color: var(--teal); }
.chip.tag i { font-style: normal; opacity: .7; font-family: var(--mono); font-size: 10px; margin-left: 2px; }
.chip.tag.x::after { content: " ×"; opacity: .7; }
.chip.small { font-size: 10.5px; padding: 1px 7px; margin: 1px 3px 1px 0; }
.chip.ext { font-family: var(--mono); font-size: 11px; }
.sec { border: 1px solid var(--rule); border-radius: 6px; margin-top: 14px; background: var(--paper-2); }
.sec > .sec-h { display: flex; justify-content: space-between; align-items: center; padding: 9px 14px; background: var(--ink); color: #fff; border-radius: 6px 6px 0 0; cursor: pointer; font-weight: 700; font-size: 13px; }
.sec > .sec-h .sub { font-weight: 400; font-size: 11.5px; opacity: .8; font-family: var(--mono); }
.sec > .sec-b { padding: 14px; }
.sec.closed > .sec-b { display: none; }
.sec > .sec-f { border-top: 1px solid var(--rule-2); padding: 7px 14px; font-size: 12px; color: var(--muted); background: var(--paper); border-radius: 0 0 6px 6px; }
.cond { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 14px; }
.cond label.f input, .cond label.f select { width: 100%; }
.range { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; }
.range input { min-width: 0; width: 100%; }
.answer { border-left: 3px solid var(--amber); background: var(--amber-2); padding: 10px 14px; border-radius: 4px; font-size: 13px; }
.answer .hl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.answer .hl > div { background: #fff; border: 1px solid var(--rule); border-radius: 4px; padding: 8px 10px; font-size: 11.5px; }
.answer .hl b { display: block; font-size: 12px; color: var(--ink); margin-bottom: 3px; word-break: break-all; }
.mem-hit { display: inline-flex; gap: 6px; align-items: center; border: 1px dashed var(--ink); border-radius: 4px; padding: 2px 8px; font-size: 11.5px; margin: 2px 4px 2px 0; background: #fff; }
.mem-hit .ty { font-family: var(--mono); font-size: 10px; color: var(--muted); }
.snip { font-size: 11px; color: var(--muted); margin-top: 2px; }
.pcount { font-family: var(--mono); font-weight: 600; color: var(--blue); cursor: pointer; }
.sugg { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.sugg .chip { font-size: 11.5px; }
/* memory page */
.md { font-size: 13px; line-height: 1.7; }
.md h1 { font-family: var(--display); font-size: 20px; margin: 0 0 8px; color: var(--ink); }
.md h2 { font-size: 13.5px; margin: 14px 0 4px; color: var(--ink); border-bottom: 1px dashed var(--rule); padding-bottom: 2px; }
.md ul { margin: 4px 0; padding-left: 18px; }
.md em { color: var(--muted); }
.md textarea { width: 100%; min-height: 420px; font-family: var(--mono); font-size: 12px; }
.mstat { display: flex; gap: 14px; font-size: 11.5px; color: var(--muted); font-family: var(--mono); flex-wrap: wrap; }
.ty-badge { font-family: var(--mono); font-size: 10px; padding: 1px 6px; border-radius: 3px; background: var(--blue-2); color: var(--blue); }
.ty-rule { background: var(--teal-2); color: var(--teal); } .ty-fact { background: var(--blue-2); color: var(--blue); } .ty-preference { background: var(--amber-2); color: #8A5A00; } .ty-reference { background: var(--rule-2); color: var(--muted); } .ty-query { background: #EFE6F7; color: #6B3FA0; }
@media (max-width: 1100px) { .fbar, .cond { grid-template-columns: repeat(2, 1fr); } .answer .hl { grid-template-columns: 1fr; } }
