:root {
  --bg: #f3efe7;
  --bg-2: #e8dfd0;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-border: rgba(82, 61, 45, 0.14);
  --ink: #1d1a17;
  --muted: #6f6258;
  --accent: #7b4f2a;
  --accent-2: #2d6a6a;
  --shadow: 0 20px 60px rgba(77, 53, 32, 0.14);
  --radius: 22px;
  --radius-sm: 14px;
  font-synthesis-weight: none;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

html,
body {
  height: 100%;
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(243, 239, 231, 0.92);
  backdrop-filter: blur(16px);
}

.access-panel {
  width: min(360px, 100%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  padding: 22px;
}

.access-panel h2 {
  margin: 0 0 18px;
  font-size: 1.3rem;
}

.access-panel label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.access-panel input {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--ink);
  font: inherit;
  font-size: 1.15rem;
  letter-spacing: 0.18em;
}

.access-panel button {
  width: 100%;
  margin-top: 14px;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(123, 79, 42, 0.16), transparent 30%),
    radial-gradient(circle at bottom right, rgba(45, 106, 106, 0.12), transparent 24%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  font-family: Georgia, "Times New Roman", serif;
}

.shell {
  height: 100vh;
  padding: 20px 24px;
  overflow: hidden;
}

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

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--accent-2);
  margin-bottom: 8px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 1.7vw, 1.85rem);
  line-height: 1.1;
}

.subtitle {
  max-width: 62ch;
  color: var(--muted);
  margin: 12px 0 0;
  font-size: 1rem;
  line-height: 1.5;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}

.mode-switch,
.file-chip,
.field-chip,
.ghost-button,
.toggle,
.cite-style-group {
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.mode-switch {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
}

.mode-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
}

.mode-button.active {
  background: rgba(123, 79, 42, 0.14);
  color: var(--accent);
}

.file-chip,
.field-chip,
.toggle,
.cite-style-group,
.cite-style-group label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.file-chip,
.field-chip,
.toggle,
.cite-style-group {
  padding: 10px 14px;
  cursor: pointer;
  color: var(--ink);
}

.field-chip {
  min-width: 220px;
}

.field-chip span,
.file-chip span,
.toggle span,
.cite-style-group span {
  font-size: 0.92rem;
}

.cite-style-group {
  margin: 0;
  gap: 12px;
  font: inherit;
}

.cite-style-group label {
  cursor: pointer;
}

.field-chip input,
.file-chip input {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  min-width: 0;
  outline: none;
}

.patent-number-chip input {
  width: 120px;
}

.patent-number-chip span {
  color: var(--accent);
  font-weight: 700;
}

.file-chip input {
  max-width: 170px;
}

.ghost-button {
  padding: 10px 16px;
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
}

.editor-header-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--accent);
  cursor: pointer;
  flex: 0 0 auto;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.95);
}

.toggle {
  gap: 10px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(420px, 1.1fr);
  gap: 18px;
  height: calc(100vh - 126px);
  min-height: 0;
}

.panel {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(16px);
}

.patent-panel {
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(82, 61, 45, 0.1);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.42));
}

.panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

.patent-header-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.mini-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.mini-control select {
  border: 1px solid rgba(82, 61, 45, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  font: inherit;
  padding: 4px 6px;
}

.status {
  color: var(--muted);
  font-size: 0.88rem;
  text-align: right;
}

.paper {
  padding: 24px 22px 28px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  font-size: 0.92rem;
  line-height: 1.45;
}

.paper.text-size-normal {
  font-size: 1rem;
}

.paper.text-size-large {
  font-size: 1.1rem;
}

.paper.line-spacing-normal {
  line-height: 1.62;
}

.paper.line-spacing-loose {
  line-height: 1.82;
}

.paper h3 {
  margin-top: 0;
}

.paper p {
  margin: 0 0 1em;
}

.paper .page-title {
  margin: 0 0 18px;
  font-size: 1.3rem;
}

.empty-state {
  margin: 36px auto;
  max-width: 36ch;
  text-align: center;
  color: var(--muted);
}

.editor-panel {
  display: flex;
  flex-direction: column;
}

.editor-frame {
  padding: 16px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: stretch;
}

#editor {
  background: white;
  border-radius: 18px;
  min-height: 0;
  height: 100%;
  width: 100%;
  flex: 1;
  border: 1px solid rgba(82, 61, 45, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.editor-frame > .ck.ck-editor,
.ck.ck-editor,
.ck.ck-editor__main {
  height: 100%;
  min-height: 0;
  width: 100% !important;
  max-width: none;
}

.ck.ck-editor {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
}

.ck.ck-editor__top {
  flex: 0 0 auto;
}

.ck.ck-editor__main > .ck-editor__editable {
  height: 100%;
  min-height: 0;
  width: 100%;
  max-width: none;
  overflow-y: scroll;
  overflow-x: auto;
}

.ck.ck-editor__main > .ck-editor__editable img,
#editor.fallback-editor img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 10px 0;
}

.ck.ck-editor__main > .ck-editor__editable table.patent-table,
#editor.fallback-editor table.patent-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 0.92rem;
}

.ck.ck-editor__main > .ck-editor__editable table.patent-table caption,
#editor.fallback-editor table.patent-table caption {
  caption-side: top;
  text-align: left;
  font-weight: 700;
  padding: 0 0 8px;
}

.ck.ck-editor__main > .ck-editor__editable table.patent-table th,
.ck.ck-editor__main > .ck-editor__editable table.patent-table td,
#editor.fallback-editor table.patent-table th,
#editor.fallback-editor table.patent-table td {
  border: 1px solid rgba(82, 61, 45, 0.18);
  padding: 8px 10px;
  vertical-align: top;
}

.ck.ck-editor__main > .ck-editor__editable table.patent-table th,
#editor.fallback-editor table.patent-table th {
  background: rgba(244, 236, 220, 0.7);
  font-weight: 700;
}

.ck.ck-editor__main > .ck-editor__editable table.patent-table td,
#editor.fallback-editor table.patent-table td {
  background: #fff;
}

#editor.fallback-editor {
  padding: 18px 20px;
  outline: none;
  overflow-y: scroll;
  overflow-x: auto;
  font-family: Arial, sans-serif;
  line-height: 1.55;
}

.citation-bar {
  display: flex;
  justify-content: flex-start;
  gap: 16px;
  padding: 14px 20px 18px;
  border-top: 1px solid rgba(82, 61, 45, 0.1);
  color: var(--muted);
  font-size: 0.92rem;
  background: rgba(255, 255, 255, 0.34);
}

.citation-bar strong {
  color: var(--ink);
}

.jobs-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  background: rgba(31, 26, 22, 0.24);
  backdrop-filter: blur(3px);
}

.jobs-overlay.hidden {
  display: none;
}

.jobs-panel {
  width: min(760px, 100%);
  height: 100%;
  background: rgba(255, 253, 249, 0.98);
  border-left: 1px solid rgba(82, 61, 45, 0.18);
  box-shadow: -18px 0 40px rgba(42, 34, 28, 0.18);
  display: flex;
  flex-direction: column;
}

.jobs-panel-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px;
  border-bottom: 1px solid rgba(82, 61, 45, 0.12);
}

.jobs-panel-header h2 {
  margin: 0 0 6px;
  font-size: 1.25rem;
}

.jobs-panel-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.jobs-panel-actions {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.jobs-panel-body {
  flex: 1;
  overflow: auto;
  padding: 18px 24px 28px;
}

.jobs-section {
  margin-bottom: 24px;
}

.jobs-section h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--accent);
}

.prepared-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.prepared-search {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.prepared-search input {
  border: 1px solid rgba(122, 77, 43, 0.2);
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  min-width: 180px;
}

.prepared-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.prepared-table th,
.prepared-table td {
  border-top: 1px solid rgba(82, 61, 45, 0.12);
  padding: 8px 8px;
  text-align: left;
  vertical-align: middle;
}

.prepared-table th {
  color: var(--accent);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.prepared-table td:first-child,
.prepared-table th:first-child {
  width: 34px;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.job-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  padding: 12px 0;
  border-top: 1px solid rgba(82, 61, 45, 0.12);
}

.job-row p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.job-error {
  color: #8c3328;
}

.job-row-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.small-action {
  border: 1px solid rgba(122, 77, 43, 0.2);
  background: white;
  color: var(--accent);
  border-radius: 999px;
  padding: 5px 10px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.small-action:disabled {
  cursor: wait;
  opacity: 0.65;
}

.jobs-empty {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .shell {
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .grid {
    grid-template-columns: 1fr;
    height: auto;
  }

  .panel {
    min-height: auto;
  }

  .paper {
    min-height: 360px;
  }
}
