:root {
    --font-base: 'DM Sans', sans-serif;
    --color-bg: #f3f6f5;
    --color-surface: #fff;
    --color-text: #273532;
    --color-text-muted: #71817d;
    --color-heading: #172622;
    --color-primary: #167d68;
    --color-primary-dark: #106653;
    --color-secondary: #b87828;
    --color-danger: #bf4242;
    --color-border: #dfe8e4;
    --sidebar-width: 250px;
    --topbar-height: 64px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font: 14px/1.5 var(--font-base);
}

h1, h2, h3, h4, h5, h6 { color: var(--color-heading); font-family: var(--font-base); }
a { color: var(--color-primary); }
a:hover, a:focus { color: var(--color-primary-dark); }

/* Application frame and role-aware navigation */
.app-sidebar {
    position: fixed;
    z-index: 1200;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--sidebar-width);
    overflow-x: hidden;
    overflow-y: auto;
    padding-top: 16px;
    background: #172b26;
    color: #fff;
    transition: width .2s ease, transform .2s ease;
}

.app-sidebar-header { display: flex; align-items: center; justify-content: center; }
.app-sidebar .brand {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 12px 20px;
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0;
    text-decoration: none;
}
.brand-logo { display: block; width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%; object-fit: cover; }
.brand-name { display: block; white-space: nowrap; }
.sidebar-section-label {
    display: block;
    padding: 13px 20px 6px;
    color: #a9c4b9;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    list-style: none;
    text-transform: uppercase;
}
.app-sidebar .nav-link {
    display: flex;
    min-height: 42px;
    align-items: center;
    gap: 11px;
    padding: 10px 20px;
    border-left: 3px solid transparent;
    color: #d1ded8;
    font-size: 13px;
    text-decoration: none;
    transition: background .15s ease, color .15s ease;
}
.app-sidebar .nav-link i { width: 18px; flex: 0 0 18px; text-align: center; }
.app-sidebar .nav-link:hover,
.app-sidebar .nav-link.active {
    border-left-color: #e0aa57;
    background: rgba(255,255,255,.08);
    color: #fff;
}
.nav-group details { margin: 0; }
.nav-group summary { cursor: pointer; list-style: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-summary { justify-content: space-between; }
.nav-summary-link { color: inherit; text-decoration: none; }
.nav-summary-link:hover, .nav-summary-link:focus { color: #fff; text-decoration: none; }
.nav-summary .fa-angle-down { transition: transform .2s ease; }
.nav-group details[open] > .nav-summary .fa-angle-down { transform: rotate(180deg); }
.nav-submenu { display: flex; flex-direction: column; gap: 2px; padding: 0 0 8px 16px; }
.nav-submenu .sub-link { min-height: 36px; padding: 8px 16px; font-size: 12px; }
.nav-subgroup { padding-left: 4px; }
.nav-subgroup summary.sub-summary { padding: 8px 16px; color: #d1ded8; font-size: 12px; list-style: none; }
.nav-submenu-inner { display: flex; flex-direction: column; padding-left: 10px; }
.nav-submenu-inner .inner-link { min-height: 32px; padding: 6px 12px; font-size: 11px; }

.app-topbar {
    position: fixed;
    z-index: 1300;
    top: 0;
    right: 0;
    left: var(--sidebar-width);
    display: flex;
    height: var(--topbar-height);
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    box-shadow: 0 2px 10px rgba(23,43,38,.03);
    transition: left .2s ease;
}
.topbar-heading { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-heading h4 { overflow: hidden; font-size: 17px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user-actions { display: flex; align-items: center; gap: 16px; }
.topbar-notification-toggle { position: relative; display: inline-flex !important; width: 38px; height: 38px; align-items: center; justify-content: center; border: 1px solid var(--color-border); border-radius: 5px; color: var(--color-heading); font-size: 16px; }
.topbar-notification-toggle:hover { border-color: var(--color-primary); color: var(--color-primary); }
.notification-count { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: #c74336; color: #fff; font-size: 10px; line-height: 18px; text-align: center; }
.notification-menu { width: 320px; max-width: calc(100vw - 24px); padding: 0; }
.notification-menu-heading, .notification-empty { display: block; padding: 12px 16px; color: var(--color-text-muted); }
.notification-menu-heading { border-bottom: 1px solid var(--color-border); color: var(--color-heading); font-weight: 700; }
.notification-menu .notification-menu-item { display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; white-space: normal; }
.notification-menu-item span, .notification-menu-item small { color: var(--color-text-muted); line-height: 1.4; }
.notification-menu .notification-view-all { border-top: 1px solid var(--color-border); color: var(--color-primary); font-weight: 600; text-align: center; }
.app-nav-toggle {
    display: inline-flex;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: 5px;
    background: #fff;
    color: var(--color-heading);
    cursor: pointer;
    font-size: 16px;
}
.app-nav-toggle:hover { border-color: var(--color-primary); color: var(--color-primary); }
.app-content {
    margin-left: var(--sidebar-width);
    padding: calc(var(--topbar-height) + 24px) 24px 40px;
    transition: margin-left .2s ease;
}

.sidebar-collapsed .app-sidebar { width: 72px; }
.sidebar-collapsed .app-sidebar .brand { justify-content: center; padding-right: 0; padding-left: 0; }
.sidebar-collapsed .app-sidebar .brand-name { display: none; }
.sidebar-collapsed .app-sidebar .brand-logo { width: 38px; height: 38px; flex-basis: 38px; }
.sidebar-collapsed .sidebar-section-label,
.sidebar-collapsed .app-sidebar .nav-submenu { display: none; }
.sidebar-collapsed .app-sidebar .nav-summary > .fa-angle-down { display: none; }
.sidebar-collapsed .app-sidebar nav { font-size: 0; }
.sidebar-collapsed .app-sidebar .nav-link { justify-content: center; gap: 0; padding-right: 8px; padding-left: 8px; font-size: 0; }
.sidebar-collapsed .app-sidebar .nav-link i { font-size: 17px; }
.sidebar-collapsed .app-topbar { left: 72px; }
.sidebar-collapsed .app-content { margin-left: 72px; }

/* Shared page components */
.stat-card, .panel-card {
    padding: 20px;
    border: 1px solid var(--color-border);
    border-radius: 5px;
    background: var(--color-surface);
}
.stat-card .stat-value { color: var(--color-heading); font-size: 27px; font-weight: 700; }
.stat-card .stat-label { color: var(--color-text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.stat-card.accent-primary { border-top: 3px solid var(--color-primary); }
.stat-card.accent-secondary { border-top: 3px solid var(--color-secondary); }
.stat-card.accent-success { border-top: 3px solid #39825b; }
.stat-card.accent-warning { border-top: 3px solid #d39a43; }
.stat-card.accent-danger { border-top: 3px solid var(--color-danger); }
.btn-farm-primary {
    padding: 9px 18px;
    border: 1px solid var(--color-primary);
    border-radius: 5px;
    background: var(--color-primary);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}
.btn-farm-primary:hover, .btn-farm-primary:focus { border-color: var(--color-primary-dark); background: var(--color-primary-dark); color: #fff; }
.form-control { min-height: 40px; border: 1px solid var(--color-border); border-radius: 5px; box-shadow: none; }
.form-control:focus { border-color: var(--color-primary); box-shadow: 0 0 0 2px rgba(22,125,104,.1); }
label { color: var(--color-heading); font-weight: 600; }
.table { background: #fff; }
.table > thead > tr > th { border-bottom: 1px solid var(--color-border); color: var(--color-text-muted); font-size: 11px; text-transform: uppercase; }
.table > tbody > tr > td { vertical-align: middle; }
.table-striped > tbody > tr:nth-of-type(odd) { background: #f8faf9; }
.badge-status-active { background: #39825b; color: #fff; }
.badge-status-warning { background: #c58b36; color: #fff; }
.badge-status-danger { background: var(--color-danger); color: #fff; }
.badge-status-idle { background: #8b9994; color: #fff; }

.dashboard-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.dashboard-header h3 { margin: 0; color: var(--color-heading); font-size: 25px; font-weight: 700; }
.dashboard-intro { max-width: 560px; margin: 8px 0 0; color: var(--color-text-muted); font-size: 13px; }
.eyebrow { margin: 0 0 6px; color: var(--color-primary); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.header-actions, .toolbar-controls, .quick-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.summary-card { display: flex; min-height: 140px; flex-direction: column; justify-content: center; }
.stat-meta { margin-top: 8px; color: var(--color-text-muted); font-size: 12px; }
.dashboard-panel { box-shadow: 0 5px 18px rgba(23,43,38,.035); }
.panel-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.panel-heading-row h5 { margin: 0; color: var(--color-heading); font-weight: 700; }
.flock-summary-card { height: 100%; }
.flock-summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 12px 0; }
.flock-summary-grid div { display: flex; flex-direction: column; }
.flock-summary-grid span { color: var(--color-text-muted); font-size: 11px; }
.flock-summary-grid strong { color: var(--color-heading); font-size: 18px; }
.dashboard-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; padding: 14px 16px; border: 1px solid var(--color-border); border-radius: 5px; background: #fff; }
.toolbar-label { color: var(--color-text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.filter-pill, .action-pill { display: inline-flex; min-height: 36px; align-items: center; justify-content: center; padding: 7px 12px; border: 1px solid var(--color-border); border-radius: 5px; background: #fff; color: var(--color-text); font-size: 12px; font-weight: 600; text-decoration: none; }
.filter-pill.active, .filter-pill:hover, .action-pill:hover { border-color: var(--color-primary); background: var(--color-primary); color: #fff; text-decoration: none; }
.group-switcher { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.action-pill { min-height: 40px; }
.data-table th, .data-table td { vertical-align: middle; }
.chart-wrap { position: relative; width: 100%; height: 300px; }
.donut-wrap { height: 230px; }
.financial-comparison-chart { display: flex; flex-direction: column; gap: 12px; }
.financial-comparison-chart h5 { margin-bottom: 2px !important; }
.financial-bar-row { display: grid; grid-template-columns: 82px minmax(0, 1fr) minmax(115px, auto); align-items: center; gap: 12px; color: var(--color-text-muted); font-size: 12px; }
.financial-bar-row strong { color: var(--color-heading); text-align: right; }
.financial-bar-track { height: 16px; overflow: hidden; border-radius: 3px; background: #edf2ef; }
.financial-bar { height: 100%; min-width: 0; border-radius: inherit; transition: width .25s ease; }
.financial-bar.sales-bar { background: var(--color-primary); }
.financial-bar.expenses-bar { background: var(--color-secondary); }
.expense-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.expense-row { display: grid; min-height: 30px; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.feed-list { margin: 0; padding: 0; list-style: none; }
.feed-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--color-border); }
.feed-list li:last-child { border-bottom: 0; }
.feed-list li > div { display: flex; flex: 1; flex-direction: column; }
.feed-list small, .empty-item { color: var(--color-text-muted); }
.feed-dot, .legend-dot { display: inline-block; width: 10px; height: 10px; flex: 0 0 10px; border-radius: 50%; background: var(--color-primary); }
.expense-dot { background: var(--color-secondary); }
.egg-stock-summary { display: flex; flex-direction: column; gap: 3px; margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--color-border); }
.egg-stock-summary span { color: var(--color-text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.egg-stock-summary strong { color: var(--color-primary); font-size: 24px; }
.egg-stock-summary small { color: var(--color-text-muted); }
.sales-entry-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20px; row-gap: 2px; }
.sales-entry-form .form-group { min-width: 0; margin-bottom: 14px; }
.sales-entry-form .sales-notes-group, .sales-entry-form .sales-form-submit { grid-column: 1 / -1; }
.sales-form-submit { justify-self: start; }
.health-entry-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20px; row-gap: 2px; }
.health-entry-form .form-group { min-width: 0; margin-bottom: 14px; }
.health-entry-form .health-notes-group, .health-entry-form .health-form-submit { grid-column: 1 / -1; }
.health-form-submit { justify-self: start; }
.flock-statement-form { margin-top: 16px; }
.flock-statement-form h5 { margin: 0 0 12px; }
.flock-statement-fields { display: grid; grid-template-columns: repeat(2, minmax(160px, 1fr)) auto; align-items: end; gap: 14px; }
.flock-statement-fields .form-group { margin-bottom: 0; }
.flock-statement-fields .btn { white-space: nowrap; }
.empty-item { padding-top: 18px; }

.hatchery-stats { margin-bottom: 14px; }
.hatchery-menu { margin-bottom: 20px; }
.hatchery-menu .filter-pill { display: inline-flex; align-items: center; gap: 7px; }
.hatchery-overview-note { box-shadow: 0 5px 18px rgba(23,43,38,.035); }
.hatchery-overview-note h5 { margin: 0 0 8px; color: var(--color-heading); font-weight: 700; }
.hatchery-overview-note p { margin-bottom: 16px; color: var(--color-text-muted); font-size: 13px; }
.hatchery-stats .stat-card { min-height: 132px; margin-bottom: 10px; }
.hatchery-stats .stat-value { font-size: clamp(18px, 2vw, 27px); overflow-wrap: anywhere; }
.hatchery-report-filter { display: grid; grid-template-columns: repeat(2, minmax(160px, 1fr)) auto; align-items: end; gap: 14px; margin-bottom: 20px; }
.hatchery-report-filter .form-group { margin-bottom: 0; }
.hatchery-report-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hatchery-report-stats { margin-bottom: 18px; }
.hatchery-report-stats .stat-card { min-height: 105px; margin-bottom: 10px; }
.hatchery-report-stats .stat-value { font-size: clamp(17px, 1.8vw, 24px); overflow-wrap: anywhere; }
.hatchery-panel { margin-bottom: 20px; box-shadow: 0 5px 18px rgba(23,43,38,.035); }
.hatchery-panel .panel-heading-row { align-items: flex-start; }
.hatchery-panel .panel-heading-row h5 { margin: 0; color: var(--color-heading); font-weight: 700; }
.hatchery-panel .eyebrow { margin-bottom: 5px; }
.hatchery-section-note { color: var(--color-text-muted); font-size: 12px; }
.hatchery-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 18px; row-gap: 2px; }
.hatchery-form .form-group { min-width: 0; margin-bottom: 14px; }
.hatchery-form-wide { grid-column: 1 / -1; }
.hatchery-empty-note { margin: 0; padding: 14px; border-radius: 5px; background: #f5f8f6; color: var(--color-text-muted); }
.hatchery-cell-meta { display: block; margin-top: 3px; color: var(--color-text-muted); }
.hatchery-total { color: var(--color-heading); font-size: 13px; }
.hatchery-expense-help { display: block; margin: -8px 0 16px; }
.hatchery-expense-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; padding: 10px 12px; border-radius: 5px; background: #f5f8f6; color: var(--color-text-muted); font-size: 12px; }
.hatchery-expense-summary strong { color: var(--color-heading); font-size: 14px; }

@media (max-width: 991px) {
    :root { --sidebar-width: 220px; }
    .app-content { padding-right: 18px; padding-left: 18px; }
}

@media (max-width: 767px) {
    .app-sidebar { width: min(290px, calc(100vw - 48px)); transform: translateX(-105%); box-shadow: 18px 0 40px rgba(13,35,29,.18); }
    .sidebar-mobile-open .app-sidebar { transform: translateX(0); }
    .sidebar-mobile-open::after { position: fixed; z-index: 1100; inset: 0; background: rgba(18,35,30,.38); content: ''; }
    .app-topbar { left: 0; padding: 0 14px; }
    .topbar-user-actions { gap: 8px; }
    .topbar-user-actions > .dropdown:last-child > .dropdown-toggle { display: inline-block; max-width: min(42vw, 190px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
    .notification-menu { right: -4px; width: min(320px, calc(100vw - 20px)); }
    .app-content, .sidebar-collapsed .app-content { margin-left: 0; padding: calc(var(--topbar-height) + 18px) 14px 28px; }
    .sidebar-collapsed .app-topbar { left: 0; }
    .dashboard-header, .dashboard-toolbar { align-items: flex-start; flex-direction: column; }
    .dashboard-header h3 { font-size: 22px; }
    .sales-entry-form { grid-template-columns: minmax(0, 1fr); }
    .sales-entry-form .sales-notes-group, .sales-entry-form .sales-form-submit { grid-column: 1; }
    .health-entry-form { grid-template-columns: minmax(0, 1fr); }
    .health-entry-form .health-notes-group, .health-entry-form .health-form-submit { grid-column: 1; }
    .flock-statement-fields { grid-template-columns: minmax(0, 1fr); }
    .flock-statement-fields .btn { justify-self: start; }
    .header-actions, .toolbar-controls { width: 100%; }
    .header-actions .btn, .filter-pill { flex: 1 1 auto; }
    .hatchery-form { grid-template-columns: minmax(0, 1fr); }
    .hatchery-form-wide { grid-column: 1; }
    .hatchery-report-filter { grid-template-columns: minmax(0, 1fr); }
    .hatchery-panel .panel-heading-row { flex-direction: column; }
    .hatchery-menu .filter-pill { flex: 1 1 calc(50% - 8px); }
    .nav-submenu-inner { grid-template-columns: 1fr; }
    .financial-bar-row { grid-template-columns: 70px minmax(0, 1fr); gap: 8px; }
    .financial-bar-row strong { grid-column: 2; text-align: left; }
}

@media (max-width: 380px) {
    .app-topbar { padding-right: 10px; padding-left: 10px; }
    .topbar-heading { gap: 8px; }
    .topbar-heading h4 { max-width: 32vw; font-size: 15px; }
    .topbar-user-actions { gap: 6px; }
    .topbar-user-actions > .dropdown:last-child > .dropdown-toggle { max-width: 34vw; font-size: 12px; }
}