:root {
  --green: #00a33a;
  --green-deep: #007a2c;
  --green-wash: #eaf7ee;
  --ink: #23262a;
  --ink-soft: #5a5f66;
  --ink-faint: #8a9098;
  --line: #e3e6e9;
  --paper: #ffffff;
  --mist: #f5f6f7;
  --red: #b3261e;
  --amber: #c98a00;
  --font: "IBM Plex Sans", "IBM Plex Sans Arabic", "Segoe UI", -apple-system, BlinkMacSystemFont, Tahoma, sans-serif;
}
:lang(ar) { --font: "IBM Plex Sans Arabic", "IBM Plex Sans", "Segoe UI", Tahoma, sans-serif; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* brand lockup: the SGS mark, a rule, the department */
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand img { height: 34px; width: auto; flex: none; }
.brand-rule { width: 1px; height: 30px; background: #b9bdc2; flex: none; }
.brand-dept {
  direction: ltr;
  max-width: 200px;
  color: var(--ink-soft);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
}

/* app frame */
.shell { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.topbar-tools { display: flex; align-items: center; gap: 4px; flex: none; }
.ghost {
  padding: 7px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.ghost:hover { background: var(--mist); color: var(--ink); }
.ghost svg, #lang-short { display: none; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  color: var(--ink-soft);
  font-size: 13px;
}
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.status[data-state="busy"] i { background: var(--amber); }
.status[data-state="offline"] i { background: var(--red); }

.conversation { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

/* first screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 32px 24px;
  text-align: center;
}
.welcome-ring { width: 76px; height: 76px; margin-bottom: 18px; }
.welcome h1 { margin: 0; font-size: 44px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.welcome-sub { margin: 10px 0 34px; color: var(--ink-soft); font-size: 17px; }
.prompts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.prompt {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  text-align: start;
  transition: border-color 0.15s, background 0.15s;
}
.prompt strong { color: var(--green-deep); font-size: 13px; font-weight: 600; }
.prompt span { color: var(--ink); font-size: 15px; line-height: 1.4; }
.prompt:hover { border-color: var(--green); background: var(--green-wash); }

/* conversation */
.messages { max-width: 780px; margin: 0 auto; padding: 0 24px; }
.messages:not(:empty) { padding-top: 28px; padding-bottom: 12px; }
.msg { margin-bottom: 26px; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble {
  max-width: 82%;
  padding: 10px 16px;
  border-radius: 18px;
  background: var(--mist);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.bot { display: flex; gap: 14px; align-items: flex-start; }
.mark { width: 30px; height: 30px; flex: none; margin-top: 1px; }
.mark.spinning { animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.answer { flex: 1; min-width: 0; padding-top: 2px; }
.answer-text p { margin: 0 0 10px; overflow-wrap: anywhere; }
.answer-text ul { margin: 0 0 10px; padding-inline-start: 20px; }
.answer-text li { margin-bottom: 4px; }
.answer-text li::marker { color: var(--green); }
.answer-text > :last-child { margin-bottom: 0; }
.answer-text strong { font-weight: 600; }
.answer-error { margin: 0; color: var(--red); }
.progress { margin: 3px 0 0; color: var(--ink-soft); font-size: 15px; font-variant-numeric: tabular-nums; }
.table-wrap { margin: 0 0 10px; overflow-x: auto; }
table { border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
td { padding: 6px 14px 6px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:first-child td { color: var(--ink-soft); font-weight: 600; }
.report-image { display: block; margin-top: 14px; }
.report-image img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.report-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 9px 15px;
  border-radius: 10px;
  background: var(--green-deep);
  color: #fff;
  font-size: 14.5px;
  font-weight: 500;
  text-decoration: none;
}
.report-file:hover { background: var(--green); }

/* composer */
.chat-actions { display: flex; gap: 8px; max-width: 732px; margin: 0 auto 8px; }
.chat-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 500;
  transition: border-color 0.15s, color 0.15s;
}
.chat-action:hover:not(:disabled) { border-color: var(--green); color: var(--green-deep); }
.chat-action:disabled { color: #b4b9be; cursor: default; }
#stop:not(:disabled) { border-color: var(--red); color: var(--red); }
.answer-stopped { margin: 0; color: var(--ink-soft); }
.composer-wrap {
  padding: 8px 24px 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--paper);
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 732px;
  margin: 0 auto;
  padding: 8px 8px 8px 18px;
  border: 1px solid #cfd3d7;
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 1px 6px rgba(35, 38, 42, 0.06);
  transition: border-color 0.15s;
}
[dir="rtl"] .composer { padding: 8px 18px 8px 8px; }
.composer:focus-within { border-color: var(--green); }
.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 180px;
  padding: 6px 0;
  border: 0;
  outline: 0;
  background: none;
  line-height: 1.5;
  resize: none;
}
.composer textarea::placeholder { color: var(--ink-faint); }
.send {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--green-deep);
  color: #fff;
}
.send:hover:not(:disabled) { background: var(--green); }
.send:disabled { background: #d9dcdf; cursor: default; }
.fineprint { min-height: 18px; margin: 6px 0 0; color: var(--ink-faint); font-size: 12.5px; text-align: center; }

/* change password */
.password-dialog {
  width: min(400px, calc(100vw - 32px));
  padding: 24px;
  border: 0;
  border-radius: 14px;
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(35, 38, 42, 0.22);
}
.password-dialog::backdrop { background: rgba(35, 38, 42, 0.45); }
.password-dialog h2 { margin: 0 0 18px; font-size: 20px; font-weight: 600; }
.password-dialog label { display: block; margin-bottom: 14px; color: var(--ink-soft); font-size: 14px; font-weight: 500; }
.password-dialog input:not([type="checkbox"]) {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 13px;
  border: 1px solid #cfd3d7;
  border-radius: 10px;
  color: var(--ink);
  font-size: 16px;
}
.password-dialog input:focus { outline: 0; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-wash); }
.password-dialog .show-both { display: flex; align-items: center; gap: 8px; }
.show-both input { accent-color: var(--green-deep); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.dialog-actions .ghost { display: inline-block; width: auto; height: auto; padding: 10px 14px; font-size: 15px; }
.dialog-actions .primary { margin: 0; padding: 10px 20px; }
.form-ok { color: var(--green-deep); }

/* sign in */
.login-main { position: relative; display: grid; place-items: center; min-height: 100dvh; padding: 32px 24px; }
.lang {
  position: absolute;
  top: 18px;
  inset-inline-end: 20px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
}
.lang:hover { background: var(--mist); }
.login-card { display: flex; flex-direction: column; width: 100%; max-width: 380px; }
.login-card h1 { margin: 34px 0 2px; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.login-sub { margin: 0 0 26px; color: var(--ink-soft); }
.login-card label { display: block; margin-bottom: 16px; color: var(--ink-soft); font-size: 14px; font-weight: 500; }
.login-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 14px;
  border: 1px solid #cfd3d7;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
}
.login-card input:focus { outline: 0; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-wash); }
.password-field { position: relative; display: block; margin-top: 6px; }
.password-field input { margin-top: 0; padding-inline-end: 72px; }
.show-password {
  position: absolute;
  top: 50%;
  inset-inline-end: 6px;
  padding: 5px 9px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--green-deep);
  font-size: 13.5px;
  font-weight: 600;
  transform: translateY(-50%);
}
.show-password:hover { background: var(--green-wash); }
.primary {
  margin-top: 6px;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--green-deep);
  color: #fff;
  font-weight: 600;
  transition: background 0.15s;
}
.primary:hover:not(:disabled) { background: var(--green); }
.primary:disabled { opacity: 0.6; cursor: default; }
.form-error { margin: 0 0 12px; color: var(--red); font-size: 14.5px; }
.login-note { margin: 20px 0 0; color: var(--ink-faint); font-size: 13.5px; }

@media (max-width: 720px) {
  .topbar { padding-inline: 16px; gap: 8px; }
  .brand { gap: 10px; }
  .brand img { height: 24px; }
  .brand-rule { height: 22px; }
  .brand-dept { max-width: 118px; font-size: 9.5px; }
  .status { padding: 0 4px; font-size: 0; gap: 0; }
  .topbar-tools { gap: 0; }
  .ghost { display: grid; place-items: center; min-width: 34px; height: 34px; padding: 0 5px; font-size: 12.5px; }
  .ghost svg { display: block; }
  .ghost span { display: none; }
  #lang-short { display: block; font-size: 14px; font-weight: 600; }
  .welcome { justify-content: flex-start; padding: 28px 16px 16px; }
  .welcome-ring { width: 58px; height: 58px; margin-bottom: 12px; }
  .welcome h1 { font-size: 34px; }
  .welcome-sub { margin-bottom: 22px; font-size: 15.5px; }
  .prompts { grid-template-columns: 1fr; gap: 8px; }
  .messages { padding-inline: 16px; }
  .bubble { max-width: 90%; }
  .msg.bot { gap: 10px; }
  .mark { width: 24px; height: 24px; }
  .composer-wrap { padding-inline: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .mark.spinning { animation-duration: 8s; }
  * { transition: none !important; }
}
