/* Base Reset and iOS Touch Optimization */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #111;
  color: #f5f5f5;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 20px);
  padding-bottom: env(safe-area-inset-bottom, 20px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

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

/* Sticky Offline Banner */
#offline-banner {
  background-color: #e74c3c;
  color: #fff;
  text-align: center;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  z-index: 1000;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

/* Screens Layout */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  position: relative;
}

.header-bar {
  text-align: center;
  margin-bottom: 24px;
  padding: 10px 0;
}

.header-bar h2 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #2ecc71;
  text-transform: uppercase;
}

/* Button Styling */
button, .btn-primary, .btn-secondary, .btn-add-page {
  font-size: 16px;
  font-weight: 700;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease-in-out;
  outline: none;
}

.btn-primary {
  background-color: #2ecc71;
  color: #111;
  height: 60px;
  width: 100%;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 6px 16px rgba(46, 204, 113, 0.25);
}

.btn-primary:active {
  background-color: #27ae60;
  transform: scale(0.98);
}

.btn-primary:disabled {
  background-color: #333;
  color: #666;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-secondary {
  background-color: #2c3e50;
  color: #fff;
  height: 50px;
  width: 100%;
  border: 1px solid #34495e;
}

.btn-secondary:active {
  background-color: #1a252f;
  transform: scale(0.98);
}

/* LOCK SCREEN (PIN Input) */
#pin-screen {
  align-items: center;
  justify-content: space-between;
  padding: 40px 20px;
}

.logo-container {
  text-align: center;
  margin-top: 20px;
}

.logo-container h1 {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 6px;
  color: #2ecc71;
  text-shadow: 0 0 10px rgba(46, 204, 113, 0.3);
}

.subtitle {
  font-size: 14px;
  color: #888;
  margin-top: 8px;
  letter-spacing: 1px;
}

.pin-display {
  display: flex;
  gap: 15px;
  margin: 30px 0;
}

.pin-display .dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #555;
  transition: all 0.1s ease;
}

.pin-display .dot.active {
  background-color: #2ecc71;
  border-color: #2ecc71;
  box-shadow: 0 0 8px rgba(46, 204, 113, 0.6);
}

.error-msg {
  color: #e74c3c;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  width: 100%;
  max-width: 300px;
  margin-bottom: 20px;
}

.key {
  background-color: #1e1e1e;
  color: #fff;
  height: 65px;
  border-radius: 50%;
  font-size: 24px;
  font-weight: 600;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

.key:active {
  background-color: #333;
  transform: scale(0.92);
}

.key[data-val="clear"], .key[data-val="backspace"] {
  font-size: 18px;
  background-color: #161616;
  color: #888;
}

.key[data-val="clear"]:active, .key[data-val="backspace"]:active {
  background-color: #222;
}

/* SCAN/START SCREEN */
#scan-screen {
  justify-content: center;
  align-items: center;
}

.scan-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 320px;
}

.scan-btn {
  height: 120px;
  font-size: 20px;
  letter-spacing: 2px;
}

/* CROP SCREEN */
#crop-screen {
  padding: 10px;
  justify-content: space-between;
}

.cropper-outer-container {
  flex: 1;
  background-color: #000;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#crop-image {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.crop-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

.btn-action {
  height: 50px;
  background-color: #2c3e50;
  color: #fff;
  font-weight: 600;
}

.btn-action:active {
  background-color: #1a252f;
}

.btn-action.success {
  background-color: #2ecc71;
  color: #111;
}

.btn-action.success:active {
  background-color: #27ae60;
}

.btn-action.cancel {
  background-color: #e74c3c;
  color: #fff;
}

.btn-action.cancel:active {
  background-color: #c0392b;
}

/* PREVIEW SCREEN & MULTI-PAGE GALLERY */
#preview-screen {
  padding: 15px;
  justify-content: space-between;
}

.gallery-container {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 10px 0;
  margin-bottom: 15px;
  width: 100%;
  min-height: 140px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.gallery-item {
  position: relative;
  flex: 0 0 100px;
  height: 130px;
  border-radius: 10px;
  overflow: hidden;
  background-color: #222;
  border: 2px solid #444;
  scroll-snap-align: start;
}

.gallery-item.active {
  border-color: #2ecc71;
}

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

.gallery-item .item-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  background-color: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 8px;
}

.gallery-item .btn-item-delete {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  background-color: #e74c3c;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 12px;
  border: none;
  cursor: pointer;
}

.gallery-actions {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.btn-add-page {
  background-color: #1e1e1e;
  border: 1px dashed #2ecc71;
  color: #2ecc71;
  height: 44px;
  padding: 0 20px;
  font-size: 13px;
  letter-spacing: 0.5px;
}

.btn-add-page:active {
  background-color: rgba(46, 204, 113, 0.1);
}

.destination-section {
  background-color: #181818;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid #222;
}

.section-title {
  font-size: 14px;
  font-weight: bold;
  color: #888;
  margin-bottom: 12px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.destination-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dest-btn {
  height: 50px;
  background-color: #222;
  color: #ccc;
  border: 1px solid #333;
  font-weight: 700;
  width: 100%;
}

.dest-btn.selected {
  background-color: #2ecc71;
  color: #111;
  border-color: #2ecc71;
  box-shadow: 0 4px 10px rgba(46, 204, 113, 0.2);
}

.dest-btn:active {
  transform: scale(0.99);
}

.send-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
}

.send-actions .cancel {
  flex: 0 0 30%;
  height: 60px;
  font-size: 13px;
}

.send-actions .btn-primary {
  flex: 1;
}

/* STATUS SCREEN */
#status-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.status-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 320px;
  animation: fadeIn 0.3s ease-out;
}

.status-content h2 {
  font-size: 24px;
  margin: 20px 0 10px;
  font-weight: 800;
}

.status-content p {
  font-size: 14px;
  color: #aaa;
  line-height: 1.5;
  margin-bottom: 30px;
}

/* Spinner Animation */
.spinner {
  width: 60px;
  height: 60px;
  border: 5px solid #222;
  border-top: 5px solid #2ecc71;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Icons */
.success-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: #2ecc71;
  color: #111;
  font-size: 40px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px rgba(46, 204, 113, 0.4);
}

.error-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: #e74c3c;
  color: #fff;
  font-size: 40px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px rgba(231, 76, 60, 0.4);
}

.error-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cropper Library Styling overrides to fit dark UI */
.cropper-view-box,
.cropper-face {
  border-radius: 0;
  outline: 2px solid #2ecc71;
  outline-color: #2ecc71;
}

.cropper-line {
  background-color: #2ecc71;
}

.cropper-point {
  background-color: #2ecc71;
  width: 8px;
  height: 8px;
}

.cropper-point.point-se {
  width: 15px;
  height: 15px;
}

.cropper-bg {
  background-image: none;
  background-color: #000;
}
