:root {
  --bg: radial-gradient(120% 100% at 0% 0%, #0f1b36 0%, #06101f 60%, #050910 100%);
  --card: rgba(8, 17, 34, 0.8);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8efff;
  --muted: #a9b7d9;
  --accent: #12d6c4;
  --accent-2: #2ea4ff;
  --danger: #ff6c7f;
  --radius: 16px;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; font-family: "Manrope", "Segoe UI", sans-serif; color: var(--text); }
body { background: var(--bg); }
body.modal-open { overflow: hidden; }

.bg-aura {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 80% 0%, rgba(46, 164, 255, 0.2), transparent 40%),
    radial-gradient(circle at 10% 90%, rgba(18, 214, 196, 0.16), transparent 45%);
}

.app-shell { width: min(1180px, 94vw); margin: 22px auto 40px; position: relative; z-index: 1; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
  backdrop-filter: blur(8px);
}

.compact-card { padding: 12px 16px; }
.login-card { max-width: 440px; margin: 8vh auto; }

h1, h2 { margin: 0 0 8px; }
h1 { font-size: clamp(24px, 4vw, 34px); }
h2 { font-size: clamp(18px, 2.5vw, 23px); }
.muted { color: var(--muted); }
.alert {
  background: rgba(255, 108, 127, 0.16);
  border: 1px solid rgba(255, 108, 127, 0.4);
  color: #ffd7df;
  border-radius: 10px;
  padding: 10px;
}
.alert-success {
  background: rgba(18, 214, 196, 0.16);
  border-color: rgba(18, 214, 196, 0.4);
  color: #d7fffa;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.stack { display: grid; gap: 10px; }
label { font-size: 14px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="date"], input[type="number"], input[type="file"] {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.row-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.btn-primary, .btn-secondary, .btn-ghost, .link-btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #001525;
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border);
}
.btn-ghost, .link-btn {
  background: transparent;
  border-color: rgba(18, 214, 196, 0.45);
}
.mini { width: 42px; padding: 10px 0; }

.desktop-only { display: inline-flex; }
.settings-trigger {
  min-width: 38px;
  padding: 10px 12px;
  opacity: 0.28;
  border-color: rgba(255, 255, 255, 0.12);
}
.settings-trigger:hover,
.settings-trigger:focus-visible {
  opacity: 0.78;
  border-color: rgba(18, 214, 196, 0.45);
}

.hidden { display: none !important; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(3, 8, 18, 0.68);
}

.modal-card {
  width: min(460px, 100%);
  margin: 0;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 920px; }
th, td { border-bottom: 1px solid var(--border); text-align: left; padding: 10px; }
th { color: var(--muted); font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.preview-card.hidden { display: none; }
.viewer-wrap {
  margin-top: 10px;
  position: relative;
  width: 100%;
  max-width: 920px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: #0a1226;
}

#pdf_canvas {
  width: 100%;
  display: block;
  touch-action: none;
}

.stamp-group {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  left: 0;
  top: 0;
  transform-origin: top left;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.stamp-group.hidden {
  display: none;
}

.stamp {
  width: 170px;
  max-width: 42vw;
  display: block;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.36));
}

.qr-mini {
  width: 86px;
  height: 86px;
  background: #fff;
  border-radius: 0;
  border: 0;
}

.meta-vertical {
  position: absolute;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  max-height: 88%;
  max-width: 28px;
  font-size: 8px;
  line-height: 1.1;
  background: rgba(255, 255, 255, 0.88);
  color: #1a2a46;
  padding: 3px 2px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  overflow: hidden;
  white-space: nowrap;
  z-index: 4;
}

.meta-vertical.side-left {
  left: 2px;
}

.meta-vertical.side-right {
  right: 2px;
}

.stamp-group:active {
  cursor: grabbing;
}

.checkline { display: inline-flex; gap: 8px; align-items: center; }
.mobile-docs { display: none; }

@media (max-width: 900px) {
  .grid, .row-2 { grid-template-columns: 1fr; }
  .app-shell { width: min(1180px, 96vw); margin-top: 14px; }
  .card { padding: 14px; }

  .desktop-table {
    display: none;
  }

  .desktop-only {
    display: none !important;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .mobile-docs {
    display: grid;
    gap: 10px;
  }
}

/* PDF viewer controls */

.pdf-actions {
  gap: 8px;
}

.pdf-viewer-card {
  padding: 0;
  overflow: hidden;
}

.pdf-frame {
  width: 100%;
  min-height: 74vh;
  border: 0;
  display: block;
  background: #0a1226;
}

@media (max-width: 900px) {
  .pdf-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .pdf-actions .btn-primary,
  .pdf-actions .btn-secondary,
  .pdf-actions .btn-ghost {
    width: 100%;
  }

  .pdf-frame {
    min-height: 68vh;
  }
}
