:root {
  --navy: #0b1f36;
  --navy-deep: #071526;
  --navy-soft: #143251;
  --gold: #c9a227;
  --gold-soft: #e8d48b;
  --cream: #f4efe4;
  --paper: #fbf8f2;
  --ink: #122033;
  --muted: #5b6776;
  --assistant: #ffffff;
  --user: #12385a;
  --danger: #9b2335;
  --shadow: 0 18px 50px rgba(7, 21, 38, 0.18);
  --stage: linear-gradient(180deg, #e9e1d2 0%, #d9e0e8 100%);
  --composer: #ffffff;
  --composer-field: var(--cream);
  --chip-bg: #fffaf0;
  --avatar-bg: #0b1f36;
}

html[data-theme="dark"] {
  --navy: #9ecbff;
  --navy-deep: #06111f;
  --navy-soft: #7eb6f2;
  --gold: #e2c36b;
  --gold-soft: #f3e2a6;
  --cream: #151b27;
  --paper: #121826;
  --ink: #e8eef6;
  --muted: #9aa7b8;
  --assistant: #1a2333;
  --user: #1d4e7a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --stage: radial-gradient(900px 420px at 0% 0%, rgba(80, 40, 160, 0.35), transparent 45%),
    linear-gradient(180deg, #070b14 0%, #101827 100%);
  --composer: #171e2b;
  --composer-field: #101722;
  --chip-bg: #1d2636;
  --avatar-bg: #0b1f36;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--stage);
}

.container-xl {
  width: min(1200px, 100%);
  margin-inline: auto;
  padding-inline: 1rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ico {
  width: 1em;
  height: 1em;
  fill: currentColor;
  flex-shrink: 0;
}

.app-shell {
  min-height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  overflow: hidden;
  isolation: isolate;
  color: #fff;
  padding: 0.7rem 0;
  box-shadow: 0 10px 30px rgba(8, 6, 28, 0.35);
  border-bottom: 2px solid rgba(125, 249, 255, 0.45);
  background:
    linear-gradient(120deg, #07061a, #1a0b3c, #052a4d, #3b0d5c, #063b4a, #14082e);
  background-size: 280% 280%;
  animation: aiFlow 14s ease infinite;
}

.app-header::before {
  content: "";
  position: absolute;
  inset: -40% -20%;
  background:
    radial-gradient(circle at 20% 50%, rgba(0, 255, 255, 0.22), transparent 32%),
    radial-gradient(circle at 80% 40%, rgba(168, 85, 247, 0.28), transparent 34%),
    radial-gradient(circle at 50% 100%, rgba(56, 189, 248, 0.2), transparent 36%);
  animation: aiGlow 8s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: -1;
}

.app-header::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    transparent 0%,
    rgba(255, 255, 255, 0.08) 45%,
    rgba(0, 255, 247, 0.16) 50%,
    transparent 56%
  );
  background-size: 220% 100%;
  animation: aiShine 7s linear infinite;
  pointer-events: none;
  z-index: -1;
}

.logos-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.7rem;
  flex-shrink: 0;
}

.logo-frame {
  margin: 0;
  display: grid;
  place-items: center;
}

.logo-frame img {
  display: block;
  object-fit: contain;
  max-height: 64px;
  width: auto;
}

.logo-ministry {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  overflow: hidden;
  background: #071018;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.28);
}

.logo-ministry img {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: cover;
  transform: scale(1.28);
  transform-origin: center;
  mix-blend-mode: screen;
}

.logo-company img {
  max-height: 68px;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}

.logo-diwan {
  background: #fff;
  border-radius: 14px;
  padding: 0.2rem 0.45rem;
  overflow: hidden;
}

.logo-diwan img {
  max-height: 54px;
}

.title-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: relative;
  z-index: 1;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.gov-kicker {
  margin: 0.18rem 0 0;
  color: #b8fff7;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-shadow: 0 0 12px rgba(80, 255, 247, 0.35);
}

.title-copy h1 {
  margin: 0;
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
  font-size: clamp(1.15rem, 2.2vw, 1.75rem);
  line-height: 1.35;
}

.developer-credit {
  margin: 0.35rem 0 0;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--navy-soft);
  letter-spacing: 0.03em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.header-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--navy-deep);
  background: linear-gradient(180deg, #f8e7b0, var(--gold));
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.88rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.header-chip-doc {
  padding: 0.32rem 0.7rem;
  font-size: 0.8rem;
}

.header-chip:hover {
  color: var(--navy-deep);
  filter: brightness(1.05);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(8, 12, 28, 0.35);
  color: #fff;
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  font-weight: 700;
  font-size: 0.84rem;
  backdrop-filter: blur(8px);
  box-shadow: 0 0 16px rgba(80, 255, 247, 0.2);
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

@keyframes aiFlow {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes aiGlow {
  0% { transform: translate3d(-4%, 0, 0) scale(1); opacity: 0.75; }
  100% { transform: translate3d(6%, -6%, 0) scale(1.08); opacity: 1; }
}

@keyframes aiShine {
  0% { background-position: 120% 0; }
  100% { background-position: -40% 0; }
}

.chat-stage {
  flex: 1;
  min-height: 0;
  padding: 1.1rem 0 1.4rem;
}

.chat-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 1.1rem;
  height: 100%;
  min-height: 0;
}

.info-panel {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.info-card {
  background: var(--paper);
  border: 1px solid rgba(201, 162, 39, 0.28);
  border-radius: 18px;
  padding: 1.15rem 1.2rem;
  box-shadow: var(--shadow);
}

.info-card h2 {
  font-size: 1.05rem;
  margin-bottom: 0.7rem;
  color: var(--navy);
}

.info-card ul {
  padding-right: 1.1rem;
  margin: 0;
  color: var(--muted);
}

.info-card li + li {
  margin-top: 0.4rem;
}

.info-card.muted p {
  margin: 0 0 0.35rem;
  color: var(--muted);
}

.info-card a {
  color: var(--navy-soft);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--paper);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid rgba(11, 31, 54, 0.08);
}

.chat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1.2rem 1.1rem 0.6rem;
  background:
    linear-gradient(180deg, rgba(11, 31, 54, 0.03), transparent 120px),
    repeating-linear-gradient(
      -18deg,
      rgba(201, 162, 39, 0.035) 0 12px,
      transparent 12px 24px
    );
}

.msg {
  display: flex;
  gap: 0.7rem;
  margin-bottom: 1rem;
  max-width: min(92%, 720px);
  animation: rise 0.28s ease;
}

.msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
  margin-right: auto;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 1.05rem;
}

.msg.assistant .avatar {
  background: var(--avatar-bg);
  color: var(--gold);
  border: 2px solid var(--gold);
}

.msg.assistant .bot-avatar {
  width: 52px;
  height: 52px;
  overflow: hidden;
  background: #0b1f36;
  box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.28);
}

.bot-robot {
  width: 118%;
  height: 118%;
  object-fit: contain;
  mix-blend-mode: screen;
  transform: translateY(4%);
}

.msg.user .avatar {
  background: var(--gold);
  color: var(--navy);
}

.bubble {
  border-radius: 18px;
  padding: 0.85rem 1rem;
  line-height: 1.85;
  box-shadow: 0 8px 20px rgba(11, 31, 54, 0.08);
}

.msg.assistant .bubble {
  background: var(--assistant);
  border: 1px solid rgba(11, 31, 54, 0.08);
  border-top-right-radius: 6px;
}

.msg.user .bubble {
  background: linear-gradient(180deg, #1a4a72, #12385a);
  color: #fff;
  border-top-left-radius: 6px;
}

.bubble p {
  margin: 0 0 0.55rem;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble a {
  color: #fff;
  font-weight: 700;
  word-break: break-word;
}

.bubble a.chat-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  unicode-bidi: isolate;
  background: linear-gradient(180deg, #1a4a72, #12385a);
  color: #fff !important;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  margin: 0.35rem 0.15rem;
  max-width: 100%;
  line-height: 1.4;
}

.bubble a.chat-link-url {
  direction: ltr;
  unicode-bidi: isolate;
  word-break: break-all;
  overflow-wrap: anywhere;
}

.msg.user .bubble a {
  color: #ffe9a6;
}

.bubble ul,
.bubble ol {
  margin: 0.2rem 0 0.5rem;
  padding-right: 1.2rem;
}

.bubble strong {
  color: var(--navy);
}

.msg.user .bubble strong {
  color: var(--gold-soft);
}

.time {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.msg.user .time {
  color: rgba(255, 255, 255, 0.7);
}

.typing {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
  min-height: 1.4rem;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  animation: pulse 1s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

.bubble.streaming .stream-body::after {
  content: "▍";
  display: inline;
  margin-right: 0.15rem;
  color: var(--gold);
  animation: pulse 1s infinite ease-in-out;
}

.composer {
  background: var(--composer);
  border-top: 1px solid rgba(11, 31, 54, 0.08);
  padding: 0.75rem 0.9rem 0.85rem;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

.quick-actions button {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  border: 1px solid rgba(201, 162, 39, 0.5);
  background: var(--chip-bg);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.28rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
}

.quick-actions button:hover {
  background: var(--avatar-bg);
  color: var(--gold-soft);
}

.composer-form {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  background: transparent;
  border: 1px solid rgba(11, 31, 54, 0.18);
  border-radius: 16px;
  padding: 0.45rem 0.45rem 0.45rem 0.7rem;
}

.composer-form textarea {
  flex: 1;
  border: 0;
  resize: none;
  background: transparent;
  outline: none;
  min-height: 3.2em;
  max-height: 140px;
  font-family: inherit;
  font-size: 0.98rem;
  line-height: 1.7;
  color: var(--ink);
  font-weight: 400;
}

.composer-form textarea::placeholder {
  color: var(--muted);
  opacity: 1;
  font-weight: 500;
}

html[data-theme="dark"] .composer-form {
  border-color: rgba(158, 203, 255, 0.28);
}

.send-btn {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, #1a4a72, #071526);
  color: var(--gold);
  display: grid;
  place-items: center;
  font-size: 1.15rem;
}

.send-btn:disabled {
  opacity: 0.55;
}

.composer-note {
  margin: 0.55rem auto 0;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.9;
  color: var(--navy);
  max-width: 46rem;
}

.composer-note.is-expanded {
  -webkit-line-clamp: unset;
  max-height: none;
}

.composer-note strong {
  font-weight: 700;
}

.error-bubble {
  background: #fff3f3 !important;
  border-color: rgba(155, 35, 53, 0.25) !important;
  color: var(--danger);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes pulse {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 991.98px) {
  .app-header {
    padding: 0.4rem 0;
  }

  .chat-stage {
    padding: 0.55rem 0 0.65rem;
  }

  .chat-layout {
    grid-template-columns: 1fr;
  }

  .info-panel {
    display: none;
  }

  .title-inner {
    flex-wrap: wrap;
    gap: 0.45rem;
  }

  .header-brand {
    width: 100%;
    gap: 0.55rem;
  }

  .logos-row {
    gap: 0.35rem;
  }

  .logo-frame img,
  .logo-company img {
    max-height: 38px;
  }

  .logo-ministry {
    width: 38px;
    height: 38px;
  }

  .logo-diwan {
    padding: 0.1rem 0.28rem;
    border-radius: 8px;
  }

  .logo-diwan img {
    max-height: 32px;
  }

  .title-copy h1 {
    font-size: 0.98rem;
    line-height: 1.3;
  }

  .gov-kicker {
    font-size: 0.68rem;
    margin-top: 0.1rem;
  }

  .header-actions {
    width: 100%;
    gap: 0.35rem;
  }

  .header-chip,
  .theme-toggle {
    padding: 0.28rem 0.55rem;
    font-size: 0.74rem;
  }

  .header-chip-doc {
    padding: 0.22rem 0.48rem;
    font-size: 0.7rem;
  }

  .composer {
    padding: 0.45rem 0.55rem 0.5rem;
  }

  .composer-note {
    margin: 0.28rem auto 0;
    font-size: 0.62rem;
    line-height: 1.45;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    cursor: pointer;
  }

  .developer-credit {
    font-size: 0.72rem;
    margin-top: 0.12rem;
  }

  .quick-actions {
    margin-bottom: 0.4rem;
    gap: 0.28rem;
  }

  .quick-actions button {
    font-size: 0.72rem;
    padding: 0.2rem 0.55rem;
  }
}

@media (max-width: 575.98px) {
  .header-actions {
    justify-content: stretch;
  }

  .header-chip,
  .theme-toggle {
    flex: 1;
    justify-content: center;
  }

  .theme-toggle .theme-label {
    display: none;
  }

  .theme-toggle {
    flex: 0 0 auto;
    min-width: 40px;
    padding: 0.28rem 0.5rem;
  }
}
