/* images.css - full-page invoice viewer with bottom horizontal drawer */
:root{
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* iOS safe-area: keep fixed controls out of the notch / dynamic island */

.fab {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 16px);
  right: calc(var(--safe-right) + 16px);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid rgba(200, 200, 200, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 50;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  color: #fff;
}

.back {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  left: calc(var(--safe-left) + 12px);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid rgba(200, 200, 200, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  z-index: 55;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.back .material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
  color: #fff;
  font-variation-settings: 'wght' 400;
}

/* ---------- 3D glassy icon treatment (round + single-border) ---------- */
:root{
  /* Softer, less "shiny" glass look */
  --icon-glass-bg1: rgba(255,255,255,0.10);
  --icon-glass-bg2: rgba(255,255,255,0.04);
  --icon-glass-border: rgba(255,255,255,0.20);
  --icon-glass-shadow: rgba(0,0,0,0.22);
  --icon-glass-inner: rgba(255,255,255,0.14);
}

/* Apply the glass treatment to the *button surfaces* (avoids double borders and keeps perfect circles) */
.fab,
.back,
.top-paste,
.fab-action,
.close-edit{
  background: linear-gradient(135deg, var(--icon-glass-bg1), var(--icon-glass-bg2));
  border: 1px solid var(--icon-glass-border);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  box-shadow:
    0 8px 18px var(--icon-glass-shadow),
    inset 0 1px 0 var(--icon-glass-inner);
}

/* Keep these controls perfectly round */
.fab, .back, .top-paste, .fab-action, .close-edit{ border-radius: 50%; }

/* Remove any extra chrome borders that would look like a second outline */
.fab { border-width: 1px; }
.back, .top-paste { border-width: 1px; }

/* Add a soft specular highlight on the button surface */
.fab::after,
.back::after,
.top-paste::after,
.fab-action::after,
.close-edit::after{
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,0.35), rgba(255,255,255,0) 60%);
  pointer-events: none;
  opacity: 0.45;
}

/* Ensure the pseudo-element can position correctly */
.fab, .back, .top-paste{ overflow: hidden; }
.fab-action, .close-edit{ position: relative; overflow: hidden; }

/* Keep icon glyphs clean (no backgrounds/borders on the glyph itself) */
.material-symbols-outlined{
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  text-shadow: 0 1px 0 rgba(0,0,0,0.25);
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

/* Edit tool tiles: give the icon itself a small round glass puck, without adding a second border */
.edit-btn .edit-icon{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--icon-glass-bg1), var(--icon-glass-bg2));
  box-shadow:
    0 8px 18px rgba(0,0,0,0.18),
    inset 0 1px 0 rgba(255,255,255,0.14);
  position: relative;
  overflow: hidden;
}
.edit-btn .edit-icon::after{
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.32), rgba(255,255,255,0) 60%);
  pointer-events: none;
  opacity: 0.45;
}

/* Subtle press feedback */
.fab:active,
.back:active,
.top-paste:active,
.fab-action:active,
.close-edit:active{
  transform: translateY(1px);
  box-shadow:
    0 5px 12px rgba(0,0,0,0.22),
    inset 0 1px 0 rgba(255,255,255,0.12);
}


.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 40;
}
.scrim.open {
  opacity: 1;
  pointer-events: auto;
}

/* Bottom horizontal mini-drawer that opens left from the FAB */
.fab-drawer {
  position: fixed;
  bottom: 16px;
  right: 72px; /* 44px fab + ~12-16px gap */
  display: flex;
  flex-direction: row-reverse; /* first action nearest the fab */
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 999px;
  background: transparent;
  border: 1.5px solid rgba(200, 200, 200, 0.85);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  transform: scaleX(0.5);
  transform-origin: right center;
  opacity: 0;
  pointer-events: none;
  transition: transform .18s ease-out, opacity .18s ease-out;
  z-index: 49;
}

.fab-drawer.open {
  transform: scaleX(1);
  opacity: 1;
  pointer-events: auto;
}

.fab-action {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.fab-action:hover {
  background: rgba(0,0,0,0.08);
}

.fab-action-icon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #fff;
}

/* Material Symbols helper (if user loads font) */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: normal;
  font-style: normal;
  font-size: 22px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
}

/* --- Full-page horizontal image viewer --- */

.strip {
  position: fixed;
  inset: 0;
  display: flex;
  overflow-x: scroll;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  background: #000;
}

.slide {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  scroll-snap-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto; /* allow panning when zoomed */
}

.slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  touch-action: pan-x pan-y pinch-zoom;
  -webkit-user-drag: none;
}

/* Page indicator (e.g. "2/7") */
.page-indicator {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  z-index: 50;
  pointer-events: none;
}

/* Hide chrome (back button, FAB, scrim, mini-drawer, indicator) in immersive mode */
body.chrome-hidden .back,
body.chrome-hidden .fab,
body.chrome-hidden .scrim,
body.chrome-hidden .fab-drawer,
body.chrome-hidden .page-indicator,
body.chrome-hidden .top-paste {
  opacity: 0;
  pointer-events: none;
}

/* Hide edit drawer in immersive mode too */
body.chrome-hidden .edit-drawer {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(100%) !important;
}

/* Fit-width mode for invoices: page spans full width, scroll vertically */
body.fit-width .slide img {
  width: 100%;
  height: auto;
  max-width: none;
  max-height: none;
  object-fit: contain;
}

.top-paste {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  right: calc(var(--safe-right) + 12px);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid rgba(200, 200, 200, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  z-index: 55;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.top-paste .material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
  color: #fff;
  font-variation-settings: 'wght' 400;
}

.top-paste.top-paste--dim {
  opacity: 0.35;
}

/* Edit Drawer Styles */
.edit-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(28, 28, 30, 0.98);
  backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px 30px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 60;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.edit-drawer.open {
  transform: translateY(0);
}

.edit-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.edit-drawer-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
}

.close-edit {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s;
}

.close-edit:hover {
  background: rgba(255, 255, 255, 0.2);
}

.edit-controls {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.edit-control-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

/* In Straighten mode, show only the slider controls (no top tool icons) */
body.straighten-only .edit-control-group {
  display: none;
}

.edit-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 16px 8px;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 80px;
}

.edit-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

.edit-btn.active {
  background: rgba(0, 122, 255, 0.15);
  border-color: rgba(0, 122, 255, 0.3);
}

.edit-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

.edit-label {
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}

/* Slider controls */
.slider-control {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 20px;
  margin-top: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.slider-control label {
  display: block;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 16px;
}

.slider-control input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  margin-bottom: 20px;
  outline: none;
}

.slider-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #007AFF;
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.slider-control input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #007AFF;
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.slider-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.small-btn {
  padding: 10px 20px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 80px;
  text-align: center;
}

.small-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.small-btn.primary {
  background: #007AFF;
  border-color: #007AFF;
  font-weight: 600;
}

.small-btn.primary:hover {
  background: #0056CC;
  border-color: #0056CC;
}

/* Crop controls */
.crop-control {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 20px;
  margin-top: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.crop-buttons {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.aspect-ratios {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.aspect-btn {
  padding: 12px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}

.aspect-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.aspect-btn.active {
  background: #007AFF;
  border-color: #007AFF;
  font-weight: 600;
}

/* Hidden utility class */
.hidden {
  display: none !important;
}

/* Crop overlay styles */
.crop-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  /* Dim the outside area without making the whole image look too dark */
  background: rgba(0, 0, 0, 0.35);
  display: none;
}

.crop-overlay.active {
  display: block;
}

.crop-container {
  position: absolute;
  /* JS sets left/top/width/height in viewport pixels based on the image rect. */
  top: 0;
  left: 0;
  cursor: move;
  border: 2px solid #007AFF;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  resize: none;
  overflow: visible;
  touch-action: none;
  min-width: 100px;
  min-height: 100px;
}


/* While cropping, prevent the underlying image from interpreting pinch/scroll as zoom */
body.cropping .slide img {
  touch-action: none !important;
}

.crop-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  background: #007AFF;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.crop-handle.nw { top: -10px; left: -10px; cursor: nw-resize; }
.crop-handle.ne { top: -10px; right: -10px; cursor: ne-resize; }
.crop-handle.sw { bottom: -10px; left: -10px; cursor: sw-resize; }
.crop-handle.se { bottom: -10px; right: -10px; cursor: se-resize; }

.crop-overlay-buttons {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  z-index: 71;
}

/* Load error style */
.load-error {
  opacity: 0.7;
  filter: grayscale(1);
  cursor: pointer;
}

.load-error:hover {
  opacity: 0.9;
}


/* --- Edit mini-drawer (matches main drawer style) --- */
.edit-mini-drawer {
  right: calc(var(--safe-right) + 72px);
  bottom: calc(var(--safe-bottom) + 16px);
  z-index: 61; /* above main drawer */
}

/* Make the big edit drawer icon-only (no title/labels) */
.edit-drawer-header { display: none; }
.edit-label { display: none; }
.edit-btn {
  min-height: 0;
  padding: 12px 8px;
  gap: 0;
}
.edit-icon { margin-bottom: 0; }
