:root {
  --bg: #e8eaed;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --border: #d4d7dc;
  --accent: #00b14f;
  --accent-text: #ffffff;
  --danger: #c62828;
  --page-shadow: 0 1px 3px rgb(0 0 0 / 0.18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #2b2d31;
    --surface: #1e1f22;
    --text: #e6e7e9;
    --muted: #a0a4ab;
    --border: #3a3d42;
    --accent: #1fc46b;
    --accent-text: #0b1f13;
    --danger: #ff8a80;
    --page-shadow: 0 1px 4px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
  /* logo chữ tối: đặt trên nền sáng để đọc được ở dark mode */
  .logo { background: #fff; border-radius: 6px; padding: 2px 6px; }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 64px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo {
  display: block;
  flex: none;
  height: 52px;
  width: auto;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pager {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

button, .btn {
  height: 32px;
  min-width: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

button:disabled { opacity: 0.45; cursor: default; }
button:not(:disabled):hover, .btn:hover { border-color: var(--muted); }

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn.primary { margin-left: 8px; }

main {
  position: relative;
  flex: 1;
  min-height: 0;
}

#viewerContainer {
  position: absolute;
  inset: 0;
  overflow: auto;
  outline: none;
}

/* thay viền trang mặc định của pdf.js bằng bóng nhẹ */
.pdfViewer .page {
  border: none;
  box-shadow: var(--page-shadow);
  margin: 12px auto;
}

.status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
}
.status.error { color: var(--danger); }
.status.error .spinner { display: none; }
.status p { margin: 0; max-width: 420px; }

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

.open-form {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(560px, calc(100% - 32px));
  height: fit-content;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.open-form h1 { margin: 0 0 4px; font-size: 18px; }
.open-form p { margin: 0 0 16px; color: var(--muted); }
.open-form .row { display: flex; gap: 8px; }
.open-form input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.open-form button { height: 36px; }

.popout {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--page-shadow);
}

/* chế độ nhúng iframe: ẩn toolbar giống gview embedded */
body.embedded .toolbar,
body.no-header .toolbar { display: none; }

@media (max-width: 600px) {
  .toolbar { gap: 8px; padding: 0 8px; height: 56px; }
  .logo { height: 40px; }
  .fit, .pager { display: none; }
  .btn.primary { margin-left: 4px; }
  .pdfViewer .page { margin: 8px auto; }
}
