/* ============================================
   DairyPro - Main Stylesheet
   Mobile-first, Clean & Professional
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- CSS Variables --- */
:root {
    --primary:        #0f7d4b;
    --primary-light:  #16a864;
    --primary-dark:   #0a5c37;
    --primary-bg:     #e8f7ef;
    --accent:         #f59e0b;
    --accent-dark:    #d97706;
    --danger:         #ef4444;
    --danger-bg:      #fef2f2;
    --info:           #3b82f6;
    --info-bg:        #eff6ff;
    --surface:        #ffffff;
    --surface-2:      #f8fafc;
    --surface-3:      #f1f5f9;
    --border:         #e2e8f0;
    --border-focus:   #0f7d4b;
    --text-1:         #0f172a;
    --text-2:         #475569;
    --text-3:         #94a3b8;
    --shadow-sm:      0 1px 3px rgba(0,0,0,.08);
    --shadow-md:      0 4px 16px rgba(0,0,0,.10);
    --shadow-lg:      0 8px 32px rgba(0,0,0,.12);
    --radius-sm:      8px;
    --radius-md:      12px;
    --radius-lg:      16px;
    --radius-xl:      24px;
    --font:           'Plus Jakarta Sans', sans-serif;
    --font-mono:      'JetBrains Mono', monospace;
    --sidebar-w:      260px;
    --header-h:       64px;
    --transition:     0.2s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--surface-2);
    color: var(--text-1);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }

/* ============================================
   AUTH PAGES (Login / Register)
   ============================================ */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #064e2e 0%, #0f7d4b 50%, #16a864 100%);
    position: relative;
    overflow: hidden;
}

.auth-page::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 40px 36px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
    animation: slideUp .4s ease;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

.auth-logo .logo-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 12px rgba(15,125,75,.3);
}

.auth-logo .logo-text {
    font-size: 26px;
    font-weight: 800;
    color: var(--text-1);
    letter-spacing: -0.5px;
}

.auth-logo .logo-sub {
    font-size: 12px;
    color: var(--text-3);
    font-weight: 500;
    margin-top: -4px;
}

.auth-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-1);
    margin-bottom: 6px;
}

.auth-subtitle {
    font-size: 14px;
    color: var(--text-2);
    margin-bottom: 28px;
}

/* ============================================
   APP LAYOUT
   ============================================ */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-w);
    background: #0a1f14;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 200;
    transition: transform var(--transition);
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.07);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo .s-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-logo .s-name {
    font-size: 18px;
    font-weight: 800;
    color: #f8fafc;
    letter-spacing: -.3px;
}

.sidebar-shop {
    margin-top: 10px;
    padding: 10px 12px;
    background: rgba(255,255,255,.06);
    border-radius: var(--radius-sm);
}

.sidebar-shop .shop-label {
    font-size: 10px;
    color: var(--text-3);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.sidebar-shop .shop-name {
    font-size: 14px;
    font-weight: 600;
    color: #e2e8f0;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    padding: 16px 12px;
    flex: 1;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,.25);
    padding: 0 8px;
    margin: 16px 0 6px;
}

.nav-section-label:first-child { margin-top: 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,.6);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.nav-item:hover {
    background: rgba(255,255,255,.08);
    color: #f8fafc;
}

.nav-item.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    box-shadow: 0 2px 8px rgba(15,125,75,.4);
}

.nav-item .n-icon { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-item .n-text { flex: 1; }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,.07);
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(239,68,68,.12);
    color: #fca5a5;
    border: none;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
}

.logout-btn:hover { background: rgba(239,68,68,.22); color: #f87171; }

/* --- Top Header --- */
.top-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-2);
    padding: 4px;
}

.header-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-1);
    flex: 1;
}

.header-date {
    font-size: 12px;
    color: var(--text-3);
    font-family: var(--font-mono);
}

/* --- Main Content --- */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.page-body {
    padding: 24px 20px;
    flex: 1;
}

/* ============================================
   COMPONENTS
   ============================================ */

/* --- Form Elements --- */
.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    color: var(--text-1);
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(15,125,75,.12);
}

.form-control::placeholder { color: var(--text-3); }

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 d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    border: none;
    transition: all var(--transition);
    white-space: nowrap;
    min-height: 44px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    box-shadow: 0 2px 8px rgba(15,125,75,.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(15,125,75,.4); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--surface-3);
    color: var(--text-2);
    border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1.5px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }

.btn-accent { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #fff; }

.btn-sm { padding: 7px 12px; font-size: 12px; min-height: 34px; }
.btn-full { width: 100%; }
.btn-icon { padding: 8px; min-height: 36px; }

/* --- Cards --- */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-1);
}

.card-body { padding: 20px; }

/* --- Stat Cards --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 18px 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 60px; height: 60px;
    border-radius: 0 0 0 60px;
    opacity: .06;
}

.stat-card.green::after  { background: var(--primary); }
.stat-card.amber::after  { background: var(--accent); }
.stat-card.blue::after   { background: var(--info); }
.stat-card.red::after    { background: var(--danger); }

.stat-icon {
    font-size: 22px;
    margin-bottom: 10px;
    display: block;
}

.stat-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-1);
    line-height: 1.2;
    font-family: var(--font-mono);
}

.stat-label {
    font-size: 12px;
    color: var(--text-3);
    font-weight: 500;
    margin-top: 3px;
}

.stat-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 20px;
    margin-top: 6px;
}

.badge-green { background: var(--primary-bg); color: var(--primary); }
.badge-amber { background: #fef3c7; color: var(--accent-dark); }
.badge-red   { background: var(--danger-bg); color: var(--danger); }
.badge-blue  { background: var(--info-bg); color: var(--info); }
.badge-gray  { background: var(--surface-3); color: var(--text-2); }

/* --- Tables --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-3);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-1);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }

.data-table .actions { display: flex; gap: 6px; }

/* --- Badges / Pills --- */
.pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.pill-green  { background: var(--primary-bg); color: var(--primary-dark); }
.pill-amber  { background: #fef3c7; color: #92400e; }
.pill-red    { background: var(--danger-bg); color: #991b1b; }
.pill-blue   { background: var(--info-bg); color: #1e40af; }
.pill-gray   { background: var(--surface-3); color: var(--text-2); }

/* --- Toast Notifications --- */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: var(--radius-md);
    background: var(--text-1);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    max-width: 320px;
    animation: toastIn .3s ease;
    pointer-events: all;
}

.toast.success { background: var(--primary-dark); }
.toast.error   { background: #991b1b; }
.toast.info    { background: #1e40af; }
.toast.warning { background: #92400e; }

.toast-icon { font-size: 16px; flex-shrink: 0; }

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 500;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(40px);
    transition: transform var(--transition);
}

.modal-overlay.open .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.modal-title { font-size: 17px; font-weight: 700; }

.modal-close {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--surface-3);
    border: none;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-2);
}

.modal-body { padding: 20px; }

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-3);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .empty-title { font-size: 15px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.empty-state .empty-desc { font-size: 13px; }

/* --- Section Header --- */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.section-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-1);
}

/* --- Divider --- */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* --- Overlay for mobile sidebar --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 199;
}

/* --- Loading spinner --- */
.spinner {
    width: 20px; height: 20px;
    border: 2.5px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    display: inline-block;
}

/* --- Calc display --- */
.calc-display {
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-top: 8px;
}

.calc-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-2);
    padding: 2px 0;
}

.calc-total {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-1);
    padding-top: 8px;
    margin-top: 8px;
    border-top: 1.5px solid var(--border);
}

/* --- Chart wrapper --- */
.chart-wrap {
    padding: 16px;
    height: 200px;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    border-top: 1px solid var(--border);
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes slideUp  { from { opacity:0; transform:translateY(20px) } to { opacity:1; transform:none } }
@keyframes toastIn  { from { opacity:0; transform:translateX(30px) } to { opacity:1; transform:none } }
@keyframes spin     { to { transform:rotate(360deg) } }
@keyframes fadeIn   { from { opacity:0 } to { opacity:1 } }

.animate-in { animation: slideUp .3s ease; }

/* ============================================
   RESPONSIVE - MOBILE FIRST
   ============================================ */
@media (max-width: 768px) {
    :root { --header-h: 58px; }

    /* Sidebar hidden by default on mobile */
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay.open { display: block; }

    .menu-toggle { display: block; }

    .main-content { margin-left: 0; }

    .page-body { padding: 16px 14px; }

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

    .stat-card { padding: 14px 12px; }
    .stat-value { font-size: 20px; }

    .form-row { grid-template-columns: 1fr; gap: 0; }

    .auth-card { padding: 28px 22px; }

    #toast-container { left: 12px; right: 12px; bottom: 16px; }
    .toast { max-width: 100%; }

    .modal { border-radius: var(--radius-xl) var(--radius-xl) 0 0; }

    .data-table th, .data-table td { padding: 10px 10px; }

    .header-date { display: none; }
}

@media (max-width: 420px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-value { font-size: 18px; }
}

/* --- Utility --- */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-3); }
.text-danger { color: var(--danger); }
.text-success { color: var(--primary); }
.text-mono   { font-family: var(--font-mono); }
.fw-700      { font-weight: 700; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.hidden { display: none !important; }
