:root {
  --navy: #0b2e59;
  --navy-700: #103a6e;
  --blue: #1b6ec2;
  --blue-50: #eef5fc;
  --ink: #1a2230;
  --muted: #5a6675;
  --line: #e3e8ef;
  --bg: #f4f6f9;
  --white: #fff;
  --green: #1f8a4c;
  --amber: #b7791f;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(11, 46, 89, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Brand ---------- */
.brand-mark {
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--white);
  background: var(--navy);
  padding: 6px 12px;
  border-radius: 8px;
  display: inline-block;
}
.brand-mark.sm { font-size: 13px; padding: 4px 8px; letter-spacing: 1px; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-700) 55%, var(--blue) 130%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
  padding: 32px 30px 28px;
}
.brand { text-align: center; margin-bottom: 18px; }
.brand .brand-mark { font-size: 22px; }
.brand-sub { margin-top: 10px; font-weight: 600; color: var(--navy); letter-spacing: .3px; }
.login-intro { color: var(--muted); font-size: 14px; line-height: 1.55; text-align: center; margin: 0 0 14px; }
.login-note { color: var(--muted); font-size: 11.5px; line-height: 1.5; text-align: center; margin: 0 0 20px; opacity: .85; }
#login-form { display: flex; flex-direction: column; gap: 14px; }
#login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink); }
#login-form input {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#login-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-50); }
#login-btn {
  margin-top: 6px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  transition: background .15s;
}
#login-btn:hover { background: var(--navy-700); }
#login-btn:disabled { opacity: .6; cursor: default; }
.sso-buttons { display: flex; flex-direction: column; gap: 10px; margin-bottom: 4px; }
.sso-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font-size: 14.5px; font-weight: 600; text-decoration: none;
  transition: border-color .15s, box-shadow .15s;
}
.sso-btn:hover { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-50); }
.sso-icon { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 5px; font-weight: 800; background: #fff; color: #4285F4; border: 1px solid var(--line); font-size: 13px; }
.sso-icon.ms { color: #fff; background: #2F2F2F; border-color: #2F2F2F; }
.sso-divider { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0; }
.sso-divider::before, .sso-divider::after { content: ""; flex: 1; border-bottom: 1px solid var(--line); }
.sso-divider span { padding: 0 12px; }
.login-footer { color: rgba(255,255,255,.8); font-size: 12.5px; margin-top: 22px; }
.error-msg { color: #c0392b; font-size: 13px; min-height: 16px; text-align: center; }

/* ---------- Chat ---------- */
.chat-view { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 5;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--navy); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.who { color: var(--muted); font-size: 13px; }
.link-btn { background: none; border: none; color: var(--blue); font-size: 13px; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 26px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

.msg { display: flex; gap: 12px; }
.msg .avatar {
  flex: 0 0 32px; height: 32px; width: 32px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: #4a5568; }
.msg.bot .avatar { background: var(--navy); }
.bubble {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  line-height: 1.6;
  font-size: 15px;
  box-shadow: 0 2px 6px rgba(11,46,89,.04);
  max-width: 88%;
}
.msg.user .bubble { background: var(--navy); color: #fff; border-color: var(--navy); }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ol, .bubble ul { margin: 8px 0; padding-left: 22px; }
.bubble li { margin: 4px 0; }
.bubble strong { font-weight: 700; }
.cite {
  display: inline-block; vertical-align: super; font-size: 10.5px; font-weight: 700;
  color: var(--blue); background: var(--blue-50); border-radius: 5px;
  padding: 0 4px; margin: 0 1px; text-decoration: none; cursor: pointer;
}
.cite:hover { background: #d6e6f7; }

/* feedback */
.feedback { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fb-prompt { font-size: 12.5px; color: var(--muted); }
.fb-btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 3px 9px; font-size: 14px; line-height: 1.2; }
.fb-btn:hover { border-color: var(--blue); background: var(--blue-50); }
.fb-thanks { font-size: 12.5px; color: var(--green); font-weight: 600; }
.fb-note-row { display: flex; gap: 8px; width: 100%; margin-top: 6px; }
.fb-note { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 13px; outline: none; }
.fb-note:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-50); }
.fb-send { border: none; background: var(--blue); color: #fff; border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 700; }
.fb-send:hover { background: var(--navy-700); }

/* confidence chip */
.meta-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.chip { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.chip.high { background: #e7f6ec; color: var(--green); }
.chip.medium { background: #fdf3e0; color: var(--amber); }
.chip.low { background: #fcebea; color: #c0392b; }

/* sources */
.sources { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.sources summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.source-item { display: flex; gap: 8px; padding: 7px 0; font-size: 13px; border-bottom: 1px solid #f0f3f7; }
.source-item:last-child { border-bottom: none; }
.source-num { flex: 0 0 22px; height: 22px; border-radius: 6px; background: var(--blue-50); color: var(--blue); font-weight: 700; display: grid; place-items: center; font-size: 11px; }
.source-item a { color: var(--navy); text-decoration: none; word-break: break-word; }
.source-item a:hover { text-decoration: underline; }
.source-item .tier { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* escalation card */
.escalation {
  margin-top: 14px; border: 1px solid #cfe0f3; background: var(--blue-50);
  border-radius: 12px; padding: 14px 16px;
}
.escalation .esc-head { font-weight: 700; color: var(--navy); display: flex; align-items: center; gap: 8px; }
.escalation .esc-reason { color: var(--muted); font-size: 13.5px; margin: 6px 0 10px; }
.escalation .esc-contact { font-size: 14px; }
.escalation .esc-contact div { margin: 2px 0; }
.esc-people { display: flex; flex-direction: column; gap: 10px; }
.esc-person { border-left: 2px solid #cfe0f3; padding: 2px 0 2px 10px; }
.ep-name { font-size: 14px; }
.ep-role { color: var(--muted); font-weight: 500; font-size: 13px; }
.ep-note { font-size: 12.5px; color: var(--muted); font-style: italic; margin: 1px 0 2px; }
.ep-contact { font-size: 13px; color: var(--ink); margin-top: 1px; }
.esc-actions { margin-top: 12px; display: flex; gap: 10px; flex-wrap: wrap; }
.esc-status { margin-top: 10px; font-size: 13.5px; color: var(--green); line-height: 1.5; }
.btn {
  border: none; border-radius: 9px; padding: 9px 16px; font-weight: 700; font-size: 14px;
  background: var(--blue); color: #fff; text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--navy-700); }
.btn.ghost { background: #fff; color: var(--blue); border: 1px solid #cfe0f3; }

/* composer */
.composer-wrap { border-top: 1px solid var(--line); background: var(--white); padding: 12px 16px 14px; }
.suggestions { max-width: 820px; margin: 0 auto 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.suggestion {
  border: 1px solid var(--line); background: #fff; color: var(--navy);
  border-radius: 20px; padding: 7px 14px; font-size: 13px; font-weight: 500;
}
.suggestion:hover { border-color: var(--blue); background: var(--blue-50); }
.composer { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 15px; font-family: inherit; line-height: 1.5;
  max-height: 160px; outline: none;
}
.composer textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-50); }
#ask-btn {
  border: none; border-radius: 12px; background: var(--blue); color: #fff;
  font-weight: 700; font-size: 15px; padding: 12px 22px; height: 46px;
}
#ask-btn:hover { background: var(--navy-700); }
#ask-btn:disabled { opacity: .55; cursor: default; }
.disclaimer { max-width: 820px; margin: 10px auto 0; color: var(--muted); font-size: 11.5px; text-align: center; line-height: 1.5; }

/* typing dots */
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #9aa7b8; animation: blink 1.3s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

.welcome { text-align: center; color: var(--muted); margin: 30px auto; max-width: 540px; }
.welcome h2 { color: var(--navy); margin-bottom: 8px; }
.welcome p { line-height: 1.6; }

@media (max-width: 560px) {
  .bubble { max-width: 96%; }
  .who { display: none; }
}

/* ---------- Admin dashboard ---------- */
.admin-view { min-height: 100%; display: flex; flex-direction: column; }
.admin-main { max-width: 1080px; width: 100%; margin: 0 auto; padding: 22px 18px 60px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.card-value { font-size: 28px; font-weight: 800; color: var(--navy); }
.card-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.card-hint { font-size: 11px; color: var(--amber); margin-top: 2px; }

.panel-grid { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 820px) { .panel-grid { grid-template-columns: 1fr; } }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 14px; font-size: 14px; color: var(--navy); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h3 { margin: 0; }
.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* bar chart */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar { width: 70%; min-height: 2px; background: linear-gradient(180deg, var(--blue), var(--navy)); border-radius: 4px 4px 0 0; }
.bar-x { font-size: 9.5px; color: var(--muted); margin-top: 5px; }
.bar-n { font-size: 10px; color: var(--ink); font-weight: 600; }

/* rank lists */
.ranklist { display: flex; flex-direction: column; gap: 8px; }
.rank-row { position: relative; display: flex; align-items: center; justify-content: space-between; padding: 7px 10px; border-radius: 7px; overflow: hidden; background: var(--bg); }
.rank-bar { position: absolute; left: 0; top: 0; bottom: 0; background: var(--blue-50); z-index: 0; }
.rank-name { position: relative; z-index: 1; font-size: 13px; color: var(--ink); text-transform: capitalize; }
.rank-count { position: relative; z-index: 1; font-size: 13px; font-weight: 700; color: var(--navy); }

/* search */
.search-box { border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; font-size: 14px; min-width: 240px; outline: none; }
.search-box:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-50); }

/* admin knowledge queue */
.kb-queue { display: flex; flex-direction: column; gap: 14px; margin-bottom: 12px; }
.kb-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fbfcfe; }
.kb-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kb-lab { font-size: 11.5px; font-weight: 700; color: var(--muted); margin: 6px 0 3px; text-transform: uppercase; letter-spacing: .4px; }
.kb-edit { width: 100%; }
.kb-textarea { width: 100%; min-height: 84px; resize: vertical; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font-size: 14px; font-family: inherit; line-height: 1.5; outline: none; }
.kb-textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-50); }
.kb-raw { margin-top: 8px; }
.kb-raw summary { font-size: 12.5px; color: var(--muted); cursor: pointer; }
.kb-raw-body { font-size: 13px; color: var(--ink); white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 8px; margin-top: 6px; max-height: 220px; overflow-y: auto; }
.kb-actions { display: flex; gap: 10px; margin-top: 12px; }
.kb-add { margin-top: 6px; }
.kb-add > summary { font-size: 13px; font-weight: 600; color: var(--blue); cursor: pointer; }
.kb-add form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.kb-add-row { display: flex; gap: 8px; }

/* admin reset (danger) */
.reset-zone { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.reset-note { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 0 0 10px; }
.btn.danger { background: #c0392b; }
.btn.danger:hover { background: #a93226; }

/* admin domains panel */
.hint-inline { font-size: 11.5px; font-weight: 400; color: var(--muted); }
.domain-form { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.domain-form .search-box { flex: 1; min-width: 160px; }
.domain-list { display: flex; flex-direction: column; gap: 6px; }
.domain-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--bg); border-radius: 8px; }
.domain-name { font-weight: 600; color: var(--ink); font-size: 13.5px; }
.domain-dist { font-size: 12px; color: var(--muted); }
.domain-x { margin-left: auto; border: none; background: none; color: #c0392b; font-size: 13px; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.domain-x:hover { background: #fcebea; }

/* admin feedback panel */
.fb-counts { font-size: 13px; font-weight: 700; }
.fb-counts .fb-up { color: var(--green); margin-right: 10px; }
.fb-counts .fb-down { color: #c0392b; }
.feedback-list { display: flex; flex-direction: column; gap: 10px; }
.fb-item { border-left: 3px solid var(--line); padding: 8px 0 8px 12px; }
.fb-item.down { border-left-color: #c0392b; background: #fdf2f1; border-radius: 0 8px 8px 0; }
.fb-item.up { border-left-color: var(--green); }
.fb-line { display: flex; align-items: baseline; gap: 8px; }
.fb-icon { font-size: 14px; }
.fb-q { flex: 1; font-size: 14px; color: var(--ink); font-weight: 600; }
.fb-note-text { font-size: 13px; color: #b03a2e; margin: 4px 0 2px 22px; font-style: italic; }
.fb-who { font-size: 12px; color: var(--muted); margin-left: 22px; }

/* activity feed */
.activity { display: flex; flex-direction: column; }
.act-row { padding: 12px 0; border-bottom: 1px solid #f0f3f7; }
.act-row:last-child { border-bottom: none; }
.act-meta { font-size: 12.5px; color: var(--muted); }
.act-meta strong { color: var(--ink); }
.act-time { float: right; }
.act-q { font-size: 14.5px; color: var(--ink); margin: 4px 0 7px; }
.act-tags { display: flex; gap: 8px; align-items: center; }
.tag-esc { font-size: 11px; font-weight: 700; color: var(--blue); background: var(--blue-50); padding: 2px 8px; border-radius: 20px; text-transform: capitalize; }
.tag-no { font-size: 11px; font-weight: 700; color: #c0392b; background: #fcebea; padding: 2px 8px; border-radius: 20px; }
