:root {
  --bg: #f4f8fd;
  --bg-soft: #eef4fc;
  --panel: #ffffff;
  --panel-soft: #f8fbff;
  --border: #d7e3f2;
  --border-strong: #c6d6eb;
  --text: #0f2450;
  --muted: #7d8faa;
  --muted-strong: #5f7390;
  --primary: #2f67f6;
  --primary-hover: #2258e3;
  --primary-soft: #dbe8ff;
  --success: #1ca36d;
  --success-soft: #daf4ea;
  --draft-soft: #e9f1ff;
  --danger: #d14d61;
  --shadow: 0 18px 45px rgba(25, 53, 102, 0.08);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(47, 103, 246, 0.08), transparent 30%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 15px 16px;
  color: var(--text);
  background: #ffffff;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus {
  border-color: rgba(47, 103, 246, 0.45);
  box-shadow: 0 0 0 4px rgba(47, 103, 246, 0.08);
}

textarea {
  resize: vertical;
  min-height: 320px;
}

.app {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 32px;
  background: rgba(255, 255, 255, 0.84);
  border-bottom: 1px solid rgba(215, 227, 242, 0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 1.3rem;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary) 0%, #477cff 100%);
  box-shadow: 0 12px 22px rgba(47, 103, 246, 0.24);
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.connection-badge {
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  background: var(--draft-soft);
  color: var(--primary);
}

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

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: var(--primary);
  background: linear-gradient(135deg, #ffffff 0%, #dce8ff 100%);
  border: 1px solid var(--border);
}

.main-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 32px auto 48px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.card {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(215, 227, 242, 0.95);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.connection-panel {
  display: grid;
  grid-template-columns: 1.05fr 1.45fr;
  gap: 24px;
  padding: 24px 26px;
  margin-bottom: 28px;
}

.connection-copy h2,
.page-head h1,
.modal-card h2,
.empty-state h3,
.upload-dropzone h3 {
  margin: 0;
}

.connection-copy p,
.editor-meta,
.list-caption,
.empty-state p,
.field span + .hint,
.editor-footer-note,
.upload-dropzone p {
  color: var(--muted);
}

.connection-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.editor-head {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--primary);
}

.page-head h1 {
  font-size: clamp(2.2rem, 3vw, 3.4rem);
  line-height: 1.05;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 700;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

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

.btn:disabled,
.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  transform: none;
}

.btn-primary {
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary) 0%, #477cff 100%);
  box-shadow: 0 14px 30px rgba(47, 103, 246, 0.22);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover) 0%, #3f70ea 100%);
}

.btn-secondary {
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border);
  box-shadow: 0 12px 22px rgba(15, 36, 80, 0.04);
}

.btn-ghost {
  color: var(--text);
  background: #f6f9fd;
  border: 1px solid var(--border);
}

.btn-danger {
  color: #ffffff;
  background: var(--danger);
  box-shadow: 0 14px 28px rgba(209, 77, 97, 0.18);
}

.btn-danger:hover {
  background: #bd4053;
}

.documents-panel {
  padding: 22px;
}

.document-list,
.units-list {
  display: grid;
  gap: 16px;
}

.hidden {
  display: none !important;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 290px;
  gap: 10px;
  padding: 32px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
}

.empty-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 50%;
}

.empty-icon svg {
  width: 28px;
  height: 28px;
}

.list-caption {
  margin: 16px 0 0;
  text-align: center;
  font-size: 0.97rem;
}

.document-card {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #ffffff;
  color: inherit;
  text-align: left;
  box-shadow: 0 12px 25px rgba(15, 36, 80, 0.04);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.document-card:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 103, 246, 0.28);
  box-shadow: 0 18px 30px rgba(15, 36, 80, 0.08);
}

.document-open-area {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.document-open-area:focus-visible {
  outline: 3px solid rgba(47, 103, 246, 0.22);
  outline-offset: 2px;
}

.document-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--primary);
  background: var(--primary-soft);
}

.document-icon svg {
  width: 20px;
  height: 20px;
}

.document-title {
  display: block;
  margin: 0 0 6px;
  font-size: 1.1rem;
  font-weight: 700;
}

.document-meta {
  display: block;
  margin: 0;
  color: var(--muted);
}

.document-side {
  display: flex;
  align-items: center;
  gap: 14px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  color: var(--muted-strong);
  background: #f6f9fd;
  border: 1px solid var(--border);
  transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.icon-btn:hover {
  color: var(--text);
  background: #eef4fc;
}

.icon-btn.danger {
  color: var(--danger);
  background: #fff5f7;
  border-color: rgba(209, 77, 97, 0.22);
}

.icon-btn.danger:hover {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.status-chip,
.meta-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 700;
}

.status-chip.draft {
  color: var(--primary);
  background: var(--draft-soft);
}

.status-chip.processed,
.status-chip.active {
  color: var(--success);
  background: var(--success-soft);
}

.meta-chip {
  color: var(--muted-strong);
  background: #f4f7fb;
}

.document-arrow {
  color: #b5c3d7;
  font-size: 1.35rem;
  line-height: 1;
}

.editor-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 26px;
}

.breadcrumb-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  color: var(--muted-strong);
  background: transparent;
  font-weight: 700;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.editor-card,
.upload-card {
  padding: 22px;
}

.field {
  display: grid;
  gap: 10px;
}

.field span {
  font-weight: 700;
}

.upload-card {
  margin-top: 18px;
}

.upload-dropzone {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 180px;
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: 18px;
  background: linear-gradient(180deg, #f9fcff 0%, #f4f9ff 100%);
  color: var(--text);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.upload-dropzone.dragover {
  border-color: var(--primary);
  background: linear-gradient(180deg, #f4f8ff 0%, #ebf3ff 100%);
}

.upload-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--primary);
  background: var(--primary-soft);
}

.upload-icon svg {
  width: 24px;
  height: 24px;
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
}

.editor-footer-note {
  margin: 0;
}

.units-list {
  margin-top: 6px;
}

.unit-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 25px rgba(15, 36, 80, 0.04);
}

.unit-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.unit-text {
  margin: 0;
  color: var(--text);
  line-height: 1.65;
  white-space: pre-wrap;
}

.unit-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toggle-group {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--muted-strong);
}

.switch {
  position: relative;
  display: inline-flex;
  width: 48px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  padding: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d8e3f5;
  transition: background 0.2s ease;
}

.switch-slider::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 4px 10px rgba(15, 36, 80, 0.12);
  transition: transform 0.2s ease;
}

.switch input:checked + .switch-slider {
  background: linear-gradient(135deg, var(--primary) 0%, #5a87ff 100%);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(9, 18, 33, 0.48);
  z-index: 50;
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  padding: 24px;
  border-radius: 22px;
  background: #ffffff;
  border: 1px solid var(--border);
  box-shadow: 0 30px 70px rgba(8, 17, 33, 0.24);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--muted-strong);
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 22px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 320px;
  padding: 14px 16px;
  border-radius: 16px;
  color: #ffffff;
  background: rgba(15, 36, 80, 0.96);
  box-shadow: 0 20px 35px rgba(15, 36, 80, 0.2);
  z-index: 60;
}

.toast.error {
  background: rgba(179, 56, 77, 0.96);
}

@media (max-width: 960px) {
  .main-shell {
    width: min(100%, calc(100% - 24px));
    margin-top: 20px;
  }

  .connection-panel,
  .connection-grid,
  .page-head,
  .editor-top,
  .editor-footer,
  .unit-head,
  .unit-meta-row {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .document-card {
    grid-template-columns: 1fr;
  }

  .document-side,
  .editor-actions,
  .modal-actions {
    justify-content: stretch;
  }

  .btn,
  .document-card,
  .editor-actions .btn,
  .modal-actions .btn {
    width: 100%;
  }

  .topbar {
    padding: 16px 18px;
  }

  .topbar-right {
    gap: 8px;
  }

  .connection-badge {
    display: none;
  }
}
