/* DocSigner Mobile - Modern Mobile-First Stylesheet */

:root {
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --primary-accent: #38bdf8;
  --primary-accent-hover: #0284c7;
  --whatsapp-green: #25d366;
  --whatsapp-hover: #1eb956;
  --border-color: #334155;
  --danger: #ef4444;
  --a4-ratio: 1.4142;
  --safe-bottom: env(safe-area-inset-bottom, 12px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Top App Bar */
.top-bar {
  height: 56px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 10;
}

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

.brand-icon {
  width: 28px;
  height: 28px;
  color: var(--primary-accent);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.brand-subtitle {
  font-size: 0.65rem;
  color: var(--primary-accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:active {
  background: var(--primary-accent);
  color: #0f172a;
}

/* Main Container */
.main-container {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #090d16;
}

/* Upload Hero / Welcome Screen */
.upload-card {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  max-width: 480px;
  margin: 0 auto;
}

.hero-icon-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.12);
  border: 2px dashed rgba(56, 189, 248, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.upload-hero h2 {
  font-size: 1.4rem;
  margin-bottom: 8px;
  font-weight: 700;
}

.upload-hero p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.45;
  margin-bottom: 24px;
}

.upload-buttons {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.btn-primary-large {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #0f172a;
  border: none;
  padding: 14px 20px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 15px rgba(56, 189, 248, 0.3);
  cursor: pointer;
}

.btn-secondary-large {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 13px 20px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

.features-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  text-align: left;
}

.feature-item {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 10px 14px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.feat-badge {
  background: rgba(56, 189, 248, 0.15);
  color: var(--primary-accent);
  font-size: 0.7rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 6px;
  min-width: 44px;
  text-align: center;
}

.feature-item strong {
  display: block;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.feature-item p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Workspace Area */
.workspace-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Viewport Wrapper */
.viewport-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  overflow: auto;
  position: relative;
}

/* Document Page (A4 Box) */
.document-page {
  position: relative;
  background-color: #ffffff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.7);
  border-radius: 4px;
  overflow: hidden;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: pan-x pan-y;
}

#pageCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* Interactive Signature Element */
.sig-element {
  position: absolute;
  top: 60%;
  left: 55%;
  width: 140px;
  height: 70px;
  border: 1.5px dashed #0284c7;
  background: rgba(56, 189, 248, 0.04);
  touch-action: none;
  cursor: move;
  user-select: none;
  z-index: 20;
}

.sig-drag-bar {
  position: absolute;
  top: -24px;
  left: 0;
  right: 0;
  height: 22px;
  background: #0284c7;
  color: white;
  border-radius: 4px 4px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
  font-size: 0.65rem;
  font-weight: 600;
  touch-action: none;
}

.sig-remove-btn {
  background: transparent;
  border: none;
  color: white;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0 4px;
}

/* Key Feature: MULTIPLY BLEND MODE */
.sig-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  mix-blend-mode: multiply;
  display: block;
}

/* Resize Handle on bottom right */
.sig-resize-handle {
  position: absolute;
  bottom: -8px;
  right: -8px;
  width: 28px;
  height: 28px;
  background: #0284c7;
  border: 2px solid white;
  border-radius: 50%;
  touch-action: none;
  cursor: nwse-resize;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

/* Floating Quick Presets Bar */
.floating-presets {
  position: absolute;
  bottom: 54px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 25;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.preset-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.preset-pill {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 12px;
  cursor: pointer;
}

.preset-pill:active {
  background: var(--primary-accent);
  color: #0f172a;
}

/* Sub-controls Bar (Scale slider & Target page) */
.sub-controls-bar {
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  gap: 12px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.scale-control, .target-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-text {
  color: var(--text-secondary);
  font-weight: 500;
}

#sigScaleSlider {
  width: 90px;
  accent-color: var(--primary-accent);
}

.styled-select {
  background: var(--bg-main);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  outline: none;
}

/* Sticky Bottom Navigation */
.bottom-nav {
  height: calc(64px + var(--safe-bottom));
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px var(--safe-bottom);
  flex-shrink: 0;
  z-index: 30;
}

.nav-page-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-main);
  padding: 4px 8px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-indicator {
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 42px;
  text-align: center;
  color: var(--primary-accent);
}

.nav-action-btn {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border-radius: 10px;
  gap: 3px;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 600;
}

.nav-primary-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  cursor: pointer;
}

.nav-primary-btn:active {
  transform: scale(0.97);
}

/* Bottom Sheet (Signatures Drawer) */
.bottom-sheet {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.bottom-sheet.open {
  pointer-events: auto;
  opacity: 1;
}

.sheet-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.sheet-content {
  position: relative;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  border-radius: 20px 20px 0 0;
  padding: 16px 20px calc(20px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
}

.bottom-sheet.open .sheet-content {
  transform: translateY(0);
}

.sheet-drag-indicator {
  width: 36px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  margin: 0 auto 12px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sheet-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.sheet-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--text-primary);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 0.9rem;
  cursor: pointer;
}

.signatures-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  overflow-y: auto;
  max-height: 260px;
  margin-bottom: 16px;
  padding: 4px;
}

.sig-card {
  background: #ffffff;
  border: 2px solid transparent;
  border-radius: 10px;
  height: 85px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  cursor: pointer;
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.sig-card.active {
  border-color: var(--primary-accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.4);
}

.sig-card img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.sig-card-tag {
  position: absolute;
  top: 4px;
  left: 6px;
  background: rgba(15, 23, 42, 0.8);
  color: white;
  font-size: 0.6rem;
  padding: 1px 5px;
  border-radius: 4px;
}

.btn-secondary-full {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

/* Export Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 120;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: 20px;
  }
}

.modal-card {
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  padding: 20px 20px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 600px) {
  .modal-card {
    border-radius: 16px;
    border: 1px solid var(--border-color);
    padding: 24px;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.input-with-action {
  display: flex;
  gap: 8px;
}

.styled-input {
  flex: 1;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
}

.styled-input:focus {
  border-color: var(--primary-accent);
}

.btn-quick-plus {
  background: rgba(56, 189, 248, 0.15);
  color: var(--primary-accent);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 0 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.btn-quick-plus:active {
  background: var(--primary-accent);
  color: #0f172a;
}

.input-hint {
  display: block;
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.quality-card {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 12px;
  border-radius: 10px;
}

.quality-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #34d399;
  margin-bottom: 4px;
}

.quality-desc {
  font-size: 0.75rem;
  color: #cbd5e1;
  line-height: 1.4;
}

/* Progress Bar */
.progress-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-text {
  font-size: 0.75rem;
  color: var(--primary-accent);
  font-weight: 600;
}

.progress-bar {
  height: 6px;
  background: var(--bg-main);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #10b981);
  transition: width 0.2s ease;
}

/* WhatsApp Primary Button */
.btn-whatsapp {
  background: linear-gradient(135deg, #25d366, #128c7e);
  color: white;
  border: none;
  padding: 14px 20px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 15px rgba(37, 211, 102, 0.35);
  cursor: pointer;
  width: 100%;
  margin-bottom: 8px;
}

.btn-whatsapp:active {
  transform: scale(0.98);
}
