/* ==========================================================================
   PDF to Flipbook Converter — application styles
   ========================================================================== */

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --on-primary: #ffffff;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --text: #1a1d29;
  --muted: #555c6e;
  --border: #e1e4ec;
  --border-strong: #c9cdd8;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warning-soft: #fffaeb;
  --warning-text: #93370d;
  --success: #067647;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.06);
  --focus: 0 0 0 3px rgba(79, 70, 229, 0.45);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: rgba(129, 140, 248, 0.14);
    --on-primary: #0f1020;
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #1f2330;
    --text: #eceef4;
    --muted: #a6adbd;
    --border: #2b3040;
    --border-strong: #3d4356;
    --danger: #fda29b;
    --danger-soft: rgba(240, 68, 56, 0.14);
    --warning-soft: rgba(247, 144, 9, 0.14);
    --warning-text: #fec84b;
    --success: #75e0a7;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    --focus: 0 0 0 3px rgba(129, 140, 248, 0.55);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2 { line-height: 1.25; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.05em 0.35em;
  border-radius: 5px;
}

.container { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 16px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  padding: 8px 14px; border-radius: 8px;
  background: var(--primary); color: var(--on-primary);
  font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: 12px; }

:focus-visible { outline: none; box-shadow: var(--focus); }
main:focus { outline: none; }

/* ---------- Header / footer ---------- */
.app-header { padding: 32px 0 8px; }
.header-inner { display: flex; align-items: center; gap: 16px; }
.app-logo { flex: none; border-radius: 12px; box-shadow: var(--shadow); }
.app-title { margin: 0; font-size: clamp(1.5rem, 4vw, 2rem); font-weight: 750; letter-spacing: -0.02em; }
.app-tagline { margin: 4px 0 0; color: var(--muted); font-size: 1.05rem; }

.app-footer { padding: 24px 0 40px; color: var(--muted); font-size: 0.875rem; text-align: center; }
.app-footer p { margin: 0; }

/* ---------- Notices ---------- */
.privacy-note {
  display: flex; align-items: center; gap: 8px;
  margin: 16px 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--text);
  font-size: 0.95rem;
}
.privacy-note svg { flex: none; color: var(--primary); }

.alert {
  display: flex; align-items: flex-start; gap: 10px;
  margin: 0 0 16px;
  padding: 12px 12px 12px 16px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
}
.alert.is-info {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}
.alert-icon { flex: none; margin-top: 2px; }
.alert-message { flex: 1; margin: 0; font-weight: 500; }

.icon-btn {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: 0; border-radius: 8px;
  background: transparent; color: inherit;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(127, 127, 127, 0.15); }

/* ---------- Cards ---------- */
.card {
  margin: 0 0 20px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.card-head h2 { margin: 0; font-size: 1.2rem; font-weight: 700; }
.card-head h2:focus { outline: none; }
.step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex: none;
  border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  font-size: 0.875rem; font-weight: 700;
}

.hint { margin: 6px 0 0; color: var(--muted); font-size: 0.875rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-lg { min-height: 52px; padding: 12px 26px; font-size: 1.05rem; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.875rem; }
.file-btn:focus-within { box-shadow: var(--focus); }

/* ---------- Dropzone ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 240px;
  padding: 32px 20px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--primary); }
.dropzone.is-dragover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone-icon { color: var(--primary); margin-bottom: 8px; }
.dropzone-title { margin: 0; font-size: 1.15rem; font-weight: 650; }
.dropzone-or { margin: 6px 0 10px; color: var(--muted); }

/* ---------- File info ---------- */
.file-info {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.file-badge {
  flex: none;
  display: flex; align-items: center; justify-content: center;
  width: 52px; height: 64px;
  border-radius: 8px;
  background: #d92d20; color: #fff;
  font-weight: 800; font-size: 0.85rem; letter-spacing: 0.05em;
}
.file-meta { flex: 1 1 320px; display: grid; grid-template-columns: minmax(0, 2fr) 1fr 1fr; gap: 12px; margin: 0; min-width: 0; }
.file-meta dt, .stats dt { color: var(--muted); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.file-meta dd, .stats dd { margin: 2px 0 0; font-weight: 600; }
.file-name { overflow-wrap: anywhere; }
.file-actions { display: flex; gap: 8px; }

/* ---------- Settings ---------- */
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.field-group {
  margin: 0; min-width: 0;
  padding: 16px 18px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.field-group-wide { grid-column: 1 / -1; }
.field-group legend { padding: 0 6px; font-weight: 700; }
.optional { color: var(--muted); font-weight: 400; }
.field { margin-top: 12px; min-width: 0; }
.field:first-of-type { margin-top: 4px; }
.field label, .field .label { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-weight: 600; font-size: 0.925rem; }
.field output { color: var(--primary); font-variant-numeric: tabular-nums; }

select, input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
select:focus-visible, input[type="text"]:focus-visible { border-color: var(--primary); }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.custom-quality { padding: 4px 12px 12px; margin-top: 12px; border-radius: var(--radius-sm); background: var(--surface-2); }

.switch {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px;
  font-weight: 500;
  cursor: pointer;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative; flex: none;
  width: 44px; height: 26px;
  border-radius: 13px;
  background: var(--border-strong);
  transition: background 0.15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }
.switch input:disabled + .switch-track { opacity: 0.5; }

.branding-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.branding-grid .field:first-of-type { margin-top: 12px; }
.color-row { display: flex; gap: 8px; }
.color-row input[type="color"] {
  flex: none; width: 52px; height: 44px; padding: 3px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer;
}
.color-row input[type="text"] { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-transform: lowercase; }
.logo-row { display: flex; align-items: center; gap: 12px; }
.logo-preview {
  display: flex; align-items: center; justify-content: center; flex: none;
  width: 88px; height: 56px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted); font-size: 0.75rem;
  overflow: hidden;
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-actions { display: flex; flex-wrap: wrap; gap: 6px; }

fieldset:disabled .switch, fieldset:disabled label { cursor: not-allowed; }

/* ---------- Convert / progress ---------- */
.convert-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.convert-row .hint { margin: 0; }
.progress { margin-top: 20px; }
.progress-head { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; margin-bottom: 8px; }
.progress-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-bar { height: 12px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--primary); border-radius: 6px; transition: width 0.2s ease-out; }
.progress-percent { margin: 6px 0 0; color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }

/* ---------- Result ---------- */
.stale-note {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--warning-text);
  font-weight: 500;
}
.stale-note p { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 0 0 18px; }
.stats > div { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.preview {
  position: relative;
  height: min(72vh, 680px);
  min-height: 380px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  background: #d8dce3;
}
.preview iframe { display: block; width: 100%; height: 100%; border: 0; }
.preview-hint { margin-bottom: 18px; }
.result-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .settings, .branding-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .app-header { padding-top: 20px; }
  .card { padding: 18px 16px; border-radius: 14px; }
  .dropzone { min-height: 200px; padding: 24px 14px; }
  .file-meta { grid-template-columns: 1fr 1fr; }
  .file-meta > div:first-child { grid-column: 1 / -1; }
  .file-actions { width: 100%; }
  .file-actions .btn { flex: 1; }
  .convert-row .btn, .result-actions .btn { width: 100%; }
  .preview { height: 70vh; min-height: 420px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
