/* ORMSA brand tokens — adjust to match the official brand guide */
:root {
  --brand: #f26b1d;          /* safety orange */
  --brand-dark: #c9530f;
  --navy: #13233a;
  --navy-2: #1c3150;
  --bg: #e9edf1;
  --panel: #ffffff;
  --panel-2: #f4f6f8;
  --line: #e1e5ea;
  --text: #17202b;
  --muted: #667281;
  --bubble-in: #ffffff;
  --bubble-out: #ffe6d4;
  --bubble-bot: #e6eef8;
  --chat-bg: #efe9e2;
  --danger: #d93a3a;
  --ok: #2e9b5f;
  --shadow: 0 1px 0.5px rgba(0,0,0,.13);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1420; --panel: #131d2b; --panel-2: #1a2636; --line: #243246; --text: #e6ebf1; --muted: #8b98a8;
    --bubble-in: #1c2838; --bubble-out: #5a3014; --bubble-bot: #1d3352; --chat-bg: #0f1823;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14.5px; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; background: var(--brand); color: #fff; padding: 9px 16px; font-weight: 600; }
button:hover { background: var(--brand-dark); }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
input, textarea, select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; width: 100%; outline: none; }
input:focus, textarea:focus { border-color: var(--brand); }
.hidden { display: none !important; }

/* Brand mark */
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 800; font-size: 12px; display: grid; place-items: center; letter-spacing: .5px; flex: none; }
.brand-mark.big { width: 64px; height: 64px; font-size: 18px; border-radius: 16px; margin: 0 auto 12px; }
.brand-mark.huge { width: 96px; height: 96px; font-size: 26px; border-radius: 24px; margin: 0 auto 20px; }

/* Login */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(160deg, var(--navy), var(--navy-2)); padding: 16px; }
.login-card { background: var(--panel); padding: 32px; border-radius: 16px; width: 100%; max-width: 360px; text-align: center; display: grid; gap: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 8px; color: var(--muted); }
.error { color: var(--danger); min-height: 1em; font-size: 13px; }

/* Layout */
.app { height: 100vh; height: 100dvh; display: grid; grid-template-columns: minmax(300px, 30%) 1fr; max-width: 1600px; margin: 0 auto; position: relative; }
@media (min-width: 1440px) { body { padding: 18px 0; } .app { height: calc(100vh - 36px); box-shadow: 0 6px 24px rgba(0,0,0,.12); } }

/* Sidebar */
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.side-head, .chat-head { height: 60px; display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--navy); color: #fff; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; flex: 1; min-width: 0; }
.head-actions { display: flex; gap: 2px; }
.icon-btn { background: transparent; color: inherit; padding: 8px; border-radius: 50%; display: grid; place-items: center; line-height: 1; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.status-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; font-size: 12.5px; background: var(--panel-2); color: var(--muted); cursor: pointer; border-bottom: 1px solid var(--line); }
.status-bar .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex: none; }
.status-bar.ok .dot { background: var(--ok); }
.search { padding: 8px 12px; }
.search input { background: var(--panel-2); border: 0; border-radius: 8px; }
.filters { display: flex; gap: 6px; padding: 0 12px 8px; overflow-x: auto; }
.chip { background: var(--panel-2); color: var(--muted); padding: 5px 12px; border-radius: 16px; font-weight: 500; font-size: 13px; white-space: nowrap; }
.chip:hover { background: var(--line); }
.chip.active { background: #fde3d2; color: var(--brand-dark); }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item { display: flex; gap: 12px; padding: 10px 14px; cursor: pointer; align-items: center; }
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--panel-2); }
.chat-item .meta { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.chat-item .top, .chat-item .bottom { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.chat-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .time { font-size: 12px; color: var(--muted); flex: none; }
.chat-item .time.unread { color: var(--brand); font-weight: 600; }
.chat-item .preview { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--brand); color: #fff; border-radius: 10px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 12px; display: grid; place-items: center; font-weight: 700; flex: none; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 10px; font-weight: 600; flex: none; }
.tag.ai { background: #e2ecf8; color: #2a5d9a; }
.tag.human { background: #e3f3ea; color: #1f7a48; }
.tag.alert { background: #fde2e2; color: var(--danger); }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: #cfd8e3; color: #33475f; display: grid; place-items: center; font-weight: 700; flex: none; font-size: 15px; }
.chat-head .avatar { width: 40px; height: 40px; }
.empty-list { padding: 30px 20px; text-align: center; color: var(--muted); }

/* Chat */
.chat { position: relative; display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.empty { margin: auto; text-align: center; max-width: 460px; padding: 24px; color: var(--muted); }
.empty h2 { color: var(--text); font-weight: 400; font-size: 28px; margin: 0 0 10px; }
.chat-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head .who { flex: 1; min-width: 0; cursor: pointer; }
.chat-head .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .sub { font-size: 12.5px; opacity: .75; }
.chat-head .back { display: none; }
.bot-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.bot-toggle input { display: none; }
.switch { width: 38px; height: 22px; background: rgba(255,255,255,.3); border-radius: 12px; position: relative; transition: .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.bot-toggle input:checked + .switch { background: var(--brand); }
.bot-toggle input:checked + .switch::after { left: 19px; }
.attention { background: #fde2e2; color: #8a1f1f; padding: 8px 16px; font-size: 13px; text-align: center; }
.messages {
  flex: 1; overflow-y: auto; padding: 18px 7% 10px; display: flex; flex-direction: column; gap: 3px;
  background-image: radial-gradient(rgba(19,35,58,.06) 1px, transparent 1px);
  background-size: 18px 18px;
}
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 5px 12px; border-radius: 8px; margin: 10px 0; box-shadow: var(--shadow); }
.bubble { max-width: min(65%, 560px); padding: 6px 9px 8px; border-radius: 8px; box-shadow: var(--shadow); position: relative; white-space: pre-wrap; word-wrap: break-word; line-height: 1.38; }
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 0; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 0; }
.bubble.out.bot { background: var(--bubble-bot); }
.bubble .sender { font-size: 12px; font-weight: 700; margin-bottom: 2px; }
.bubble.bot .sender { color: #2a5d9a; }
.bubble.staff .sender { color: var(--brand-dark); }
.bubble .time { float: right; font-size: 11px; color: var(--muted); margin: 6px 0 -4px 12px; }
.bubble a { color: #2a6fb3; }
.bubble.cont { margin-top: -1px; border-radius: 8px; }
.typing { padding: 4px 7%; font-size: 12.5px; color: var(--muted); font-style: italic; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px; background: var(--panel-2); flex: none; }
.composer textarea { resize: none; max-height: 140px; border: 0; border-radius: 10px; padding: 10px 14px; }
.composer .send { border-radius: 50%; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; flex: none; }
.composer .send svg { width: 20px; height: 20px; fill: #fff; }

/* Drawer */
.drawer { position: absolute; right: 0; top: 0; bottom: 0; width: min(380px, 100%); background: var(--panel); border-left: 1px solid var(--line); padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; z-index: 5; box-shadow: -6px 0 18px rgba(0,0,0,.08); }
.drawer header, .modal-card header { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.drawer h3, .modal-card h3 { margin: 0; font-size: 17px; }
.drawer .icon-btn, .modal-card .icon-btn { color: var(--muted); font-size: 18px; width: 36px; height: 36px; }
.drawer .icon-btn:hover, .modal-card .icon-btn:hover { background: var(--panel-2); }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(8,16,28,.55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--panel); border-radius: 14px; width: 100%; max-width: 440px; max-height: 90vh; display: flex; flex-direction: column; padding: 0 20px 20px; gap: 12px; }
.modal-card.wide { max-width: 760px; }
.add-k { display: flex; gap: 8px; align-items: flex-start; }
.add-k textarea { resize: vertical; }
.k-tools { display: flex; gap: 8px; }
.k-tools select { width: 160px; flex: none; }
.k-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: grid; gap: 8px; }
.k-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 6px; }
.k-item .k-meta { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.k-item .k-meta .grow { flex: 1; }
.k-item .k-text { white-space: pre-wrap; }
.k-item textarea { resize: vertical; }
.k-item button { padding: 4px 10px; font-size: 12.5px; }
.src { font-size: 11px; padding: 1px 8px; border-radius: 10px; font-weight: 700; text-transform: uppercase; }
.src.auto { background: #e2ecf8; color: #2a5d9a; }
.src.staff { background: #fde3d2; color: var(--brand-dark); }
.src.website { background: #e3f3ea; color: #1f7a48; }
.k-item.fresh { border-color: var(--brand); }
.connect-body { text-align: center; display: grid; gap: 14px; justify-items: center; }
.connect-body img { width: 264px; height: 264px; border-radius: 8px; background: #fff; padding: 8px; }
.connect-body ol { text-align: left; color: var(--muted); margin: 0; padding-left: 20px; }

/* Toasts */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 30; width: min(420px, calc(100% - 32px)); }
.toast { background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); cursor: pointer; font-size: 13.5px; }
.toast.alert { background: var(--danger); }

/* Mobile: one pane at a time */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .chat-head .back { display: grid; }
  .bot-toggle span:first-child { display: none; }
  .messages { padding: 14px 10px 8px; }
  .bubble { max-width: 85%; }
  .typing { padding: 4px 12px; }
  .add-k { flex-direction: column; }
  .add-k button { width: 100%; }
}
