* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }

.layout { display: flex; min-height: 100vh; }

.sidebar { width: 220px; background: #1a1a2e; color: #e0e0e0; padding: 1rem; display: flex; flex-direction: column; gap: 0.25rem; flex-shrink: 0; }
.sidebar .brand { font-size: 1.4rem; font-weight: 700; color: #fff; margin-bottom: 1.5rem; padding-bottom: 0.75rem; border-bottom: 1px solid #333; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.6rem; line-height: 1; cursor: pointer; padding: 0; }
/* Desktop hide/show of the whole sidebar (#37). Hidden by default so they never appear on
   mobile — the desktop rules that show them live in the min-width:769px block below. */
.nav-hide { display: none; }
.nav-show { display: none; }
.sidebar .nav-link { color: #b0b0c0; text-decoration: none; padding: 0.5rem 0.75rem; border-radius: 6px; display: block; }
.sidebar .nav-link:hover { background: #2a2a4a; color: #fff; }
.sidebar-footer { margin-top: auto; padding-top: 1rem; border-top: 1px solid #333; }
.sidebar-footer .user-name { display: block; color: #888; font-size: 0.85rem; padding: 0.25rem 0.75rem; }
.sidebar-footer .sidebar-version { display: block; color: #666; font-size: 0.72rem; line-height: 1.3; padding: 0.5rem 0.75rem 0; }

.content { flex: 1; padding: 1.5rem 2rem; background: #f5f6fa; overflow-y: auto; }

h1 { margin-bottom: 1rem; }
h2 { margin: 1.5rem 0 0.75rem; }

a { color: #0052cc; }
a:hover { text-decoration: underline; }

.table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin: 1rem 0; }
.table th, .table td { padding: 0.6rem 1rem; text-align: left; border-bottom: 1px solid #eee; }
.table th { background: #f8f9fa; font-weight: 600; font-size: 0.85rem; color: #555; text-transform: uppercase; letter-spacing: 0.03em; }
.table tbody tr:hover { background: #f0f4ff; }

.btn { display: inline-block; padding: 0.45rem 1rem; border: none; border-radius: 6px; cursor: pointer; font-size: 0.9rem; text-decoration: none; color: #fff; }
.btn-primary { background: #0052cc; }
.btn-primary:hover { background: #003d99; }
.btn-secondary { background: #0891b2; }
.btn-secondary:hover { background: #0670a0; }
.btn-success { background: #16a34a; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: #dc3545; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

.card { background: #fff; border-radius: 8px; padding: 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin: 1rem 0; }

.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.25rem; color: #333; }
.form-control { width: 100%; padding: 0.4rem 0.6rem; border: 1px solid #ccc; border-radius: 4px; font-size: 0.9rem; }
.form-control:focus { outline: none; border-color: #0052cc; box-shadow: 0 0 0 2px rgba(0,82,204,0.2); }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

.text-danger { color: #dc3545; }
.validation-summary-errors ul { color: #dc3545; margin: 0.5rem 0; padding-left: 1.25rem; }

.status-badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 12px; font-size: 0.8rem; font-weight: 600; }
.status-empty { background: #e8f5e9; color: #2e7d32; }
.status-inplacement { background: #e3f2fd; color: #1565c0; }
.status-maintenance { background: #fff3e0; color: #e65100; }
.status-active { background: #e3f2fd; color: #1565c0; }
.status-catching { background: #fff3e0; color: #e65100; }
.status-completed { background: #f5f5f5; color: #757575; }
.status-planned { background: #e8eaf6; color: #3949ab; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1rem; }
.detail-card { background: #fff; border-radius: 8px; padding: 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.detail-card h3 { margin-bottom: 0.75rem; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 1rem; }
dt { font-weight: 600; color: #555; font-size: 0.85rem; }
dd { margin: 0; }

/* Navigation groups */
.nav-group { margin-top: 0.5rem; }
.nav-group-header { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.75rem; color: #e0e0e0; font-size: 0.85rem; font-weight: 600; cursor: pointer; border-radius: 6px; user-select: none; }
.nav-group-header:hover { background: #2a2a4a; }
.nav-group-header .chevron { font-size: 0.6rem; transition: transform 0.15s; }
.nav-group.collapsed .chevron { transform: rotate(-90deg); }
.nav-group.collapsed .nav-group-body { display: none; }
.nav-group-body { padding-left: 0.5rem; }
.nav-sub-header { display: block; font-size: 0.65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #666; padding: 0.4rem 0.75rem 0.15rem; margin-top: 0.25rem; }
.nav-group-body .nav-link { font-size: 0.85rem; padding: 0.35rem 0.75rem; }
.sidebar .nav-link.active { background: #2a2a4a; color: #fff; }
.status-decommissioned { background: #efebe9; color: #4e342e; }
.status-maintenance { background: #fff3e0; color: #e65100; }

/* QA Status badges */
.status-draft { background: #f5f5f5; color: #757575; }
.status-reviewed { background: #e8f5e9; color: #2e7d32; }
.status-open { background: #ffebee; color: #c62828; }
.status-inprogress { background: #fff3e0; color: #e65100; }
.status-closed { background: #f5f5f5; color: #757575; }
.status-minor { background: #fff3e0; color: #e65100; }
.status-major { background: #ffebee; color: #c62828; }
.status-critical { background: #b71c1c; color: #fff; }

/* QA Evaluation grid */
.eval-grid { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin: 1rem 0; }
.eval-grid th, .eval-grid td { padding: 0.4rem 0.6rem; text-align: center; border-bottom: 1px solid #eee; border-right: 1px solid #eee; font-size: 0.85rem; }
.eval-grid th { background: #f8f9fa; font-weight: 600; font-size: 0.75rem; color: #555; text-transform: uppercase; letter-spacing: 0.03em; }
.eval-grid td:first-child, .eval-grid th:first-child { text-align: left; min-width: 180px; }
.eval-grid .section-header { background: #e8eaf6; font-weight: 700; text-align: center; font-size: 0.8rem; color: #3949ab; }

/* Pass/Fail/NA toggle buttons */
.toggle-group { display: inline-flex; border-radius: 4px; overflow: hidden; border: 1px solid #ccc; }
.toggle-group input[type="radio"] { display: none; }
.toggle-group label { padding: 0.2rem 0.5rem; font-size: 0.75rem; cursor: pointer; background: #fff; border-right: 1px solid #ccc; font-weight: 600; }
.toggle-group label:last-child { border-right: none; }
.toggle-group input[value="pass"]:checked + label { background: #e8f5e9; color: #2e7d32; }
.toggle-group input[value="fail"]:checked + label { background: #ffebee; color: #c62828; }
.toggle-group input[value="na"]:checked + label { background: #f5f5f5; color: #757575; }

/* NCR panel */
.ncr-panel { background: #fff8e1; border: 1px solid #ffe082; border-radius: 6px; padding: 1rem; margin: 0.5rem 0; }
.ncr-card { background: #fff; border: 1px solid #e0e0e0; border-radius: 6px; padding: 0.75rem; margin: 0.5rem 0; display: flex; gap: 1rem; align-items: flex-start; }
.ncr-card .ncr-info { flex: 1; }
.ncr-card .ncr-info p { margin: 0.25rem 0; font-size: 0.85rem; }
.ncr-indicator { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #c62828; margin-right: 0.25rem; vertical-align: middle; }

/* QA Calendar */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin: 1rem 0; }
.calendar-header { background: #f8f9fa; padding: 0.5rem; text-align: center; font-weight: 600; font-size: 0.8rem; color: #555; }
.calendar-day { min-height: 80px; padding: 0.4rem; border: 1px solid #eee; position: relative; }
.calendar-day .day-number { font-size: 0.8rem; font-weight: 600; color: #333; }
.calendar-day.empty { background: #fafafa; }
.calendar-day.status-none { background: #f5f5f5; }
.calendar-day.status-draft { background: #f5f5f5; }
.calendar-day.status-completed { background: #e3f2fd; }
.calendar-day.status-reviewed { background: #e8f5e9; }
.calendar-day.has-ncr { border: 2px solid #c62828; }
.calendar-day .day-status { font-size: 0.7rem; margin-top: 0.25rem; }

/* Demand calendar */
.calendar-day.has-override { background: #fff8e1; border-color: #ffe082; }

/* QA Stats */
.stats-row { display: flex; gap: 1rem; margin: 1rem 0; }
.stat-card { background: #fff; border-radius: 8px; padding: 1rem 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); flex: 1; text-align: center; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; color: #333; }
.stat-card .stat-label { font-size: 0.8rem; color: #777; margin-top: 0.25rem; }

/* Tabs */
.tab-bar { display: flex; gap: 0; border-bottom: 2px solid #ddd; margin-bottom: 1rem; }
.tab { padding: 0.6rem 1.25rem; text-decoration: none; color: #555; font-weight: 600; font-size: 0.9rem; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tab:hover { color: #333; border-bottom-color: #aaa; text-decoration: none; }
.tab-active { color: #0052cc; border-bottom-color: #0052cc; }
.tab-count { font-size: 0.75rem; font-weight: 400; color: #888; margin-left: 0.25rem; }
.tab-active .tab-count { color: #0052cc; }

/* Filter bar */
.filter-bar { display: flex; gap: 0.75rem; align-items: end; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .form-control { min-width: 150px; }

/* Catch Planner */
.catch-legend { display: flex; gap: 1rem; margin-bottom: 1rem; font-size: 0.8rem; color: #555; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 0.3rem; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid #ddd; display: inline-block; }
.catch-grid { font-size: 0.85rem; }
.catch-grid th, .catch-grid td { padding: 0.4rem 0.5rem; text-align: center; vertical-align: top; }
.catch-farm-header { background: #e8eaf6; color: #3949ab; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.catch-shed-header { min-width: 110px; font-size: 0.8rem; vertical-align: bottom; }
.catch-header-cell { background: #f8f9fa; }
.catch-week-label { text-align: left; white-space: nowrap; background: #f8f9fa; }
.catch-week-group { background: #e8eaf6; font-weight: 600; font-size: 0.85rem; padding: 0.4rem 0.75rem; }
.catch-cell { position: relative; min-width: 100px; }
.catch-cell-info { display: flex; justify-content: space-between; gap: 0.25rem; margin-bottom: 0.2rem; }
.catch-input { width: 80px; display: inline-block; padding: 0.2rem 0.4rem; font-size: 0.85rem; text-align: right; }
.catch-density-req { font-size: 0.65rem; color: #e65100; margin-top: 0.15rem; }
.catch-density-warn { color: #c62828; font-weight: 600; }
.catch-balance { font-size: 0.65rem; color: #888; margin-top: 0.15rem; }

/* Density View */
.density-grid { font-size: 0.8rem; }
.density-grid th, .density-grid td { padding: 0.3rem 0.4rem; text-align: center; vertical-align: middle; }
.density-date-header { background: #f8f9fa; min-width: 80px; text-align: left; }
.density-date-cell { text-align: left; white-space: nowrap; background: #f8f9fa; }
.density-shed-header { min-width: 100px; font-size: 0.8rem; vertical-align: bottom; }
.density-cell { min-width: 90px; position: relative; }
.density-cell-main { font-size: 0.9rem; font-weight: 700; }
.density-cell-detail { font-size: 0.6rem; color: #888; }

/* Placement Schedule */
.schedule-container { border: 1px solid #ddd; border-radius: 8px; overflow: hidden; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.schedule-header { display: flex; border-bottom: 2px solid #ddd; background: #f8f9fa; }
.schedule-farm-header { padding: 0.4rem 0.75rem; background: #e8eaf6; font-weight: 700; font-size: 0.85rem; color: #3949ab; }
.schedule-row { display: flex; border-bottom: 1px solid #eee; min-height: 36px; }
.schedule-row:hover { background: #f8f9ff; }
.schedule-shed-label { width: 160px; min-width: 160px; padding: 0.4rem 0.75rem; font-size: 0.85rem; display: flex; align-items: center; gap: 0.4rem; border-right: 1px solid #ddd; background: #fafafa; }
.schedule-timeline { flex: 1; position: relative; min-height: 32px; }
.schedule-month { position: absolute; top: 0; height: 100%; border-left: 1px solid #ddd; padding: 0.3rem 0.5rem; font-size: 0.75rem; font-weight: 600; color: #555; }
.schedule-today-marker { position: absolute; top: 0; width: 2px; height: 100%; background: #c62828; z-index: 2; }
.schedule-today-line { position: absolute; top: 0; width: 1px; height: 100%; background: #c62828; opacity: 0.3; z-index: 1; }
.schedule-bar { position: absolute; top: 4px; height: 24px; border-radius: 4px; border: 1px solid; display: flex; align-items: center; justify-content: center; text-decoration: none; z-index: 3; overflow: hidden; cursor: pointer; }
.schedule-bar:hover { opacity: 0.85; text-decoration: none; }
.schedule-bar-text { font-size: 0.65rem; font-weight: 600; white-space: nowrap; padding: 0 4px; }
.schedule-bar-active { background: #e3f2fd; border-color: #1565c0; color: #1565c0; }
.schedule-bar-catching { background: #fff3e0; border-color: #e65100; color: #e65100; }
.schedule-bar-completed { background: #f5f5f5; border-color: #9e9e9e; color: #757575; }
.schedule-bar-planned { background: #e8eaf6; border-color: #3949ab; border-style: dashed; color: #3949ab; }

/* Shed Timeline */
.timeline { max-width: 700px; }
.timeline-date { font-weight: 700; font-size: 0.85rem; color: #333; margin-top: 1rem; margin-bottom: 0.25rem; padding-bottom: 0.25rem; border-bottom: 1px solid #ddd; }
.timeline-event { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0; font-size: 0.85rem; }
.timeline-badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 10px; font-size: 0.7rem; font-weight: 600; min-width: 70px; text-align: center; }
.timeline-desc { flex: 1; color: #333; }
.timeline-link { font-size: 0.75rem; color: #0052cc; }
.timeline-placement { background: #e3f2fd; color: #1565c0; }
.timeline-completed { background: #f5f5f5; color: #757575; }
.timeline-weight { background: #e8f5e9; color: #2e7d32; }
.timeline-mortality { background: #ffebee; color: #c62828; }
.timeline-catch { background: #fff3e0; color: #e65100; }
.timeline-feed { background: #f3e5f5; color: #6a1b9a; }
.timeline-medication { background: #fce4ec; color: #880e4f; }
.timeline-range { background: #e0f7fa; color: #00695c; }
.timeline-downtime { background: #efebe9; color: #4e342e; }

.login-container { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #f5f6fa; }
.login-card { background: #fff; border-radius: 8px; padding: 2rem; box-shadow: 0 2px 8px rgba(0,0,0,0.1); width: 100%; max-width: 400px; }
.login-card h1 { text-align: center; margin-bottom: 1.5rem; }

@media (max-width: 768px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: column; padding: 0.5rem; gap: 0; }
    .sidebar .brand { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
    .nav-toggle { display: block; }
    /* Foldable menu: on mobile the sidebar collapses to just the top bar
       (brand + ☰). Everything else is hidden until the toggle opens it. */
    .sidebar > *:not(.sidebar-header) { display: none; }
    .sidebar.open > *:not(.sidebar-header) { display: block; }
    .detail-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; gap: 0; }
}

/* Desktop-only sidebar hide/show (#37). 769px so it never overlaps the max-width:768px
   mobile rules above (which own the .nav-toggle hamburger). */
@media (min-width: 769px) {
    .nav-hide { display: block; background: none; border: 0; color: #fff; font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 0; }
    .layout.sidebar-collapsed .sidebar { display: none; }
    .layout.sidebar-collapsed .nav-show {
        display: block;
        position: fixed;
        top: 0.75rem;
        left: 0.75rem;
        z-index: 1000;
        background: #1a1a2e;
        color: #fff;
        border: 0;
        border-radius: 6px;
        font-size: 1.4rem;
        line-height: 1;
        padding: 0.25rem 0.5rem;
        cursor: pointer;
    }
}

/* ── Catch Night ── */
.catch-night-cards { display: flex; flex-direction: column; gap: 1rem; }

.catch-night-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}
.catch-night-card.caught { border-left: 4px solid #4caf50; }
.catch-night-card.pending { border-left: 4px solid #9e9e9e; }

.catch-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1rem;
    cursor: pointer;
}
.catch-card-farm { font-size: 1.2rem; font-weight: 700; }
.catch-card-shed { font-size: 1rem; color: #555; }
.catch-card-right { text-align: right; }
.catch-card-birds { font-size: 0.9rem; color: #333; margin-bottom: 4px; }

.catch-card-result { padding: 0 1rem 1rem; color: #2e7d32; }
.catch-record-form { padding: 0 1rem 1rem; border-top: 1px solid #f0f0f0; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-caught  { background: #e8f5e9; color: #2e7d32; }
.badge-pending { background: #f5f5f5; color: #616161; }
.badge-optimized { background: #f3e5f5; color: #7b1fa2; }

/* Desktop shows table, hides cards. Mobile shows cards, hides table. */
@media (min-width: 768px) {
    .d-desktop-none { display: none !important; }
}
@media (max-width: 767px) {
    .d-mobile-none { display: none !important; }
}

.impersonation-banner {
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 1rem;
    background: #b45309;
    color: #fff;
    font-weight: 600;
}
.impersonation-banner .impersonation-stop {
    background: #fff;
    color: #b45309;
    border: none;
    border-radius: 4px;
    padding: 0.25rem 0.75rem;
    cursor: pointer;
    font-weight: 600;
}
