/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── TOKENS ── */
:root {
  --bg:            #0c0e13;
  --bg-card:       #111318;
  --bg-raised:     #181c24;
  --bg-hover:      #1e232e;
  --border:        rgba(255,255,255,0.06);
  --border-med:    rgba(255,255,255,0.10);
  --border-strong: rgba(255,255,255,0.15);
  --text-1:        #f0f2f7;
  --text-2:        #8c93a8;
  --text-3:        #50566a;
  --accent:        #4f8ef7;
  --accent-dim:    rgba(79,142,247,0.12);
  --accent-hover:  #6fa3ff;
  --success:       #30c97a;
  --danger:        #f04b4b;
  --radius-sm:     6px;
  --radius:        10px;
  --radius-lg:     14px;
  --header-h:      62px;
  --toolbar-h:     44px;
  --font:          'Inter', system-ui, -apple-system, sans-serif;
  --font-display:  'Space Grotesk', system-ui, sans-serif;
  --ease:          cubic-bezier(0.16, 1, 0.3, 1);
}

html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── WATERMARK ── */
#watermark-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  overflow: hidden;
}
.wm-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-35deg);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 500;
  color: rgba(255,255,255,0.022);
  letter-spacing: 0.25em;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  /* Repeat via text-shadow to tile without JS */
  text-shadow:
    -600px -300px rgba(255,255,255,0.022),  600px -300px rgba(255,255,255,0.022),
    -600px  0px rgba(255,255,255,0.022),     600px  0px rgba(255,255,255,0.022),
    -600px  300px rgba(255,255,255,0.022),   600px  300px rgba(255,255,255,0.022),
    -1200px -600px rgba(255,255,255,0.022), 1200px -600px rgba(255,255,255,0.022),
    -1200px  600px rgba(255,255,255,0.022), 1200px  600px rgba(255,255,255,0.022),
    0 -600px rgba(255,255,255,0.022),        0  600px rgba(255,255,255,0.022);
}

/* ── HEADER ── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--header-h);
  background: rgba(12,14,19,0.85);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 12px;
}

.header-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

/* Avatar */
.avatar-wrap {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid var(--border-med);
  flex-shrink: 0;
  position: relative;
  background: var(--bg-raised);
}
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.avatar-initials {
  display: none;
  width: 100%;
  height: 100%;
  background: var(--accent-dim);
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  align-items: center;
  justify-content: center;
}

.header-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.header-role {
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 1px;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.btn-icon:hover {
  color: var(--text-1);
  border-color: var(--border-med);
  background: var(--bg-raised);
}
.btn-icon:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-download {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(79,142,247,0.4);
  background: var(--accent-dim);
  color: var(--accent);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-download:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-download:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-download:active { opacity: 0.85; }

/* ── TOOLBAR ── */
.viewer-toolbar {
  position: sticky;
  top: var(--header-h);
  z-index: 100;
  height: var(--toolbar-h);
  background: rgba(17,19,24,0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.toolbar-inner {
  max-width: 860px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.page-controls,
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.nav-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-1);
  border-color: var(--border-med);
}
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.nav-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.page-info {
  font-size: 12.5px;
  color: var(--text-2);
  min-width: 54px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.page-sep { margin: 0 3px; color: var(--text-3); }

.zoom-label {
  font-size: 12px;
  color: var(--text-2);
  min-width: 40px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.zoom-reset { margin-left: 2px; }

/* ── MAIN VIEWER ── */
.viewer-main {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

.viewer-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 320px;
  position: relative;
  transition: filter 0.3s;
}
.viewer-container.devtools-open {
  filter: blur(10px);
  pointer-events: none;
}

/* Loading */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 80px 0;
  color: var(--text-3);
  font-size: 13.5px;
}
.loading-text { color: var(--text-2); }

.spinner-ring {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border-med);
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Error */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 80px 24px;
  color: var(--text-2);
  font-size: 14px;
  text-align: center;
}
.error-state small { font-size: 12px; color: var(--text-3); }
.error-state code {
  font-family: ui-monospace, monospace;
  background: var(--bg-raised);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
}

/* PDF canvas area */
#pdf-canvas-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.page-wrap {
  position: relative;
  width: 100%;
  line-height: 0; /* remove gap below canvas */
}

.page-wrap + .page-wrap {
  border-top: 1px solid var(--border);
}

.page-wrap canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  pointer-events: none;
  -webkit-user-drag: none;
  user-drag: none;
}

/* Link overlay */
.link-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}
.link-layer a {
  position: absolute;
  pointer-events: all;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.1s;
}
.link-layer a:hover {
  background: rgba(79,142,247,0.2);
  outline: 1px solid rgba(79,142,247,0.45);
}
.link-layer a:focus-visible {
  outline: 2px solid var(--accent);
}

/* ── BLUR OVERLAY (visibility change) ── */
#blur-overlay {
  position: fixed;
  inset: 0;
  z-index: 8000;
  background: rgba(12,14,19,0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
}
.blur-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-1);
}
.blur-sub {
  font-size: 13px;
  color: var(--text-3);
}

/* ── PROTECT NOTICE ── */
.protect-notice {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid rgba(240,75,75,0.3);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 12.5px;
  z-index: 9999;
  pointer-events: none;
  white-space: nowrap;
  animation: fade-in 0.15s ease;
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;

  /* Hidden by default — JS toggles .is-open */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.modal-overlay.is-open {
  opacity: 1;
  pointer-events: all;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 448px;
  position: relative;
  transform: translateY(10px);
  transition: transform 0.2s var(--ease);
  overflow: hidden;
}
.modal-overlay.is-open .modal-card {
  transform: translateY(0);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.modal-close:hover {
  color: var(--text-1);
  background: var(--bg-hover);
  border-color: var(--border-med);
}
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 22px 22px 0;
}
.modal-icon-wrap {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--accent-dim);
  border: 1px solid rgba(79,142,247,0.2);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.modal-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 3px;
}
.modal-subtitle { font-size: 12.5px; color: var(--text-3); }

.modal-body {
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.modal-notice {
  font-size: 12px;
  color: var(--text-2);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  line-height: 1.6;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.req { color: var(--accent); }
.opt { color: var(--text-3); font-weight: 400; }

.form-group input,
.form-group textarea {
  background: var(--bg-raised);
  border: 1px solid var(--border-med);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  color: var(--text-1);
  font-family: var(--font);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  resize: vertical;
  width: 100%;
}
.form-group input:hover,
.form-group textarea:hover { border-color: var(--border-strong); }
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,142,247,0.12);
}
.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text-3); }

.field-error {
  font-size: 11.5px;
  color: var(--danger);
  min-height: 15px;
  display: block;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: -2px;
}
.checkbox-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin-top: 1px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.checkbox-row label {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.55;
  cursor: pointer;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
}

.btn-cancel {
  padding: 0 14px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-med);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.btn-cancel:hover { background: var(--bg-hover); color: var(--text-1); }
.btn-cancel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-confirm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, opacity 0.12s;
}
.btn-confirm:hover:not(:disabled) { background: var(--accent-hover); }
.btn-confirm:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-confirm:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 11px 18px;
  font-size: 13px;
  color: var(--text-1);
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.toast.success { border-color: rgba(48,201,122,0.3); color: var(--success); }
.toast.error   { border-color: rgba(240,75,75,0.3);  color: var(--danger);  }

/* ── ANIMATIONS ── */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ── RESPONSIVE ── */
@media (max-width: 560px) {
  .header-role { display: none; }
  .btn-download span { display: none; }
  .btn-download { padding: 0 10px; }
  .viewer-main { padding: 16px 12px 60px; }
  .modal-card { max-width: 100%; border-radius: var(--radius); }
  .modal-header, .modal-body, .modal-footer { padding-left: 16px; padding-right: 16px; }
  .toast { white-space: normal; text-align: center; }
}

/* ── NO PRINT ── */
@media print { body { display: none !important; } }

/* ── REDUCED MOTION ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
