*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-light: #eff6ff;
  --gray-50: #f8fafc;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,0.10);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 0 40px;
}

/* ── Header ── */
header {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 14px 20px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-logo {
  height: 62px;
  width: auto;
  flex-shrink: 0;
}

.header-app-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--blue);
  text-align: right;
  line-height: 1.3;
}

/* ── Main ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 16px;
}

#canvas { display: none; }

/* ── Galerie ── */
#gallery-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.gallery-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--gray-200);
  box-shadow: var(--shadow);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-delete {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.gallery-count {
  font-size: 0.8rem;
  color: var(--gray-600);
  font-weight: 600;
  text-align: center;
}

/* ── Absender E-Mail ── */
.sender-section {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sender-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.sender-section input[type="email"] {
  flex: 1;
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  color: var(--gray-800);
  outline: none;
  transition: border-color 0.15s;
}

.sender-section input[type="email"]:focus {
  border-color: var(--blue);
}

/* ── Modus-Toggle ── */
.mode-toggle {
  display: flex;
  background: var(--gray-200);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.mode-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--gray-600);
  transition: all 0.15s;
}

.mode-btn.active {
  background: #fff;
  color: var(--gray-800);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

/* ── Empfänger + Dokumenttyp nebeneinander ── */
.select-row {
  display: flex;
  gap: 10px;
}

.select-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

/* ── Empfänger-Dropdown ── */
.recipient-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.email-select {
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--gray-800);
  background: #fff;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.email-select:focus {
  border-color: var(--blue);
}

/* ── Nachricht ── */
.message-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-field textarea {
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--gray-800);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

.message-field textarea:focus {
  border-color: var(--blue);
}

.saved-badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--green);
  white-space: nowrap;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Buttons ── */
.action-section {
  display: flex;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); opacity: 0.85; }

.btn-primary {
  flex: 1;
  background: var(--blue);
  color: #fff;
}
.btn-primary:hover { background: var(--blue-dark); }

.btn-secondary {
  flex: 1;
  background: #fff;
  color: var(--blue);
  border: 2px solid var(--blue);
}
.btn-secondary:hover { background: var(--blue-light); }

.send-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.target-info {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--blue-light);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--blue-dark);
  font-weight: 500;
  word-break: break-all;
}

.btn-send {
  width: 100%;
  background: var(--green);
  color: #fff;
  padding: 16px;
  font-size: 1rem;
  border-radius: var(--radius);
}
.btn-send:hover { background: #15803d; }

.btn-ghost {
  width: 100%;
  background: transparent;
  color: var(--gray-600);
  font-size: 0.85rem;
  padding: 10px;
}
.btn-ghost:hover { background: var(--gray-200); }

/* ── Status ── */
.status {
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
}
.status.success { background: #dcfce7; color: #166534; }
.status.error   { background: #fee2e2; color: #991b1b; }

/* ── Camera Modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.modal-title-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: max(16px, env(safe-area-inset-top)) 20px 20px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
  pointer-events: none;
}

.modal-title-bar h2 {
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 24px 40px max(32px, calc(env(safe-area-inset-bottom) + 20px));
  background: linear-gradient(to top, rgba(0,0,0,0.65), transparent);
}

.btn-capture {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  border: 3px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.capture-inner {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.1s;
}
.btn-capture:active .capture-inner { transform: scale(0.9); }

.flip-btn-inline {
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 50%;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.btn-weiter {
  background: rgba(255,255,255,0.92);
  color: #1e293b;
  border: none;
  border-radius: 22px;
  padding: 12px 22px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(4px);
  letter-spacing: 0.2px;
}

/* ── PIN-Screen ── */
.pin-screen {
  position: fixed;
  inset: 0;
  background: #0d1b2e;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 320px;
  padding: 32px 24px;
}

.pin-logo {
  width: 110px;
  height: 110px;
  object-fit: contain;
  border-radius: 16px;
}

.pin-title {
  color: #fff;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.pin-dots {
  display: flex;
  gap: 16px;
}

.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.pin-dot.filled {
  background: #fff;
  border-color: #fff;
}

.pin-error {
  color: #f87171;
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-6px); }
  80%       { transform: translateX(6px); }
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
}

.pin-key {
  background: rgba(255,255,255,0.08);
  border: 1.5px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  color: #fff;
  font-size: 1.5rem;
  font-weight: 600;
  height: 68px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.pin-key:active {
  background: rgba(255,255,255,0.22);
  transform: scale(0.94);
}

.pin-key--delete {
  background: rgba(220,38,38,0.2);
  border-color: rgba(220,38,38,0.3);
}

/* ── Erfolgs-Screen ── */
.success-screen {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.success-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 32px;
  text-align: center;
}

.success-icon {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: #dcfce7;
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
}

.success-content h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--gray-800);
}

.success-content p {
  font-size: 1rem;
  color: var(--gray-600);
  line-height: 1.5;
}

.success-countdown {
  margin-top: 8px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--blue-light);
  color: var(--blue);
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Loading ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #fff;
  font-weight: 600;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Sperrbildschirm ── */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lock-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px 32px;
  text-align: center;
}

.lock-logo {
  width: 110px;
  height: auto;
  border-radius: 22px;
}

.lock-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gray-800);
}

.lock-hint {
  font-size: 0.9rem;
  color: var(--gray-600);
  margin-bottom: 4px;
}

.btn-lock-action {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 16px 28px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-lock-action:hover { background: var(--blue-dark); }

.btn-lock-reset {
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: 0.82rem;
  cursor: pointer;
  text-decoration: underline;
  margin-top: -8px;
}

.lock-error {
  color: var(--red);
  font-size: 0.88rem;
  font-weight: 500;
}

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

/* ── Desktop ── */
@media (min-width: 640px) {
  .app {
    margin: 0 auto;
    padding: 0 0 60px;
  }
  header { padding: 20px 24px; }
  main { padding: 28px 24px; }
}
