:root {
  --bg-start: #050c1f;
  --bg-end: #0b1226;
  --surface: rgba(13, 23, 46, 0.9);
  --surface-alt: rgba(15, 23, 42, 0.65);
  --border: rgba(148, 163, 184, 0.18);
  --heading: #f8fafc;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #8b5cf6;
  --accent-strong: #a78bfa;
  --accent-soft: rgba(129, 140, 248, 0.15);
  --danger: #f87171;
  --success: #4ade80;
  --radius-lg: 20px;
  --radius: 14px;
  --shadow: 0 30px 60px rgba(3, 7, 18, 0.55);
}

* {
  box-sizing: border-box;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.25), transparent 45%),
    radial-gradient(circle at 80% 0%, rgba(14, 165, 233, 0.2), transparent 40%),
    linear-gradient(135deg, var(--bg-start), var(--bg-end));
  color: var(--text);
}

#app {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 32px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

h1,
h2,
h3 {
  color: var(--heading);
  margin: 0 0 8px;
}

p {
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

header.card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.dashboard-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-auto-rows: auto;
  align-items: start;
  gap: 24px;
}

.dashboard-heading {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dashboard-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  width: 100%;
}

.dashboard-title-row > h1 {
  flex: 1 1 auto;
  margin-bottom: 0;
  min-width: 0;
}

.dashboard-actions {
  grid-column: 2 / 3;
  grid-row: 2 / 3;
  justify-self: end;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.dashboard-action-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.dashboard-logo {
  flex: 0 0 auto;
  max-height: 36px;
  max-width: 120px;
  width: auto;
  object-fit: contain;
  border-radius: 8px;
  display: block;
}

.dashboard-actions .dashboard-logo {
  margin: 0 auto;
  padding-bottom: 16px;
}

.kb-stat {
  margin-top: 8px;
  padding: 18px 22px;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 1px solid rgba(148, 163, 184, 0.25);
  max-width: 360px;
}

.kb-stat-value {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--heading);
  margin: 4px 0;
  transition: color 0.2s ease;
}

.kb-stat-value[data-state='loading'] {
  font-size: 1.1rem;
  color: var(--muted);
}

.kb-stat-value[data-state='error'] {
  font-size: 1.1rem;
  color: var(--danger);
}

.kb-stat-hint {
  font-size: 0.9rem;
}

.hidden {
  display: none;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
  font-weight: 600;
  color: var(--text);
}

input[type='text'],
input[type='password'] {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(8, 13, 27, 0.8);
  color: var(--heading);
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

input[type='text']:focus,
input[type='password']:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.35);
}

button {
  background: linear-gradient(120deg, var(--accent), var(--accent-strong));
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  box-shadow: 0 15px 30px rgba(129, 140, 248, 0.35);
}

button:hover {
  transform: translateY(-1px);
}

button:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

button.secondary {
  background: rgba(148, 163, 184, 0.25);
  box-shadow: none;
}

button.danger {
  background: var(--danger);
  box-shadow: 0 10px 20px rgba(248, 113, 113, 0.4);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.muted {
  color: var(--muted);
  font-size: 0.95rem;
}

.error {
  color: var(--danger);
  min-height: 20px;
  margin-top: 12px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.upload-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.upload-dropzone {
  position: relative;
  border: 1px dashed rgba(148, 163, 184, 0.4);
  border-radius: var(--radius);
  padding: 28px;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.upload-dropzone input[type='file'] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.dropzone-body {
  display: flex;
  align-items: center;
  gap: 20px;
}

.dropzone-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.dropzone-title {
  font-size: 1.15rem;
  font-weight: 600;
}

.dropzone-sub {
  margin-top: 4px;
  color: var(--muted);
}

.dropzone-file {
  margin-top: 10px;
  color: var(--heading);
  font-weight: 500;
}

.upload-dropzone[data-state='dragging'] {
  border-color: var(--accent);
  box-shadow: 0 20px 40px rgba(129, 140, 248, 0.25);
  transform: translateY(-2px);
}

.upload-dropzone[data-state='busy'] {
  opacity: 0.5;
  pointer-events: none;
}

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

.upload-queue {
  display: flex;
  gap: 16px;
  align-items: stretch;
  flex-wrap: wrap;
}

.upload-queue .upload-actions {
  min-width: 180px;
  justify-content: flex-end;
  align-items: center;
}

.upload-queue .upload-actions button {
  width: 100%;
  max-width: 220px;
}

.upload-file-list {
  flex: 1;
  min-height: 96px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-file-list.has-items .upload-file-empty {
  display: none;
}

.upload-file-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.upload-file-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.upload-file-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.upload-file-details {
  flex: 1;
}

.upload-file-name {
  margin: 0;
  font-weight: 600;
  color: var(--heading);
}

.upload-file-meta {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.upload-file-error {
  margin-top: 4px;
  font-size: 0.8rem;
}

.upload-file-status {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: capitalize;
}

.upload-file-item[data-status='success'] .upload-file-status {
  color: var(--success);
}

.upload-file-item[data-status='success'] .upload-file-progress-fill {
  background: linear-gradient(120deg, var(--success), #22c55e);
}

.upload-file-item[data-status='error'] .upload-file-status {
  color: var(--danger);
}

.upload-file-item[data-status='error'] .upload-file-progress-fill {
  background: linear-gradient(120deg, var(--danger), #fbbf24);
}

.upload-file-item[data-status='error'] .upload-file-error {
  color: var(--danger);
}

.upload-file-item[data-status='uploading'] .upload-file-status {
  color: #93c5fd;
}

.upload-file-progress {
  margin-top: 8px;
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.upload-file-progress-fill {
  display: block;
  height: 100%;
  width: var(--file-progress, 0%);
  border-radius: inherit;
  background: linear-gradient(120deg, var(--accent), var(--accent-strong));
  position: relative;
}

.upload-file-progress-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 10%, rgba(255, 255, 255, 0.4) 50%, transparent 90%);
  animation: progressSheen 2s linear infinite;
  opacity: 0.4;
}

.upload-file-remove {
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  box-shadow: none;
}

.upload-file-remove:hover {
  background: rgba(148, 163, 184, 0.15);
}

.upload-progress {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.upload-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
}

.progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.25);
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  width: var(--progress, 0%);
  border-radius: inherit;
  background: linear-gradient(120deg, var(--accent), var(--accent-strong));
  transition: width 0.2s ease;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 15%, rgba(255, 255, 255, 0.5) 50%, transparent 85%);
  animation: progressSheen 1.8s linear infinite;
  opacity: 0.4;
}

.upload-progress.is-indeterminate .progress-fill {
  width: 45%;
  animation: progressPulse 1.4s ease-in-out infinite;
}

.upload-progress.is-indeterminate .progress-fill::after {
  opacity: 0;
}

@keyframes progressPulse {
  0% {
    transform: translateX(-50%);
  }
  50% {
    transform: translateX(60%);
  }
  100% {
    transform: translateX(120%);
  }
}

@keyframes progressSheen {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, 0.1);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  text-align: left;
}

th {
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

tr:last-child td {
  border-bottom: none;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  min-width: 120px;
  text-align: center;
}

.doc-status-cell {
  text-align: center;
  vertical-align: middle;
}

.doc-status-cell .status-chip {
  justify-content: center;
}

.doc-updated {
  white-space: nowrap;
  min-width: 170px;
}

.doc-row-removing {
  animation: docRowFade 0.35s ease forwards;
}

@keyframes docRowFade {
  to {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.status-uploading {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
}

.status-uploaded,
.status-ready {
  background: rgba(74, 222, 128, 0.15);
  color: var(--success);
}

.status-indexing {
  background: rgba(234, 179, 8, 0.18);
  color: #fde047;
}

.status-replacing {
  background: rgba(14, 165, 233, 0.18);
  color: #7dd3fc;
}

.status-failed {
  background: rgba(248, 113, 113, 0.2);
  color: #fecaca;
}

.status-deleted {
  background: rgba(148, 163, 184, 0.18);
  color: #cbd5f5;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.doc-actions button {
  margin-right: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 32px;
}

.modal-content {
  background: rgba(13, 23, 46, 0.98);
  border-radius: var(--radius-lg);
  width: min(960px, 90vw);
  height: 80vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

iframe {
  flex: 1;
  border: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: #fff;
}

#login-view {
  max-width: 420px;
  margin: 80px auto;
}

@media (max-width: 768px) {
  #app {
    padding: 20px;
  }

  header.card,
  .section-heading,
  .actions,
  .dropzone-body {
    flex-direction: column;
    align-items: flex-start;
  }

  .dashboard-header {
    display: flex;
    flex-direction: column;
  }

  .dashboard-actions {
    width: 100%;
    align-items: center;
  }

  .dashboard-action-buttons {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .dashboard-title-row {
    width: 100%;
  }

  .kb-stat {
    width: 100%;
  }

  .upload-actions {
    width: 100%;
    justify-content: stretch;
  }

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

  .dropzone-icon {
    width: 54px;
    height: 54px;
  }

  table {
    min-width: unset;
  }
}