:root {
  --bg-start: #f2f7f7;
  --bg-end: #dde8ff;
  --ink: #1d2f4d;
  --muted: #5f6b82;
  --card: rgba(255, 255, 255, 0.86);
  --stroke: rgba(23, 66, 118, 0.14);
  --accent: #0b7a75;
  --accent-2: #1463b0;
  --success: #0e8c4f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  min-height: 100vh;
  background: linear-gradient(140deg, var(--bg-start), var(--bg-end));
  color: var(--ink);
  position: relative;
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

.bg-shape {
  position: fixed;
  z-index: 0;
  border-radius: 50%;
  filter: blur(30px);
  opacity: 0.4;
}

.shape-a {
  width: 280px;
  height: 280px;
  background: #94ffc5;
  top: -90px;
  right: 8%;
}

.shape-b {
  width: 340px;
  height: 340px;
  background: #79b9ff;
  bottom: -140px;
  left: -80px;
}

.dashboard {
  max-width: 900px;
  margin: 0 auto;
  padding: 44px 18px 48px;
  position: relative;
  z-index: 1;
}

.hero {
  animation: rise 700ms ease both;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 66px;
  height: 66px;
  object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(16, 42, 89, 0.2);
  background: #fff;
}

.badge {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--accent-2);
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(1.5rem, 4vw, 2.3rem);
  line-height: 1.2;
}

.subtitle {
  margin: 14px 0 0;
  color: var(--muted);
  max-width: 640px;
}

.tool-menu {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-tab {
  border: 1px solid #bfd4f5;
  background: #f7fbff;
  color: #1a4f88;
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.tool-tab.active {
  background: linear-gradient(135deg, #0b7a75, #1463b0);
  border-color: transparent;
  color: #fff;
}

.converter-card {
  margin-top: 24px;
  backdrop-filter: blur(6px);
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 20px 35px rgba(13, 53, 103, 0.12);
  animation: rise 850ms ease both;
}

.tool-page {
  display: none;
}

.tool-page.active {
  display: block;
}

.coming-card {
  background: #f7fbff;
  border: 1px solid #d5e3fb;
  border-radius: 12px;
  padding: 16px;
}

.coming-card h2 {
  margin: 0;
  font-size: 1.12rem;
}

.coming-card p {
  margin: 10px 0 0;
  color: #4c607f;
}

.coming-note {
  display: inline-block;
  margin-top: 12px;
  padding: 4px 10px;
  border-radius: 99px;
  background: #e9fbef;
  border: 1px solid #bfe8ce;
  color: #17643d;
  font-size: 0.8rem;
  font-weight: 800;
}

.pdf2img-form {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.pdf-merge-form {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.pdf-text-form {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.text-result {
  margin: 0;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fff;
  border: 1px solid #d4e2fb;
  border-radius: 10px;
  padding: 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.86rem;
  line-height: 1.45;
  color: #1f3151;
}

.pdf-merge-item .file-thumb-wrap {
  background: #eef4ff;
}

.pdf-icon {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #1b5797;
}

.pdf-range-field {
  margin-top: 8px;
}

.pdf-range-field input {
  font-size: 0.82rem;
}

.merge-lock-row {
  margin-top: 8px;
}

.merge-lock-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
}

.merge-lock-badge.checking {
  background: #eef2ff;
  border: 1px solid #d4defd;
  color: #344f8f;
}

.merge-lock-badge.unlocked {
  background: #e9fbef;
  border: 1px solid #c3ebd0;
  color: #1e6c41;
}

.merge-lock-badge.locked,
.merge-lock-badge.locked-ok {
  background: #fff7e8;
  border: 1px solid #f4dab0;
  color: #8a5a12;
}

.merge-lock-badge.error {
  background: #fff0f0;
  border: 1px solid #f3cccc;
  color: #a23434;
}

.merge-pass-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.merge-pass-row .file-btn {
  flex: 0 0 auto;
}

.pdf2img-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.pdf2img-item {
  background: #fff;
  border: 1px solid #d8e5fb;
  border-radius: 10px;
  padding: 10px;
}

.pdf2img-item img {
  width: 100%;
  display: block;
  border-radius: 8px;
  border: 1px solid #dce7fb;
  background: #fff;
}

.pdf2img-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.pdf2img-head span {
  font-size: 0.84rem;
  font-weight: 800;
  color: #203d66;
}

.upload-zone {
  display: block;
  border: 2px dashed #7ab2db;
  border-radius: 14px;
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), #edf6ff);
  transition: all 180ms ease;
}

.upload-zone:hover,
.upload-zone.drag-over {
  transform: translateY(-1px);
  border-color: #2f8cc9;
  box-shadow: 0 10px 20px rgba(20, 99, 176, 0.12);
}

.upload-zone input {
  display: none;
}

.upload-title {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: #11467f;
}

.upload-subtitle {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.file-list {
  margin: 16px 0;
  display: grid;
  gap: 10px;
}

.file-empty {
  background: #f4f8ff;
  border: 1px dashed #c9daff;
  color: #4c6286;
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.file-item {
  background: #fbfdff;
  border: 1px solid #d9e5fb;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  grid-template-columns: 72px 1fr auto;
  align-items: center;
  gap: 10px;
}

.file-thumb-wrap {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  border: 1px solid #d9e5fb;
  background: #fff;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.file-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 180ms ease;
}

.file-meta {
  min-width: 0;
}

.file-name {
  margin: 0;
  color: #1d3861;
  font-size: 0.93rem;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.file-size {
  margin: 4px 0 0;
  color: #5f6b82;
  font-size: 0.82rem;
}

.image-size-tools {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.inline-field {
  display: inline-grid;
  gap: 4px;
}

.inline-field span {
  font-size: 0.72rem;
  color: #5b7197;
  font-weight: 700;
}

.inline-field select,
.inline-field input {
  border: 1px solid #c8d9fb;
  border-radius: 7px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 0.8rem;
}

.inline-custom {
  display: flex;
  gap: 8px;
}

.inline-custom.hidden {
  display: none;
}

.crop-tools {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.crop-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.crop-badge {
  font-size: 0.72rem;
  font-weight: 800;
  color: #1e6c41;
  background: #e9fbef;
  border: 1px solid #c3ebd0;
  border-radius: 99px;
  padding: 2px 8px;
}

.file-btn.crop {
  border-color: #bfd9ff;
  color: #1b5797;
  background: #f3f8ff;
}

.file-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-btn {
  border: 1px solid #c9d9fb;
  background: #fff;
  color: #1d4f8b;
  border-radius: 6px;
  padding: 5px 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.file-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.file-btn.danger {
  border-color: #f3c7c7;
  color: #b54343;
  background: #fff9f9;
}

.primary-btn {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease;
}

.secondary-btn {
  width: 100%;
  border: 1px solid #bcd2f6;
  border-radius: 12px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: #1d4f8b;
  background: #f6faff;
  cursor: pointer;
  margin-bottom: 10px;
}

.secondary-btn.hidden {
  display: none;
}

.secondary-btn:hover {
  background: #edf5ff;
}

.settings-panel {
  margin: 12px 0;
  border: 1px solid #d9e5fb;
  border-radius: 12px;
  background: #f8fbff;
  padding: 12px;
}

.settings-panel.hidden {
  display: none;
}

.settings-panel h3 {
  margin: 0 0 10px;
  font-size: 0.98rem;
}

.preset-tools {
  display: flex;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.preset-tools .field {
  flex: 1;
}

.preset-tools .secondary-btn {
  width: auto;
  margin: 0;
  white-space: nowrap;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

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

.field span {
  font-size: 0.82rem;
  color: #4d607f;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid #c7d9fb;
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.9rem;
  color: #18385f;
  background: #fff;
}

.field.hidden {
  display: none;
}

.primary-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.primary-btn:disabled {
  cursor: wait;
  opacity: 0.75;
}

.status-text {
  margin: 12px 0 0;
  min-height: 20px;
  color: var(--muted);
}

.status-text.success {
  color: var(--success);
  font-weight: 600;
}

.status-text.error {
  color: #b83535;
  font-weight: 600;
}

.progress-wrap {
  margin-top: 10px;
}

.progress-wrap.hidden {
  display: none;
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 99px;
  background: #e4efff;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0b7a75, #1463b0);
  transition: width 220ms ease;
}

.progress-text {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: #4b5f82;
  font-weight: 700;
}

.result-panel {
  margin-top: 16px;
  border: 1px solid #d4e2fb;
  border-radius: 12px;
  padding: 12px;
  background: #f8fbff;
}

.result-panel.hidden {
  display: none;
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.result-head h2 {
  margin: 0;
  font-size: 1rem;
}

.download-btn {
  text-decoration: none;
  background: #0c6cb7;
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 700;
}

.preview-frame {
  width: 100%;
  height: 460px;
  border: 1px solid #d4e2fb;
  border-radius: 10px;
  background: #fff;
}

.crop-modal {
  position: fixed;
  inset: 0;
  background: rgba(18, 33, 58, 0.55);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 16px;
  overflow-y: auto;
}

.crop-modal.hidden {
  display: none;
}

.crop-dialog {
  width: min(940px, 100%);
  background: #fff;
  border-radius: 14px;
  border: 1px solid #cadcff;
  box-shadow: 0 24px 42px rgba(17, 47, 89, 0.25);
  overflow: hidden;
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
}

.crop-head {
  padding: 12px 14px;
  border-bottom: 1px solid #e2ebfb;
  flex-shrink: 0;
}

.crop-head h3 {
  margin: 0;
  font-size: 1rem;
}

.crop-body {
  padding: 12px;
  background: #f7faff;
  max-height: 70vh;
  overflow: auto;
  min-height: 0;
}

.crop-body img {
  display: block;
  max-width: 100%;
  max-height: 62vh;
}

#docCropCanvas {
  display: block;
  max-width: 100%;
  border: 1px solid #d6e4fb;
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

.crop-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px;
  border-top: 1px solid #e2ebfb;
  flex-shrink: 0;
}

.crop-actions .secondary-btn,
.crop-actions .primary-btn {
  width: auto;
  margin: 0;
}

.edit-dialog {
  width: min(980px, 100%);
}

.edit-body {
  display: grid;
  grid-template-columns: minmax(240px, 340px) 1fr;
  gap: 14px;
  padding: 12px;
  background: #f7faff;
  overflow: auto;
  min-height: 0;
  flex: 1;
}

.edit-preview-wrap {
  background: #fff;
  border: 1px solid #d7e4fb;
  border-radius: 10px;
  padding: 10px;
}

.edit-preview-wrap img {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  display: block;
  border-radius: 8px;
  background: #fff;
}

.edit-preview-info {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: #4d6182;
  font-weight: 700;
}

.edit-tools {
  background: #fff;
  border: 1px solid #d7e4fb;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 10px;
}

.edit-rotate-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

#editEnhanceManualWrap {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

#editEnhanceManualWrap.hidden {
  display: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 640px) {
  .dashboard {
    padding-top: 28px;
  }

  .converter-card {
    padding: 16px;
  }

  .file-item {
    grid-template-columns: 56px 1fr;
  }

  .file-thumb-wrap {
    width: 56px;
    height: 56px;
  }

  .file-actions {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: flex-end;
  }

  .preview-frame {
    height: 360px;
  }

  .tool-menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .pdf2img-grid {
    grid-template-columns: 1fr;
  }

  .edit-body {
    grid-template-columns: 1fr;
  }

  #editEnhanceManualWrap {
    grid-template-columns: 1fr;
  }

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

  .preset-tools .secondary-btn {
    width: 100%;
  }

  .crop-modal {
    padding: 10px;
    place-items: start center;
  }

  .crop-dialog {
    max-height: calc(100dvh - 20px);
  }

  .crop-body {
    max-height: calc(100dvh - 170px);
  }

  .edit-body {
    max-height: calc(100dvh - 170px);
    overflow: auto;
  }
}
