:root {
  --bg: #0e151b;
  --panel: #17222b;
  --panel-2: #1d2a34;
  --ink: #f4f7f9;
  --muted: #a9b7c0;
  --line: #324554;
  --accent: #1da1f2;
  --accent-2: #19b87a;
  --danger: #ef6461;
  --shadow: 0 18px 44px rgba(0, 0, 0, .28);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(29, 161, 242, .16), transparent 35%),
    linear-gradient(315deg, rgba(25, 184, 122, .12), transparent 40%),
    var(--bg);
}
button, input, textarea, select { font: inherit; }
button {
  border: 1px solid rgba(255,255,255,.12);
  background: var(--accent);
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
}
button.secondary { background: #263744; color: var(--ink); }
button.danger { background: var(--danger); }
.button-link {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid rgba(255,255,255,.12);
  background: var(--accent);
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  text-decoration: none;
}
.button-link:hover {
  filter: brightness(1.08);
}
button.active {
  background: var(--accent-2);
  border-color: rgba(255,255,255,.35);
  color: #06140f;
}
button.danger.active {
  background: var(--danger);
  color: white;
  box-shadow: 0 0 0 2px rgba(239, 100, 97, .28);
}
button:disabled { opacity: .55; cursor: wait; }
.button-like {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(255,255,255,.12);
  background: #263744;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
  margin: 0;
}
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101920;
  color: var(--ink);
  padding: 10px 11px;
}
textarea { min-height: 140px; resize: vertical; }
label { display: block; color: var(--muted); font-size: .92rem; margin-bottom: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.login-body { display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(430px, 100%);
  background: rgba(23, 34, 43, .92);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 900;
}
.login-card h1 { margin: 16px 0 4px; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent-2); }
.error { margin-top: 12px; color: #ffaaa8; font-weight: 700; min-height: 20px; }
.app-shell { width: min(1440px, calc(100% - 28px)); margin: 0 auto; padding: 22px 0 46px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  background: rgba(23, 34, 43, .88);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.topbar h1 { margin: 0; font-size: clamp(1.8rem, 3vw, 2.8rem); }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0;
}
.tab {
  background: #20303b;
  color: var(--muted);
}
.tab.active { background: var(--accent); color: white; }
.tool-panel {
  display: none;
  border: 1px solid var(--line);
  background: rgba(23, 34, 43, .9);
  border-radius: 10px;
  padding: 18px;
}
.tool-panel.active { display: block; }
.panel-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 18px;
}
.tools-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 18px;
  align-items: start;
}
.tool-column {
  display: grid;
  gap: 18px;
  align-content: start;
}
.workspace-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}
.workspace-card { min-height: 390px; }
.workspace-layout .cover-card { grid-column: 1 / -1; }
.single-panel { max-width: 520px; }
.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.card h2, .card h3 { margin: 0 0 12px; }
.stack { display: grid; gap: 12px; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.compact-actions { margin-top: 0; }
.push-right { margin-left: auto; }
.workspace-download-row { align-items: center; }
.dropzone {
  border: 1px dashed #5f788b;
  border-radius: 8px;
  padding: 18px;
  background: #111c24;
}
.dropzone input { padding: 0; border: 0; background: transparent; }
.tool-dropzone {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 130px;
  cursor: pointer;
  text-align: center;
}
.tool-dropzone.dragging {
  border-color: var(--accent);
  background: rgba(29, 161, 242, .12);
}
.tool-dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.tool-dropzone strong {
  color: var(--ink);
}
.tool-dropzone span {
  color: var(--muted);
}
.certify-file-list {
  display: grid;
  gap: 8px;
  max-height: 148px;
  overflow: auto;
}
.certify-file-row {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101920;
  cursor: pointer;
}
.certify-file-row.selected {
  border-color: var(--accent);
  background: rgba(29, 161, 242, .12);
}
.certify-file-row input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}
.certify-file-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.big-dropzone {
  display: grid;
  grid-template-rows: 1fr;
  min-height: 270px;
  border: 2px dashed #5f788b;
  border-radius: 8px;
  padding: 14px;
  background: #101920;
}
.big-dropzone.empty {
  min-height: 300px;
}
.big-dropzone.has-files {
  min-height: 170px;
  align-items: stretch;
}
.big-dropzone.dragging {
  border-color: var(--accent);
  background: rgba(29, 161, 242, .12);
}
.big-dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.drop-title {
  display: block;
  font-size: 1.35rem;
  font-weight: 900;
  color: var(--ink);
}
.drop-intro {
  display: grid;
  place-items: center;
  min-height: 100%;
  text-align: center;
  border: 0;
}
.drop-subtitle {
  display: block;
  max-width: 330px;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}
.file-list {
  display: grid;
  gap: 8px;
  align-content: start;
  min-height: 100%;
  max-height: 420px;
  overflow: auto;
  border: 0;
  background: transparent;
  padding: 0;
}
.file-list[hidden] { display: none; }
.file-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: stretch;
  gap: 8px;
  border: 1px solid #8a8f93;
  background: #151b20;
  padding: 4px;
}
.file-row.pending { opacity: .78; }
.drag-handle {
  display: grid;
  place-items: center;
  border: 1px solid #9da2a6;
  color: var(--muted);
  cursor: grab;
}
.file-info {
  display: grid;
  align-content: center;
  min-width: 0;
}
.file-info strong, .file-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-info span {
  color: var(--muted);
  font-size: .82rem;
}
.file-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.mini {
  min-width: 58px;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: .86rem;
}
.empty-state {
  display: grid;
  place-items: center;
  min-height: 130px;
  color: var(--muted);
}
.filename-box {
  border: 1px solid var(--line);
  padding: 10px;
}
.radio-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}
.radio-grid label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  color: var(--ink);
}
.radio-grid input[type="radio"] {
  width: auto;
  accent-color: var(--accent);
}
.other-name {
  flex: 1 1 280px;
}
.other-name input[type="text"] {
  min-width: 180px;
  padding: 5px 8px;
}
.cover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.cover-header h2 {
  margin: 0;
}
.cover-header .check-row {
  margin: 0;
  white-space: nowrap;
}
.cover-editor-dock {
  display: grid;
  gap: 10px;
}
.editor-toolbar {
  display: grid;
  grid-template-columns: minmax(120px, 180px) 86px repeat(10, 54px) 58px 54px;
  gap: 6px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  background: #111920;
  border-radius: 8px;
}
.editor-toolbar button {
  min-width: 54px;
  height: 50px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}
.editor-toolbar select {
  width: 100%;
  padding: 8px;
}
.editor-toolbar input[type="color"] {
  width: 58px;
  height: 50px;
  padding: 3px;
}
.text-tool {
  font-size: 1.38rem;
}
.italic-tool {
  font-style: italic;
}
.underline-tool {
  text-decoration: underline;
}
.icon-tool svg {
  width: 31px;
  height: 31px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.thumb-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.rich-editor {
  min-height: 210px;
  border: 1px solid #8a8f93;
  background: #f8fafc;
  color: #111;
  border-radius: 4px;
  padding: 14px;
  line-height: 1.35;
  overflow: auto;
}
.rich-editor:empty::before {
  content: "Type the cover page here.";
  color: #66717a;
}
.status {
  white-space: pre-wrap;
  color: var(--muted);
  background: #101920;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 48px;
}
.editor-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
}
.editor-pages-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-self: stretch;
}
.editor-workbench {
  display: grid;
  gap: 12px;
  align-content: start;
}
.editor-controls {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121b22;
  padding: 12px;
}
.editor-controls .actions {
  margin-top: 0;
  justify-content: center;
  align-items: center;
}
.editor-controls .editor-tool-row {
  justify-content: center;
}
.editor-controls .editor-done-row {
  justify-content: center;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.editor-done-row button {
  min-width: 180px;
}
.editor-controls .editor-page-row {
  justify-content: center;
}
.page-counter {
  display: inline-grid;
  place-items: center;
  min-width: 70px;
  color: var(--ink);
  font-weight: 900;
}
.thumbs { display: grid; gap: 10px; max-height: 76vh; overflow: auto; padding-right: 3px; }
.thumb {
  position: relative;
  border: 1px solid var(--line);
  background: #111c24;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  overflow: hidden;
}
.thumb.active { outline: 2px solid var(--accent); }
.thumb-preview {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1.28;
  overflow: hidden;
  border-radius: 6px;
  background: #e7ebef;
}
.thumb img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  background: white;
  transform-origin: center;
}
.thumb.removed::after {
  content: "X";
  position: absolute;
  inset: 8px;
  display: grid;
  place-items: center;
  color: rgba(239, 100, 97, .92);
  font-size: 5rem;
  font-weight: 900;
  line-height: 1;
  background: rgba(0, 0, 0, .28);
  pointer-events: none;
  z-index: 1;
}
.thumb-side {
  position: absolute;
  bottom: 8px;
  display: grid;
  gap: 5px;
  align-items: center;
  justify-items: center;
  z-index: 2;
}
.thumb-left {
  left: 9px;
}
.thumb-right {
  right: 9px;
}
.thumb-check {
  margin: 0;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 5px;
  background: rgba(10, 18, 25, .86);
  border: 1px solid rgba(255,255,255,.18);
}
.thumb-check input { width: 17px; height: 17px; accent-color: var(--accent); }
.thumb-label {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  margin: 0;
  color: var(--ink);
  font-weight: 900;
  background: rgba(10, 18, 25, .86);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 5px;
  min-width: 44px;
  text-align: center;
  padding: 5px 8px;
  z-index: 2;
}
.thumb-icon {
  width: 28px;
  height: 28px;
  min-width: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: rgba(10, 18, 25, .86);
  border: 1px solid rgba(255,255,255,.18);
  color: #f5f8fb;
}
.thumb-icon:hover {
  background: var(--accent);
}
.thumb-remove.active,
.thumb-remove:hover {
  background: var(--danger);
}
.pages-footer {
  margin-top: 0;
}
.pages-footer button {
  width: 100%;
}
.fact-find-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.fact-find-actions .button-link {
  min-height: 52px;
}
.hover-preview {
  position: fixed;
  z-index: 1000;
  display: none;
  width: 280px;
  max-height: 380px;
  padding: 8px;
  border: 1px solid var(--line);
  background: #111920;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.hover-preview img {
  width: 100%;
  display: block;
  background: white;
}
.canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  max-width: 100%;
  height: min(68vh, 720px);
  min-height: 360px;
  padding: 14px;
  background: #d4d9de;
  border-radius: 8px;
  overflow: hidden;
}
#editorCanvas { display: block; max-width: 100%; height: auto; touch-action: none; }
.modal-open {
  overflow: hidden;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 9, 13, .72);
}
.modal-backdrop[hidden] {
  display: none;
}
.cover-modal {
  width: min(1120px, 96vw);
  height: min(820px, 92vh);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  box-shadow: var(--shadow);
  padding: 16px;
}
.cover-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.cover-modal-header h2 {
  margin: 0;
}
.cover-modal-body {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}
.cover-modal-body .rich-editor {
  min-height: 0;
  height: 100%;
}
.context-menu {
  position: fixed;
  z-index: 1200;
  display: none;
  grid-template-columns: 1fr;
  min-width: 190px;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111920;
  box-shadow: var(--shadow);
  pointer-events: auto;
}
.context-menu button {
  width: 100%;
  border-radius: 5px;
  background: #263744;
  text-align: left;
}
.context-menu button:hover {
  background: #315066;
}
.overlay-box {
  position: absolute;
  border: 2px solid var(--accent-2);
  background: rgba(25, 184, 122, .16);
  pointer-events: none;
}
.overlay-box.redact { border-color: var(--danger); background: rgba(239, 100, 97, .22); }
@media (max-width: 900px) {
  .panel-grid, .tools-grid, .workspace-layout, .editor-layout, .row { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .file-row { grid-template-columns: 22px 1fr; }
  .file-actions { grid-column: 1 / -1; flex-wrap: wrap; }
  .push-right { margin-left: 0; }
  .cover-header { align-items: flex-start; flex-direction: column; }
  .editor-toolbar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .fact-find-actions { grid-template-columns: 1fr; }
}
