/* Ibsen Photo PWA — styling ported from the native app's design tokens. */

:root {
  --background: #e2e2e2;
  --surface: #ffffff;
  --navy: #1B3A5B;
  --navy-dark: #16283D;
  --navy-muted: #3A5E86;
  --text-primary: #16283D;
  --text-secondary: #5A6B7B;
  --text-on-navy: #ffffff;
  --border: #cfcfcf;
  --danger: #C0432E;
  --success: #2E7D5B;
  --overlay: rgba(22, 40, 61, 0.35);

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 32px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

/* The `hidden` attribute must always win over the display rules below
   (.view, .install-banner and .ios-sheet all set display: flex). Without
   this, hidden screens/popups would render stacked on top of each other. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--background);
  color: var(--text-primary);
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
}

.view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary { background: var(--navy); color: var(--text-on-navy); }
.btn-primary:disabled { background: var(--navy-muted); opacity: 0.5; cursor: default; }
.btn-outline {
  background: transparent;
  color: var(--navy);
  border: 1.5px solid var(--navy);
}
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 8px 10px; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; }

/* ---------- Install banner ---------- */
.install-banner {
  position: fixed;
  left: var(--sp-md);
  right: var(--sp-md);
  top: calc(var(--safe-top) + var(--sp-sm));
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  box-shadow: 0 6px 20px rgba(22, 40, 61, 0.18);
}
.install-logo { width: 40px; height: 40px; border-radius: var(--radius-sm); }
.install-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.install-text strong { font-size: 14px; color: var(--navy-dark); }
.install-text span { font-size: 12px; color: var(--text-secondary); }
.install-actions { display: flex; align-items: center; gap: var(--sp-xs); }

/* ---------- iOS install sheet ---------- */
.ios-sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--overlay);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--sp-md);
  padding-bottom: calc(var(--safe-bottom) + var(--sp-lg));
}
.ios-sheet-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--sp-lg);
  max-width: 420px;
  width: 100%;
}
.ios-sheet-logo { width: 56px; height: 56px; border-radius: var(--radius-md); }
.ios-sheet-card h2 { margin: var(--sp-md) 0 var(--sp-sm); color: var(--navy-dark); font-size: 20px; }
.ios-sheet-card p { margin: 0 0 var(--sp-sm); color: var(--text-secondary); font-size: 14px; }
.ios-sheet-card ol { margin: 0 0 var(--sp-lg); padding-left: 20px; color: var(--text-primary); font-size: 14px; line-height: 1.6; }
.ios-share-icon {
  display: inline-block;
  font-weight: 700;
  color: var(--navy);
  border: 1px solid var(--navy-muted);
  border-radius: 4px;
  padding: 0 5px;
  line-height: 1.2;
}

/* ---------- Top bar ---------- */
.top-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: calc(var(--safe-top) + var(--sp-md)) var(--sp-lg) var(--sp-md);
}
.brand-logo { height: 34px; width: auto; }

/* ---------- Camera ---------- */
.camera-card {
  position: relative;
  flex: 1;
  margin: 0 var(--sp-md) var(--sp-md);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
}
#camera-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--sp-md);
}
.camera-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.count-pill {
  background: var(--overlay);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
}
.pill-button {
  background: var(--overlay);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.camera-footer {
  display: flex;
  justify-content: center;
  padding-bottom: var(--sp-sm);
}
.capture-button {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.25);
  border: 3px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.capture-inner {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-pill);
  background: #fff;
}
.capture-button:active .capture-inner { transform: scale(0.9); }
.camera-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-lg);
  color: #fff;
  background: rgba(0, 0, 0, 0.65);
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- Thumbnails ---------- */
.thumbnails-container { padding: 0 var(--sp-md) calc(var(--safe-bottom) + var(--sp-md)); }
.section-title { font-size: 14px; font-weight: 600; color: var(--text-primary); margin: 0 0 var(--sp-sm); }
.thumbnails {
  display: flex;
  gap: var(--sp-sm);
  overflow-x: auto;
  padding-bottom: var(--sp-md);
}
.thumb-wrapper { position: relative; flex: 0 0 auto; }
.thumb-wrapper img { width: 64px; height: 64px; border-radius: var(--radius-sm); object-fit: cover; display: block; }
.thumb-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #fff;
  border: none;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Preview ---------- */
.preview-view { background: var(--background); }
.preview-image {
  flex: 1;
  min-height: 0;
  object-fit: contain;
  margin: calc(var(--safe-top) + var(--sp-md)) var(--sp-md) var(--sp-md);
  border-radius: var(--radius-lg);
}
.preview-buttons {
  display: flex;
  gap: var(--sp-md);
  padding: 0 var(--sp-md) calc(var(--safe-bottom) + var(--sp-md));
}

/* ---------- Email ---------- */
.email-view { background: var(--background); overflow: hidden; }
.email-scroll {
  flex: 1;
  overflow-y: auto;
  padding: calc(var(--safe-top) + var(--sp-lg)) var(--sp-lg) calc(var(--safe-bottom) + var(--sp-lg));
}
.email-header { margin-bottom: var(--sp-lg); }
.email-header .brand-logo { height: 40px; margin-bottom: var(--sp-md); display: block; }
.title { font-size: 26px; font-weight: 800; color: var(--navy-dark); margin: 0; }
.subtitle { font-size: 14px; font-weight: 500; color: var(--text-secondary); margin: 2px 0 0; }
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--sp-md);
  margin-bottom: var(--sp-md);
}
.label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 var(--sp-sm);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.input-row {
  display: flex;
  align-items: center;
  background: var(--background);
  padding: 4px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.input-row.invalid { border-color: var(--danger); }
.input-field {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 8px 0;
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  outline: none;
}
.input-suffix { font-size: 16px; font-weight: 600; color: var(--navy-muted); margin-left: 2px; }
.error-text { color: var(--danger); font-size: 13px; font-weight: 500; margin: var(--sp-sm) 0 0; }
.email-photos { display: flex; gap: var(--sp-sm); overflow-x: auto; }
.email-photos img { width: 88px; height: 88px; border-radius: var(--radius-md); object-fit: cover; flex: 0 0 auto; }
.button-row { display: flex; gap: var(--sp-md); margin-top: var(--sp-xs); }
.note { color: var(--text-secondary); font-size: 13px; line-height: 1.5; margin-top: var(--sp-lg); }

.result-box {
  padding: var(--sp-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-md);
  border: 1px solid;
  font-size: 14px;
  font-weight: 500;
}
.result-box.success { background: rgba(46, 125, 91, 0.12); border-color: var(--success); }
.result-box.error { background: rgba(192, 67, 46, 0.12); border-color: var(--danger); }

/* ---------- Spinner ---------- */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
