:root {
    --primary: #2d5016;
    --primary-light: #4a7c2c;
    --accent: #6ba547;
    --muted: #6b7280;
    --border: #e5e7eb;
    --card: #ffffff;
    --bg: #f5f7fa;
}

* {
    box-sizing: border-box;
}

body {
    background: var(--bg);
    color: #222;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
}

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

.sidebar {
    background: #1f3d13;
    box-shadow: 2px 0 16px rgba(15, 23, 42, 0.16);
    color: #fff;
    display: flex;
    flex-direction: column;
    height: 100vh;
    left: 0;
    min-height: 100vh;
    position: fixed;
    top: 0;
    width: 264px;
    z-index: 20;
}

.sidebar .logo {
    background: rgba(255, 255, 255, 0.06);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    margin-bottom: 10px;
    padding: 18px 16px;
    text-align: left;
}

.sidebar .logo h3 {
    align-items: center;
    color: #fff;
    display: flex;
    font-size: 20px;
    font-weight: 700;
    gap: 10px;
    margin: 0;
}

.sidebar .logo small {
    color: rgba(255, 255, 255, 0.85);
    font-size: 12px;
}

.sidebar nav {
    flex: 1;
    flex-wrap: nowrap;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 6px 10px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar nav::-webkit-scrollbar {
    display: none;
}

.sidebar .nav-link {
    align-items: center;
    border: 1px solid transparent;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.86);
    display: flex;
    font-size: 14px;
    gap: 12px;
    line-height: 1.2;
    margin: 3px 0;
    min-height: 42px;
    padding: 10px 12px;
    text-decoration: none;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    width: 100%;
}

.sidebar .nav-link i {
    flex: 0 0 20px;
    opacity: 0.92;
    text-align: center;
}

.sidebar .nav-link span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.sidebar .nav-link.active {
    background: #fff;
    border-color: #fff;
    color: var(--primary);
}

.sidebar .nav-link.schedule-overdue-nav,
.sidebar .nav-link.schedule-overdue-nav:hover {
    background: #dc3545;
    border-color: #dc3545;
    color: #fff;
}

.sidebar .nav-link.schedule-new-nav,
.sidebar .nav-link.schedule-new-nav:hover {
    background: #198754;
    border-color: #198754;
    color: #fff;
}

.sidebar .logout-section {
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    margin-top: auto;
    padding: 10px;
}

.sidebar-toggle {
    align-items: center;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    color: #fff;
    display: none;
    height: 38px;
    justify-content: center;
    position: relative;
    width: 42px;
}

.sidebar-toggle.has-unread {
    background: #dc3545;
    border-color: #f8a0a8;
}

.sidebar-toggle-unread {
    align-items: center;
    background: #dc3545;
    border: 2px solid #1f3d13;
    border-radius: 999px;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    height: 19px;
    justify-content: center;
    line-height: 1;
    min-width: 19px;
    padding: 0 4px;
    position: absolute;
    right: -7px;
    top: -7px;
}

.main-content {
    flex: 1;
    margin-left: 264px;
    overflow-x: hidden;
    padding: 24px;
}

.topbar {
    align-items: center;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 20px;
    padding: 18px 22px;
}

.topbar h1 {
    color: var(--primary);
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    text-wrap: balance;
}

.topbar-actions,
.topbar-form {
    align-items: center;
    display: flex;
    gap: 10px;
}

.topbar-actions {
    flex-wrap: nowrap;
    justify-content: flex-end;
}

.topbar-form {
    flex-wrap: nowrap;
}

.topbar-actions .btn {
    align-items: center;
    display: inline-flex;
    justify-content: center;
    white-space: nowrap;
}

.topbar-actions .btn-sm {
    min-height: 38px;
}

.topbar-form .form-label {
    white-space: nowrap;
}

.topbar-form .form-select {
    min-width: 96px;
}

.content-card,
.card-box,
.chart-container,
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    padding: 20px;
}

.system-notifications-card {
    padding: 12px;
}

.system-notifications-card summary {
    align-items: center;
    cursor: pointer;
    display: flex;
    font-size: 1rem;
    font-weight: 600;
    gap: 6px;
    list-style: none;
}

.system-notifications-card.has-overdue-notifications {
    border: 1px solid #dc3545;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, .1);
}

.system-notifications-card.has-overdue-notifications summary {
    color: #b02a37;
}

.system-notifications-card.has-overdue-notifications summary::after {
    color: #dc3545;
}

.system-notifications-card summary::-webkit-details-marker {
    display: none;
}

.system-notifications-card summary::after {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-size: .75rem;
    font-weight: 900;
    margin-left: auto;
    transition: transform .2s ease;
}

.system-notifications-card[open] summary {
    margin-bottom: 8px;
}

.system-notifications-card[open] summary::after {
    transform: rotate(180deg);
}

.notification-count {
    background: #dc3545;
    border-radius: 999px;
    color: #fff;
    font-size: .7rem;
    line-height: 1.4;
    min-width: 20px;
    padding: 1px 6px;
    text-align: center;
}

.system-notifications-list {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.system-notification {
    border-radius: 6px;
    font-size: .82rem;
    line-height: 1.25;
    margin-bottom: 0 !important;
    min-width: 0;
    padding: 8px 10px;
}

.system-notification strong {
    font-size: .88rem;
}

.system-notification .small {
    display: block;
    line-height: 1.25;
    margin-top: 3px;
}

@media (max-width: 576px) {
    .system-notifications-card {
        padding: 10px;
    }

    .system-notifications-list {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    min-height: 132px;
    overflow: hidden;
    position: relative;
}

.stat-card::before {
    background: rgba(74, 124, 44, 0.1);
    border-bottom-left-radius: 120px;
    content: "";
    height: 96px;
    position: absolute;
    right: 0;
    top: 0;
    width: 120px;
}

.stat-icon {
    color: var(--primary-light);
    font-size: 30px;
    opacity: 0.14;
    position: absolute;
    right: 18px;
    top: 18px;
}

.stat-label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    margin-bottom: 14px;
    position: relative;
    text-transform: uppercase;
}

.stat-value {
    color: var(--primary);
    font-size: 30px;
    font-weight: 700;
    line-height: 1.1;
    position: relative;
}

.stat-number {
    color: var(--primary);
    font-size: 30px;
    font-weight: 700;
    line-height: 1.1;
    position: relative;
}

.card-title,
.chart-title {
    color: var(--primary);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
}

.activity-list {
    display: grid;
    gap: 8px;
}

.activity-item {
    align-items: flex-start;
    background: #fff;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    display: flex;
    gap: 12px;
    padding: 12px 0;
}

.activity-item:last-child {
    border-bottom: 0;
}

.activity-icon {
    align-items: center;
    background: #e8f5e9;
    border-radius: 50%;
    color: var(--primary);
    display: inline-flex;
    flex: 0 0 36px;
    height: 36px;
    justify-content: center;
    width: 36px;
}

.activity-content {
    align-items: flex-start;
    display: flex;
    flex: 1;
    gap: 12px;
    justify-content: space-between;
    min-width: 0;
}

.activity-action {
    align-items: center;
    color: #1f2937;
    display: flex;
    flex-wrap: wrap;
    font-size: 14px;
    font-weight: 700;
    gap: 6px;
}

.activity-user {
    color: var(--primary);
}

.activity-type {
    background: #eef7ea;
    border: 1px solid #d7ead0;
    border-radius: 999px;
    color: #1f2937;
    display: inline-flex;
    font-size: 12px;
    padding: 3px 8px;
}

.activity-time {
    align-items: center;
    color: var(--muted);
    display: flex;
    flex: 0 0 auto;
    font-size: 13px;
    gap: 6px;
    margin-top: 1px;
    white-space: nowrap;
}

@media (max-width: 576px) {
    .activity-content {
        display: block;
    }

    .activity-time {
        margin-top: 5px;
        white-space: normal;
    }
}

.btn {
    border-radius: 6px;
    font-weight: 600;
}

.btn-primary,
.page-item.active .page-link {
    background: var(--primary-light);
    border-color: var(--primary-light);
}

.btn-primary:hover,
.btn-primary:focus-visible {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-green-export {
    background: var(--primary);
    border: none;
    color: #fff;
}

.btn-green-export:hover,
.btn-green-export:focus-visible {
    background: var(--primary-light);
    color: #fff;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 0.2rem rgba(74, 124, 44, 0.22);
}

label,
.form-label {
    margin-bottom: 6px;
}

.form-control,
.form-select {
    min-height: 38px;
}

/* Hide circular initial/avatar icons used in chat lists when requested */
.chat-avatar { display: none !important; }

/* Unread badge pulse animation when count increases */
@keyframes badgePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.18); }
    100% { transform: scale(1); }
}
.badge-pulse {
    animation: badgePulse 650ms cubic-bezier(.2,.9,.2,1);
    box-shadow: 0 0 0 6px rgba(220,53,69,0.08);
}

.filter-section {
    align-items: end;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.filter-section > div {
    flex: 1 1 180px;
    min-width: 0;
}

.filter-section .btn,
.filter-section button {
    min-height: 38px;
}

.filter-inline-form {
    flex: 1 1 320px;
}

.action-buttons,
.modal-footer,
.content-action-header,
.btn-toolbar,
.btn-group-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.action-buttons form {
    display: inline-flex !important;
}

.modal-footer {
    align-items: center;
}

.content-card .row,
.chart-container .row,
.card-box .row {
    row-gap: 16px;
}

.btn + .btn,
form + form {
    margin-left: 0;
}

.table {
    font-size: 14px;
}

.table thead th {
    background: #f8f9fa;
    color: var(--primary);
    font-weight: 700;
}

.table tbody td {
    vertical-align: middle;
}

.table tbody tr:hover {
    background: #fafafa;
}

.pagination {
    justify-content: center;
    margin-top: 15px;
}

.auth-page {
    align-items: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 32px 16px;
}

.auth-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: 720px;
    padding: 32px;
    width: 100%;
}

.auth-card-sm {
    max-width: 450px;
}

.auth-header {
    margin-bottom: 28px;
    text-align: center;
}

.auth-header h1 {
    color: var(--primary);
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 10px;
}

.auth-header p {
    color: var(--muted);
    font-size: 14px;
    margin: 0;
}

.auth-card label {
    color: #333;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}

.form-icon {
    color: var(--primary-light);
}

.form-section-title {
    border-bottom: 2px solid var(--primary-light);
    color: var(--primary);
    font-size: 16px;
    font-weight: 700;
    margin: 24px 0 16px;
    padding-bottom: 10px;
}

.required {
    color: #dc3545;
}

.weather-widget {
    background: linear-gradient(135deg, #3b82f6, #0f766e);
    border-radius: 8px;
    color: #fff;
    margin-bottom: 20px;
    padding: 30px;
    text-align: center;
}

.weather-widget .temp {
    font-size: 56px;
    font-weight: 700;
}

.weather-widget .condition {
    font-size: 18px;
}

.weather-bar {
    align-items: center;
    background: linear-gradient(135deg, #1565c0, #0277bd);
    border-radius: 8px;
    color: #fff;
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    margin-bottom: 20px;
    padding: 12px 16px;
}

.weather-bar .wx-item {
    align-items: center;
    display: inline-flex;
    gap: 6px;
    min-height: 28px;
    white-space: nowrap;
}

.weather-bar .wx-temp {
    font-size: 22px;
    font-weight: 700;
}

.weather-bar .wx-source {
    font-size: 11px;
    margin-left: auto;
    opacity: 0.75;
    white-space: nowrap;
}

.crop-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 18px;
    padding: 20px;
}

.crop-card h5 {
    color: var(--primary);
    font-weight: 700;
    margin-bottom: 10px;
}

.crop-info {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-top: 16px;
}

.crop-info-item {
    background: #f8faf7;
    border: 1px solid #e7efe1;
    border-radius: 8px;
    padding: 12px;
}

.crop-info-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.crop-info-value {
    color: #1f2937;
    font-weight: 700;
    margin-top: 4px;
}

.status-badge,
.category-badge,
.quality-badge {
    border-radius: 999px;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.4;
    padding: 8px 14px;
    white-space: nowrap;
    min-width: auto;
}

.stage-planning,
.stage-assigned {
    background: #64748b;
}

.stage-soil-preparing {
    background: #8B3A3A;
}

.stage-planted,
.stage-seedling {
    background: #65a30d;
}

.stage-growing,
.stage-vegetative {
    background: #16a34a;
}

.stage-flowering,
.stage-fruiting {
    background: #ca8a04;
}

.stage-ready-for-harvest,
.stage-harvest-ready {
    background: #d97706;
}

.stage-harvested {
    background: #0284c7;
}

.quality-a {
    background: #16a34a;
}

.quality-b {
    background: #ca8a04;
}

.quality-c {
    background: #ea580c;
}

.quality-d {
    background: #dc2626;
}

.schedule-item {
    background: #fff;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary-light);
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 14px;
}

.schedule-item.overdue {
    border-left-color: #dc2626;
}

.schedule-item.completed {
    background: #f8faf7;
    border-left-color: #16a34a;
    opacity: 0.86;
}

.schedule-item-row {
    align-items: flex-start;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.schedule-actions {
    align-items: flex-end;
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 8px;
    text-align: right;
}

.schedule-date {
    color: var(--primary-light);
    font-size: 14px;
    font-weight: 700;
}

.schedule-activity,
.schedule-crop {
    color: #1f2937;
    font-weight: 700;
}

.schedule-location,
.schedule-empty {
    color: var(--muted);
}

.message-item {
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    padding: 12px 14px;
    transition: background-color 0.2s ease;
}

.message-item:hover {
    background: #f8faf7;
}

.message-item.unread {
    background: #eff8e8;
    font-weight: 700;
}

.message-status {
    align-items: center;
    display: inline-flex;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
}

.message-status-unread {
    color: #c1121f;
}

.message-status-read {
    color: var(--muted);
}

.farm-info {
    background: #e8f5e9;
    border: 1px solid #cfe8d1;
    border-radius: 8px;
    margin-bottom: 20px;
    padding: 15px;
}

.metric-mini-card,
.visual-panel-card {
    align-items: flex-start;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    display: flex;
    gap: 12px;
    padding: 16px;
}

.metric-icon-circle {
    align-items: center;
    border-radius: 50%;
    display: flex;
    flex-shrink: 0;
    font-size: 20px;
    height: 48px;
    justify-content: center;
    width: 48px;
}

.metric-txt-info h6 {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    margin: 0;
}

.metric-txt-info h3 {
    color: var(--primary);
    font-size: 20px;
    font-weight: 700;
    margin: 4px 0;
}

.metric-txt-info p {
    font-size: 12px;
    margin: 2px 0;
}

.visual-panel-card {
    display: block;
}

.visual-panel-card h5,
.chart-container h5 {
    color: var(--primary);
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 16px;
}

.month-box-item {
    background: #f9f9f9;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    text-align: center;
}

.month-box-item h6 {
    font-size: 12px;
    font-weight: 600;
    margin: 0 0 6px;
}

.month-item-row {
    display: flex;
    font-size: 12px;
    justify-content: space-between;
    padding: 2px 0;
}

.footer-summary-node {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    padding: 12px;
    text-align: center;
}

.chart-wrapper {
    min-height: 350px;
    position: relative;
}

.chart-wrapper-sm {
    height: 280px;
    min-height: 280px;
}

.chart-wrapper-md {
    height: 260px;
    min-height: 260px;
}

.chart-wrapper canvas {
    height: 100% !important;
    width: 100% !important;
}

#map {
    border-radius: 8px;
    min-height: 480px;
}

@media (max-width: 768px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        border-bottom: 1px solid rgba(255, 255, 255, 0.16);
        box-shadow: 0 6px 18px rgba(15, 23, 42, 0.16);
        height: auto;
        min-height: auto;
        position: sticky;
        top: 0;
        width: 100%;
    }

    .sidebar .logo {
        align-items: center;
        display: grid;
        gap: 2px 12px;
        grid-template-columns: 1fr auto;
        margin-bottom: 0;
        padding: 12px 14px;
        text-align: left;
    }

    .sidebar-toggle {
        display: inline-flex;
        grid-column: 2;
        grid-row: 1 / span 2;
    }

    .sidebar .logo h3 {
        font-size: 18px;
        grid-column: 1;
    }

    .sidebar .logo small {
        font-size: 11px;
        grid-column: 1;
    }

    .sidebar nav {
        display: flex;
        flex: none;
        flex-direction: column !important;
        gap: 6px;
        max-height: 0;
        overflow: hidden;
        padding: 0 10px;
    }

    .sidebar .nav-link {
        border-radius: 8px;
        flex: 0 0 auto;
        font-size: 13px;
        margin: 0;
        min-height: 38px;
        padding: 9px 12px;
    }

    .sidebar .nav-link i {
        flex-basis: auto;
    }

    .sidebar .logout-section {
        border-top: 1px solid rgba(255, 255, 255, 0.12);
        display: none;
        margin-top: 0;
        padding: 8px 10px 10px;
    }

    .sidebar .logout-section .nav-link {
        justify-content: flex-start;
    }

    .sidebar.is-open nav {
        max-height: none;
        overflow: visible;
        padding: 8px 10px 10px;
    }

    .sidebar.is-open .logout-section {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 14px;
    }

    .filter-section {
        align-items: stretch;
        display: grid;
        gap: 12px;
        grid-template-columns: 1fr;
    }

    .filter-section > div,
    .filter-section .btn,
    .filter-section button {
        width: 100%;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar h1 {
        font-size: 22px;
    }

    .topbar-actions,
    .topbar-form {
        align-items: stretch;
        flex-wrap: wrap;
        width: 100%;
    }

    .topbar-actions {
        justify-content: stretch;
    }

    .topbar-actions .btn,
    .topbar-form .form-select {
        width: 100%;
    }

    .weather-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .weather-bar .wx-source {
        margin-left: 0;
        white-space: normal;
    }

    .schedule-item-row {
        flex-direction: column;
    }

    .schedule-actions {
        align-items: flex-start;
        text-align: left;
        width: 100%;
    }

    .auth-card {
        padding: 24px;
    }
}

/* Growth Stage Legend for Maps */
.map-legend {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    top: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    padding: 12px;
    position: absolute;
    right: 20px;
    width: 220px;
    z-index: 360; /* sit under interactive side-panel controls */
    pointer-events: auto;
}

.summary-legend {
    margin-bottom: 16px;
    position: static;
    width: 100%;
}

.legend-title {
    color: #1f2937;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.legend-item {
    align-items: center;
    display: flex;
    gap: 12px;
    margin-bottom: 10px;
    padding: 6px 0;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-color {
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 3px;
    display: inline-block;
    flex-shrink: 0;
    height: 20px;
    width: 20px;
}

.legend-label {
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
}

@media (max-width: 768px) {
    .map-legend {
        top: auto;
        bottom: 10px;
        right: 10px;
        width: 200px;
    }
    
    .legend-label {
        font-size: 12px;
    }
}
