:root {
  --bg: #0f1419;
  --bg-elev: #171d25;
  --bg-card: #1c2430;
  --border: #2a3542;
  --text: #e8edf2;
  --muted: #8b98a8;
  --primary: #e63946;
  --primary-hover: #ff4d5a;
  --secondary: #2d6cdf;
  --secondary-hover: #3f7df0;
  --ok: #2fbf71;
  --err-bg: #3a1c21;
  --err-border: #7a2c37;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Top bar */
.topbar {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
}
.brand { display: flex; align-items: center; gap: 14px; max-width: 1100px; margin: 0 auto; }
.brand-icon {
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 1px;
  padding: 10px 12px;
  border-radius: 10px;
}
.brand h1 { font-size: 18px; margin: 0; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* Layout */
.container {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* Form */
.url-form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.url-row { display: flex; gap: 10px; }
.url-row input {
  flex: 1;
  min-width: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
.url-row input:focus { border-color: var(--secondary); }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: #fff;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); }
.btn-secondary:hover { background: var(--secondary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--muted); }

/* Status / error */
.status {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.status::before {
  content: "";
  width: 14px; height: 14px;
  border: 2px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
.error {
  margin-top: 16px;
  padding: 14px;
  border-radius: 10px;
  background: var(--err-bg);
  border: 1px solid var(--err-border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.error-text { font-size: 14px; line-height: 1.45; }
.error-text strong { display: block; margin-bottom: 2px; }

/* Result */
.result { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.doc-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 14px; align-items: flex-start; }
.doc-title { font-size: 16px; font-weight: 700; }
.doc-info { color: var(--muted); font-size: 13px; margin-top: 4px; }
.doc-info .ok { color: var(--ok); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Viewer */
.viewer {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 60vh;
}
.viewer:fullscreen { border: 0; border-radius: 0; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}
.tb-group { display: flex; align-items: center; gap: 6px; }
.tb-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}
.tb-btn.tb-text { width: auto; padding: 0 12px; font-size: 13px; font-weight: 600; }
.tb-btn:hover { border-color: var(--muted); }
.tb-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-ctrl { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.page-ctrl input {
  width: 56px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 8px;
  text-align: center;
  font-size: 14px;
}
.zoom-level { min-width: 48px; text-align: center; font-size: 13px; color: var(--muted); }

.canvas-wrap {
  flex: 1;
  overflow: auto;
  background: #0a0e13;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  position: relative;
}
#pdf-canvas {
  background: #fff;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  max-width: none;
}

.spinner {
  position: absolute;
  top: 50%; left: 50%;
  width: 36px; height: 36px;
  margin: -18px 0 0 -18px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Footer / toast */
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; border-top: 1px solid var(--border); }
.toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  background: #222c38;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 50;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}

/* Mobile */
@media (max-width: 640px) {
  .url-row { flex-direction: column; }
  .url-row .btn { width: 100%; }
  .actions { width: 100%; }
  .actions .btn { flex: 1 1 calc(50% - 4px); padding: 11px 8px; font-size: 13px; }
  .toolbar { justify-content: center; }
  .canvas-wrap { padding: 8px; }
  .brand h1 { font-size: 16px; }
}
