:root {
  --bg-primary: #0b0f19;
  --bg-card: rgba(23, 32, 54, 0.7);
  --bg-card-hover: rgba(30, 41, 69, 0.85);
  --accent-blue: #3b82f6;
  --accent-indigo: #6366f1;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: rgba(255, 255, 255, 0.08);
  --radius-lg: 16px;
  --radius-md: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(99, 102, 241, 0.12) 0px, transparent 50%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 40px;
}

.container {
  width: 100%;
  max-width: 760px;
  padding: 20px;
}

/* Glassmorphism Card */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  transition: all 0.3s ease;
}

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

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

.logo-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-indigo));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1.3rem;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}

h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-badge.error {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}

.status-badge.error .status-dot {
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}

/* Tabs */
.tabs {
  display: flex;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 24px;
  border: 1px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  padding: 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tab-btn.active {
  background: var(--accent-blue);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Form controls */
.form-group {
  margin-bottom: 18px;
}

label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
}

input:focus, select:focus {
  border-color: var(--accent-blue);
}

.dropzone {
  border: 2px dashed var(--accent-blue);
  border-radius: var(--radius-lg);
  padding: 36px 20px;
  text-align: center;
  background: rgba(59, 130, 246, 0.04);
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropzone:hover {
  background: rgba(59, 130, 246, 0.08);
  border-color: var(--accent-cyan);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-indigo));
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
}

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

.btn-secondary {
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-weight: 600;
  cursor: pointer;
}

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

/* Scan Preview & Output */
.scan-preview {
  margin-top: 20px;
  text-align: center;
}

.scan-preview img {
  max-width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

/* Modal for Auth Setup */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-card {
  background: #172036;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 30px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.qr-code-img {
  width: 200px;
  height: 200px;
  margin: 16px auto;
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

/* Responsiveness Improvements */
@media (max-width: 600px) {
  .grid-2 {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .header-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  .header-bar > div {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .tabs {
    flex-wrap: wrap;
  }
  .tab-btn {
    padding: 10px 4px;
    font-size: 0.85rem;
    gap: 4px;
  }
  .glass-card {
    padding: 16px;
  }
  .dropzone {
    padding: 24px 12px;
  }
}

/* Print Preview Styles */
.preview-area-card {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 18px;
}

.preview-sheet-wrapper {
  padding: 20px 0;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
  display: flex;
  justify-content: center;
  align-items: center;
}

.preview-sheet {
  width: 100%;
  max-width: 280px;
  aspect-ratio: var(--sheet-aspect, 0.707); /* default A4 is 210/297 = 0.707 */
  background: #ffffff;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  transition: aspect-ratio 0.3s ease;
  cursor: default;
}

.preview-sheet.custom-mode {
  cursor: grab;
}

.preview-sheet.custom-mode:active {
  cursor: grabbing;
}

.preview-clip-container {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  overflow: hidden;
}

#previewCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #ffffff;
}

#customCropControls input[type="range"] {
  accent-color: var(--accent-blue);
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

