:root {
    --agri-green: #10b981;
    --agri-dark: #064e3b;
    --agri-bg: #f0fdf4;
    --text-main: #1f2937;
    --text-light: #6b7280;
    --white: #ffffff;
    --radius: 12px;
}

body {
    background-color: var(--agri-bg);
    font-family: 'Inter', -apple-system, sans-serif;
    margin: 0;
    padding: 0;
}

.agri-container {
    max-width: 1200px;
    margin: 40px auto;
    padding: 0 20px;
}

/* --- HEADER & TOP BAR --- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap; /* Allows wrapping on mobile */
    gap: 16px;
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--agri-dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.count-badge {
    font-size: 16px;
    color: #6b7280;
    font-weight: normal;
    margin-left: 8px;
}

.actions-group {
    display: flex;
    gap: 10px;
}

/* --- BUTTON STYLES (Responsive) --- */
.btn-download {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    border: 1px solid transparent;
    white-space: nowrap;
    height: 42px; /* Fixed height to match inputs */
    box-sizing: border-box;
}

/* Primary PDF Button - Solid Green */
.btn-pdf {
    background-color: var(--agri-dark);
    color: white;
    border-color: var(--agri-dark);
}

.btn-pdf:hover {
    background-color: var(--agri-green);
    border-color: var(--agri-green);
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.3);
}

/* Secondary CSV Button - White Outline */
.btn-csv {
    background-color: white;
    color: var(--text-main);
    border-color: #d1d5db;
}

.btn-csv:hover {
    background-color: #f9fafb;
    border-color: var(--agri-dark);
    color: var(--agri-dark);
}

/* --- METRICS GRID --- */
.metrics-grid {
    display: grid;
    /* Smart grid: Fits as many cards as possible, min width 160px */
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
    width: 100%;
}

.metric-card {
    background: white;
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid #f3f4f6;
    cursor: pointer;
    transition: all 0.2s ease;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-color: var(--agri-green);
}

.metric-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0; /* Prevents icon from squishing */
}

.metric-label {
    font-size: 12px;
    color: var(--text-light);
    font-weight: 500;
    margin-bottom: 2px;
}

.metric-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-main);
}

/* --- FILTERS BAR --- */
/* --- FILTERS BAR (Modern Grid Layout) --- */
.filters-bar {
    background: var(--white);
    padding: 24px; /* More breathing room */
    border-radius: 16px; /* Modern rounded corners */
    box-shadow: 0 4px 20px rgba(0,0,0,0.03); /* Soft, premium shadow */
    margin-bottom: 24px;
    border: 1px solid #f3f4f6;
}

/* The Grid Container */
/* Update the Grid to have 5 columns */
.filters-form {
    display: grid;
    /* Search(2fr) | Date(1fr) | Date(1fr) | Status(1fr) | Reset(auto) */
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
    gap: 16px;
    width: 100%;
    align-items: end;
}

/* --- RESET BUTTON STYLE --- */
.btn-reset {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 44px; /* Matches input height exactly */
    padding: 0 16px;
    border-radius: 10px;
    background-color: white;
    border: 1px solid #e5e7eb;
    color: #6b7280;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-reset:hover {
    background-color: #fee2e2; /* Light Red Hover */
    border-color: #fca5a5;
    color: #dc2626;
}

/* --- RESPONSIVE ADJUSTMENTS --- */

/* Tablet: Switch to 3 columns, Reset button takes full width at bottom or fits in */
@media (max-width: 1024px) {
    .filters-form {
        grid-template-columns: 1fr 1fr 1fr;
    }
    .search-group {
        grid-column: span 3;
    }
    /* Make reset button span full width on tablet or sit in the last slot */
    .reset-group {
        grid-column: span 3; /* Full width row at the bottom */
    }
    .btn-reset {
        width: 100%;
    }
}

/* Mobile: Stack everything */
@media (max-width: 640px) {
    .filters-form {
        display: flex;
        flex-direction: column;
    }
    .reset-group {
        width: 100%;
    }
}

/* Input Groups (Label + Input) */
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-light);
    font-weight: 700;
    margin-left: 2px;
}

/* Inputs Styling */
.search-input, .filter-select, .date-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 10px; /* Matching the card radius */
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
    color: var(--text-main);
    background-color: #f9fafb; /* Slight grey bg for inputs */
    height: 44px; /* Standard touch-friendly height */
    box-sizing: border-box;
    -webkit-appearance: none; /* Removes default styling on iOS */
}

.search-input:focus, .filter-select:focus, .date-input:focus {
    border-color: var(--agri-green);
    background-color: white;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

/* Add custom arrow for Select dropdown */
.filter-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 32px;
}

/* --- RESPONSIVE GRID --- */

/* Tablet (Portrait) */
@media (max-width: 1024px) {
    .filters-form {
        /* 2 columns: Search takes full top row, others split bottom */
        grid-template-columns: 1fr 1fr 1fr;
    }
    .search-group {
        grid-column: span 3; /* Full width on top */
    }
}

/* Mobile (Phones) */
@media (max-width: 640px) {
    .filters-bar {
        padding: 16px;
    }

    .filters-form {
        display: flex; /* Switch to Flex Stack on mobile */
        flex-direction: column;
        gap: 16px;
    }

    .search-group, .filter-group {
        width: 100%;
    }
}

.search-input, .filter-select, .date-input {
    padding: 10px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    color: var(--text-main);
    height: 42px; /* Fixed height for consistency */
    box-sizing: border-box;
}

.search-input:focus, .filter-select:focus, .date-input:focus {
    border-color: var(--agri-green);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.search-input { min-width: 200px; flex-grow: 1; }
.date-label { font-size: 12px; font-weight: 600; color: var(--text-light); margin-right: 4px; white-space: nowrap;}

/* --- TABLE STYLES --- */
.data-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.agri-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.agri-table th {
    background-color: #f9fafb;
    padding: 16px 24px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-light);
    border-bottom: 1px solid #e5e7eb;
}

.agri-table td {
    padding: 16px 24px;
    border-bottom: 1px solid #f3f4f6;
    color: var(--text-main);
    vertical-align: middle;
}

.agri-table tr:hover { background-color: #fcfdfc; }

.land-info { display: flex; align-items: center; gap: 12px; font-weight: 500; }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid white; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }

/* Status Badges */
.badge { padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-block; white-space: nowrap; }
.status-pending { background: #fef3c7; color: #d97706; }
.status-in_progress { background: #dbeafe; color: #2563eb; }
.status-completed { background: #d1fae5; color: #059669; }
.status-hold { background: #fee2e2; color: #dc2626; }
.status-cancelled { background: #f3f4f6; color: #4b5563; }

/* --- MOBILE RESPONSIVENESS (PHONES & TABLETS) --- */
@media (max-width: 768px) {
    /* Stack the Top Bar */
    .top-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .actions-group {
        width: 100%;
        gap: 10px;
    }

    /* Make buttons full width on mobile for easier tapping */
    .btn-download {
        flex: 1;
    }

    /* Stack the Filters */
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-input, .date-input, .filter-select {
        width: 100%;
    }

    /* Adjust table for mobile (Card View) */
    .agri-table thead { display: none; }
    .agri-table, .agri-table tbody, .agri-table tr, .agri-table td { display: block; width: 100%; box-sizing: border-box;}

    .agri-table tr {
        margin-bottom: 15px;
        border-bottom: 2px solid #f3f4f6;
        padding-bottom: 10px;
    }

    .agri-table td {
        padding: 10px 20px;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
    }

    .agri-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-light);
        font-size: 12px;
        text-transform: uppercase;
        text-align: left;
    }

    .land-info { flex-direction: row-reverse; }
}

/* --- PRINT PDF STYLES --- */
@media print {
    .filters-bar, .btn-download, .top-bar .actions-group, nav, .navbar, header, footer, .metrics-grid {
        display: none !important;
    }

    body, .agri-container {
        background-color: white !important;
        margin: 0 !important;
        padding: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    .data-card { box-shadow: none !important; border: none !important; }
    .agri-table th { background-color: #f3f4f6 !important; color: black !important; border-bottom: 2px solid #000 !important; }
    .agri-table td { border-bottom: 1px solid #ddd !important; }

    /* Ensure title prints nicely */
    .top-bar { margin-bottom: 10px; display: block; }
    .page-title { color: black; font-size: 28px; }

    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* --- PAGINATION STYLES --- */
.pagination-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-top: 1px solid #f3f4f6;
    background-color: white;
    flex-wrap: wrap;
    gap: 12px;
}

.page-info {
    font-size: 13px;
    color: var(--text-light);
}

.page-links nav {
    display: flex;
    gap: 4px;
}

/* Kaminari Buttons */
.page-links a, .page-links span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 6px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    color: var(--text-main);
    border: 1px solid transparent;
}

/* Hover State */
.page-links a:hover {
    background-color: var(--agri-bg);
    color: var(--agri-dark);
    border-color: #dbeafe;
}

/* Active/Current Page */
.page-links .current {
    background-color: var(--agri-dark);
    color: white;
    border-color: var(--agri-dark);
}

/* Disabled */
.page-links .gap, .page-links .disabled {
    color: #9ca3af;
    pointer-events: none;
}

/* Print Hide */
@media print {
    .pagination-wrapper { display: none !important; }
}

/* --- Active Card Highlight --- */
.metric-card.active-card {
    border: 2px solid var(--agri-green);
    background-color: #ecfdf5; /* Light green background */
    transform: translateY(-2px); /* Lift it up slightly */
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}