:root {
  color-scheme: light dark;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: #0f172a;
  color: #e2e8f0;
  --sidebar-width: 360px;
  --sidebar-min: 280px;
  --sidebar-max: 520px;
  --viewer-min: 260px;
  --original-width: 50%;
}

body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top, rgba(45, 212, 191, 0.15), rgba(15, 23, 42, 0.9));
  min-height: 100vh;
}

body.resizing {
  user-select: none;
  cursor: col-resize;
}

.card {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 16px;
  padding: 1.2rem 1.4rem;
  backdrop-filter: blur(14px);
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.7);
  overflow: auto;
}

.controls h1 {
  margin-top: 0;
  font-size: 1.9rem;
}

.subtitle {
  color: rgba(226, 232, 240, 0.7);
  margin-bottom: 1.5rem;
}

.helper-text {
  font-size: 0.85rem;
  color: rgba(226, 232, 240, 0.65);
  margin-bottom: 0.75rem;
}

.layout {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: var(--sidebar-width, 360px) 6px minmax(0, 1fr);
  column-gap: 0;
  padding: 2rem;
  max-width: 1600px;
  margin: 0 auto;
  align-items: stretch;
}

.layout-resizer {
  grid-column: 2;
  grid-row: 1;
  background: rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  cursor: col-resize;
  transition: background 0.2s ease;
  position: relative;
}

.layout-resizer::before {
  content: "";
  position: absolute;
  inset: 25%;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.55);
}

.layout-resizer:hover,
.layout-resizer:focus-visible {
  background: rgba(148, 163, 184, 0.4);
}

.helper-text.subtle {
  color: rgba(226, 232, 240, 0.55);
  margin-top: 0.35rem;
}

.preview {
  display: flex;
  flex-direction: column;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.viewers {
  display: flex;
  align-items: stretch;
  gap: 1rem;
  height: 100%;
}

.viewer {
  display: flex;
  flex-direction: column;
  background: rgba(30, 41, 59, 0.85);
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  overflow: hidden;
  min-height: 420px;
  min-width: var(--viewer-min);
}

.viewer[data-panel="original"] {
  flex: 0 0 var(--original-width);
}

.viewer[data-panel="output"] {
  flex: 1 1 auto;
}

.viewer-resizer {
  cursor: col-resize;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.25);
  align-self: stretch;
  position: relative;
  width: 10px;
}

.viewer-resizer::before {
  content: "";
  position: absolute;
  inset: 20%;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.55);
}

.viewer-resizer:hover,
.viewer-resizer:focus-visible {
  background: rgba(148, 163, 184, 0.38);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    row-gap: 1.5rem;
    column-gap: 0;
    padding: 1.5rem;
    width: 100%;
  }

  .controls,
  .preview {
    grid-column: 1;
  }

  .layout-resizer {
    display: none;
  }
}

@media (max-width: 768px) {
  .layout {
    padding: 1.25rem 1rem 2.5rem;
    row-gap: 1.25rem;
  }

  .viewers {
    flex-direction: column;
    gap: 1rem;
  }

  .viewer {
    min-width: 0;
    min-height: 260px;
  }

  .viewer-resizer {
    display: none;
  }
}

.field input[type="file"] {
  padding: 0.6rem;
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.8);
  color: inherit;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

fieldset.field {
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}

fieldset.field label {
  display: block;
  margin-bottom: 0.4rem;
}

#jobs-list {
  display: grid;
  gap: 1rem;
}

button.primary {
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
  background: linear-gradient(135deg, #22d3ee, #8b5cf6);
  box-shadow: 0 12px 22px -12px rgba(34, 211, 238, 0.55);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px -14px rgba(34, 211, 238, 0.65);
}

button.secondary,
a.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.95rem;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: linear-gradient(130deg, rgba(15, 23, 42, 0.85), rgba(30, 41, 59, 0.75));
  color: #38bdf8;
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

button.secondary:hover,
a.secondary:hover {
  background: rgba(59, 130, 246, 0.24);
  border-color: rgba(94, 234, 212, 0.55);
  color: #e0f2fe;
  box-shadow: 0 14px 24px -16px rgba(37, 99, 235, 0.45);
}

button.secondary:focus-visible,
a.secondary:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.6);
  outline-offset: 2px;
}

button.secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

button.tertiary,
a.tertiary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.5);
  color: rgba(226, 232, 240, 0.75);
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

button.tertiary:hover,
a.tertiary:hover {
  background: rgba(30, 41, 59, 0.7);
  color: #bae6fd;
  border-color: rgba(59, 130, 246, 0.35);
}

button.tertiary:focus-visible,
a.tertiary:focus-visible {
  outline: 2px solid rgba(148, 163, 184, 0.5);
  outline-offset: 2px;
}

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

article.job-card {
  background: linear-gradient(165deg, rgba(15, 23, 42, 0.92), rgba(30, 41, 59, 0.78));
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 18px;
  padding: 1.2rem 1.35rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.8rem 1.2rem;
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 36px -28px rgba(15, 23, 42, 0.95);
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

article.job-card::before,
article.job-card::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

article.job-card::before {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.16), rgba(34, 197, 94, 0.08) 45%, transparent 75%);
  border-radius: inherit;
  transition: opacity 0.3s ease;
}

article.job-card::after {
  background: radial-gradient(circle at top right, rgba(56, 189, 248, 0.16), transparent 60%);
  transition: opacity 0.3s ease;
}

article.job-card:hover {
  border-color: rgba(56, 189, 248, 0.45);
  transform: translateY(-4px);
  box-shadow: 0 26px 44px -26px rgba(56, 189, 248, 0.45);
}

article.job-card:hover::before,
article.job-card:hover::after {
  opacity: 1;
}
.job-card-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.job-card-title {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: #e2e8f0;
}

.job-card-subtitle {
  font-size: 0.82rem;
  color: rgba(226, 232, 240, 0.65);
}

.job-meta-grid {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  font-size: 0.82rem;
  color: rgba(226, 232, 240, 0.7);
}

.job-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
}

.job-meta-item strong {
  font-weight: 600;
  color: rgba(226, 232, 240, 0.85);
}

.job-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.job-status-pill svg,
.job-status-pill .status-icon {
  width: 0.85rem;
  height: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.job-status-pill.pending,
.job-status-pill.queued {
  background: rgba(234, 179, 8, 0.16);
  color: #facc15;
}

.job-status-pill.processing {
  background: rgba(59, 130, 246, 0.18);
  color: #60a5fa;
}

.job-status-pill.completed {
  background: rgba(34, 197, 94, 0.16);
  color: #4ade80;
}

.job-status-pill.failed {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
}

.job-card-status {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: flex-end;
}

.job-error {
  grid-column: 1 / -1;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
}

.job-card-footer {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.jobs-empty {
  text-align: center;
  color: rgba(226, 232, 240, 0.55);
  padding: 2rem;
  font-style: italic;
  border: 1px dashed rgba(148, 163, 184, 0.3);
  border-radius: 12px;
}

.job-actions button {
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
}

button.danger {
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(15, 23, 42, 0.6);
  color: #f87171;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

button.danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.8);
  color: #fca5a5;
}

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

.toc-review-cta {
  margin-top: 1rem;
}

.toc-review-cta button {
  width: 100%;
}

#progress-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#progress-list li {
  background: rgba(30, 41, 59, 0.7);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  font-size: 0.9rem;
}

#progress-list .timestamp {
  display: block;
  font-size: 0.75rem;
  color: rgba(148, 163, 184, 0.7);
  margin-bottom: 0.25rem;
}

#metrics table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

#metrics th,
#metrics td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

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

.preview {
  display: flex;
  flex-direction: column;
}

.viewers {
  gap: 1rem;
  height: 100%;
}

.viewer {
  display: flex;
  flex-direction: column;
  background: rgba(30, 41, 59, 0.85);
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  overflow: hidden;
  min-height: 420px;
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1rem;
  background: rgba(15, 23, 42, 0.9);
}

.viewer-header a {
  color: #38bdf8;
  font-size: 0.85rem;
  text-decoration: none;
}

.viewer iframe {
  flex: 1 1 auto;
  border: none;
  width: 100%;
  background: rgba(15, 23, 42, 0.6);
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 1000;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 18px;
  width: min(960px, 92vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 70px -20px rgba(15, 23, 42, 0.8);
  overflow: hidden;
  transition: width 0.3s ease, max-height 0.3s ease;
}

.modal-dialog.fullscreen-tree {
  width: 98vw;
  max-height: 98vh;
}

.modal-header,
.modal-footer {
  padding: 1.1rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.92);
}

.modal-header {
  gap: 1rem;
}

.toc-view-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  user-select: none;
}

.toggle-switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  background: rgba(148, 163, 184, 0.3);
  border-radius: 24px;
  transition: background 0.3s ease;
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #e2e8f0;
  border-radius: 50%;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: linear-gradient(135deg, #22d3ee, #8b5cf6);
  border-color: rgba(34, 211, 238, 0.6);
}

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

.toggle-switch:hover .toggle-slider {
  background: rgba(148, 163, 184, 0.4);
}

.toggle-switch input:checked:hover + .toggle-slider {
  background: linear-gradient(135deg, #2dd4bf, #a78bfa);
}

.toggle-label {
  font-size: 0.9rem;
  color: rgba(226, 232, 240, 0.85);
  font-weight: 500;
  white-space: nowrap;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.4rem;
}

.modal-body {
  padding: 1.4rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.modal-footer {
  gap: 0.8rem;
}

.modal-footer .primary {
  width: auto;
}

.modal-footer .secondary {
  width: auto;
}

.modal-dialog.alert-modal {
  width: min(420px, 92vw);
  max-width: 420px;
}

.credits-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
}

.credits-modal .modal-dialog,
.credits-check-modal .modal-dialog {
  width: min(560px, 92vw);
}

.credits-balance-card {
  padding: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: rgba(15, 23, 42, 0.6);
}

.credits-balance-card strong {
  font-size: 2.25rem;
  color: #22d3ee;
}

.credits-purchase-group {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.credits-quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.5rem;
}

.credits-quick-option {
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 999px;
  padding: 0.4rem 0.5rem;
  background: transparent;
  color: #e2e8f0;
  font-weight: 600;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.credits-quick-option.active,
.credits-quick-option:hover {
  border-color: rgba(34, 211, 238, 0.8);
  background: rgba(34, 211, 238, 0.15);
}

.credits-custom-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  box-sizing: border-box;
}

.credits-custom-field input,
.credits-shortage-actions input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.6);
  padding: 0.5rem 0.75rem;
  color: #e2e8f0;
}

.credits-summary-grid {
  margin-top: 0.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.credits-summary-grid strong {
  font-size: 1.2rem;
}

.credits-summary-grid .label,
.credits-balance-card .label,
.credits-shortage p,
.credits-purchase-group .helper-text {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: rgba(226, 232, 240, 0.65);
}

.credits-file-list {
  margin-top: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 12px;
  max-height: 240px;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.4);
}

.credits-file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  gap: 1rem;
}

.credits-file-item:last-child {
  border-bottom: none;
}

.credits-file-item .file-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow: hidden;
  flex: 1;
}

.credits-file-item .filename {
  font-weight: 600;
  color: #f1f5f9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.credits-file-item .pages {
  font-size: 0.78rem;
  color: rgba(226, 232, 240, 0.55);
}

.text-btn {
  background: none;
  border: none;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.text-btn.danger {
  color: #f87171;
  background: rgba(239, 68, 68, 0.1);
}

.text-btn.danger:hover {
  color: #ffffff;
  background: rgba(239, 68, 68, 0.8);
}

.credits-file-row {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.credits-file-row:last-child {
  border-bottom: none;
}

.credits-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 0.75rem;
}

.credits-shortage {
  margin-top: 1rem;
  padding: 0.9rem;
  border-radius: 12px;
  border: 1px solid rgba(250, 204, 21, 0.4);
  background: rgba(250, 204, 21, 0.1);
}

.credits-shortage-actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
}

.alert-modal-content {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.alert-modal-icon {
  flex: 0 0 44px;
  height: 44px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  background: rgba(59, 130, 246, 0.2);
  color: #bfdbfe;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.alert-modal-message {
  margin: 0;
  font-size: 0.95rem;
  color: rgba(226, 232, 240, 0.9);
  line-height: 1.5;
}

#alert-modal[data-variant="success"] .alert-modal-icon {
  background: rgba(34, 197, 94, 0.2);
  color: #bbf7d0;
  border-color: rgba(34, 197, 94, 0.45);
}

#alert-modal[data-variant="warning"] .alert-modal-icon {
  background: rgba(251, 191, 36, 0.2);
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.45);
}

#alert-modal[data-variant="error"] .alert-modal-icon {
  background: rgba(239, 68, 68, 0.2);
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.55);
}

.icon-button {
  border: none;
  background: transparent;
  color: rgba(226, 232, 240, 0.8);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.25rem;
  transition: color 0.2s ease;
}

.icon-button:hover {
  color: #38bdf8;
}

.helper-list {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.85rem;
  color: rgba(226, 232, 240, 0.7);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.helper-list strong {
  color: rgba(226, 232, 240, 0.9);
}

/* Tree View Styles */
.toc-tree {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 50vh;
  overflow-y: auto;
  padding: 0.5rem;
  background: rgba(15, 23, 42, 0.4);
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  transition: max-height 0.3s ease;
}

.fullscreen-tree .toc-tree {
  max-height: calc(98vh - 240px);
  min-height: calc(98vh - 240px);
}

.toc-tree-item {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  transition: background 0.15s ease;
}

.toc-tree-item.dragging {
  opacity: 0.5;
}

.toc-tree-item.drag-over .toc-item-content {
  background: rgba(59, 130, 246, 0.15);
  outline: 2px dashed rgba(59, 130, 246, 0.6);
  outline-offset: -2px;
}

.toc-tree-item.drop-before .toc-item-content {
  box-shadow: inset 0 2px 0 rgba(56, 189, 248, 0.65), 0 -2px 6px rgba(34, 197, 94, 0.25);
}

.toc-tree-item.drop-after .toc-item-content {
  box-shadow: inset 0 -2px 0 rgba(56, 189, 248, 0.65), 0 2px 6px rgba(34, 197, 94, 0.25);
}

.toc-item-content:hover {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(148, 163, 184, 0.4);
}

.toc-item-content:active {
  cursor: grabbing;
}

.toc-item-handle {
  display: flex;
  align-items: center;
  color: rgba(148, 163, 184, 0.5);
  font-size: 1rem;
  cursor: grab;
}

.toc-item-handle:active {
  cursor: grabbing;
}

.toc-item-expand {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: rgba(148, 163, 184, 0.7);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
  transition: color 0.15s ease;
}

.toc-item-expand:hover {
  color: #38bdf8;
}

.toc-item-expand.hidden {
  visibility: hidden;
}

.toc-item-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.toc-item-title {
  flex: 1;
  font-size: 0.9rem;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-item-page {
  font-size: 0.75rem;
  color: rgba(148, 163, 184, 0.7);
  background: rgba(15, 23, 42, 0.6);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  white-space: nowrap;
}

.toc-item-actions {
  display: flex;
  gap: 0.3rem;
}

.toc-item-action {
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.5);
  color: #e2e8f0;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.toc-item-action:hover:not(:disabled) {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.5);
  color: #60a5fa;
}

.toc-item-action:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.toc-item-action.toc-item-delete:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

.toc-item-children {
  margin-left: 2rem;
  border-left: 2px solid rgba(148, 163, 184, 0.25);
  padding-left: 0.5rem;
  margin-top: 0.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  position: relative;
}

.toc-item-children::before {
  content: '';
  position: absolute;
  left: -2px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, rgba(148, 163, 184, 0.25), rgba(148, 163, 184, 0.1));
}

.toc-item-children.collapsed {
  display: none;
}

.toc-item-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  position: relative;
}

.toc-item-content::before {
  content: attr(data-level);
  position: absolute;
  left: 0.3rem;
  top: 0.2rem;
  font-size: 0.6rem;
  color: rgba(148, 163, 184, 0.5);
  font-weight: 600;
  background: rgba(15, 23, 42, 0.6);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  line-height: 1;
}

.toc-item-content.selected-parent {
  background: rgba(34, 211, 238, 0.2);
  border-color: rgba(34, 211, 238, 0.5);
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.2);
  cursor: pointer;
}

.toc-item-content.selected-parent::after {
  content: '✓ Selected as parent';
  position: absolute;
  right: 0.5rem;
  top: 0.2rem;
  font-size: 0.65rem;
  color: #22d3ee;
  font-weight: 600;
  background: rgba(15, 23, 42, 0.8);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  line-height: 1;
}

/* Search Results Styles */
.search-container {
  position: relative;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 350px;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 10px;
  margin-top: 0.3rem;
  z-index: 100;
  box-shadow: 0 10px 30px -10px rgba(15, 23, 42, 0.8);
}

.search-result-item {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  cursor: pointer;
  transition: background 0.15s ease;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item.selected {
  background: rgba(59, 130, 246, 0.2);
}

.search-result-title {
  font-size: 0.9rem;
  color: #e2e8f0;
  margin-bottom: 0.3rem;
  font-weight: 500;
}

.search-result-meta {
  display: flex;
  gap: 0.6rem;
  font-size: 0.75rem;
  color: rgba(148, 163, 184, 0.7);
  margin-bottom: 0.3rem;
}

.search-result-badge {
  background: rgba(59, 130, 246, 0.2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: #60a5fa;
}

.search-result-context {
  font-size: 0.75rem;
  color: rgba(148, 163, 184, 0.6);
  font-style: italic;
  line-height: 1.3;
}

.search-no-results {
  padding: 1rem;
  text-align: center;
  color: rgba(148, 163, 184, 0.6);
  font-size: 0.85rem;
}

/* Updated form styles */
.toc-add-form-container {
  display: flex;
  gap: 0.8rem;
  align-items: flex-end;
}

.toc-add-form-container .toc-field {
  flex: 1;
}

.toc-add-actions {
  display: flex;
  gap: 0.4rem;
}

.manual-entry-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  margin-top: 0.6rem;
}

button.small {
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

.parent-selection {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.8rem;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 10px;
  margin-top: 0.6rem;
}

.parent-selection-label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  font-size: 0.85rem;
}

.parent-selection-label > span:first-child {
  font-size: 0.75rem;
  color: rgba(148, 163, 184, 0.7);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.selected-parent-text {
  color: #38bdf8;
  font-weight: 500;
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 45vh;
  overflow-y: auto;
  padding-right: 0.4rem;
}

.toc-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) 140px 120px 160px;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(30, 41, 59, 0.82);
}

.toc-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.toc-field label {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.85);
}

.toc-list input[type="text"],
.toc-list input[type="number"],
.toc-add-form input[type="text"],
.toc-add-form input[type="number"] {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.7);
  color: inherit;
}

.toc-row-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toc-action {
  padding: 0.45rem 0.7rem;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.55);
  color: #e2e8f0;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.toc-action:hover {
  background: rgba(59, 130, 246, 0.25);
  border-color: rgba(59, 130, 246, 0.5);
}

.toc-add-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.fullscreen-tree .toc-add-form,
.fullscreen-tree .helper-text,
.fullscreen-tree .helper-list {
  display: none;
}

.fullscreen-tree .modal-body {
  gap: 0.5rem;
}

.toc-add-row-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) 140px 120px 160px;
  gap: 0.75rem;
  align-items: end;
}

.add-button-cell {
  display: flex;
  align-items: flex-end;
}

.add-button-cell .secondary {
  width: 100%;
}

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

body.modal-open {
  overflow: hidden;
}

/* Admin dashboard layout */
body.admin-page {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  min-height: 100vh;
  padding: 2rem 2.5rem 3rem;
}

.admin-header {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.admin-header-text h1 {
  margin: 0;
}

.admin-header-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-main {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.admin-callout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.admin-dashboard {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.admin-toolbar .toolbar-left,
.admin-toolbar .toolbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: rgba(226, 232, 240, 0.78);
}

.toggle input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: #38bdf8;
}

.field.compact {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field.compact select {
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.6);
  color: inherit;
}

.summary-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.summary-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1rem;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.6);
}

.summary-card .metric-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(148, 163, 184, 0.7);
}

.summary-card .metric-value {
  font-size: 1.4rem;
  font-weight: 600;
  color: #e2e8f0;
}

.summary-card .metric-subtext {
  font-size: 0.8rem;
  color: rgba(226, 232, 240, 0.6);
}

.admin-visuals {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.admin-chart {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.admin-chart canvas {
  width: 100% !important;
  max-height: 400px;
}

.admin-dashboard .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.admin-dashboard .card-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.table-responsive {
  overflow-x: auto;
}

.admin-dashboard table {
  width: 100%;
  border-collapse: collapse;
}

.admin-dashboard thead {
  background: rgba(15, 23, 42, 0.6);
}

.admin-dashboard th,
.admin-dashboard td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  font-size: 0.9rem;
}

.admin-dashboard tbody tr:hover {
  background: rgba(59, 130, 246, 0.12);
}

.storage-grid {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.storage-grid dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgba(148, 163, 184, 0.7);
}

.storage-grid dd {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 500;
  color: #e2e8f0;
}

#admin-last-updated {
  font-size: 0.8rem;
  color: rgba(226, 232, 240, 0.6);
}

.modal-dialog.admin-modal {
  max-width: 420px;
}

.modal-dialog.admin-modal .modal-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.admin-dashboard input[type="search"],
.admin-dashboard select {
  padding: 0.45rem 0.6rem;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.6);
  color: inherit;
}

.admin-dashboard input[type="search"]:focus,
.admin-dashboard select:focus {
  outline: 2px solid rgba(56, 189, 248, 0.5);
  outline-offset: 2px;
}

.admin-dashboard tbody td {
  color: rgba(226, 232, 240, 0.85);
}

.admin-dashboard tbody td:nth-child(5),
.admin-dashboard tbody td:nth-child(6) {
  font-variant-numeric: tabular-nums;
}

@media (max-width: 960px) {
  .admin-callout {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-callout button {
    width: 100%;
  }

  body.admin-page {
    padding: 1.5rem 1.25rem 2.5rem;
  }

  .admin-header,
  .admin-main {
    max-width: 100%;
  }

  .admin-header {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .admin-toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .admin-toolbar .toolbar-left,
  .admin-toolbar .toolbar-right {
    width: 100%;
    justify-content: flex-start;
  }

  .admin-visuals {
    grid-template-columns: 1fr;
  }

  .admin-dashboard .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .admin-dashboard .card-actions {
    width: 100%;
  }

  .admin-dashboard .card-actions input,
  .admin-dashboard .card-actions select,
  .admin-dashboard .card-actions button {
    width: 100%;
  }

  .layout {
    grid-template-columns: 1fr;
    row-gap: 1.5rem;
  }

  .layout-resizer {
    display: none;
  }

  .viewers {
    flex-direction: column;
  }

  .viewer {
    flex: 1 1 auto;
    min-width: unset;
  }

  .viewer-resizer {
    display: none;
  }

  .modal-dialog {
    width: min(640px, 94vw);
  }

  .toc-row,
  .toc-add-row-grid {
    grid-template-columns: 1fr;
  }

  .toc-row-actions {
    justify-content: flex-start;
  }
}

.loading-spinner {
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top: 4px solid #38bdf8;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  animation: spin 1s linear infinite;
  display: inline-block;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Auth Page Layout */
body.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1rem;
  gap: 1rem;
  overflow-y: auto;
}

.auth-shell {
  width: min(420px, 100%);
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 18px;
  padding: 2.25rem 2rem;
  box-shadow: 0 30px 70px -20px rgba(15, 23, 42, 0.8);
}

.auth-shell h1 {
  margin: 0 0 0.75rem;
  font-size: 1.75rem;
}

.auth-intro {
  margin: 0 0 1.75rem;
  color: rgba(226, 232, 240, 0.75);
  line-height: 1.5;
}

.auth-footer {
  margin-top: 1.75rem;
  text-align: center;
  color: rgba(226, 232, 240, 0.7);
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  flex-wrap: wrap;
}

.auth-footer a {
  color: #22d3ee;
  text-decoration: none;
  font-weight: 500;
}

.auth-footer a:hover,
.auth-footer a:focus {
  text-decoration: underline;
}

@media (max-width: 520px) {
  body.auth-page {
    padding: 1.5rem 1rem;
  }

  .auth-shell {
    padding: 1.75rem 1.5rem;
    border-radius: 16px;
  }

  .auth-shell h1 {
    font-size: 1.5rem;
  }
}

/* Auth Modal Styles */
.auth-modal {
  max-width: 440px;
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid rgba(148, 163, 184, 0.2);
}

.auth-tab {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  color: rgba(226, 232, 240, 0.7);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
  margin-bottom: -2px;
}

.auth-tab.active {
  color: #22d3ee;
  border-bottom-color: #22d3ee;
}

.auth-tab:hover {
  color: #e2e8f0;
}

.auth-form .field {
  margin-bottom: 1.2rem;
}

.auth-form input {
  width: 100%;
  padding: 0.75rem;
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.8);
  color: inherit;
  border: 1px solid rgba(148, 163, 184, 0.3);
  font-size: 1rem;
}

.auth-form input:focus {
  outline: none;
  border-color: #22d3ee;
}

.auth-form .field label {
  font-weight: 500;
  margin-bottom: 0.4rem;
}

.auth-form .helper-text {
  font-size: 0.8rem;
  color: rgba(226, 232, 240, 0.6);
  margin-top: 0.25rem;
}

.error-message {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.full-width {
  width: 100%;
}

/* App Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.app-header h1 {
  margin: 0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: rgba(226, 232, 240, 0.8);
}

/* View Tabs */
.view-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid rgba(148, 163, 184, 0.2);
}

.view-tab {
  padding: 0.75rem 1.5rem;
  border: none;
  background: transparent;
  color: rgba(226, 232, 240, 0.7);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
  margin-bottom: -2px;
}

.view-tab.active {
  color: #22d3ee;
  border-bottom-color: #22d3ee;
}

.view-tab:hover {
  color: #e2e8f0;
}

