/* UnionSPACE Case Advisor */
:root {
  --ink: #1a2233;
  --muted: #6b7486;
  --line: #e3e7ee;
  --bg: #f5f7fa;
  --card: #fff;
  --brand: #13294b;
  --accent: #f26b21;
  --green: #1d8a4e;
  --green-bg: #e6f5ec;
  --red: #c62828;
  --red-bg: #fdecec;
  --amber: #b26a00;
  --amber-bg: #fff4d6;
  --rule-bg: #fff1c2;
  --rule-line: #e6a700;
  --blue: #1f5fbf;
  --blue-bg: #e7effb;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--blue); }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: .95rem; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; background: var(--brand); color: #fff; padding: 10px 20px; }
.brand { color: #fff; text-decoration: none; font-size: 1.15rem; }
.brand b { color: var(--accent); }
.brand span { font-size: .85rem; opacity: .75; margin-left: 4px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: #dfe6f3; text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: .92rem; }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.logout { display: flex; gap: 10px; align-items: center; font-size: .85rem; opacity: .9; margin: 0; }
button.link { background: none; border: 0; color: #fff; text-decoration: underline; cursor: pointer; padding: 0; font: inherit; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 16px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.count { background: var(--red); color: #fff; border-radius: 20px; padding: 0 10px; font-size: .9rem; vertical-align: middle; }

/* Cards and layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.empty { text-align: center; color: var(--muted); padding: 40px; }
details.card > summary { cursor: pointer; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.grid2 > .card { margin-bottom: 16px; }
.split { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
@media (max-width: 860px) {
  .grid2, .grid3, .split { grid-template-columns: 1fr; }
}

/* Forms */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 12px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid #cfd6e1; border-radius: 7px; font: inherit; font-weight: 400; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-bg); border-color: var(--blue); }
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; }
textarea { resize: vertical; }
form.inline { display: inline; margin: 0; }
.btn { display: inline-block; padding: 9px 16px; border-radius: 7px; border: 1px solid #cfd6e1; background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: #f0f3f8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #d95a14; }
.btn.danger { color: var(--red); }
.btn.big { padding: 12px 24px; font-size: 1.05rem; }
.btn:disabled { opacity: .6; cursor: wait; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { margin-top: 4px; }

/* Alerts and pills */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert.ok { background: var(--green-bg); border-color: #b7e0c6; color: #11502d; }
.alert.warn { background: var(--amber-bg); border-color: #f0d48a; color: #6b4300; }
.alert.error { background: var(--red-bg); border-color: #f3b9b9; color: #8e1c1c; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 20px; font-size: .8rem; font-weight: 600; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.blue { background: var(--blue-bg); color: var(--blue); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }

/* Tables */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
table.list { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfd; }
table.list tbody tr:hover { background: #fafcff; cursor: pointer; }
table.list.static tbody tr:hover { cursor: default; }
td.clip { max-width: 360px; }

/* Confidence score */
.score { display: inline-block; min-width: 46px; text-align: center; padding: 2px 8px; border-radius: 8px; font-weight: 800; font-size: 1.05rem; }
.score small { font-weight: 500; font-size: .7rem; opacity: .8; }
.score.high { background: var(--green-bg); color: var(--green); }
.score.mid { background: var(--blue-bg); color: var(--blue); }
.score.low { background: var(--red); color: #fff; }

/* Answer card */
.legend { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; font-size: .85rem; color: var(--muted); margin: 4px 0 12px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
.swatch.rule { background: var(--rule-bg); border-left: 4px solid var(--rule-line); }
.swatch.red { background: var(--red); }
.question { border-left: 5px solid var(--green); }
.question.needs-officer { border-left-color: var(--red); }
.q-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.qnum { display: inline-block; background: var(--brand); color: #fff; border-radius: 6px; padding: 0 7px; font-size: .85rem; margin-right: 4px; }
.q-score { text-align: right; flex-shrink: 0; }
.why summary { font-size: .8rem; color: var(--muted); cursor: pointer; }
.why p { margin: 4px 0; font-size: .82rem; text-align: left; max-width: 340px; }
.why .adj { color: var(--amber); }
.verdict { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; padding: 10px 12px; border-radius: 8px; background: #f7f9fc; margin: 8px 0 4px; font-size: 1.05rem; }
.verdict-label { font-weight: 800; padding: 2px 10px; border-radius: 6px; white-space: nowrap; }
.verdict-label.yes { background: var(--green); color: #fff; }
.verdict-label.no { background: var(--red); color: #fff; }
.verdict-label.yesif { background: var(--blue); color: #fff; }
.verdict-label.nobut { background: var(--amber); color: #fff; }
.verdict-text { font-weight: 600; }
.question ul, .card ul { padding-left: 20px; margin: 6px 0; }
.question li, .card li { margin: 4px 0; }

/* Hard-rule lines: amber so consultants see the answer follows company policy */
.rule-line { background: var(--rule-bg) !important; border-left: 4px solid var(--rule-line); padding: 4px 8px; border-radius: 4px; list-style-position: inside; }
li.rule-line { margin-left: -20px; }
.rule-badge { display: inline-block; background: var(--rule-line); color: #3d2a00; font-size: .72rem; font-weight: 700; padding: 0 7px; border-radius: 10px; margin-left: 4px; white-space: nowrap; }
.wording-flag { font-size: .72rem; color: var(--red); border: 1px dashed var(--red); padding: 0 5px; border-radius: 8px; margin-left: 4px; }
.price { display: inline-block; font-weight: 700; color: var(--green); margin-left: 4px; white-space: nowrap; }

/* Red escalation box */
.escalation { background: var(--red-bg); border: 2px solid var(--red); border-radius: 8px; padding: 12px 14px; margin: 12px 0; }
.esc-title { color: #fff; background: var(--red); margin: -12px -14px 10px; padding: 8px 14px; font-weight: 800; border-radius: 5px 5px 0 0; }
.escalation p { margin: 4px 0; }
.esc-q { margin-top: 8px; background: #fff; border-radius: 6px; overflow: hidden; }
.esc-q th, .esc-q td { text-align: left; padding: 7px 10px; border-bottom: 1px solid #f3c9c9; vertical-align: top; width: 50%; }
.esc-q th { font-size: .78rem; text-transform: uppercase; color: var(--red); }
[lang=th] { font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif; }

.insight { border-top: 4px solid var(--accent); }
.upsell { border-top: 4px solid var(--green); }
.sources li { word-break: break-word; }
.facts { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 12px 0 0; }
.facts dt { color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; }
.officer-note { border-left: 4px solid var(--green); padding: 4px 12px; margin-bottom: 12px; background: var(--green-bg); border-radius: 4px; }
.officer-form, .grade-form { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.grade { padding: 6px 0; border-bottom: 1px solid var(--line); }
.stars { color: var(--accent); letter-spacing: 2px; }
ul.plain { list-style: none; padding: 0; }

/* Researching spinner */
.researching { display: flex; gap: 16px; align-items: center; background: var(--blue-bg); border-color: #c5d7f2; }
.spinner { width: 34px; height: 34px; border: 4px solid #c5d7f2; border-top-color: var(--blue); border-radius: 50%; animation: spin 1s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Similar answers panel */
.similar { position: sticky; top: 16px; }
.similar-item { display: block; text-decoration: none; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: .88rem; }
.similar-item:hover { border-color: var(--blue); }
.similar-item ul { margin: 4px 0 0; padding-left: 16px; }

/* Tabs */
.tabs { display: flex; gap: 4px; background: #e9edf3; padding: 3px; border-radius: 8px; }
.tabs a { padding: 5px 12px; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a.active { background: #fff; color: var(--ink); }

/* Login */
.login { max-width: 380px; margin: 10vh auto; text-align: center; }
.login h1 { font-size: 2rem; color: var(--brand); }
.login h1 b { color: var(--accent); }
.login form { text-align: left; }
.login .btn { width: 100%; }

/* Admin */
.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; min-width: 160px; }
.stat b { display: block; font-size: 1.5rem; }
.bar { height: 10px; background: #e9edf3; border-radius: 5px; overflow: hidden; margin-top: 6px; }
.bar span { display: block; height: 100%; background: var(--green); }
.bar span.warn { background: var(--amber); }
.bar span.over { background: var(--red); }
.rule-card { border-left: 5px solid var(--rule-line); }
.rule-card.inactive { opacity: .55; border-left-color: #ccc; }
.rule-card .rule-text { background: var(--rule-bg); padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
.search-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.search-bar label { flex: 1; min-width: 160px; margin: 0; }
