/* --- CSS DEĞİŞKENLERİ --- */
:root,
body {
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --sub: #64748b;
    --accent: #10b981;
    /* Gelir Rengi */
    --danger: #ef4444;
    /* Gider Rengi */
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --header-bg: #ffffff;
    --predict: #8b5cf6;
    color-scheme: light;
}

:root.dark-mode,
body.dark-mode {
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f1f5f9;
    --sub: #94a3b8;
    --accent: #34d399;
    --danger: #f87171;
    --border: #334155;
    --header-bg: #1e293b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 20px;
    padding-bottom: 100px;
    transition: background-color 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    touch-action: manipulation;
    overscroll-behavior-y: contain;
}
html.capacitor-android body {
    padding-top: max(48px, env(safe-area-inset-top, 48px)) !important;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: max(100px, calc(100px + env(safe-area-inset-bottom, 0px)));
}
html.capacitor-android body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: max(48px, env(safe-area-inset-top, 48px));
    background: var(--bg);
    z-index: 9998;
}

/* HEADER & NAV */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    background: var(--header-bg);
    padding: 10px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.tutar-badge {
    font-size: 18px;
    font-weight: 900;
    color: var(--accent);
    text-align: right;
}

.tutar-badge.negatif {
    color: var(--danger);
}

.btn-toggle {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
}

/* PATRON MENÜSÜ */
.nav-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.nav-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    border-radius: 10px;
    min-width: 80px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
    background: var(--border);
    color: var(--sub);
    border: 2px solid transparent;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.nav-tab.active {
    background: var(--card);
    color: var(--text);
    border-color: var(--accent);
    box-shadow: var(--shadow);
}

/* KARTLAR */
.card {
    background: var(--card);
    border-radius: 16px;
    padding: 15px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 15px;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* GARSON GRID */
.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.product-card {
    background: var(--card);
    height: 135px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    box-shadow: var(--shadow);
    border: 2px solid transparent;
    position: relative;
    transition: transform 0.1s, background-color 0.3s ease, border-color 0.3s ease;
}

.product-card:active {
    transform: scale(0.96);
}

.product-card.secili {
    border-color: var(--accent);
    background: rgba(16, 185, 129, 0.05);
}

.btn-azalt {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 36px;
    height: 36px;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    z-index: 10;
}

.adet-badge {
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 8px;
    margin-top: 8px;
}

/* ALT BAR */
.bottom-bar {
    position: fixed;
    bottom: 25px;
    left: 20px;
    right: 20px;
    background: var(--header-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 15px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    gap: 10px;
    justify-content: center;
    z-index: 100;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

html.capacitor-android .bottom-bar {
    bottom: max(10px, calc(10px + env(safe-area-inset-bottom, 0px)));
}

.btn-main {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 12px;
    flex: 3;
    font-size: 16px;
    font-weight: 700;
}

.btn-clear {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 12px;
    flex: 1;
    font-size: 20px;
}

/* GİDER FORMU */
.expense-form {
    display: flex;
    gap: 10px;
    flex-direction: column;
}

.form-input {
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.form-btn {
    padding: 12px;
    border-radius: 8px;
    border: none;
    background: var(--danger);
    color: white;
    font-weight: 800;
    cursor: pointer;
}

/* FİNANS TABLOSU */
.finance-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.finance-table th {
    text-align: left;
    color: var(--sub);
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}

.finance-table td {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: bold;
}

.badge.gelir {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent);
}

.badge.gider {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.log-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding: 10px 0;
    font-size: 13px;
}

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--card);
    padding: 20px;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    transition: background-color 0.3s ease;
    -webkit-overflow-scrolling: touch;
}

.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
    margin-bottom: 20px;
}

/* LOGIN PAGE */
.login-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5000;
    padding: 20px;
    box-sizing: border-box;
}

.login-card {
    background: var(--card);
    padding: 35px 30px;
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    width: 88%;
    max-width: 380px;
    border: 1px solid var(--border);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.dark-mode .login-card {
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

html.capacitor-android .login-container {
    padding-top: max(48px, env(safe-area-inset-top, 48px));
}

/* SCROLL CONTAINER - Table fixes */
.scroll-container {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) var(--bg);
    -webkit-overflow-scrolling: touch;
}

.scroll-container::-webkit-scrollbar {
    width: 6px;
}

.scroll-container::-webkit-scrollbar-track {
    background: var(--bg);
}

.scroll-container::-webkit-scrollbar-thumb {
    background-color: var(--accent);
    border-radius: 10px;
}
/* Toast animasyonları */
.toast-fade-enter-active { transition: all 0.25s ease; }
.toast-fade-leave-active  { transition: all 0.2s ease; }
.toast-fade-enter-from    { opacity: 0; transform: translateX(30px); }
.toast-fade-leave-to      { opacity: 0; transform: translateX(30px); }

/* iOS input zoom engelleme */
input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="search"],
input[type="url"],
select,
textarea {
    font-size: 16px !important;
}

/* ==================== MOBİL UYUMLULUK ==================== */

/* --- TELEFON (dikey, ≤600px) --- */
@media (max-width: 600px) {
    body {
        padding: 10px;
        padding-bottom: 80px;
    }
    html.capacitor-android body {
        padding-top: max(48px, env(safe-area-inset-top, 48px)) !important;
    }

    /* Header */
    header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px;
    }
    .tutar-badge {
        font-size: 15px;
    }

    /* Nav tab'lar — kompakt */
    .nav-tabs {
        gap: 4px;
    }
    .nav-tab {
        min-width: 0;
        padding: 8px 6px;
        font-size: 10px;
    }

    /* Masa seçim: mobilde taşma düzeltmesi */
    .masa-container {
        height: auto !important;
        justify-content: flex-start !important;
        padding-top: 5px !important;
    }
    .masa-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        max-width: 100% !important;
        gap: 8px !important;
    }

    /* Ürün grid'i: tek sütun */
    .grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* Ürün kartları */
    .product-card {
        height: auto;
        min-height: 90px;
        padding: 12px;
    }

    /* Alt bar */
    .bottom-bar {
        bottom: 10px;
        left: 8px;
        right: 8px;
        padding: 10px;
        border-radius: 12px;
        gap: 8px;
    }
    html.capacitor-android .bottom-bar {
        bottom: max(10px, calc(10px + env(safe-area-inset-bottom, 0px)));
    }
    .btn-main {
        font-size: 14px;
        padding: 10px;
    }
    .btn-clear {
        font-size: 16px;
        padding: 10px;
    }

    /* Kartlar */
    .card {
        padding: 12px;
        border-radius: 12px;
        margin-bottom: 10px;
    }

    /* Finans tablosu */
    .finance-table {
        font-size: 11px;
    }
    .finance-table td,
    .finance-table th {
        padding: 6px 2px;
    }

    /* Modal */
    .modal-content {
        padding: 15px;
        border-radius: 12px;
        width: 95%;
    }

    /* Login */
    .login-card {
        padding: 25px;
    }

    /* Chart */
    .chart-container {
        height: 220px;
    }

    /* Log item */
    .log-item {
        font-size: 12px;
        padding: 8px 0;
    }

    /* --- Flex form wrapper: mobilde dikey dizilim --- */
    .mobile-form-wrap {
        flex-direction: column !important;
    }
    .mobile-form-wrap .form-input,
    .mobile-form-wrap select.form-input {
        min-width: 0 !important;
        flex: none !important;
        width: 100% !important;
        box-sizing: border-box;
    }
    .mobile-form-wrap .form-btn {
        min-width: 0 !important;
        flex: none !important;
        width: 100% !important;
        box-sizing: border-box;
    }
    .mobile-form-wrap > div {
        width: 100% !important;
        flex: none !important;
    }

    /* Expense form (gider gir) */
    .expense-form {
        gap: 8px;
    }
    .expense-form .form-input,
    .expense-form .form-btn {
        min-width: 0 !important;
        width: 100% !important;
        box-sizing: border-box;
    }

    /* --- DEPO: Hammadde kartları tek sütun --- */
    .card [style*="display:grid"] {
        grid-template-columns: 1fr !important;
    }

    /* Hammadde kart butonları — yan yana kalabilir ama küçük */
    .card [style*="display:flex; gap:5px"] .form-btn {
        flex: 1 !important;
        width: auto !important;
        font-size: 10px !important;
        padding: 6px 4px !important;
    }

    /* Reçete tablosu — küçük font, sığdır */
    .card table {
        font-size: 11px !important;
    }
    .card table th,
    .card table td {
        padding: 6px 5px !important;
    }

    /* Select'ler mobilde tam genişlik */
    select.form-input {
        width: 100% !important;
    }
}

/* --- TABLET (≤900px) --- */
@media (min-width: 601px) and (max-width: 900px) {
    body {
        padding: 15px;
        padding-bottom: 90px;
    }
    html.capacitor-android body {
        padding-top: max(48px, env(safe-area-inset-top, 48px)) !important;
    }

    .masa-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .product-card {
        height: 115px;
    }

    .bottom-bar {
        bottom: 15px;
        left: 15px;
        right: 15px;
    }

    .chart-container {
        height: 260px;
    }
}

/* --- DESKTOP (>900px) --- */
@media (min-width: 901px) {
    .grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
