/* =========================================================
   PDF Merger — stylesheet
   Pure CSS. No frameworks. Light + dark themes via
   prefers-color-scheme. Red accent color.
   ========================================================= */

:root {
  --accent: #e15757;
  --accent-dark: #be4141;
  --accent-contrast: #ffffff;

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-alt: #fafafa;
  --border: #e2e2e6;
  --text: #1a1a1e;
  --text-muted: #63636b;
  --danger-bg: #fdecec;
  --danger-text: #8a1f1f;
  --danger-border: #f3b8b8;
  --success-bg: #eafaf0;
  --success-text: #1f6b3a;
  --success-border: #b7e6c6;
  --shadow: 0 1px 2px rgba(20, 20, 25, 0.06), 0 8px 24px rgba(20, 20, 25, 0.08);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --focus-ring: 0 0 0 3px rgba(225, 87, 87, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --surface: #1b1b1e;
    --surface-alt: #222226;
    --border: #303035;
    --text: #f1f1f3;
    --text-muted: #a3a3ab;
    --danger-bg: #3a1c1c;
    --danger-text: #ff9b9b;
    --danger-border: #6b2b2b;
    --success-bg: #163524;
    --success-text: #7fe0a4;
    --success-border: #245a3a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}

/* Must win over any component's own `display` declaration
   (e.g. .stats-bar/.controls use display:flex at equal specificity). */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
}

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

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

/* Focus visibility for accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

.app-shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
  text-align: center;
  margin-bottom: 20px;
}

.app-header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin: 0;
}

/* ---------- Main ---------- */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Notification ---------- */
.notification {
  border-radius: var(--radius-md);
  padding: 10px 13px;
  font-size: 0.83rem;
  border: 1px solid transparent;
}

.notification.is-error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: var(--danger-border);
}

.notification.is-success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: var(--success-border);
}

/* ---------- Upload area ---------- */
.upload-area {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px 16px;
  text-align: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.upload-area.is-dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
}

.upload-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.upload-icon {
  width: 35px;
  height: 35px;
  color: var(--accent);
  margin-bottom: 5px;
}

.upload-text {
  font-weight: 600;
  font-size: 0.84rem;
  margin: 0;
}

.upload-or {
  color: var(--text-muted);
  font-size: 0.68rem;
  margin: 2px 0 8px;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  padding: 8px 18px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-alt);
}

.btn-large {
  padding: 10px 22px;
  font-size: 0.8rem;
}

/* ---------- Stats bar ---------- */
.stats-bar {
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 13px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------- File list ---------- */
.file-list-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.file-row:last-child {
  border-bottom: none;
}

.file-row.is-dragging {
  opacity: 0.4;
}

.file-row.sortable-ghost {
  background: var(--surface-alt);
  border: 1px dashed var(--accent);
}

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  touch-action: none;
  background: transparent;
  border: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.file-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.file-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-name {
  font-size: 0.74rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta {
  font-size: 0.64rem;
  color: var(--text-muted);
}

.remove-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
}

.remove-btn:hover {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: var(--danger-border);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 26px 13px;
  margin: 0;
  font-size: 0.74rem;
}

/* ---------- Controls ---------- */
.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.filename-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filename-row label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
}

.filename-row input {
  font-family: inherit;
  font-size: 0.76rem;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
}

.split-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.split-row label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
}

.split-row input {
  font-family: inherit;
  font-size: 0.76rem;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  width: 100%;
}

.split-hint {
  font-size: 0.62rem;
  color: var(--text-muted);
  margin: 0;
}

.action-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.action-row .btn-large {
  flex: 1;
  min-width: 160px;
}

/* ---------- Results ---------- */
.results-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 13px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.results-title {
  font-size: 0.78rem;
  font-weight: 700;
  margin: 0;
}

.results-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
}

.result-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result-name {
  font-size: 0.74rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-meta {
  font-size: 0.64rem;
  color: var(--text-muted);
}

.result-download {
  flex-shrink: 0;
  text-decoration: none;
  padding: 6px 14px;
}

/* ---------- Spinner ---------- */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  margin-top: 26px;
  color: var(--text-muted);
  font-size: 0.68rem;
}

.app-footer p {
  margin: 2px 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .app-shell {
    padding: 20px 14px 36px;
  }

  .app-header h1 {
    font-size: 1.1rem;
  }

  .upload-area {
    padding: 22px 12px;
  }

  .stats-bar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
  }

  .action-row {
    flex-direction: column;
  }

  .action-row .btn-large {
    width: 100%;
  }
}

/* High contrast support */
@media (prefers-contrast: more) {
  :root {
    --border: #808088;
  }
}
