/* ===== VARIABLES ===== */
:root {
  --bg:          #0e0e10;
  --surface:     #1a1a1e;
  --surface2:    #26262c;
  --border:      rgba(255,255,255,0.08);
  --purple:      #c084fc;
  --purple-dark: #a855f7;
  --purple-glow: rgba(192,132,252,0.18);
  --green:       #4ade80;
  --yellow:      #fbbf24;
  --red:         #f87171;
  --text:        #f4f4f5;
  --text2:       rgba(244,244,245,0.5);
  --radius:      16px;
  --radius-sm:   12px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  overflow: hidden;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ===== LOGIN ===== */
.login-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(32px + var(--safe-top)) 24px calc(32px + var(--safe-bottom));
  background: radial-gradient(ellipse at 50% -10%, rgba(168,85,247,0.2) 0%, transparent 55%);
  overflow-y: auto;
}

.login-logo {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, #a855f7, #7c3aed);
  border-radius: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
  margin-bottom: 20px;
  box-shadow: 0 12px 40px rgba(168,85,247,0.35);
}

.login-app-name {
  font-size: 30px; font-weight: 800;
  letter-spacing: -1px; margin-bottom: 4px;
}

.login-app-name span { color: var(--purple); }

.login-sub {
  color: var(--text2); font-size: 14px;
  margin-bottom: 48px;
}

.login-form { width: 100%; max-width: 380px; }

/* ===== FIELDS ===== */
.field { margin-bottom: 14px; }

.field label {
  display: block; font-size: 11px; font-weight: 700;
  color: var(--text2); text-transform: uppercase;
  letter-spacing: 0.8px; margin-bottom: 8px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  padding: 15px 16px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
}

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

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23c084fc' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 44px;
}

.field select option { background: #1a1a1e; }

.field textarea { resize: none; line-height: 1.5; }

/* ===== BUTTONS ===== */
.btn {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; width: 100%;
  padding: 16px; border: none;
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.2px;
}

.btn:active { transform: scale(0.96); opacity: 0.8; }
.btn:disabled { opacity: 0.38; cursor: default; transform: none !important; }

.btn-primary {
  background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(168,85,247,0.32);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(239,68,68,0.28);
}

.btn-success {
  background: linear-gradient(135deg, #22c55e 0%, #15803d 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(34,197,94,0.28);
}

/* ===== SHELL ===== */
.shell {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  padding-top: var(--safe-top);
}

.shell-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.shell-user {
  display: flex; align-items: center; gap: 10px;
}

.shell-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, #a855f7, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

.shell-name {
  font-size: 14px; font-weight: 600; color: var(--text);
}

.shell-logout {
  background: none; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text2);
  font-size: 12px; font-weight: 600; font-family: inherit;
  padding: 6px 12px; cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.shell-logout:active { color: var(--red); border-color: var(--red); }

.shell-content {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
}

.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 10px 4px 12px;
  border: none; background: none;
  color: var(--text2);
  font-size: 10px; font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: color 0.15s;
  gap: 5px;
}

.nav-btn.active { color: var(--purple); }
.nav-btn.active svg { filter: drop-shadow(0 0 6px rgba(192,132,252,0.6)); }

.nav-btn svg { width: 24px; height: 24px; stroke-width: 1.5; }

/* ===== VIEW ===== */
.view {
  padding: 20px 16px;
  padding-bottom: 32px;
}

.view-title {
  font-size: 24px; font-weight: 800;
  letter-spacing: -0.5px; margin-bottom: 24px;
}

/* ===== QR SCANNER ===== */
.qr-view {
  height: 100%; position: relative;
  display: flex; flex-direction: column;
  background: #000;
}

.qr-video-wrapper {
  flex: 1; position: relative; overflow: hidden;
}

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

#qr-canvas { display: none; }

/* Dark mask with cutout */
.scan-mask {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}

.scan-window {
  width: min(260px, 68vw);
  aspect-ratio: 1;
  border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.52);
  position: relative;
}

.corner {
  position: absolute; width: 24px; height: 24px;
  border-color: var(--purple); border-style: solid;
}
.corner.tl { top: -1px; left: -1px; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.corner.tr { top: -1px; right: -1px; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.corner.bl { bottom: -1px; left: -1px; border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.corner.br { bottom: -1px; right: -1px; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

.scan-line {
  position: absolute; left: 6px; right: 6px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--purple) 30%, var(--purple) 70%, transparent);
  border-radius: 2px;
  animation: scanline 2.2s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(192,132,252,0.8);
}

@keyframes scanline {
  0%, 100% { top: 6px; opacity: 0; }
  8% { opacity: 1; }
  92% { opacity: 1; }
  100% { top: calc(100% - 6px); }
}

.scan-hint {
  position: absolute; bottom: 16px; left: 0; right: 0;
  text-align: center; font-size: 13px;
  color: rgba(255,255,255,0.65);
  pointer-events: none;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.scan-status {
  position: absolute; top: calc(16px + var(--safe-top));
  left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 100px;
  padding: 6px 16px;
  font-size: 12px; color: rgba(255,255,255,0.7);
  white-space: nowrap;
  pointer-events: none;
}

/* ===== RESULT SHEET ===== */
.result-sheet {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 8px 20px calc(20px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.38s cubic-bezier(0.34, 1.3, 0.64, 1);
  border-top: 1px solid var(--border);
  z-index: 10;
  max-height: 82vh;
  overflow-y: auto;
}

.result-sheet.show { transform: translateY(0); }

.sheet-handle {
  width: 40px; height: 4px;
  background: rgba(255,255,255,0.18);
  border-radius: 2px;
  margin: 8px auto 20px;
}

.result-badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 16px; border-radius: 100px;
  font-weight: 800; font-size: 13px;
  letter-spacing: 0.5px; margin-bottom: 10px;
}

.badge-taze   { background: rgba(74,222,128,0.14);  color: var(--green); }
.badge-riskli { background: rgba(251,191,36,0.14);  color: var(--yellow); }
.badge-iade   { background: rgba(248,113,113,0.14); color: var(--red); }
.badge-hata   { background: rgba(156,163,175,0.12); color: #9ca3af; }

.result-product { font-size: 20px; font-weight: 800; margin-bottom: 4px; }

.result-meta {
  color: var(--text2); font-size: 13px; line-height: 1.6;
  margin-bottom: 6px;
}

.result-barcode {
  font-family: 'Courier New', monospace; font-size: 12px;
  color: var(--text2); margin-bottom: 12px;
}

.result-warning {
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.22);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px; color: var(--red);
  margin: 12px 0; line-height: 1.5;
}

.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }

/* ===== PHOTO CAPTURE ===== */
.photo-overlay {
  position: absolute; inset: 0;
  background: #000;
  display: flex; flex-direction: column;
  z-index: 20;
}

.photo-video {
  flex: 1; width: 100%; object-fit: cover;
}

.photo-controls {
  padding: 20px 24px;
  padding-bottom: calc(20px + var(--safe-bottom));
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.capture-ring {
  width: 74px; height: 74px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.85);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}

.capture-ring::after {
  content: ''; width: 58px; height: 58px;
  border-radius: 50%; background: #fff;
  transition: transform 0.1s;
}

.capture-ring:active::after { transform: scale(0.88); }

.photo-cancel-btn {
  background: rgba(255,255,255,0.14); border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm); color: #fff;
  padding: 10px 18px; font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer;
  transition: opacity 0.15s;
}

.photo-cancel-btn:active { opacity: 0.7; }

.photo-preview {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  gap: 16px; background: #000;
}

.photo-preview img {
  max-width: 100%; max-height: 58vh;
  border-radius: var(--radius);
  object-fit: contain;
}

.photo-preview-actions { width: 100%; display: flex; flex-direction: column; gap: 10px; }

/* ===== FILE UPLOAD ===== */
.file-upload-box {
  position: relative; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px; padding: 22px 16px;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer; transition: border-color 0.15s;
  text-align: center; min-height: 90px;
}

.file-upload-box.has-file {
  border-color: var(--purple);
  background: var(--purple-glow);
}

.file-upload-box input[type="file"] {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}

.upload-icon { font-size: 26px; }
.upload-label { font-size: 13px; color: var(--text2); }
.file-upload-box.has-file .upload-label { color: var(--purple); font-weight: 600; }
.upload-sub { font-size: 11px; color: var(--text2); margin-top: 2px; }

/* ===== TOAST ===== */
.toast {
  position: fixed; z-index: 999;
  top: calc(20px + var(--safe-top));
  left: 16px; right: 16px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  border: 1px solid var(--border);
  transform: translateY(calc(-100% - var(--safe-top) - 40px));
  transition: transform 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
  pointer-events: none;
}

.toast.show { transform: translateY(0); }
.toast-ok   { border-left: 3px solid var(--green); }
.toast-err  { border-left: 3px solid var(--red); }

/* ===== SPINNER ===== */
.spin {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  animation: rot 0.65s linear infinite;
  display: inline-block; flex-shrink: 0;
}

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

/* ===== CAMERA PERMISSION DENIED ===== */
.no-cam {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; gap: 14px; padding: 40px;
  text-align: center;
}

.no-cam .icon { font-size: 52px; }
.no-cam .title { font-size: 17px; font-weight: 700; }
.no-cam .sub { font-size: 13px; color: var(--text2); line-height: 1.6; }
