/*
  Renk değişkenleri: tüm dosya renkleri buradan okur (var(--bg) gibi).
  Koyu tema: zemin tam siyah değil koyu gri; kartlar zeminden biraz açık
  (koyu temada "yükseklik" gölgeyle değil açıklıkla gösterilir);
  yazı tam beyaz değil → göz daha az yorulur.
*/
:root {
    --bg: #0d0f13;
    --card: #15181e;
    --surface: #1d2129;
    --surface-hover: #252a34;
    --text: #e7e9ee;
    --muted: #8a92a3;
    --border: #262b35;
    --accent: #5b8cff;
    --green: #3ecf8e;
    --red: #ff5c6c;
    --radius: 14px;

    /* Tarayıcının kendi çizdiği parçalar (scrollbar, öneri listesi) da koyu olsun. */
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    /* Telefonda linke dokununca çıkan mavi kutuyu kapatır. */
    -webkit-tap-highlight-color: transparent;
}

.icon { flex-shrink: 0; display: block; }

/* ---------- Üst menü ---------- */
.site-header {
    position: sticky;           /* kaydırınca üstte kalır */
    top: 0;
    z-index: 5;
    padding: 10px 20px;
    background: rgba(13, 15, 19, .85);
    backdrop-filter: blur(10px);   /* arkadan geçen içerik bulanık görünür */
    border-bottom: 1px solid var(--border);
}
/* Header içi: .container içeriğiyle aynı genişlik → logo ve menü içerikle hizalı.
   1060 = container 1100px - iki yandaki 20px iç boşluk. */
.header-inner {
    max-width: 1060px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-weight: 700;
    font-size: 1.1rem;
    text-decoration: none;
}
.logo .icon { color: var(--accent); }

.nav { display: flex; gap: 4px; }
.nav a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 10px;
    color: var(--muted);
    text-decoration: none;
    font-size: .95rem;
    transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface); color: var(--text); }
.nav a.active { background: var(--surface); color: var(--text); }
.nav a.active .icon { color: var(--accent); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px 40px; }

.page-head { margin-bottom: 18px; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; }
h2 { font-size: .95rem; font-weight: 600; color: var(--muted); margin: 28px 0 10px; }

.muted { color: var(--muted); font-weight: 400; }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .92em; }
.nowrap { white-space: nowrap; }
.green { color: var(--green); }
.red { color: var(--red); }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; }
label { font-size: .85rem; color: var(--muted); font-weight: 500; }

input {
    width: 100%;
    /* 16px: iPhone Safari 16px'ten küçük yazılı input'a dokununca sayfayı zoom'lar. */
    font-size: 16px;
    padding: 12px 14px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: #5f6676; }
input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(91, 140, 255, .2);   /* odak halkası */
}
input[readonly] { background: transparent; border-style: dashed; color: var(--text); }
input.input-error { color: var(--red); border-color: var(--red); }

/* Barkod alanı: kamera butonu input'un İÇİNDE, sağ kenarda.
   position: relative → butonun "absolute" konumu bu kutuya göre hesaplanır. */
.input-group { position: relative; }
.input-group input { padding-right: 52px; }   /* yazı butonun altına girmesin */
.input-group .icon-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);   /* dikeyde ortala */
}

/* Küçük kare ikon buton (kamera, kapat) */
.icon-btn {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background .15s, color .15s;
}
.icon-btn:hover, .icon-btn:active { background: var(--surface-hover); color: var(--accent); }

.btn {
    font-size: 16px;
    font-weight: 600;
    padding: 13px 16px;
    margin-top: 6px;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
    color: #fff;
    transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(.99); }
.btn-primary { background: var(--accent); }
.btn-danger { background: var(--red); }

/* ---------- Mesajlar ---------- */
.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border-radius: 10px;
    border: 1px solid;
    animation: flash-in .25s ease-out;
}
.flash-success { color: var(--green); border-color: rgba(62, 207, 142, .4); background: rgba(62, 207, 142, .08); }
.flash-error { color: var(--red); border-color: rgba(255, 92, 108, .4); background: rgba(255, 92, 108, .08); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- Giriş/çıkış sayfası yerleşimi ---------- */
/* PC'de iki eşit sütun: solda form, sağda son işlemler.
   align-items: start → sütunlar kendi yüksekliğinde kalır, form uzamaz. */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.split .recent h2 { margin-top: 0; }

/* ---------- Son işlemler listesi ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: 0; }
.list-title { font-weight: 500; }
.list-sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.list-time { color: var(--muted); font-size: .8rem; white-space: nowrap; }

/* ---------- Özet kartları ---------- */
.stats {
    display: grid;
    /* auto-fit + minmax: ekran genişliğine göre 4, 2 veya 1 sütun olur. */
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.stat { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { color: var(--muted); font-size: .8rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Arama ---------- */
/* Büyüteç ikonu input'un içinde solda. */
.search { position: relative; margin-bottom: 16px; }
.search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 42px; }

/* Ürün bazında adetler: tıklanabilir etiketler */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px 7px 12px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    font-size: .9rem;
}
.chip:hover { border-color: var(--accent); }
.chip b { background: var(--bg); padding: 1px 8px; border-radius: 999px; font-size: .8rem; }

/* ---------- Tablo ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: .78rem; font-weight: 600; }
.badge-in { color: var(--green); background: rgba(62, 207, 142, .12); }
.badge-out { color: var(--red); background: rgba(255, 92, 108, .12); }

/* ---------- Kamera penceresi ---------- */
/* [hidden] özniteliği aşağıdaki display:flex tarafından ezilmesin diye açıkça gizliyoruz. */
.modal[hidden] { display: none; }
.modal {
    position: fixed;
    inset: 0;                   /* tüm ekranı kapla */
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, .8);
    backdrop-filter: blur(4px);
}
.modal-box {
    width: 100%;
    max-width: 460px;
    padding: 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding-left: 4px; }
#camera-reader { width: 100%; border-radius: 10px; overflow: hidden; background: #000; min-height: 200px; }
#camera-reader video { display: block; }
.modal-box p { margin: 10px 0 2px; }

/* ================= Telefon (dar ekran) ================= */
@media (max-width: 640px) {
    /* backdrop-filter kaldırılır: bu özellik, içindeki position:fixed öğeleri
       ekrana göre değil header'a göre konumlandırır → alt menü yukarıda kalırdı. */
    .site-header { padding: 12px 16px; backdrop-filter: none; background: var(--bg); }
    .container { padding: 18px 14px 100px; }  /* alttaki menü içeriği örtmesin */

    /* Menü ekranın altına sabitlenir: başparmakla kolay erişim (uygulama gibi). */
    .nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 0;
        /* safe-area-inset-bottom: iPhone'un alt çizgisinin altında kalmasın. */
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
        background: rgba(21, 24, 30, .95);
        backdrop-filter: blur(10px);
        border-top: 1px solid var(--border);
    }
    .nav a { flex-direction: column; gap: 3px; padding: 6px 0; font-size: .72rem; }
    .nav a.active { background: transparent; color: var(--accent); }

    .form { padding: 16px; }
    .split { grid-template-columns: 1fr; }   /* telefonda alt alta */
    .split .recent h2 { margin-top: 8px; }

    /* Tablo → kart: her satır ayrı bir kutu, her hücre "Başlık: değer" satırı.
       Dar ekranda 6 sütunlu tabloyu yatay kaydırmaktan çok daha okunaklı. */
    table.responsive thead { display: none; }
    table.responsive tr { display: block; padding: 10px 14px; border-bottom: 1px solid var(--border); }
    table.responsive tbody tr:last-child { border-bottom: 0; }
    table.responsive td {
        display: flex;
        justify-content: space-between;
        gap: 16px;
        padding: 4px 0;
        border: 0;
        text-align: right;
    }
    /* attr(data-label): HTML'deki data-label="Barkod" değerini başlık olarak yazar. */
    table.responsive td::before {
        content: attr(data-label);
        color: var(--muted);
        font-family: system-ui, sans-serif;
        font-size: .8rem;
        text-align: left;
    }
}
