/* =====================================================================
   SunPrint — C15 PRO Mobile Thermal Printer Web App
   FinWise-Inspired Layout + Sunset Color Palette
   ===================================================================== */

:root {
  --sunset-gradient: linear-gradient(135deg, #F43F5E 0%, #FF6B5B 48%, #FF9F43 100%);
  --sunset-card: linear-gradient(135deg, #FF6B5B 0%, #FF9A56 100%);
  --bg-outer: #26182A;
  --bg-sheet: #FFF9F5;
  --bg-card: #FFFFFF;
  --bg-soft: #FFEFE6;
  --bg-pill: #FDE8DC;
  --text-main: #2D1E2F;
  --text-muted: #7C6577;
  --accent: #FF6B5B;
  --accent-dark: #E14949;
  --ok: #10B981;
  --danger: #F43F5E;
  --border: #F2DDD2;
  --shadow: 0 8px 22px rgba(244, 63, 94, 0.08);
  --nav-h: 68px;
}

body.theme-dark {
  --sunset-gradient: linear-gradient(135deg, #9F1239 0%, #C2410C 55%, #D97706 100%);
  --sunset-card: linear-gradient(135deg, #BE123C 0%, #EA580C 100%);
  --bg-outer: #0E0914;
  --bg-sheet: #191322;
  --bg-card: #241C30;
  --bg-soft: #2F243D;
  --bg-pill: #2F243D;
  --text-main: #FFF5EE;
  --text-muted: #B8A5B8;
  --border: #362947;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

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

html, body {
  height: 100%;
  font-family: "Prompt", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-outer);
  color: var(--text-main);
  overflow-x: hidden;
}

.app-shell {
  width: 100%;
  max-width: 460px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--sunset-gradient);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

@media (min-width: 540px) {
  body { padding: 14px 0; }
  .app-shell {
    min-height: calc(100dvh - 28px);
    border-radius: 34px;
    overflow: hidden;
  }
}

/* ==================== HERO HEADER (FinWise Style) ==================== */
.hero-header {
  padding: calc(env(safe-area-inset-top, 10px) + 14px) 20px 20px;
  color: #fff;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.hero-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.hero-sub {
  font-size: 0.76rem;
  opacity: 0.9;
}

.hero-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1rem;
  backdrop-filter: blur(6px);
}

.icon-btn:active { transform: scale(0.92); }

/* Bluetooth Status Pill Card inside Hero */
.ble-bar {
  background: rgba(45, 20, 44, 0.26);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ble-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ble-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #FDE047;
  box-shadow: 0 0 0 4px rgba(253, 224, 71, 0.25);
  flex-shrink: 0;
}

.ble-dot.connected {
  background: #34D399;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.28);
}

.ble-name {
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ble-sub {
  font-size: 0.7rem;
  opacity: 0.86;
}

.ble-connect-btn {
  border: none;
  background: #FFFFFF;
  color: var(--accent-dark);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 8px 13px;
  border-radius: 13px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.ble-connect-btn:active { transform: scale(0.95); }

/* ==================== CURVED SHEET ==================== */
.main-sheet {
  flex: 1;
  background: var(--bg-sheet);
  border-radius: 32px 32px 0 0;
  padding: 18px 16px calc(var(--nav-h) + 92px);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.08);
}

.tab-view {
  display: none;
  animation: fadeUp 0.18s ease;
}
.tab-view.active { display: block; }

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

/* ==================== CARDS & FORM CONTROLS ==================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 14px 15px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

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

.card-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-group { margin-bottom: 10px; }
.form-group:last-child { margin-bottom: 0; }

.form-group label {
  display: block;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--bg-sheet);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
}

.form-textarea {
  resize: vertical;
  min-height: 70px;
}

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

.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.soft-btn {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--accent-dark);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 13px;
  cursor: pointer;
}

.soft-btn:active { transform: scale(0.96); }

.outline-btn {
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 13px;
  cursor: pointer;
}

.sunset-btn {
  border: none;
  background: var(--sunset-gradient);
  color: #fff;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(244, 63, 94, 0.25);
}

.sunset-btn:active { transform: scale(0.97); }
.sunset-btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* Segmented Pills */
.seg-row {
  display: flex;
  background: var(--bg-pill);
  padding: 4px;
  border-radius: 15px;
  gap: 4px;
}

.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 7px 6px;
  border-radius: 11px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--sunset-card);
  color: #fff;
  font-weight: 600;
}

/* Check Row */
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  cursor: pointer;
}

.check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* Range Slider */
.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.range-val {
  min-width: 40px;
  text-align: right;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-dark);
}

/* Receipt Items List */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.item-chip {
  background: var(--bg-sheet);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 9px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.item-chip-name {
  font-size: 0.84rem;
  font-weight: 600;
}

.item-chip-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.item-del-btn {
  border: none;
  background: rgba(244, 63, 94, 0.12);
  color: var(--danger);
  width: 28px;
  height: 28px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 700;
  flex-shrink: 0;
}

/* ==================== LIVE 57MM PREVIEW CARD ==================== */
.preview-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 12px 14px;
  margin-top: 4px;
  box-shadow: var(--shadow);
}

.preview-stage {
  background: #E5E7EB;
  border-radius: 16px;
  padding: 12px;
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  justify-content: center;
}

body.theme-dark .preview-stage {
  background: #120D1A;
}

#previewCanvas {
  width: 100%;
  max-width: 280px;
  height: auto;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  image-rendering: pixelated;
}

/* ==================== STICKY PRINT ACTION DOCK ==================== */
.print-dock {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 460px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 26;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
}

.copies-pill {
  display: flex;
  align-items: center;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 3px;
  gap: 2px;
}

.copies-btn {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  border: none;
  background: var(--bg-card);
  color: var(--text-main);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

.copies-num {
  min-width: 34px;
  text-align: center;
  font-size: 0.84rem;
  font-weight: 700;
}

.print-main-btn {
  flex: 1;
  border: none;
  background: var(--sunset-gradient);
  color: #fff;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 700;
  padding: 11px 14px;
  border-radius: 15px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(244, 63, 94, 0.32);
}

.print-main-btn:disabled { opacity: 0.6; }

/* ==================== BOTTOM NAVIGATION DOCK ==================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 460px;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 25;
}

@media (min-width: 540px) {
  .bottom-nav {
    bottom: 14px;
    border-radius: 0 0 34px 34px;
  }
  .print-dock {
    bottom: calc(var(--nav-h) + 14px);
  }
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  cursor: pointer;
}

.nav-item .nav-ic { font-size: 1.2rem; line-height: 1.1; }
.nav-item.active { color: var(--accent); font-weight: 700; }

/* ==================== MODALS (SETTINGS & PDF CROPPER) ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 10, 24, 0.62);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
}

.modal-backdrop.hidden { display: none; }

.bottom-sheet {
  width: 100%;
  max-width: 460px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--bg-card);
  border-radius: 28px 28px 0 0;
  padding: 12px 18px calc(20px + env(safe-area-inset-bottom, 0px));
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 99px;
  background: var(--border);
  margin: 0 auto 12px;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg-soft);
  color: var(--text-main);
  cursor: pointer;
}

/* Cropper Canvas */
.crop-canvas-wrap {
  background: #374151;
  border-radius: 16px;
  padding: 8px;
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
  touch-action: none;
}

#cropCanvas {
  max-width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
  border-radius: 6px;
}

.crop-badge-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.crop-pill {
  background: var(--bg-soft);
  color: var(--accent-dark);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 99px;
}

/* Progress Toast */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #2D1E2F;
  color: #FFF5EE;
  padding: 10px 16px;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 500;
  z-index: 90;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.hidden { display: none !important; }
