/* ===== MILK NOTEBOOK - MAIN STYLES v2 ===== */
:root {
    --primary:      #2563eb;
    --primary-dark: #1d4ed8;
    --secondary:    #10b981;
    --danger:       #ef4444;
    --warning:      #f59e0b;
    --info:         #3b82f6;
    --bg:           #f1f5f9;
    --card:         #ffffff;
    --text:         #1e293b;
    --text-muted:   #64748b;
    --border:       #e2e8f0;
    --sidebar-w:    240px;
    --nav-h:        56px;
    --shadow:       0 1px 3px rgba(0,0,0,0.1);
    --radius:       10px;
    /* Mobile safe area for notches/status bar */
    --safe-top:     env(safe-area-inset-top, 0px);
    --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

/* Dark Mode */
body.dark {
    --bg:         #0f172a;
    --card:       #1e293b;
    --text:       #f1f5f9;
    --text-muted: #94a3b8;
    --border:     #334155;
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { 
    -webkit-text-size-adjust: 100%;
    /* Enable safe area support */
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    overflow-x: hidden;
    min-width: 0;
    /* Add top padding for mobile status bar */
    padding-top: env(safe-area-inset-top, 0px);
}
a { text-decoration: none; color: inherit; }
img, svg { max-width: 100%; }

/* ── NAVBAR ── */
.navbar {
    position: fixed; 
    top: 0; 
    left: 0; 
    right: 0;
    /* Account for mobile status bar */
    height: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--primary); color: #fff;
    display: flex; align-items: center;
    padding-left: 12px;
    padding-right: 12px;
    z-index: 1000;
    gap: 0; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    min-width: 0;
}
.nav-toggle {
    background: none; border: none; color: #fff;
    font-size: 20px; cursor: pointer;
    flex-shrink: 0; padding: 4px 8px;
    display: block; order: 1;
}
.nav-brand {
    font-size: 16px; font-weight: 700;
    flex: 1; text-align: center;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    min-width: 0; order: 2;
}
.nav-brand i { margin-right: 6px; }
.nav-user {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; flex-shrink: 0; order: 3;
}
.nav-username { font-size: 12px; white-space: nowrap; }
.btn-logout {
    background: rgba(255,255,255,0.2);
    padding: 6px 10px; border-radius: 6px; color: #fff;
    flex-shrink: 0;
}
.btn-logout:hover { background: rgba(255,255,255,0.3); }
.btn-ikon {
    background: rgba(255,255,255,0.2);
    padding: 6px 10px; border-radius: 6px; color: #fff;
    flex-shrink: 0; display: flex; align-items: center; gap: 4px;
    font-size: 12px; font-weight: 600;
}
.btn-ikon:hover { background: rgba(255,255,255,0.35); }
.ikon-label { font-size: 11px; }
.dark-toggle {
    background: rgba(255,255,255,0.2); border: none;
    color: #fff; padding: 6px 10px; border-radius: 6px;
    cursor: pointer; font-size: 14px; flex-shrink: 0;
}

/* ── LAYOUT ── */
.layout {
    display: flex;
    /* Account for navbar + safe area */
    margin-top: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
    min-height: calc(100vh - var(--nav-h) - env(safe-area-inset-top, 0px));
    min-width: 0;
}

/* ── SIDEBAR OVERLAY (mobile backdrop) ── */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 850;
}

/* ── SIDEBAR ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--card);
    border-right: 1px solid var(--border);
    position: fixed; top: var(--nav-h); bottom: 0;
    overflow-y: auto; overflow-x: hidden;
    transition: transform 0.3s ease; z-index: 900;
    flex-shrink: 0;
}
.nav-menu { list-style: none; padding: 10px 0; }
.nav-menu li a {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 16px; color: var(--text-muted);
    transition: all 0.2s; border-left: 3px solid transparent;
    font-size: 13px; white-space: nowrap;
}
.nav-menu li a:hover,
.nav-menu li a.active {
    background: #eff6ff; color: var(--primary);
    border-left-color: var(--primary);
}
body.dark .nav-menu li a:hover,
body.dark .nav-menu li a.active { background: #1e3a5f; }
.nav-menu li a i { width: 18px; text-align: center; flex-shrink: 0; }

/* ── MAIN CONTENT ── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1; padding: 20px;
    min-width: 0; overflow-x: hidden;
}

/* ── CARDS ── */
.card {
    background: var(--card); border-radius: var(--radius);
    box-shadow: var(--shadow); border: 1px solid var(--border);
    padding: 16px; margin-bottom: 16px;
    min-width: 0; overflow: hidden;
}
.card-title {
    font-size: 15px; font-weight: 600;
    margin-bottom: 14px; color: var(--text);
}

/* ── STAT CARDS ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px; margin-bottom: 16px;
}
.stats-grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
.stats-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 600px) {
    .stats-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
    .stats-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
}
/* cols-3 पर mobile में last card full width */
.stats-grid.cols-3 > .stat-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
}
.stat-card {
    background: var(--card); border-radius: var(--radius);
    padding: 14px 10px; display: flex; flex-direction: column;
    align-items: center; text-align: center; gap: 8px;
    box-shadow: var(--shadow); border: 1px solid var(--border);
    min-width: 0; overflow: hidden;
}
.stat-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: #fff; flex-shrink: 0; order: 2;
}
.stat-icon.blue   { background: var(--primary); }
.stat-icon.green  { background: var(--secondary); }
.stat-icon.orange { background: var(--warning); }
.stat-icon.red    { background: var(--danger); }
.stat-card > div { order: 1; width: 100%; }
.stat-value { font-size: 18px; font-weight: 700; line-height: 1.2; word-break: break-all; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
table { width: 100%; border-collapse: collapse; min-width: 400px; }
th, td {
    padding: 9px 12px; text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
th { background: #f8fafc; font-weight: 600; font-size: 12px; color: var(--text-muted); }
body.dark th { background: #1a2744; }
tr:hover td { background: #f8fafc; }
body.dark tr:hover td { background: #1a2744; }

/* ── FORMS ── */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block; font-weight: 500;
    margin-bottom: 5px; font-size: 13px;
}
.form-control {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 7px; font-size: 14px;
    background: var(--card); color: var(--text);
    transition: border-color 0.2s;
    -webkit-appearance: none; appearance: none;
}
.form-control:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
select.form-control { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ── BUTTONS ── */
.btn {
    padding: 9px 16px; border-radius: 7px; border: none;
    cursor: pointer; font-size: 14px; font-weight: 500;
    display: inline-flex; align-items: center; gap: 6px;
    transition: all 0.2s; white-space: nowrap; flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-success  { background: var(--secondary); color: #fff; }
.btn-success:hover  { background: #059669; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: #dc2626; }
.btn-warning  { background: var(--warning); color: #fff; }
.btn-warning:hover  { background: #d97706; }
.btn-sm       { padding: 5px 10px; font-size: 12px; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover  { background: var(--bg); }

/* ── BADGES ── */
.badge { padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }

/* ── PAGE HEADER ── */
.page-header {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
}
.page-title { font-size: 18px; font-weight: 700; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── SEARCH BAR ── */
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.search-bar .form-control { flex: 1; min-width: 160px; max-width: 300px; }

/* ── ALERTS ── */
.alert {
    padding: 11px 14px; border-radius: 8px;
    margin-bottom: 14px; font-size: 13px;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── MODAL ── */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.55); z-index: 2000;
    align-items: flex-end; justify-content: center;
    padding: 0;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--card); border-radius: 16px 16px 0 0;
    padding: 20px; width: 100%; max-width: 520px;
    max-height: 92vh; overflow-y: auto;
    animation: slideUp 0.25s ease;
}
@keyframes slideUp {
    from { transform: translateY(60px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
    display: flex; justify-content: space-between;
    align-items: center; margin-bottom: 16px;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
    background: none; border: none; font-size: 22px;
    cursor: pointer; color: var(--text-muted);
    width: 32px; height: 32px; display: flex;
    align-items: center; justify-content: center;
    border-radius: 50%; flex-shrink: 0;
}
.modal-close:hover { background: var(--bg); }

/* ── MILK RECEIVER BUTTON ── */
.btn-receiver {
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff; border: none;
}
.btn-receiver:hover { background: linear-gradient(135deg, #059669, #047857); }

/* ── CALC BOX ── */
.calc-box {
    background: #f0fdf4; padding: 10px 14px;
    border-radius: 8px; margin-bottom: 14px;
    font-weight: 600; color: #065f46;
    min-height: 38px; font-size: 14px;
    border: 1px solid #a7f3d0;
}
body.dark .calc-box { background: #0d2b1e; color: #6ee7b7; border-color: #065f46; }

/* ── LOGIN PAGE ── */
.login-page {
    min-height: 100vh; display: flex;
    align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1d4ed8, #2563eb, #0ea5e9);
    padding: 16px;
}
.login-card {
    background: #fff; border-radius: 16px;
    padding: 32px 24px; width: 100%; max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo i { font-size: 44px; color: var(--primary); }
.login-logo h1 { font-size: 20px; font-weight: 700; margin-top: 8px; }
.login-logo p { color: var(--text-muted); font-size: 13px; }

/* ── PRINT ── */
@media print {
    .navbar, .sidebar, .btn, .no-print,
    .modal-overlay { display: none !important; }
    .main-content { margin-left: 0 !important; padding: 0 !important; }
    .card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
    table { min-width: unset; }
    th, td { white-space: normal; }
}

/* ══════════════════════════════════════════
   RESPONSIVE — TABLET (≤ 900px)
══════════════════════════════════════════ */
@media (max-width: 900px) {
    .nav-toggle { display: block; }
    .nav-username { display: none; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.15); }
    .sidebar-overlay.show { display: block; }
    .main-content { margin-left: 0; padding: 14px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════════════════
   RESPONSIVE — MOBILE (≤ 600px)
══════════════════════════════════════════ */
@media (max-width: 600px) {
    :root { --nav-h: 52px; }

    .nav-brand { font-size: 14px; }
    .nav-brand i { margin-right: 4px; }

    .main-content { padding: 10px; }

    /* Cards */
    .card { padding: 12px; border-radius: 8px; }
    .card-title { font-size: 14px; margin-bottom: 10px; }

    /* Stats */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
    .stat-card { padding: 10px; gap: 8px; }
    .stat-icon { width: 36px; height: 36px; font-size: 16px; border-radius: 8px; }
    .stat-value { font-size: 16px; }
    .stat-label { font-size: 10px; }

    /* Page header */
    .page-title { font-size: 16px; }
    .page-header { gap: 8px; }
    .page-header-actions { width: 100%; }
    .page-header-actions .btn { flex: 1; justify-content: center; }

    /* Forms */
    .form-row, .form-row-3 { grid-template-columns: 1fr; gap: 0; }
    .form-group { margin-bottom: 12px; }
    .form-control { font-size: 16px; /* prevent iOS zoom */ padding: 10px 12px; }

    /* Buttons */
    .btn { padding: 10px 14px; font-size: 13px; }
    .btn-sm { padding: 6px 10px; font-size: 12px; }

    /* Modal — full bottom sheet on mobile */
    .modal { border-radius: 16px 16px 0 0; padding: 16px; max-height: 95vh; }

    /* Tables */
    th, td { padding: 8px 10px; font-size: 12px; }

    /* Filter bar */
    .filter-bar { flex-direction: column; }
    .filter-bar .form-group { width: 100%; }
    .filter-bar .form-control { max-width: 100%; }

    /* Search bar */
    .search-bar .form-control { max-width: 100%; }

    /* Two-col grids → single col */
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"] {
        display: block !important;
    }
}

/* ══════════════════════════════════════════
   RESPONSIVE — SMALL MOBILE (≤ 380px)
══════════════════════════════════════════ */
@media (max-width: 380px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-value { font-size: 14px; }
    .btn { font-size: 12px; padding: 8px 10px; }
}
