:root {
  --bg: #f3f3f6;
  --surface: #ffffff;
  --surface-soft: #fbf7ef;
  --line: #e3e0e8;
  --line-strong: #d5d0dc;
  --text: #2f3140;
  --muted: #7a7d89;
  --purple: #8c4a8f;
  --purple-deep: #7b377f;
  --purple-soft: #f5ecf6;
  --orange: #f6aa12;
  --orange-deep: #ea9a08;
  --teal: #19c6c8;
  --teal-soft: #dff8f9;
  --danger: #d74b5a;
  --ok: #368764;
  --navy: #232934;
  --shadow: 0 16px 36px rgba(31, 35, 46, .08);
  --shadow-small: 0 8px 18px rgba(31, 35, 46, .08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.container {
  width: min(1220px, calc(100% - 32px));
  margin-inline: auto;
}

.top-accent {
  height: 14px;
  background: linear-gradient(90deg, #0dbfc4 0%, #30d0d2 100%);
}

.app-header {
  height: 66px;
  background: rgba(255, 255, 255, .95);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}


.header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
}

.brand {
  color: var(--purple-deep);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-lockup {
  display: grid;
  gap: 1px;
}

.brand-lockup strong {
  font-size: 1.15rem;
  letter-spacing: -.02em;
  color: var(--navy);
}

.brand-lockup small {
  color: var(--purple);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--navy);
  background: var(--teal-soft);
  border: 1px solid #9adfe2;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .85);
}

.ghost-btn,
.lang-btn,
.mini-btn,
.primary-btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #4d5260;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: .86rem;
  font-weight: 700;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease, background .14s ease, color .14s ease;
}

.ghost-btn:hover,
.lang-btn:hover,
.mini-btn:hover {
  transform: translateY(-1px);
  border-color: #c7bfce;
  box-shadow: var(--shadow-small);
}

.ghost-btn:disabled,
.mini-btn:disabled {
  opacity: .48;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.primary-btn {
  color: #fff;
  background: linear-gradient(180deg, var(--orange) 0%, var(--orange-deep) 100%);
  border-color: var(--orange-deep);
  min-width: 250px;
  box-shadow: 0 10px 22px rgba(246, 170, 18, .28);
}

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(246, 170, 18, .34);
}
.primary-btn:disabled { opacity: .55; cursor: wait; transform: none; }

.app-shell { padding: 34px 0 64px; }

.eyebrow {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--teal);
  font-weight: 800;
  font-size: .74rem;
  letter-spacing: .14em;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

h1 {
  margin: 0;
  color: var(--purple-deep);
  font-size: clamp(1.7rem, 2.9vw, 2.2rem);
  line-height: 1.1;
  letter-spacing: -.035em;
}

.section-head p,
.workspace-head p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.work-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.work-summary span {
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #575c68;
  font-size: .8rem;
  font-weight: 750;
}

.option-row.option-htmlpdf {
  grid-template-columns: 1fr;
}

.htmlpdf-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  width: 100%;
}

.htmlpdf-column {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 7px;
  min-width: 0;
}

.htmlpdf-panel-title {
  color: #5c6170;
  font-size: .78rem;
  font-weight: 800;
}

.option-htmlpdf textarea,
.html-file-drop {
  width: 100%;
  height: 320px;
  min-height: 320px;
}

.option-htmlpdf textarea {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  color: var(--navy);
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: .86rem;
  font-weight: 500;
  line-height: 1.45;
  resize: vertical;
}

.html-file-drop {
  border: 2px dashed #d9d2dc;
  border-radius: 8px;
  background: linear-gradient(180deg, #fff 0%, #fcfbfe 100%);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 9px;
  padding: 20px;
  text-align: center;
  color: #565d69;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease, transform .15s ease;
}

.html-file-drop input {
  display: none;
}

.html-file-drop:hover,
.html-file-drop.drag-over {
  border-color: var(--purple);
  background: linear-gradient(180deg, #fff 0%, var(--purple-soft) 100%);
  box-shadow: 0 0 0 4px rgba(140, 74, 143, .10);
  transform: translateY(-1px);
}

.html-file-drop-icon {
  font-size: 2rem;
  line-height: 1;
  color: var(--teal);
}

.html-file-drop strong {
  color: #4f5562;
  font-size: .96rem;
}

.html-file-drop small {
  color: #8a8996;
  line-height: 1.45;
  font-size: .8rem;
}

.htmlpdf-note {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.45;
  font-weight: 650;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.tool-card {
  min-height: 88px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: #4a4d57;
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 14px 10px;
  text-align: center;
  box-shadow: 0 2px 0 rgba(31, 35, 46, .03);
}

.tool-card:hover {
  transform: translateY(-1px);
  border-color: #c6becd;
  box-shadow: var(--shadow-small);
}

.tool-card.active {
  border-color: var(--purple);
  background: linear-gradient(180deg, #fff 0%, var(--purple-soft) 100%);
  color: var(--purple-deep);
  box-shadow: 0 0 0 2px rgba(140, 74, 143, .12), var(--shadow-small);
}

.tool-icon {
  font-size: 1.55rem;
  line-height: 1;
  color: currentColor;
}

.tool-card span:last-child {
  font-size: .84rem;
  line-height: 1.2;
  font-weight: 800;
}

.workspace {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

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

.workspace-head h2 {
  margin: 0;
  color: var(--navy);
  font-size: 1.22rem;
  letter-spacing: -.015em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace-head h2::before {
  content: "✦";
  color: var(--purple);
  font-size: 1rem;
}

.workspace-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.drop-zone {
  min-height: 160px;
  border: 2px dashed #d9d2dc;
  border-radius: 8px;
  background: linear-gradient(180deg, #fff 0%, #fcfbfe 100%);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: #565d69;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}

.drop-zone input { display: none; }
.drop-zone.drag-over {
  border-color: var(--purple);
  background: linear-gradient(180deg, #fff 0%, var(--purple-soft) 100%);
  box-shadow: 0 0 0 4px rgba(140, 74, 143, .10);
}
.drop-zone.compact {
  min-height: 84px;
  grid-template-columns: auto 1fr;
  justify-items: start;
  text-align: left;
  gap: 12px;
  padding: 16px 18px;
}
.drop-zone.compact small { grid-column: 2; }

.drop-icon {
  font-size: 2rem;
  color: var(--teal);
}
.drop-zone strong {
  display: block;
  color: #4f5562;
  font-size: 1rem;
}
.drop-zone small {
  display: block;
  margin-top: 4px;
  color: #9a97a3;
}

.file-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  align-items: flex-start;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: min(100%, 520px);
  min-width: 0;
  border: 1px solid #eadfc4;
  background: #fffaf0;
  padding: 7px 12px;
  border-radius: 999px;
  color: #575c68;
  font-size: .78rem;
  font-weight: 750;
}

.file-chip b {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip span {
  flex: 0 0 auto;
  white-space: nowrap;
  color: var(--muted);
  font-weight: 650;
}

.tool-options,
.page-toolbar {
  margin-top: 16px;
  border: 1px solid #eee4c8;
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.option-row {
  display: grid;
  grid-template-columns: 1fr 140px 140px;
  gap: 12px;
}

.option-row.option-htmlpdf {
  grid-template-columns: minmax(0, 1fr);
}

.option-row.option-htmlpdf .htmlpdf-layout {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  width: 100%;
}

.option-row label {
  display: grid;
  gap: 6px;
  color: #5c6170;
  font-size: .78rem;
  font-weight: 800;
}

.option-row input,
.option-row select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  padding: 0 11px;
  color: var(--navy);
  font-weight: 650;
}

.option-compress { grid-template-columns: 1fr 1fr; }

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.toolbar-group { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-hint { color: #7b7e8c; font-size: .82rem; }
.mini-btn.danger { color: var(--danger); border-color: #efc1c6; }
.mini-btn.danger:hover { background: #fff4f5; }

.pages-area {
  margin-top: 22px;
}

.empty-pages {
  min-height: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #9a99a6;
  background: linear-gradient(180deg, #fff 0%, #fafafd 100%);
}

.empty-pages[hidden],
.page-grid[hidden] {
  display: none !important;
}

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 18px 16px;
}

.page-tile {
  position: relative;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 7px rgba(31, 35, 46, .05);
  user-select: none;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, opacity .16s ease;
}

.page-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-small);
}

.page-tile.selected {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(140, 74, 143, .14), var(--shadow-small);
}

.page-tile.deleted { opacity: .35; }

.page-number-badge,
.drag-handle {
  position: absolute;
  top: 7px;
  z-index: 2;
  min-width: 24px;
  height: 24px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: .72rem;
  font-weight: 850;
}
.page-number-badge {
  right: 7px;
  color: #fff;
  background: var(--purple);
  padding: 0 7px;
}
.drag-handle {
  left: 7px;
  color: #69707c;
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  cursor: grab;
}
.drag-handle:active { cursor: grabbing; }

.page-thumb {
  height: 190px;
  padding: 8px;
  background: #faf8fc;
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-thumb img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  border: 1px solid #ece7ef;
  background: #fff;
  transform-origin: center center;
}

.page-meta {
  padding: 7px 8px 9px;
  text-align: center;
  border-top: 1px solid var(--line);
  background: #fff;
}
.page-meta strong {
  display: block;
  font-size: .72rem;
  color: #414652;
  line-height: 1.25;
}
.page-meta small {
  display: block;
  color: #9a97a3;
  font-size: .68rem;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-tile-actions {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 0 8px 8px;
  background: #fff;
}
.tile-action {
  width: 27px;
  height: 27px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: #5a5f6c;
  display: grid;
  place-items: center;
  font-weight: 900;
}
.tile-action:hover { border-color: #c7bfce; background: #faf7fc; }
.tile-action.danger { color: var(--danger); }

.sortable-ghost {
  opacity: .45;
  border: 2px dashed var(--purple);
}
.sortable-chosen { transform: scale(.98); }

.bottom-actions {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.status {
  color: #7a7d89;
  font-size: .86rem;
  line-height: 1.4;
}
.status.ok { color: var(--ok); font-weight: 800; }
.status.error { color: var(--danger); font-weight: 800; }
.status.busy { color: var(--purple); font-weight: 800; }

@media (max-width: 1100px) {
  .tool-grid { grid-template-columns: repeat(3, 1fr); }
  .section-head { align-items: flex-start; flex-direction: column; }
  .work-summary { justify-content: flex-start; }
}

@media (max-width: 920px) {
  .htmlpdf-layout {
    grid-template-columns: 1fr;
  }

  .option-htmlpdf textarea,
  .html-file-drop {
    height: 240px;
    min-height: 240px;
  }
}

@media (max-width: 720px) {
  .container { width: min(100% - 20px, 1220px); }
  .app-shell { padding-top: 24px; }
  .tool-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .tool-card { min-height: 82px; }
  .workspace { padding: 16px; }
  .workspace-head, .page-toolbar, .bottom-actions { flex-direction: column; align-items: stretch; }
  .workspace-actions { justify-content: flex-start; }
  .option-row, .option-compress { grid-template-columns: 1fr; }
  .drop-zone.compact { grid-template-columns: 1fr; text-align: center; justify-items: center; }
  .drop-zone.compact small { grid-column: auto; }
  .page-grid { grid-template-columns: repeat(auto-fill, minmax(122px, 1fr)); gap: 12px; }
  .page-thumb { height: 164px; }
  .primary-btn { width: 100%; min-width: unset; }
}
