*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --sidebar-width: 270px;
    --navbar-height: 64px;
    --dairy-primary: #2d6a4f;
    --dairy-primary-light: #40916c;
    --dairy-primary-pale: #d8f3dc;
    --dairy-primary-dark: #1b4332;
    --dairy-accent: #52b788;
    --dairy-bg: #f1f5f9;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(45, 106, 79, 0.22);
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--dairy-bg);
    color: #1e293b;
    font-size: 14px;
    min-height: 100vh;
}

/* ====== Enlistment-style Left Slider Bar ====== */
#sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    max-height: 100vh;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, #111827 100%);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1030;
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

#sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-brand {
    padding: 1rem 1.15rem;
    height: var(--navbar-height);
    min-height: var(--navbar-height);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.sidebar-brand .brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--dairy-primary), var(--dairy-primary-dark));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(45, 106, 79, 0.35);
}

.sidebar-brand .brand-text {
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.2;
}

.sidebar-brand .brand-text small {
    display: block;
    font-weight: 400;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 0.15rem;
}

/* Sidebar Nav Scrollable Area */
.sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0.65rem 1.5rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(82, 183, 136, 0.45) rgba(0, 0, 0, 0.2);
    -webkit-overflow-scrolling: touch;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(82, 183, 136, 0.45);
    border-radius: 6px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(82, 183, 136, 0.75);
}

.sidebar-footer {
    flex-shrink: 0;
    background: rgba(15, 23, 42, 0.95);
}

.nav-section-label {
    padding: 0.45rem 0.75rem 0.35rem;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.35);
    font-weight: 700;
}

.sidebar-nav .nav-item .nav-link {
    color: var(--sidebar-text);
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.15rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
    text-decoration: none;
    border-left: 3px solid transparent;
}

.sidebar-nav .nav-item .nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-nav .nav-item .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
    border-left-color: var(--dairy-accent);
}

.sidebar-nav .nav-link i {
    font-size: 0.95rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.9;
    transition: color 0.15s ease;
}

.sidebar-nav .nav-item .nav-link.active i {
    color: var(--dairy-accent);
}

/* Sidebar User Footer */
.sidebar-footer {
    padding: 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-footer .user-info {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.65rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--sidebar-text);
}

.sidebar-footer .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--dairy-primary), var(--dairy-primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: #fff;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-footer .user-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
}

.sidebar-footer .user-role {
    font-size: 0.68rem;
    color: rgba(255, 255, 255, 0.55);
}

/* ====== Main Content Layout ====== */
#main-content {
    margin-left: var(--sidebar-width);
    transition: margin-left 0.25s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

/* ====== Top Navbar ====== */
.top-navbar {
    height: var(--navbar-height);
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 1020;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.top-navbar .btn-toggle-sidebar {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    width: 40px;
    height: 40px;
    padding: 0;
    color: #334155;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.top-navbar .btn-toggle-sidebar:hover {
    background: #f1f5f9;
    color: var(--dairy-primary);
    border-color: #cbd5e1;
}

.top-navbar .breadcrumb {
    margin: 0;
    font-size: 0.82rem;
}

.top-navbar .breadcrumb-item + .breadcrumb-item::before {
    color: #9ca3af;
}

.top-navbar .breadcrumb-item a {
    color: var(--dairy-primary);
    text-decoration: none;
    font-weight: 500;
}

.top-navbar .breadcrumb-item.active {
    color: #374151;
    font-weight: 600;
}

/* ====== Page Content ====== */
.page-content {
    padding: 1.5rem;
    flex: 1;
}

/* ====== Site Footer ====== */
.site-footer {
    background: #fff;
    border-top: 1px solid #e2e8f0;
    padding: 0.85rem 1.25rem;
    font-size: 0.75rem;
    color: #64748b;
}

.site-footer strong {
    color: var(--dairy-primary-dark);
}

/* ====== Overlay ====== */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 1025;
    backdrop-filter: blur(2px);
}

#sidebar-overlay.show {
    display: block;
}

/* Responsive Behavior */
@media (max-width: 991.98px) {
    #sidebar {
        transform: translateX(calc(-1 * var(--sidebar-width)));
    }

    #sidebar.show {
        transform: translateX(0);
    }

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

body.sidebar-open {
    overflow: hidden;
}


/* ── KPI Cards ── */
.kpi-card {
    background: #fff;
    border-radius: 0.875rem;
    border: 1px solid #e8ede9;
    box-shadow: 0 2px 8px rgba(45,106,79,0.06);
    overflow: hidden;
    height: 100%;
    transition: transform 0.2s, box-shadow 0.2s;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(45,106,79,0.12);
}

.kpi-card-bar {
    height: 4px;
    width: 100%;
}

.kpi-card-body {
    padding: 1.25rem 1.25rem 1.1rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.kpi-card-left {
    flex: 1;
    min-width: 0;
}

.kpi-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    margin-bottom: 0.35rem;
}

.kpi-value {
    font-size: 1.65rem;
    font-weight: 800;
    color: #1a2e1f;
    line-height: 1.15;
    margin-bottom: 0.3rem;
    word-break: break-all;
}

.kpi-trend {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 50px;
}

.kpi-trend-up   { background: #dcfce7; color: #16a34a; }
.kpi-trend-down { background: #fee2e2; color: #dc2626; }

.kpi-sub {
    font-size: 0.72rem;
    color: #94a3b8;
    margin-top: 0.2rem;
}

.kpi-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

/* Legacy compat */
.dairy-stat-card { background: #fff; border-radius: 0.75rem; padding: 1.25rem; border: 1px solid #e2e8e4; box-shadow: 0 1px 3px rgba(45,106,79,0.05); height: 100%; }
.dairy-stat-icon { width: 48px; height: 48px; border-radius: 0.625rem; display: flex; align-items: center; justify-content: center; font-size: 1.35rem; }
.dairy-stat-value { font-size: 1.75rem; font-weight: 700; color: var(--dairy-primary-dark); line-height: 1.2; }
.dairy-stat-label { font-size: 0.8rem; color: #64748b; font-weight: 500; }

/* Page header */
.dairy-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.dairy-page-header h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--dairy-primary-dark);
    margin: 0;
}

/* Cards */
.dairy-card {
    background: #fff;
    border-radius: 0.75rem;
    border: 1px solid #e2e8e4;
    box-shadow: 0 1px 3px rgba(45, 106, 79, 0.05);
}

.dairy-card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e2e8e4;
    font-weight: 600;
    color: var(--dairy-primary-dark);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dairy-card-body {
    padding: 1.25rem;
}

/* Buttons */
.btn-dairy {
    background-color: var(--dairy-primary);
    border-color: var(--dairy-primary);
    color: #fff;
}

.btn-dairy:hover,
.btn-dairy:focus {
    background-color: var(--dairy-primary-dark);
    border-color: var(--dairy-primary-dark);
    color: #fff;
}

.btn-dairy-outline {
    color: var(--dairy-primary);
    border-color: var(--dairy-primary);
}

.btn-dairy-outline:hover {
    background-color: var(--dairy-primary);
    border-color: var(--dairy-primary);
    color: #fff;
}

/* Tables */
.dairy-table thead th {
    background-color: var(--dairy-primary-pale);
    color: var(--dairy-primary-dark);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 2px solid var(--dairy-primary-light);
    white-space: nowrap;
}

.dairy-table tbody tr:hover {
    background-color: rgba(216, 243, 220, 0.35);
}

/* Forms */
.form-control:focus,
.form-select:focus {
    border-color: var(--dairy-primary-light);
    box-shadow: 0 0 0 0.2rem rgba(64, 145, 108, 0.2);
}

/* Alerts */
.dairy-alert {
    border-radius: 0.625rem;
    border: none;
    padding: 0.875rem 1.125rem;
}

/* Tabs */
.nav-tabs-dairy .nav-link {
    color: #64748b;
    border: none;
    border-bottom: 2px solid transparent;
    font-weight: 500;
    padding: 0.75rem 1.25rem;
}

.nav-tabs-dairy .nav-link.active {
    color: var(--dairy-primary);
    border-bottom-color: var(--dairy-primary);
    background: transparent;
}

/* Badge */
.badge-dairy {
    background-color: var(--dairy-primary-pale);
    color: var(--dairy-primary-dark);
}

/* Milk entry grid */
.milk-entry-table input[type="number"] {
    width: 80px;
    text-align: center;
    padding: 0.35rem;
}

.milk-entry-table .cow-name {
    font-weight: 600;
    color: var(--dairy-primary-dark);
}

.milk-entry-totals {
    background: var(--dairy-primary-pale);
    font-weight: 700;
}

/* Guest layout */
.dairy-guest-bg {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--dairy-primary-dark) 0%, var(--dairy-primary) 50%, var(--dairy-primary-light) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.dairy-guest-card {
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    overflow: clip;
    max-width: 440px;
    width: 100%;
}

.dairy-guest-header {
    background: var(--dairy-primary-pale);
    padding: 2rem 2rem 1.5rem;
    text-align: center;
}

.dairy-guest-header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--dairy-primary-dark);
    margin: 0.5rem 0 0;
}

.dairy-guest-body {
    padding: 2rem;
}

/* Pagination override */
.pagination .page-link {
    color: var(--dairy-primary);
}

.pagination .page-item.active .page-link {
    background-color: var(--dairy-primary);
    border-color: var(--dairy-primary);
}

/* Chart containers */
.chart-container {
    position: relative;
    height: 280px;
}
