/* MRUSMAN AI chat — full-height conversation layout. Uses the site's tokens
   where present, with safe fallbacks for the admin. */
/* The site's own OFL-licensed Arabic-script font (also used by the invoice and
   proposal tools); it covers the Urdu letters too. Loaded from this origin only. */
@font-face { font-family: "MRU Noto Sans Arabic"; src: url("/assets/fonts/NotoSansArabic.ttf") format("truetype"); font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }

.mai {
  --mai-bg: var(--surface, #ffffff);
  --mai-soft: var(--surface-muted, #f4f3ef);
  --mai-user-bg: #f0efeb;
  --mai-ink: var(--text-primary, #101114);
  --mai-muted: var(--text-muted, #566178);
  --mai-line: var(--border, #e4e5e1);
  --mai-line-strong: var(--border-strong, #ced0cb);
  --mai-accent: var(--color-accent, #cbed32);
  --mai-violet: var(--color-accent2, #6d5ef8);
  --mai-dark: var(--color-ink, #101114);
  --mai-danger: var(--danger, #b63a43);
  --mai-ok: var(--success, #167650);
  --mai-col: 768px;
  position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; height: 100%;
  background: var(--mai-bg); color: var(--mai-ink); font-size: 16px; line-height: 1.65;
}
.mai-body, .mai-compose textarea, .mai-card, .mai-welcome, .mai-starter { font-family: var(--font-sans, Inter), "MRU Noto Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif; }
.mai :lang(ur) { font-family: "MRU Noto Sans Arabic", "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", "Segoe UI", Tahoma, sans-serif; line-height: 2; }
.mai :lang(ar) { font-family: "MRU Noto Sans Arabic", "Noto Naskh Arabic", "Segoe UI", Tahoma, sans-serif; line-height: 1.9; }
.mai :lang(hi) { font-family: "Nirmala UI", "Noto Sans Devanagari", Mangal, "Kohinoor Devanagari", sans-serif; line-height: 1.8; }
.mai-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mai :focus-visible { outline: 2px solid var(--mai-violet); outline-offset: 2px; }
.mai-col { width: min(100% - 32px, var(--mai-col)); margin-inline: auto; }

/* top bar */
.mai-head { flex: none; display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 12px 0 14px; border-bottom: 1px solid var(--mai-line); background: var(--mai-bg); z-index: 2; }
.mai-head__who { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; margin-inline-end: auto; }
.mai-head__who strong { font-family: var(--font-display, inherit); font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.mai-head__tools { display: flex; align-items: center; gap: 2px; }
.mai-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--mai-muted); }
.mai-dot[hidden] { display: none; }
.mai-dot i { width: 7px; height: 7px; border-radius: 50%; background: var(--mai-ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--mai-ok) 16%, transparent); }
.mai-dot.is-off i { background: #9aa1ad; box-shadow: none; }
.mai-avatar { flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--mai-accent); color: var(--mai-dark); }
.mai-avatar svg { width: 15px; height: 15px; }
.mai-avatar--lg { width: 52px; height: 52px; }
.mai-avatar--lg svg { width: 26px; height: 26px; }
.mai-avatar--pulse { animation: mai-pulse 1.6s ease-in-out infinite; }
@keyframes mai-pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--mai-accent) 40%, transparent); } }
.mai-lang select { font: inherit; font-size: 13px; height: 34px; padding: 0 6px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--mai-ink); cursor: pointer; max-width: 118px; }
.mai-lang select:hover { background: var(--mai-soft); }
.mai-icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--mai-ink); cursor: pointer; }
.mai-icon-btn[hidden] { display: none; }
.mai-icon-btn svg { width: 19px; height: 19px; }
.mai-icon-btn:hover { background: var(--mai-soft); }

/* conversation */
.mai-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.mai-log { display: flex; flex-direction: column; gap: 24px; padding: 28px 0 20px; min-height: 100%; box-sizing: border-box; }
.mai-welcome { margin: auto; text-align: center; padding: 16px 0 8px; animation: mai-rise .4s ease both; }
.mai-welcome[hidden] { display: none; }
.mai-welcome .mai-avatar { margin-bottom: 14px; }
.mai-welcome h2 { font-family: var(--font-display, inherit); font-size: clamp(24px, 4vw, 32px); line-height: 1.15; margin: 0 0 8px; letter-spacing: -0.025em; }
.mai-welcome p { margin: 0 auto; color: var(--mai-muted); max-width: 460px; font-size: 15.5px; }

.mai-msg { display: flex; gap: 14px; align-items: flex-start; animation: mai-rise .25s ease both; }
@keyframes mai-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.mai-user { justify-content: flex-end; }
.mai-bubble { min-width: 0; overflow-wrap: anywhere; }
.mai-user .mai-bubble { max-width: min(85%, 600px); background: var(--mai-user-bg); color: var(--mai-ink); padding: 10px 16px; border-radius: 22px; }
.mai-user .mai-bubble a { color: inherit; }
.mai-assistant .mai-bubble { flex: 1; padding-top: 1px; }
.mai-assistant > .mai-avatar { margin-top: 2px; }
.mai-streaming .mai-body > :last-child::after, .mai-streaming .mai-body:empty::after { content: ""; display: inline-block; width: 9px; height: 9px; margin-inline-start: 5px; border-radius: 50%; background: var(--mai-dark); vertical-align: middle; animation: mai-blink 1s ease-in-out infinite; }
.mai-streaming .mai-body > ul:last-child::after, .mai-streaming .mai-body > ol:last-child::after { display: none; }
@keyframes mai-blink { 50% { opacity: .25; transform: scale(.8); } }
.mai-body p { margin: 0 0 .8em; } .mai-body p:last-child { margin-bottom: 0; }
.mai-body ul, .mai-body ol { margin: .25em 0 .85em; padding-inline-start: 1.35em; }
.mai-body ul:last-child, .mai-body ol:last-child { margin-bottom: 0; }
.mai-body li { margin: .3em 0; padding-inline-start: .15em; }
.mai-body li::marker { color: var(--mai-muted); }
.mai-body strong { font-weight: 650; }
.mai-body a { color: var(--mai-violet); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .2em; }
.mai-body pre { direction: ltr; text-align: left; background: #111317; color: #f2f2f2; padding: 12px 14px; border-radius: 12px; overflow-x: auto; font-size: 13.5px; }
.mai-body code { font-size: .9em; background: var(--mai-soft); padding: .1em .4em; border-radius: 6px; }
.mai-body pre code { background: none; padding: 0; }
.mai-cite { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-inline-start: 3px; border-radius: 9px; background: var(--mai-soft); color: var(--mai-muted); font-size: 11px; font-weight: 700; text-decoration: none !important; vertical-align: 2px; line-height: 1; box-sizing: border-box; }
.mai-cite:hover { background: var(--mai-dark); color: #fff; }

.mai-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.mai-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--mai-muted); align-self: center; margin-inline-end: 2px; }
.mai-source { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; height: 30px; padding: 0 11px 0 5px; border: 1px solid var(--mai-line); border-radius: 15px; background: var(--mai-bg); font-size: 12.5px; color: var(--mai-ink); text-decoration: none; transition: border-color .15s, background .15s; box-sizing: border-box; }
.mai-source b { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 10px; background: var(--mai-soft); font-size: 11px; color: var(--mai-muted); }
.mai-source span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
a.mai-source:hover { border-color: var(--mai-line-strong); background: var(--mai-soft); }
.mai-tools { display: flex; gap: 2px; margin-top: 8px; margin-inline-start: -8px; }
.mai-mini { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent; color: var(--mai-muted); font: inherit; font-size: 12.5px; cursor: pointer; }
.mai-mini svg { width: 16px; height: 16px; }
.mai-mini:hover { background: var(--mai-soft); color: var(--mai-ink); }
@media (hover: hover) { .mai-tools { opacity: 0; transition: opacity .15s; } .mai-msg:hover .mai-tools, .mai-msg:last-child .mai-tools, .mai-tools:focus-within { opacity: 1; } }

.mai-typing { display: flex; gap: 14px; align-items: center; animation: mai-rise .25s ease both; }
.mai-typing__box { display: inline-flex; align-items: center; gap: 10px; color: var(--mai-muted); font-size: 14px; }
.mai-dots { display: inline-flex; gap: 4px; }
.mai-dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: mai-bounce 1.2s infinite ease-in-out; }
.mai-dots i:nth-child(2) { animation-delay: .15s; } .mai-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes mai-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-4px); opacity: 1; } }

/* dock: starters, status, composer */
.mai-dock { flex: none; position: relative; padding: 0 0 max(10px, env(safe-area-inset-bottom)); background: var(--mai-bg); }
.mai-dock::before { content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 20px; background: linear-gradient(to bottom, transparent, var(--mai-bg)); pointer-events: none; }
.mai-jump { position: absolute; left: 50%; bottom: calc(100% + 12px); transform: translateX(-50%); display: inline-grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--mai-line); border-radius: 50%; background: var(--mai-bg); color: var(--mai-ink); box-shadow: 0 6px 18px -8px rgb(16 17 20 / .35); cursor: pointer; z-index: 3; animation: mai-rise .2s ease both; }
.mai-jump[hidden] { display: none; }
.mai-jump svg { width: 18px; height: 18px; }
.mai-starters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.mai-starters::-webkit-scrollbar { display: none; }
.mai-starters[hidden] { display: none; }
.mai-starter { flex: none; font-size: 14px; line-height: 1.3; padding: 10px 14px; border: 1px solid var(--mai-line); border-radius: 18px; background: var(--mai-bg); color: var(--mai-ink); cursor: pointer; white-space: nowrap; transition: border-color .15s, background .15s; text-align: start; }
.mai-starter:hover { border-color: var(--mai-line-strong); background: var(--mai-soft); }
@media (min-width: 720px) {
  .mai-starters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .mai-starter { white-space: normal; border-radius: 14px; padding: 12px 14px; }
}
.mai-status { margin: 0 4px 8px; font-size: 13.5px; color: var(--mai-muted); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mai-status[hidden] { display: none; }
.mai-status.mai-error { color: var(--mai-danger); }
.mai-compose { display: flex; gap: 8px; align-items: flex-end; padding: 7px 7px 7px 18px; border: 1px solid var(--mai-line-strong); border-radius: 26px; background: var(--mai-bg); box-shadow: 0 8px 28px -14px rgb(16 17 20 / .25), 0 1px 2px rgb(16 17 20 / .04); transition: border-color .15s, box-shadow .15s; }
[dir="rtl"] .mai-compose { padding: 7px 18px 7px 7px; }
.mai-compose:focus-within { border-color: color-mix(in srgb, var(--mai-dark) 45%, var(--mai-line-strong)); box-shadow: 0 10px 32px -14px rgb(16 17 20 / .35), 0 1px 2px rgb(16 17 20 / .05); }
.mai-compose textarea { flex: 1; min-width: 0; height: 40px; resize: none; overflow-y: hidden; border: 0; background: transparent; color: var(--mai-ink); font-size: 16px; line-height: 24px; padding: 8px 0; max-height: 200px; box-sizing: border-box; }
.mai-compose textarea::placeholder { color: var(--mai-muted); opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mai-compose textarea:focus { outline: none; }
.mai-send { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--mai-dark); color: #fff; cursor: pointer; transition: transform .15s, opacity .15s; }
.mai-send[hidden] { display: none; }
.mai-send:disabled { opacity: .22; cursor: default; }
.mai-send svg { width: 20px; height: 20px; }
.mai-send:not(:disabled):hover { transform: scale(1.06); }
.mai-hint { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--mai-muted); }

/* buttons used by cards and the admin */
.mai-btn { font: inherit; font-size: 14px; font-weight: 600; min-height: 38px; padding: 7px 14px; border-radius: 10px; border: 1px solid var(--mai-line-strong); background: var(--mai-bg); color: var(--mai-ink); cursor: pointer; }
.mai-btn[hidden] { display: none; }
.mai-btn:hover { border-color: var(--mai-dark); }
.mai-btn:disabled { opacity: .55; cursor: not-allowed; }
.mai-primary { background: var(--mai-dark); color: #fff; border-color: var(--mai-dark); }
.mai-danger { color: var(--mai-danger); }
.mai-link { background: none; border: 0; padding: 4px 2px; font: inherit; font-size: 13px; color: var(--mai-muted); cursor: pointer; text-decoration: underline; min-height: 32px; }

/* cards (admin tables, drafts, proposals, contact form) */
.mai-card { margin-top: 14px; background: var(--mai-bg); border: 1px solid var(--mai-line); border-radius: 16px; padding: 16px; font-size: 14px; }
.mai-card h4 { margin: 0 0 8px; font-size: 15px; font-family: var(--font-display, inherit); }
.mai-card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mai-card th, .mai-card td { text-align: start; padding: 7px 8px; border-bottom: 1px solid var(--mai-line); vertical-align: top; }
.mai-card .mai-scroll-x { overflow-x: auto; }
.mai-card textarea, .mai-card input { width: 100%; box-sizing: border-box; font: inherit; font-size: 16px; border: 1px solid var(--mai-line-strong); border-radius: 12px; padding: 10px 12px; background: var(--mai-bg); color: var(--mai-ink); }
.mai-card label { display: block; margin: 10px 0 4px; font-weight: 600; font-size: 13px; }
.mai-card .mai-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.mai-pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--mai-soft); border: 1px solid var(--mai-line); }
.mai-pill.mai-ok { color: var(--mai-ok); } .mai-pill.mai-warn { color: #986213; } .mai-pill.mai-bad { color: var(--mai-danger); }
.mai-diff del { background: #fde2e1; text-decoration: line-through; } .mai-diff ins { background: #dcfae6; text-decoration: none; }
.mai-note { font-size: 12.5px; color: var(--mai-muted); margin: 6px 0 0; }

@media (max-width: 640px) {
  .mai-col { width: min(100% - 24px, var(--mai-col)); }
  .mai-head { height: 52px; padding: 0 6px 0 12px; }
  .mai-head .mai-avatar { width: 26px; height: 26px; }
  .mai-log { gap: 20px; padding-top: 20px; }
  .mai-msg { gap: 10px; }
  .mai-assistant > .mai-avatar { display: none; }
  .mai-user .mai-bubble { max-width: 88%; padding: 9px 15px; }
  .mai-hint { font-size: 11px; margin-top: 6px; }
  .mai-source span { max-width: 170px; }
  .mai-lang select { max-width: 96px; }
}
@media (prefers-reduced-motion: reduce) {
  .mai-msg, .mai-typing, .mai-welcome, .mai-jump { animation: none; }
  .mai-dots i, .mai-streaming .mai-body > :last-child::after, .mai-avatar--pulse { animation: none; }
  .mai-send:not(:disabled):hover { transform: none; }
}

/* Host-page resilience: the admin's `.tabler-ui button { border-radius: 0 }` and
   global textarea borders are more specific than the rules above, so the
   chat's own shapes are restated with a higher specificity here. */
.mai button.mai-starter { border-radius: 18px; }
@media (min-width: 720px) { .mai button.mai-starter { border-radius: 14px; } }
.mai button.mai-send, .mai button.mai-jump { border-radius: 50%; }
.mai button.mai-icon-btn, .mai select { border-radius: 10px; }
.mai button.mai-btn { border-radius: 10px; }
.mai button.mai-mini { border-radius: 8px; }
.mai .mai-compose textarea, .mai .mai-compose textarea:focus, .mai .mai-compose textarea:focus-visible { border: 0; box-shadow: none; outline: none; background: transparent; padding: 8px 0; min-height: 0; }
.mai .mai-card textarea, .mai .mai-card input { border: 1px solid var(--mai-line-strong); border-radius: 12px; }
