:root {
  --primary: #6C5CE7;
  --accent: #00C2D1;
  --canvas: #F5F6FC;
  --surface: #FFFFFF;
  --text-primary: #1A1B25;
  --text-secondary: #6B7280;
  --border: #E5E7EB;
  --danger: #E6435B;
  --success: #16A34A;
  --gradient: linear-gradient(135deg, var(--primary), var(--accent));
}

* { box-sizing: border-box; }

/* Must win over any element-specific `display` rule below (.modal-backdrop, .field, .view, etc.)
   so that toggling the `hidden` attribute from JS is always sufficient to hide something. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--canvas);
  color: var(--text-primary);
}

a { color: var(--primary); }

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.05rem;
}
.brand-mark { font-size: 1.4rem; }
.brand-ai {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-link {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.4rem 0.5rem;
}
.nav-link:hover { color: var(--primary); }

.nav-user {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-right: 0.25rem;
}

/* ===== Buttons ===== */
.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary {
  background: var(--gradient);
  color: #fff;
  box-shadow: 0 4px 14px rgba(108, 92, 231, 0.3);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); }
.btn-ghost {
  background: transparent;
  color: var(--text-primary);
}
.btn-ghost:hover { color: var(--primary); }
.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: rgba(108, 92, 231, 0.06); }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.85rem 1.75rem; font-size: 1rem; }

/* ===== Views ===== */
#app { max-width: 920px; margin: 0 auto; padding: 1.5rem; min-height: 70vh; }
.view { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== Hero / Viewer ===== */
.hero { text-align: center; padding: 2.5rem 1rem 1.5rem; }
.hero h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); margin: 0 0 0.5rem; }
.hero .accent {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero p { color: var(--text-secondary); margin: 0; }

.drop-zone {
  border: 2.5px dashed var(--border);
  border-radius: 20px;
  background: var(--surface);
  padding: 3rem 1.5rem;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease;
  cursor: pointer;
}
.drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(108, 92, 231, 0.05);
}
.drop-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.drop-title { font-weight: 700; font-size: 1.1rem; margin: 0 0 0.25rem; }
.drop-sub { color: var(--text-secondary); margin: 0 0 1rem; font-size: 0.85rem; }

.viewer-frame {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.viewer-filename { font-weight: 600; font-size: 0.9rem; }

.pdf-pages {
  height: 75vh;
  overflow-y: auto;
  background: #e9eaef;
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}
.pdf-pages canvas {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  background: #fff;
  max-width: 94%;
}
.pdf-pages-status {
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.feature-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin: 3rem 0 2rem;
}
.feature-strip-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  text-align: center;
}
.feature-strip-icon { font-size: 1.75rem; margin-bottom: 0.5rem; }
.feature-strip-item h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.feature-strip-item p { margin: 0; color: var(--text-secondary); font-size: 0.85rem; line-height: 1.5; }

.cta-row { text-align: center; padding: 1rem 0 3rem; }
.cta-sub { display: block; margin-top: 0.6rem; font-size: 0.8rem; color: var(--text-secondary); }

/* ===== Documents ===== */
.docs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.docs-header h1 { margin: 0; font-size: 1.5rem; }
.docs-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.docs-list { display: flex; flex-direction: column; gap: 0.75rem; }
.doc-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.25rem;
}
.doc-card-main { flex: 1; min-width: 0; }
.doc-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-card-meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.15rem; }
.doc-card-badge {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--accent);
  margin-left: 0.5rem;
}
.doc-card-actions { display: flex; gap: 0.4rem; flex-shrink: 0; flex-wrap: wrap; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.status-line {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: rgba(108, 92, 231, 0.08);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.status-line.error { background: rgba(230, 67, 91, 0.1); color: var(--danger); }
.status-line.success { background: rgba(22, 163, 74, 0.1); color: var(--success); }

/* ===== AI view ===== */
.back-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.875rem;
  cursor: pointer;
  padding: 0;
  margin-bottom: 1rem;
}
.ai-form { display: flex; flex-direction: column; gap: 0.5rem; max-width: 600px; margin-bottom: 1.5rem; }
.ai-form label { font-weight: 600; font-size: 0.875rem; }
.ai-form textarea {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  resize: vertical;
}
.ai-form .btn { align-self: flex-start; }
.ai-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 0.9rem;
  max-width: 700px;
}

/* ===== Pricing ===== */
.pricing-sub { color: var(--text-secondary); margin-top: -0.5rem; }
.pricing-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-top: 1.5rem;
}
.pricing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
}
.pricing-card h3 { margin: 0 0 0.25rem; }
.pricing-card .price { font-size: 1.5rem; font-weight: 700; margin: 0.5rem 0; }
.pricing-card .tagline { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 1rem; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.modal {
  background: #fff;
  border-radius: 18px;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  position: relative;
}
.modal-sm { max-width: 340px; }
.modal-sign { max-width: 560px; }

.sign-row {
  display: flex;
  gap: 1rem;
}
.sign-row .field { flex: 1; }
.sign-row select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}

.sign-pad-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}
.sign-canvas {
  width: 100%;
  height: 180px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}
.sign-pad-actions {
  display: flex;
  justify-content: flex-end;
  margin: 0.5rem 0 1rem;
}
.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-secondary);
}
.modal h2 { margin: 0 0 1.25rem; font-size: 1.3rem; }
.field { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.8rem; font-weight: 600; }
.field input {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.form-error {
  color: var(--danger);
  font-size: 0.825rem;
  margin-bottom: 0.75rem;
}
.modal-switch {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 1.25rem 0 0;
}
.modal-switch button {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-left: 0.25rem;
}

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-secondary);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}
.site-footer a { color: var(--text-secondary); }

@media (max-width: 600px) {
  .topbar-nav { gap: 0.4rem; }
  .nav-user { display: none; }
  .doc-card { flex-wrap: wrap; }
}
