/* ═══════════════════════════════════════════════════════
   AKILLI MARKET ASISTANI — style.css
   Mobile-first, modern card UI
═══════════════════════════════════════════════════════ */

/* ── CSS Değişkenleri ──────────────────────────────────── */
:root {
  /* Marka renkleri */
  --c-primary:       #1e40af;
  --c-primary-dark:  #1e3a8a;
  --c-primary-light: #dbeafe;
  --c-scan:          #3b82f6;

  /* Durum renkleri */
  --c-ok:            #16a34a;
  --c-ok-light:      #dcfce7;
  --c-warn:          #c2410c;
  --c-warn-light:    #ffedd5;
  --c-danger:        #dc2626;
  --c-danger-light:  #fee2e2;
  --c-success:       #15803d;

  /* Nötr renkler */
  --c-bg:            #f1f5f9;
  --c-surface:       #ffffff;
  --c-text:          #0f172a;
  --c-text-2:        #475569;
  --c-muted:         #94a3b8;
  --c-border:        #e2e8f0;

  /* Geometri */
  --r-xs:  6px;
  --r-sm:  10px;
  --r-md:  16px;
  --r-lg:  22px;
  --r-xl:  28px;

  /* Gölgeler */
  --sh-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --sh:    0 4px 14px rgba(0,0,0,.08);
  --sh-lg: 0 10px 36px rgba(0,0,0,.14);

  /* Geçiş */
  --tr: all .2s ease;

  /* Yazı tipi */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto,
          'Helvetica Neue', sans-serif;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* [hidden] özelliği display kurallarından önce gelsin */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  /* Güvenli alan destekleri (iPhone notch/home bar) */
  padding-top: env(safe-area-inset-top);
}

body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

video, canvas, img { max-width: 100%; display: block; }

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

input {
  font-family: inherit;
  font-size: inherit;
}

ul { list-style: none; }

/* ═══════════════════════════════════════════════════════
   APP HEADER
═══════════════════════════════════════════════════════ */
.app-header {
  background: linear-gradient(150deg, var(--c-primary-dark) 0%, var(--c-primary) 100%);
  color: #fff;
  padding: 1.25rem 1rem 1.75rem;
  position: sticky;
  top: 0;
  z-index: 40;
  /* Çerçeve alt kısmına hafif eğri ver */
  border-radius: 0 0 var(--r-xl) var(--r-xl);
  box-shadow: var(--sh-lg);
}

.app-title {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -.02em;
  display: flex;
  align-items: center;
  gap: .45rem;
  margin-bottom: 1rem;
}

.app-icon { font-size: 1.45rem; }

/* ── Bütçe Kartı (header içinde, cam efektli) ──────────── */
.budget-card {
  background: rgba(255,255,255,.13);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: var(--r-md);
  padding: 1rem;
  color: #fff;
}

/* Form etiket genel stili */
.form-label {
  display: block;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  opacity: .8;
  margin-bottom: .45rem;
}

/* Bütçe giriş satırı */
.budget-input-row {
  display: flex;
  gap: .5rem;
  margin-bottom: .85rem;
}

/* ₺ öneki olan input sarmalayıcı */
.prefix-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.input-prefix {
  position: absolute;
  left: .75rem;
  font-weight: 700;
  pointer-events: none;
  z-index: 1;
  font-size: 1rem;
}

/* Header içindeki input-prefix beyaz */
.budget-card .input-prefix { color: rgba(255,255,255,.75); }

/* Modal içindeki input-prefix soluk gri */
.modal-price-wrap .input-prefix { color: var(--c-muted); }

/* Header içindeki input */
.budget-card .prefix-input-wrap input {
  width: 100%;
  padding: .65rem .75rem .65rem 2rem;
  border: 1.5px solid rgba(255,255,255,.32);
  border-radius: var(--r-sm);
  background: rgba(255,255,255,.17);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  outline: none;
  transition: var(--tr);
}

.budget-card .prefix-input-wrap input::placeholder { color: rgba(255,255,255,.45); }

.budget-card .prefix-input-wrap input:focus {
  border-color: rgba(255,255,255,.75);
  background: rgba(255,255,255,.25);
  box-shadow: 0 0 0 3px rgba(255,255,255,.15);
}

/* Gizle sayı artırma/azaltma okları */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type="number"] { -moz-appearance: textfield; }

/* ── Bütçe İstatistik Kutuları ─────────────────────────── */
.budget-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .45rem;
  margin-bottom: .7rem;
}

.stat-box {
  background: rgba(255,255,255,.11);
  border-radius: var(--r-xs);
  padding: .45rem .3rem;
  text-align: center;
  transition: var(--tr);
}

.stat-label {
  display: block;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  opacity: .72;
  margin-bottom: .15rem;
}

.stat-value {
  display: block;
  font-size: .95rem;
  font-weight: 800;
  letter-spacing: -.02em;
  color: #fff; /* varsayılan */
  transition: color .3s ease;
}

/* Kalan bütçe renk durumları */
#statRemaining.state-ok   .stat-value { color: #86efac; }
#statRemaining.state-warn .stat-value { color: #fdba74; }
#statRemaining.state-over .stat-value { color: #fca5a5; }

/* ── İlerleme Çubuğu ───────────────────────────────────── */
.progress-track {
  height: 7px;
  background: rgba(255,255,255,.2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: .5rem;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  background: #86efac;
  transition: width .45s ease, background .3s ease;
  width: 0%;
}

.progress-fill.pf-warn { background: #fdba74; }
.progress-fill.pf-over { background: #fca5a5; width: 100% !important; }

/* ── Bütçe Uyarı Metni ─────────────────────────────────── */
.budget-alert {
  font-size: .76rem;
  font-weight: 600;
  text-align: center;
  padding: .3rem .6rem;
  border-radius: var(--r-xs);
  line-height: 1.4;
}

.budget-alert.alert-warn {
  background: rgba(251,146,60,.22);
  color: #fde68a;
}

.budget-alert.alert-over {
  background: rgba(239,68,68,.22);
  color: #fca5a5;
}

/* ═══════════════════════════════════════════════════════
   BUTONLAR
═══════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .65rem 1.1rem;
  border-radius: var(--r-sm);
  font-weight: 700;
  font-size: .9rem;
  letter-spacing: .01em;
  transition: var(--tr);
  min-height: 44px;
  white-space: nowrap;
  user-select: none;
}

/* Beyaz buton (header içinde) */
.btn-white {
  background: #fff;
  color: var(--c-primary);
  box-shadow: var(--sh-sm);
}
.btn-white:hover  { background: #f0f4ff; }
.btn-white:active { transform: scale(.97); }

/* Çerçeveli buton */
.btn-outline {
  background: var(--c-surface);
  color: var(--c-primary);
  border: 1.5px solid var(--c-border);
  box-shadow: var(--sh-sm);
}
.btn-outline:hover { border-color: var(--c-primary); background: var(--c-primary-light); }

/* Tarama butonu (mavi gradient) */
.btn-scan {
  background: linear-gradient(135deg, var(--c-primary), var(--c-scan));
  color: #fff;
  box-shadow: 0 4px 14px rgba(59,130,246,.4);
  flex: 2;
}
.btn-scan:hover:not(:disabled) { box-shadow: 0 6px 20px rgba(59,130,246,.5); transform: translateY(-1px); }
.btn-scan:active:not(:disabled) { transform: translateY(0); }
.btn-scan:disabled { opacity: .48; cursor: not-allowed; transform: none; box-shadow: none; }

/* Yeşil başarı butonu */
.btn-success {
  background: linear-gradient(135deg, var(--c-ok), #22c55e);
  color: #fff;
  box-shadow: 0 4px 14px rgba(22,163,74,.35);
  flex: 2;
}
.btn-success:hover { box-shadow: 0 6px 20px rgba(22,163,74,.45); }

/* Hayalet buton */
.btn-ghost {
  background: transparent;
  color: var(--c-text-2);
  border: 1.5px solid var(--c-border);
}
.btn-ghost:hover { background: var(--c-bg); }

/* Kırmızı hayalet (sepet temizle) */
.btn-danger-ghost {
  background: transparent;
  color: var(--c-danger);
  border: 1.5px solid #fecaca;
}
.btn-danger-ghost:hover { background: var(--c-danger-light); }

/* Küçük boy */
.btn-sm { padding: .38rem .75rem; min-height: 36px; font-size: .78rem; }

/* ═══════════════════════════════════════════════════════
   ANA İÇERİK
═══════════════════════════════════════════════════════ */
.app-main {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 600px;
  margin: 0 auto;
}

/* Kart ortak stili */
.section-card {
  background: var(--c-surface);
  border-radius: var(--r-md);
  box-shadow: var(--sh);
  padding: 1.15rem;
}

.section-heading {
  font-size: 1rem;
  font-weight: 800;
  color: var(--c-text);
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-bottom: .9rem;
}

/* ═══════════════════════════════════════════════════════
   KAMERA & VİEWFINDER
═══════════════════════════════════════════════════════ */
.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: #0a0f1e;
  margin-bottom: .75rem;
}

#videoFeed {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Kamera placeholder */
.cam-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  color: rgba(255,255,255,.42);
}

.ph-icon  { font-size: 2.8rem; }
.ph-label { font-size: .8rem; font-weight: 500; }

/* ── Viewfinder yapısı ─────────────────────────────────── */
.viewfinder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

/* Karartma bölümleri */
.vf-shade { background: rgba(0,0,0,.46); }
.vf-top   { flex: 1; }
.vf-bottom {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: .45rem;
}
.vf-hint {
  font-size: .7rem;
  color: rgba(255,255,255,.75);
  font-weight: 500;
  letter-spacing: .02em;
}

/* Orta satır: sol karartma | odak kutusu | sağ karartma */
.vf-mid-row { display: flex; height: 110px; }
.vf-side    { flex: 1; }

/* Şeffaf odak kutusu */
.vf-box {
  width: 230px;
  position: relative;
  overflow: hidden;
}

/* Köşe işaretçileri */
.vf-corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border-color: #ffffff;
  border-style: solid;
}
.vf-tl { top: 0; left: 0;  border-width: 3px 0 0 3px;  border-radius: 3px 0 0 0; }
.vf-tr { top: 0; right: 0; border-width: 3px 3px 0 0;  border-radius: 0 3px 0 0; }
.vf-bl { bottom: 0; left: 0;  border-width: 0 0 3px 3px; border-radius: 0 0 0 3px; }
.vf-br { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 3px 0; }

/* Tarama animasyon çizgisi */
.vf-scan-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg,
    transparent, #60a5fa 20%, #93c5fd 50%, #60a5fa 80%, transparent);
  box-shadow: 0 0 10px 3px rgba(96,165,250,.65);
  top: 0;
  opacity: 0;
}

/* Tarama aktifken animasyonu çalıştır */
.vf-scan-line.scanning {
  opacity: 1;
  animation: scanMove 1.6s ease-in-out infinite;
}

@keyframes scanMove {
  0%   { top: 0; }
  50%  { top: calc(100% - 2px); }
  100% { top: 0; }
}

/* ── Kamera kontrol butonları ──────────────────────────── */
.cam-controls {
  display: flex;
  gap: .65rem;
  margin-bottom: .65rem;
}

.cam-controls .btn-outline { flex: 1; }

/* ── OCR durum çubuğu ──────────────────────────────────── */
.ocr-status-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem .95rem;
  background: #eff6ff;
  border-radius: var(--r-sm);
  color: var(--c-primary);
  font-size: .85rem;
  font-weight: 600;
  border: 1px solid #bfdbfe;
}

/* Dönen yükleme simgesi */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid #bfdbfe;
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════
   SEPET BÖLÜMÜ
═══════════════════════════════════════════════════════ */
.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .85rem;
}

.cart-header .section-heading { margin-bottom: 0; }

.cart-meta {
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* Ürün adedi rozeti */
.badge {
  background: var(--c-primary-light);
  color: var(--c-primary);
  font-size: .7rem;
  font-weight: 800;
  padding: .18rem .6rem;
  border-radius: 999px;
  letter-spacing: .03em;
}

.cart-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

/* ── Boş Sepet Durumu ──────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 2.25rem 1rem;
  color: var(--c-muted);
}

.empty-icon { font-size: 2.4rem; margin-bottom: .5rem; }
.empty-state p     { font-size: .88rem; font-weight: 600; margin-bottom: .2rem; }
.empty-state small { font-size: .75rem; }

/* ── Sepet Öğesi ───────────────────────────────────────── */
.cart-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .7rem .9rem;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  animation: itemIn .22s ease;
  transition: opacity .2s ease, transform .2s ease;
}

@keyframes itemIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Sıra numarası balonu */
.item-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--c-primary-light);
  color: var(--c-primary);
  font-size: .7rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.item-info { flex: 1; min-width: 0; }

.item-name {
  font-size: .86rem;
  font-weight: 700;
  color: var(--c-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: .1rem;
}

.item-price {
  font-size: .78rem;
  color: var(--c-text-2);
}

.item-price strong {
  color: var(--c-primary);
  font-size: .88rem;
  font-weight: 800;
}

/* Sil butonu */
.item-remove {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--c-danger-light);
  color: var(--c-danger);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  flex-shrink: 0;
  transition: var(--tr);
  font-weight: 700;
}

.item-remove:hover { background: var(--c-danger); color: #fff; }

/* ═══════════════════════════════════════════════════════
   MODAL
═══════════════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.58);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;   /* Mobilde altta aç */
  justify-content: center;
  padding: 0;
  animation: backdropIn .2s ease;
}

@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }

/* Modal kutu */
.modal-box {
  background: var(--c-surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 1.5rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
  animation: boxUp .3s ease;
  overscroll-behavior: contain;
}

@keyframes boxUp {
  from { transform: translateY(50px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .9rem;
}

.modal-heading {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--c-text);
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--c-bg);
  color: var(--c-text-2);
  font-size: .88rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--tr);
}
.modal-close-btn:hover { background: var(--c-border); }

.modal-desc {
  font-size: .82rem;
  color: var(--c-muted);
  line-height: 1.55;
  margin-bottom: 1.2rem;
}

/* Form grubu */
.form-group { margin-bottom: 1rem; }

.form-group input {
  width: 100%;
  padding: .7rem .9rem;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: .96rem;
  font-weight: 600;
  color: var(--c-text);
  background: var(--c-bg);
  outline: none;
  transition: var(--tr);
}

.form-group input:focus {
  border-color: var(--c-primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

/* Fiyat inputu — prefix boşluğu */
.modal-price-wrap input { padding-left: 2rem; }

/* ── Ham OCR metni açılır-kapanır ──────────────────────── */
.raw-ocr-details {
  margin-bottom: 1.1rem;
  font-size: .8rem;
  color: var(--c-text-2);
}

.raw-ocr-details summary {
  cursor: pointer;
  font-weight: 600;
  padding: .35rem 0;
  user-select: none;
  list-style: none;
}
.raw-ocr-details summary::-webkit-details-marker { display: none; }
.raw-ocr-details summary::before { content: '▶  '; font-size: .65rem; }
.raw-ocr-details[open] summary::before { content: '▼  '; }

.raw-ocr-text {
  margin-top: .4rem;
  padding: .7rem;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-xs);
  font-family: 'Courier New', 'Menlo', monospace;
  font-size: .72rem;
  color: var(--c-text-2);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 110px;
  overflow-y: auto;
  line-height: 1.5;
}

/* Modal aksiyon butonu satırı */
.modal-actions {
  display: flex;
  gap: .65rem;
  padding-top: .9rem;
  border-top: 1px solid var(--c-border);
}

.modal-actions .btn-ghost { flex: 1; }

/* ═══════════════════════════════════════════════════════
   TOAST BİLDİRİMLERİ
═══════════════════════════════════════════════════════ */
.toast-zone {
  position: fixed;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  gap: .5rem;
  align-items: center;
  pointer-events: none;
  width: min(92vw, 340px);
}

.toast {
  background: #1e293b;
  color: #fff;
  padding: .65rem 1.1rem;
  border-radius: var(--r-sm);
  font-size: .84rem;
  font-weight: 600;
  box-shadow: var(--sh-lg);
  text-align: center;
  animation: toastIn .28s ease, toastOut .28s ease 2.72s forwards;
  width: 100%;
  line-height: 1.4;
}

.toast.t-success { background: var(--c-ok); }
.toast.t-error   { background: var(--c-danger); }
.toast.t-warning { background: var(--c-warn); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-8px) scale(.95); }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE DÜZELTMELER
═══════════════════════════════════════════════════════ */
@media (min-width: 480px) {
  .app-header  { padding: 1.5rem 1.5rem 2rem; }
  .app-main    { padding: 1.25rem 1.5rem; }
  .section-card { padding: 1.4rem; }
}

/* Masaüstü: modal ortada açılır */
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; padding: 1rem; }
  .modal-box {
    border-radius: var(--r-xl);
    max-height: 82dvh;
    padding: 1.75rem;
  }
}
