:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.logo:hover { text-decoration: none; }

.logo-img {
  height: 40px;
  width: auto;
  display: block;
}

.logo-divider {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 22px;
  line-height: 1;
}

.logo-product {
  color: var(--primary);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

@media (max-width: 600px) {
  .logo-img { height: 32px; }
  .logo-divider { font-size: 18px; }
  .logo-product { font-size: 17px; }
}

.nav { display: flex; gap: 6px; flex-wrap: wrap; }
.nav a {
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}
.nav a:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.nav a.active { background: var(--primary); color: white; }

.container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px;
  flex: 1;
}

.hero { text-align: center; margin-bottom: 40px; }
.hero h1 { font-size: 36px; font-weight: 700; margin-bottom: 12px; }
.hero p { font-size: 16px; color: var(--text-muted); max-width: 680px; margin: 0 auto; }

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  max-width: 1100px;
  margin: 0 auto;
}

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}
.tool-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
  text-decoration: none;
}

.tool-icon {
  width: 56px;
  height: 56px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 16px;
}

.tool-card h3 { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.tool-card p { font-size: 14px; color: var(--text-muted); }

/* Tool page */
.tool-header { text-align: center; margin-bottom: 32px; }
.tool-header h1 { font-size: 32px; font-weight: 700; margin-bottom: 10px; }
.tool-header p { color: var(--text-muted); max-width: 720px; margin: 0 auto; }

.dropzone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 60px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}
.dropzone-icon { font-size: 48px; color: var(--primary); margin-bottom: 16px; }
.dropzone-text { font-size: 16px; font-weight: 500; margin-bottom: 8px; }
.dropzone-hint { font-size: 13px; color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
  text-decoration: none;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:disabled { background: var(--text-muted); cursor: not-allowed; opacity: 0.6; }
.btn-large { padding: 16px 40px; font-size: 16px; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }

input[type="file"] { display: none; }

.workspace {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
  margin-top: 24px;
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
}

.preview-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 400px;
}
.preview-title { font-size: 14px; color: var(--text-muted); margin-bottom: 12px; }
.hint-inline { font-size: 12px; color: var(--text-muted); font-weight: normal; }

.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.page-thumb {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease;
  position: relative;
}
.page-thumb:hover { border-color: var(--primary); }
.page-thumb.selected { border-color: var(--primary); background: var(--primary-light); }
.page-thumb.rotated { border-color: var(--success); }
.page-thumb canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 4px;
  background: white;
  transition: transform 0.2s ease;
}
.page-thumb-num { font-size: 12px; color: var(--text-muted); margin-top: 6px; font-weight: 500; }

.page-thumb-actions {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 6px;
}
.page-thumb-actions button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  color: var(--text);
  transition: all 0.15s ease;
}
.page-thumb-actions button:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.rotation-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--success);
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  display: none;
}
.page-thumb.rotated .rotation-badge { display: block; }

.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  height: fit-content;
  position: sticky;
  top: 20px;
}
.sidebar h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.range-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.range-row input { flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; width: 100%; }
.range-row .remove-btn {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
}

.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.checkbox-row input { width: 16px; height: 16px; cursor: pointer; }
.checkbox-row label { font-size: 14px; cursor: pointer; }

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  margin-top: 24px;
}
.result-icon {
  width: 64px;
  height: 64px;
  background: #dcfce7;
  color: var(--success);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin-bottom: 16px;
}
.result-card h3 { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.result-card p { color: var(--text-muted); margin-bottom: 20px; }

.progress {
  background: var(--bg);
  border-radius: 8px;
  height: 8px;
  overflow: hidden;
  margin: 16px 0;
}
.progress-bar {
  background: var(--primary);
  height: 100%;
  width: 0%;
  transition: width 0.3s ease;
}

.error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 16px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.file-item-icon { color: var(--primary); font-size: 20px; }
.file-item-name { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item-size { font-size: 13px; color: var(--text-muted); }
.file-item-remove { background: transparent; border: none; color: var(--danger); cursor: pointer; font-size: 18px; }

.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: auto;
}
.footer-row {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.footer-row-sub {
  margin-top: 4px;
  font-size: 12px;
}
.footer-divider {
  color: var(--border);
}
.footer a {
  color: var(--primary);
  font-weight: 500;
}

/* ============ Статистика ============ */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stats-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.stats-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stats-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

.stats-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}
.stats-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
}
.stats-table th, .stats-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.stats-table th {
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stats-table-wide td:not(:first-child), .stats-table-wide th:not(:first-child) {
  text-align: center;
}
/* ============== IMG2PDF ============== */
.img2pdf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.img2pdf-item {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
  cursor: grab;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.img2pdf-item:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.img2pdf-item:active { cursor: grabbing; }

.img2pdf-thumb {
  width: 100%;
  height: 130px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.img2pdf-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.img2pdf-thumb-placeholder {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 1px;
}

.img2pdf-meta {
  padding: 8px 10px 10px;
  font-size: 12px;
}
.img2pdf-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.img2pdf-size {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
}

.img2pdf-item .file-item-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.img2pdf-item .file-item-remove:hover { background: rgba(220, 38, 38, 0.85); }
