/* Formix PDF - Clean & Minimal Mobile Design */

:root {
  --bg: #ffffff;
  --bg-secondary: #f7f7f8;
  --text: #111111;
  --text-secondary: #666666;
  --border: #e5e5e5;
  --primary: #111111;
  --primary-hover: #333333;
  --accent: #2563eb;
  --success: #16a34a;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1;
  gap: 3px;
}

.logo-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.6px;
  color: var(--text);
}

.logo-rule {
  display: block;
  width: 100%;
  height: 1.5px;
  background: var(--text);
}

.logo-pdf {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1.5px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text);
}

/* Main */
.main {
  flex: 1;
  padding: 20px;
  padding-bottom: 90px;
  overflow-y: auto;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Hero */
.hero {
  margin-bottom: 28px;
  text-align: center;
}

.hero h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
  line-height: 1.3;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 15px;
}

/* Feature Grid */
.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 32px;
}

.feature-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.feature-card:active {
  transform: scale(0.97);
  background: #eeeeee;
}

.feature-icon {
  font-size: 24px;
  margin-bottom: 10px;
}

.feature-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}

.feature-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Pricing Banner */
.pricing-banner {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  border: 1px solid var(--border);
}

.price {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -1px;
}

.price span {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-secondary);
}

.price-text {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 6px 0 16px;
}

/* Buttons */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.btn-primary:active {
  background: var(--primary-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  margin-top: 10px;
}

.full-width {
  width: 100%;
}

/* Form Screen */
.back-btn {
  background: none;
  border: none;
  font-size: 15px;
  color: var(--text-secondary);
  cursor: pointer;
  margin-bottom: 16px;
  padding: 0;
  font-family: inherit;
}

#formTitle {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  letter-spacing: -0.3px;
}

.pdf-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: #999;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 8px;
  margin-bottom: -6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.line-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.line-item .item-desc {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg);
  outline: none;
}

.line-item-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
}

.line-item-row input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg);
  outline: none;
  width: 100%;
}

/* Logo upload */
.logo-upload-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-upload-btn {
  display: inline-block;
  background: var(--bg-secondary);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
}

.logo-preview {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.remove-logo {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: white;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* AI Tools */
.ai-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.ai-action-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 10px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}

.ai-action-btn:active {
  background: #e8e8e8;
}

.ai-result-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.ai-result-actions .btn-primary,
.ai-result-actions .btn-secondary {
  flex: 1;
  padding: 12px;
  font-size: 14px;
}

#aiOutput {
  background: #f0fdf4;
  border-color: #bbf7d0;
}

/* Success Screen */
.success-content {
  text-align: center;
  padding-top: 60px;
}

.success-icon {
  width: 64px;
  height: 64px;
  background: #dcfce7;
  color: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  margin: 0 auto 20px;
}

.success-content h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.success-content p {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 12px;
  font-family: inherit;
  min-width: 64px;
}

.nav-item.active {
  color: var(--text);
  font-weight: 600;
}

.nav-icon {
  font-size: 20px;
}

/* Scan Screen */
.scan-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

.scan-actions {
  margin-bottom: 20px;
}

.scan-btn {
  display: block;
  text-align: center;
  cursor: pointer;
}

.scan-previews {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.scan-preview-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
}

.scan-preview-item.expanded {
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.scan-preview-top {
  position: relative;
  width: 100%;
}

.scan-preview-top img,
.scan-preview-item img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}

.scan-preview-item .page-num,
.scan-preview-top .page-num {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,0.7);
  color: white;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
}

.scan-preview-item .remove-page,
.scan-preview-top .remove-page {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 6px;
  justify-content: center;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.page-filter-btn {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}

.page-filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.filter-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
}

.scan-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-btn {
  flex: 1 1 auto;
  min-width: 64px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
}

.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.filter-btn:active {
  opacity: 0.85;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.checkbox-label input {
  width: 18px;
  height: 18px;
}

/* Account / Subscription */
.account-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  letter-spacing: -0.3px;
}

.account-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
}

.plan-card {
  text-align: center;
  padding: 24px 20px;
}

.plan-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #e5e5e5;
  color: #555;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 10px;
}

.plan-badge.active {
  background: #dcfce7;
  color: #166534;
}

.plan-name {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.plan-price {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: 16px;
}

.plan-price span {
  font-size: 15px;
  font-weight: 400;
  color: var(--text-secondary);
}

.plan-features {
  list-style: none;
  text-align: left;
  margin: 0 0 20px;
  padding: 0 8px;
}

.plan-features li {
  font-size: 14px;
  padding: 6px 0 6px 22px;
  color: var(--text);
  position: relative;
}

.plan-features li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--success);
  font-weight: 700;
}

.plan-note {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 12px;
}

.account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.account-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.account-row:first-child {
  padding-top: 0;
}

.account-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.account-value {
  font-size: 14px;
  font-weight: 500;
}

.btn-text {
  background: none;
  border: none;
  color: #dc2626;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  padding: 12px;
  margin-top: 4px;
}

.danger-zone {
  padding: 12px 16px;
}

.account-footer {
  text-align: center;
  font-size: 12px;
  color: #aaa;
  margin: 12px 0 8px;
  line-height: 1.5;
}

.legal-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 13px;
}

.legal-links a {
  color: var(--text-secondary);
  text-decoration: none;
}

.legal-links a:active {
  color: var(--text);
}

.legal-links span {
  color: #ccc;
}

/* Customer select */
.customer-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.customer-select {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23666' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.customer-select:focus {
  outline: none;
  border-color: var(--primary);
}

.btn-icon-sm {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-icon-sm:active {
  background: var(--border);
}

.save-customer-row {
  margin-top: -4px;
  margin-bottom: 4px;
}

/* Scan dual buttons */
.scan-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scan-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

/* Success / Preview */
.pdf-preview-wrap {
  width: 100%;
  height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 16px 0;
  background: #f0f0f0;
}

.pdf-preview-wrap iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

.success-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.success-actions .btn-text {
  color: var(--text-secondary);
  margin-top: 4px;
}

.file-ext-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0 4px;
  flex-shrink: 0;
}

#pdfFileNameInput {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
}

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 20px;
  font-size: 14px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  gap: 12px;
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.history-actions {
  display: flex;
  gap: 6px;
}

.page-order-row {
  display: flex;
  gap: 6px;
  padding: 8px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.page-order-btn {
  flex: 1;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
}

.page-order-btn.edit-page-btn {
  flex: 2;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Full-screen page editor */
.page-editor {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: #111;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  height: 100dvh;
}

.page-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #1a1a1a;
  color: #fff;
  gap: 12px;
}

.page-editor-header .btn-text {
  color: #aaa;
  margin: 0;
  padding: 8px;
}

.btn-primary-sm {
  background: #fff;
  color: #111;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

.page-editor-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-height: 200px;
  touch-action: none;
}

.page-editor-canvas-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.crop-box {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  box-sizing: border-box;
  touch-action: none;
}

.crop-handle {
  position: absolute;
  width: 28px;
  height: 28px;
  background: #fff;
  border-radius: 50%;
  border: 2px solid #111;
  z-index: 2;
  touch-action: none;
}

.crop-handle.tl { top: -14px; left: -14px; }
.crop-handle.tr { top: -14px; right: -14px; }
.crop-handle.bl { bottom: -14px; left: -14px; }
.crop-handle.br { bottom: -14px; right: -14px; }
.crop-handle.t { top: -14px; left: 50%; transform: translateX(-50%); width: 36px; height: 20px; border-radius: 10px; }
.crop-handle.b { bottom: -14px; left: 50%; transform: translateX(-50%); width: 36px; height: 20px; border-radius: 10px; }
.crop-handle.l { left: -14px; top: 50%; transform: translateY(-50%); width: 20px; height: 36px; border-radius: 10px; }
.crop-handle.r { right: -14px; top: 50%; transform: translateY(-50%); width: 20px; height: 36px; border-radius: 10px; }

.page-editor-toolbar {
  background: #1a1a1a;
  color: #fff;
  padding: 14px 16px 24px;
}

.page-editor-toolbar .section-label {
  color: #aaa;
}

.page-editor-toolbar .filter-btn {
  background: #2a2a2a;
  color: #ccc;
  border-color: #333;
}

.page-editor-toolbar .filter-btn.active {
  background: #fff;
  color: #111;
  border-color: #fff;
}

.page-editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.page-editor-actions .btn-secondary {
  background: #2a2a2a;
  color: #eee;
  border-color: #333;
}

.page-editor-actions .btn-text {
  grid-column: 1 / -1;
  color: #f87171;
}

/* Utility */
@media (min-width: 481px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
