:root {
  --teal: #153946;
  --teal-deep: #0d2832;
  --steel: #5e9db3;
  --steel-soft: #dceaf0;
  --accent: #fcc537;
  --accent-soft: #fff3c4;
  --ink: #153946;
  --muted: #727272;
  --line: #d9d8d6;
  --surface: #ffffff;
  --canvas: #f0efef;
  --danger: #a33535;
  --danger-soft: #fbeaea;
  --success: #2f6b4f;
  --success-soft: #e4f1e9;
  --shadow: 0 18px 50px rgba(21, 57, 70, 0.11);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans", "Noto Naskh Arabic", "Geeza Pro", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 8%, rgba(94, 157, 179, 0.13), transparent 34rem),
    linear-gradient(180deg, #f7f6f5 0%, var(--canvas) 58%, #e9e8e7 100%);
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid rgba(21, 57, 70, 0.12);
  backdrop-filter: blur(12px);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 0.85rem clamp(1rem, 4vw, 3.5rem);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  align-items: center;
  display: flex;
  gap: 0.65rem;
  min-width: 0;
}

.brand-logo {
  display: block;
  height: 2.15rem;
  width: auto;
}

.brand-fallback {
  align-items: center;
  background: var(--teal);
  border-radius: 6px;
  color: white;
  display: inline-flex;
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 700;
  height: 2.15rem;
  justify-content: center;
  letter-spacing: 0.08em;
  width: 3.2rem;
}

.brand-divider {
  background: var(--line);
  height: 1.7rem;
  margin-inline: 0.2rem;
  width: 1px;
}

.brand-name {
  color: var(--teal);
  font-family: var(--display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.topbar-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: flex-end;
}

.current-user {
  border-inline-start: 1px solid var(--line);
  color: var(--teal);
  font-size: 0.88rem;
  font-weight: 600;
  padding-inline-start: 0.7rem;
}

.main {
  flex: 1;
  margin: 0 auto;
  max-width: 1180px;
  padding: clamp(1.2rem, 3vw, 2.6rem) clamp(1rem, 4vw, 2.5rem) 3rem;
  width: 100%;
}

.button {
  border: 1px solid transparent;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  gap: 0.4rem;
  min-height: 2.6rem;
  padding: 0.55rem 1.15rem;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible,
.tab:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(94, 157, 179, 0.48);
  outline-offset: 2px;
}

.button-primary {
  background: var(--teal);
  color: #ffffff;
}

.button-primary:hover:not(:disabled) {
  background: var(--teal-deep);
}

.button-secondary {
  background: var(--steel-soft);
  color: var(--teal-deep);
}

.button-secondary:hover:not(:disabled) {
  background: #c9dfe8;
}

.button-quiet {
  background: transparent;
  border-color: rgba(21, 57, 70, 0.2);
  color: var(--teal);
}

.button-quiet:hover:not(:disabled) {
  background: rgba(21, 57, 70, 0.06);
}

.button-block {
  width: 100%;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.login-view {
  align-items: stretch;
  display: grid;
  gap: clamp(1rem, 3vw, 2.4rem);
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  margin: 1rem auto;
  max-width: 1040px;
}

.login-art {
  background:
    linear-gradient(145deg, rgba(13, 40, 50, 0.96), rgba(21, 57, 70, 0.92)),
    var(--teal);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 24rem;
  overflow: hidden;
  padding: clamp(1.5rem, 4vw, 3rem);
  position: relative;
}

.art-ring {
  border: 1px solid rgba(252, 197, 55, 0.55);
  border-radius: 50%;
  height: 26rem;
  inset-block-start: -8rem;
  inset-inline-end: -7rem;
  position: absolute;
  width: 26rem;
}

.art-ring::after {
  border: 1px solid rgba(94, 157, 179, 0.55);
  border-radius: 50%;
  content: "";
  inset: 2.6rem;
  position: absolute;
}

.art-grid {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.055) 1px, transparent 1px);
  background-size: 2.4rem 2.4rem;
  inset: 0;
  mask-image: linear-gradient(180deg, black, transparent 78%);
  position: absolute;
}

.art-kicker {
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  margin: 0 0 1.1rem;
  position: relative;
  text-transform: uppercase;
}

.art-lines {
  font-family: var(--display);
  white-space: pre-line;
  font-size: clamp(2rem, 4vw, 3.15rem);
  font-weight: 500;
  line-height: 1.08;
  margin: 0;
  position: relative;
}

.login-card {
  align-self: center;
  background: var(--surface);
  border: 1px solid rgba(21, 57, 70, 0.09);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: clamp(1.5rem, 3vw, 2rem);
}

.login-card h1 {
  font-size: clamp(1.6rem, 2.4vw, 2rem);
  line-height: 1.15;
}

.login-card .lede {
  font-size: 0.9rem;
  line-height: 1.5;
}

.eyebrow {
  color: var(--steel);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  margin: 0 0 0.6rem;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

h1 {
  font-size: clamp(1.9rem, 3.2vw, 2.65rem);
  line-height: 1.08;
}

h2 {
  font-size: clamp(1.4rem, 2.2vw, 1.8rem);
}

h3 {
  font-size: 1.05rem;
}

.lede {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.62;
  margin: 0.85rem 0 0;
  max-width: 38rem;
}

.login-form {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.field {
  display: grid;
  font-size: 0.85rem;
  font-weight: 600;
  gap: 0.42rem;
}

.field input,
.search-row input,
.chat-form textarea {
  background: #fbfbfa;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 2.9rem;
  padding: 0.7rem 0.85rem;
  transition: border-color 160ms ease, background-color 160ms ease;
  width: 100%;
}

.field input:hover,
.search-row input:hover,
.chat-form textarea:hover {
  border-color: #b9c8cd;
}

.field input:focus,
.search-row input:focus,
.chat-form textarea:focus {
  background: #ffffff;
  border-color: var(--steel);
}

.form-error {
  background: var(--danger-soft);
  border-inline-start: 4px solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 0.88rem;
  line-height: 1.45;
  margin: 0;
  padding: 0.7rem 0.85rem;
}

.fineprint {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
  margin: 1.4rem 0 0;
}

.portal-view {
  animation: rise 280ms ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.intro {
  align-items: flex-end;
  display: flex;
  gap: 2rem;
  justify-content: space-between;
  padding: 0.4rem 0 1.8rem;
}

.intro-mark {
  align-items: center;
  background: var(--teal);
  border-radius: 50%;
  color: var(--accent);
  display: flex;
  flex: 0 0 auto;
  font-family: var(--display);
  font-size: 1.5rem;
  height: 4.4rem;
  justify-content: center;
  letter-spacing: 0.04em;
  width: 4.4rem;
}

.tabs {
  border-bottom: 1px solid rgba(21, 57, 70, 0.16);
  display: flex;
  gap: clamp(1rem, 3vw, 2.5rem);
  margin-bottom: 1.6rem;
  overflow-x: auto;
}

.tab {
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: -1px;
  padding: 0.8rem 0.1rem;
  white-space: nowrap;
}

.tab:hover {
  color: var(--teal);
}

.tab[aria-selected="true"] {
  border-bottom-color: var(--accent);
  color: var(--teal);
}

.panel {
  background: var(--surface);
  border: 1px solid rgba(21, 57, 70, 0.09);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 34px rgba(21, 57, 70, 0.06);
  padding: clamp(1.1rem, 3vw, 2rem);
}

.panel-head {
  align-items: flex-start;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1.2rem;
}

.panel-head-tight {
  align-items: center;
  border-top: 1px solid var(--line);
  margin-top: 1.7rem;
  padding-top: 1.3rem;
}

.panel-sub {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
  margin: 0.4rem 0 0;
  max-width: 44rem;
}

.search-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.search-row input {
  flex: 1;
}

.status-line {
  color: var(--muted);
  font-size: 0.86rem;
  min-height: 1.2rem;
  margin: 0.5rem 0;
}

.status-strong {
  color: var(--teal);
  font-weight: 600;
}

.state-block {
  background: #faf9f8;
  border: 1px dashed #c9c7c4;
  border-radius: var(--radius-md);
  color: var(--muted);
  margin: 1rem 0;
  padding: 1.5rem;
  text-align: center;
}

.state-block p {
  margin: 0.3rem 0;
}

.state-title {
  color: var(--teal);
  font-family: var(--display);
  font-size: 1.15rem;
}

.state-error {
  background: var(--danger-soft);
  border-color: #e2bdbd;
  color: var(--danger);
}

.doc-list {
  display: grid;
  gap: 0.55rem;
}

.doc-row {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.doc-row:hover {
  background: #fbfaf8;
  border-color: #b9c8cd;
}

.doc-main {
  min-width: 0;
}

.doc-name {
  color: var(--teal);
  font-size: 0.96rem;
  font-weight: 600;
  line-height: 1.4;
  margin: 0;
  overflow-wrap: anywhere;
}

.doc-meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.78rem;
  gap: 0.35rem 0.9rem;
  margin: 0.28rem 0 0;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.32rem 0.62rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-completed {
  background: var(--success-soft);
  color: var(--success);
}

.badge-indexing,
.badge-submitted,
.badge-pending {
  background: var(--steel-soft);
  color: var(--teal);
}

.badge-review {
  background: var(--accent-soft);
  color: #6b4f00;
}

.badge-rejected {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-unknown {
  background: #ecebea;
  color: #5a5a5a;
}

.pager {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.2rem;
}

.pager-label {
  color: var(--muted);
  font-size: 0.82rem;
  min-width: 7rem;
  text-align: center;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-height: 30rem;
  min-height: 16rem;
  overflow-y: auto;
  padding: 0.2rem 0.2rem 0.6rem;
}

.message {
  border-radius: var(--radius-md);
  line-height: 1.6;
  max-width: min(46rem, 88%);
  padding: 0.85rem 1rem;
}

.message-user {
  align-self: flex-end;
  background: var(--teal);
  color: #ffffff;
}

.message-assistant {
  align-self: flex-start;
  background: #f7f8f8;
  border: 1px solid var(--line);
}

.message-error {
  align-self: flex-start;
  background: var(--danger-soft);
  border: 1px solid #e2bdbd;
  color: var(--danger);
}

.message-role {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  margin: 0 0 0.32rem;
  opacity: 0.72;
  text-transform: uppercase;
}

.message-text {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.citations {
  border-top: 1px solid rgba(21, 57, 70, 0.14);
  display: grid;
  gap: 0.5rem;
  margin-top: 0.8rem;
  padding-top: 0.7rem;
}

.citation {
  font-size: 0.82rem;
}

.citation summary {
  color: var(--teal);
  cursor: pointer;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.citation-meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.75rem;
  gap: 0.3rem 0.8rem;
  margin: 0.4rem 0;
}

.citation-text {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: #444444;
  line-height: 1.55;
  margin: 0.35rem 0 0;
  max-height: 12rem;
  overflow: auto;
  padding: 0.6rem;
  white-space: pre-wrap;
}

.chat-form {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.6rem;
  margin-top: 1rem;
  padding-top: 1rem;
}

.chat-form textarea {
  line-height: 1.5;
  min-height: 5.2rem;
  resize: vertical;
}

.chat-actions {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

.chat-actions .status-line {
  flex: 1;
  margin: 0;
}

.upload-form {
  border: 1px dashed #a9bcc4;
  border-radius: var(--radius-md);
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
}

.dropzone {
  align-items: center;
  background: #f8fafb;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  justify-content: center;
  min-height: 9rem;
  padding: 1.4rem;
  text-align: center;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.dropzone:hover,
.dropzone.is-dragging {
  background: #edf4f7;
}

.drop-title {
  color: var(--teal);
  font-family: var(--display);
  font-size: 1.2rem;
}

.drop-sub {
  color: var(--muted);
  font-size: 0.8rem;
}

.selected-file {
  color: var(--teal);
  font-size: 0.86rem;
  margin: 0;
  overflow-wrap: anywhere;
}

.upload-progress {
  accent-color: var(--accent);
  height: 0.6rem;
  width: 100%;
}

.upload-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

.notice {
  background: var(--accent-soft);
  border-inline-start: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  color: #5a4a14;
  font-size: 0.8rem;
  line-height: 1.55;
  margin: 1rem 0 0;
  padding: 0.75rem 0.9rem;
}

.upload-list {
  display: grid;
  gap: 0.5rem;
}

.upload-row {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 0.8rem 0.95rem;
}

.upload-file {
  min-width: 0;
}

.upload-name {
  color: var(--teal);
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0;
  overflow-wrap: anywhere;
}

.upload-meta {
  color: var(--muted);
  font-size: 0.76rem;
  margin: 0.25rem 0 0;
}

.upload-message {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0.35rem 0 0;
  max-width: 34rem;
}

.footer {
  align-items: center;
  border-top: 1px solid rgba(21, 57, 70, 0.12);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.74rem;
  gap: 0.5rem 1.4rem;
  justify-content: space-between;
  padding: 1rem clamp(1rem, 4vw, 3.5rem);
}

.visually-hidden {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

html[dir="rtl"] .art-lines {
  line-height: 1.3;
}

html[dir="rtl"] body {
  font-family: "Noto Naskh Arabic", "Geeza Pro", "Segoe UI", Tahoma, var(--sans);
}

html[dir="rtl"] .brand-sub,
html[dir="rtl"] .eyebrow,
html[dir="rtl"] .message-role,
html[dir="rtl"] .badge {
  letter-spacing: 0;
}

html[dir="rtl"] .button,
html[dir="rtl"] .tab,
html[dir="rtl"] input,
html[dir="rtl"] textarea {
  letter-spacing: 0;
}

@media (max-width: 860px) {
  .login-view {
    grid-template-columns: 1fr;
  }

  .login-art {
    display: none;
  }

  .art-ring {
    height: 18rem;
    inset-block-start: -8rem;
    width: 18rem;
  }

  .brand-sub {
    display: none;
  }

  .intro-mark {
    display: none;
  }
}

@media (max-width: 600px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.6rem;
  }

  .topbar-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .brand-divider {
    display: none;
  }

  .main {
    padding-top: 1rem;
  }

  .panel-head {
    flex-direction: column;
  }

  .search-row {
    flex-direction: column;
  }

  .search-row .button {
    width: 100%;
  }

  .doc-row,
  .upload-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.55rem;
  }

  .message {
    max-width: 100%;
  }

  .chat-actions,
  .upload-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-actions .button,
  .upload-actions .button {
    width: 100%;
  }

  .chat-log {
    max-height: 24rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
