/* =====================================================
   Chaiiwala - Premium Tea Business Theme
   Mobile-first, responsive, dark mode
   ===================================================== */
:root {
    --primary: #8B4513;
    --primary-dark: #6e3610;
    --secondary: #D2691E;
    --accent: #F4A460;
    --accent-soft: #fbe7d2;

    --bg: #f6f1ea;
    --surface: #ffffff;
    --surface-2: #faf6f0;
    --text: #2b2118;
    --text-muted: #8a7a68;
    --border: #ece2d5;
    --shadow: 0 2px 12px rgba(94, 56, 20, .08);

    --sidebar-w: 250px;
    --topbar-h: 60px;
    --bottomnav-h: 64px;
    --radius: 14px;
}

[data-bs-theme="dark"] {
    --bg: #1a1410;
    --surface: #251d16;
    --surface-2: #2e251c;
    --text: #f0e6da;
    --text-muted: #b3a08b;
    --border: #3a2e22;
    --shadow: 0 2px 12px rgba(0, 0, 0, .35);
    --accent-soft: #3a2a18;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, 'Noto Sans', 'Noto Sans Gujarati', 'Noto Sans Devanagari', sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); text-decoration: none; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    color: #fff;
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: .6rem;
    padding: 1.1rem 1.25rem;
    font-size: 1.3rem; font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,.15);
}
.brand-logo { font-size: 1.6rem; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem 0; }
.sidebar-nav .nav-link,
.sidebar-foot .nav-link {
    display: flex; align-items: center; gap: .85rem;
    padding: .7rem 1.25rem;
    color: rgba(255,255,255,.82);
    font-weight: 500; font-size: .95rem;
    border-left: 3px solid transparent;
}
.sidebar-nav .nav-link i { font-size: 1.15rem; width: 1.4rem; text-align: center; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-nav .nav-link.active {
    background: rgba(255,255,255,.14);
    color: #fff;
    border-left-color: var(--accent);
}
.sidebar-foot { padding: .5rem 0 1rem; border-top: 1px solid rgba(255,255,255,.15); }
.sidebar-foot .nav-link { color: #ffd9d0; }
.sidebar-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 1035;
}

/* ---------- Main ---------- */
.main-area {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex; flex-direction: column;
    min-width: 0;
}

/* ---------- Topbar ---------- */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: .5rem;
    padding: 0 1rem;
    position: sticky; top: 0; z-index: 1020;
}
.topbar-title {
    font-size: 1.15rem; font-weight: 700; margin: 0;
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: .15rem; }
.btn-icon {
    background: transparent; border: 0; color: var(--text);
    width: 42px; height: 42px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.2rem; cursor: pointer;
}
.btn-icon:hover { background: var(--surface-2); }
.badge-dot {
    position: absolute; top: 4px; right: 4px;
    background: #e23b3b; color: #fff;
    font-size: .62rem; font-weight: 700;
    min-width: 17px; height: 17px; padding: 0 4px;
    border-radius: 9px; display: flex; align-items: center; justify-content: center;
}

/* ---------- Content ---------- */
.content {
    flex: 1; padding: 1.1rem;
    padding-bottom: calc(1.1rem + env(safe-area-inset-bottom));
}

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header {
    background: transparent; border-bottom: 1px solid var(--border);
    font-weight: 600;
}

/* ---------- Stat cards ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .85rem;
}
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px){ .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: .35rem;
    position: relative; overflow: hidden;
}
.stat-card .stat-icon {
    position: absolute; right: .75rem; top: .75rem;
    width: 40px; height: 40px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; color: #fff;
    background: linear-gradient(135deg, var(--secondary), var(--accent));
}
.stat-card .stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; }
.stat-card .stat-value { font-size: 1.55rem; font-weight: 800; line-height: 1.1; }
.stat-card.alt .stat-icon { background: linear-gradient(135deg, var(--primary), var(--secondary)); }

/* ---------- Quick actions ---------- */
.quick-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: .75rem; }
@media (min-width: 576px){ .quick-grid { grid-template-columns: repeat(3,1fr); } }
@media (min-width: 992px){ .quick-grid { grid-template-columns: repeat(6,1fr); } }
.quick-btn {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem .5rem;
    text-align: center; color: var(--text); font-weight: 600; font-size: .85rem;
    display: flex; flex-direction: column; align-items: center; gap: .5rem;
    box-shadow: var(--shadow); transition: transform .12s;
}
.quick-btn:hover { transform: translateY(-2px); color: var(--primary); }
.quick-btn i {
    font-size: 1.5rem; color: #fff;
    width: 48px; height: 48px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
}

/* ---------- Buttons ---------- */
.btn-primary {
    --bs-btn-bg: var(--primary); --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-dark); --bs-btn-hover-border-color: var(--primary-dark);
    --bs-btn-active-bg: var(--primary-dark); --bs-btn-active-border-color: var(--primary-dark);
}
.btn-outline-primary {
    --bs-btn-color: var(--primary); --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary); --bs-btn-hover-border-color: var(--primary);
}
.text-primary { color: var(--primary) !important; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { color: var(--text); margin: 0; }
.table > :not(caption) > * > * { background: transparent; }
.table thead th {
    background: var(--surface-2); color: var(--text-muted);
    font-size: .78rem; text-transform: uppercase; letter-spacing: .03em;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td, .table th { vertical-align: middle; border-color: var(--border); }

/* ---------- Status badges ---------- */
.badge.bg-paid    { background:#1f9d55 !important; }
.badge.bg-partial { background:#e0a800 !important; color:#3b2c00 !important; }
.badge.bg-unpaid  { background:#d64545 !important; }
.badge.bg-active  { background:#1f9d55 !important; }
.badge.bg-inactive{ background:#9aa0a6 !important; }

/* ---------- Forms ---------- */
.form-label { font-weight: 600; font-size: .85rem; margin-bottom: .3rem; }
.form-control, .form-select {
    background: var(--surface); color: var(--text);
    border-color: var(--border); border-radius: 10px; padding: .6rem .8rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--secondary);
    box-shadow: 0 0 0 .2rem rgba(210,105,30,.18);
    background: var(--surface);
    color: var(--text);
}
.pin-input { letter-spacing: .8em; text-align: center; font-size: 1.3rem; font-weight: 700; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 1030;
    justify-content: space-around; align-items: stretch;
}
.bottom-nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: var(--text-muted); font-size: .68rem; font-weight: 600;
}
.bottom-nav-item i { font-size: 1.3rem; }
.bottom-nav-item.active { color: var(--primary); }

/* ---------- Login ---------- */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 1.25rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary) 60%, var(--accent));
}
.auth-card {
    width: 100%; max-width: 400px;
    background: var(--surface); border-radius: 20px;
    box-shadow: 0 18px 50px rgba(0,0,0,.25);
    padding: 2rem 1.75rem;
}
.auth-logo {
    width: 76px; height: 76px; margin: 0 auto 1rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 22px; display: flex; align-items: center; justify-content: center;
    font-size: 2.4rem;
}

/* ---------- Section heading ---------- */
.page-head {
    display: flex; align-items: center; gap: .75rem;
    flex-wrap: wrap; margin-bottom: 1rem;
}
.page-head h2 { font-size: 1.3rem; font-weight: 700; margin: 0; }
.page-head .ms-auto { margin-left: auto; }

/* ---------- Responsive: mobile ---------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar.open ~ .sidebar-backdrop { display: block; }
    .main-area { margin-left: 0; }
    .content { padding-bottom: calc(var(--bottomnav-h) + 1rem + env(safe-area-inset-bottom)); }
    .bottom-nav { display: flex; }
}

/* ---------- Utility ---------- */
.text-muted-2 { color: var(--text-muted) !important; }
.cursor-pointer { cursor: pointer; }
@media print {
    .sidebar, .topbar, .bottom-nav, .no-print { display: none !important; }
    .main-area { margin: 0; }
    .content { padding: 0; }
}
