/* ==========================================================================
   Base & Layout Styles
   ========================================================================== */

body {
    font-family: 'Inter', sans-serif;
    background-color: #f3f4f6;
    margin: 0;
    color: #1f2937;
}

.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background-color: #1e293b;
    color: white;
}

.content {
    flex-grow: 1;
    padding: 2rem;
}

/* ==========================================================================
   Form Styling
   ========================================================================== */

#crop-config-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

.form-section {
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    /* CHANGED: Removed overflow: hidden so tooltips can escape the card */
    overflow: visible; 
    border: 1px solid #e5e7eb;
    border-top: 4px solid #008abc;
}

.form-section-header {
    background-color: #f9fafb;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    /* ADDED: Manual border radius since overflow is now visible on parent */
    border-top-left-radius: 12px; 
    border-top-right-radius: 12px;
}

.form-section-heading {
    margin: 0;
    color: #111827;
    font-size: 1.15rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-section-body,
.form-section-body-crop-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    padding: 1.5rem;
}

.form-section-body-column-layout {
    padding: 1.5rem;
}

.form-sub-section-body-crop-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    flex-grow: 1;
}

.form-section-body-crop-details {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 2rem;
}

/* Form Inputs */
.form-fields {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-weight: 500;
    color: #4b5563;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
}

input[type="week"],
input[type="number"],
input[type="text"],
select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    background-color: #ffffff;
    color: #1f2937;
    transition: all 0.2s ease-in-out;
    box-sizing: border-box;
}

input[type="week"]:focus,
input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

input:disabled, select:disabled {
    background-color: #f3f4f6;
    cursor: not-allowed;
}

/* Radio Buttons */
.form-radio-buttons {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    padding-top: 0.5rem;
}

.form-radio-buttons input[type="radio"] {
    margin-right: 0.4rem;
    accent-color: #2563eb;
    width: 1.1rem;
    height: 1.1rem;
    cursor: pointer;
}

.form-radio-buttons label {
    font-weight: 500;
    cursor: pointer;
    font-size: 0.95rem;
}

/* Buttons */
.submit-btn-container {
    display: flex;
    justify-content: center;
    padding: 1rem 0;
}

.submit-btn {
    background-color: #059669;
    color: white;
    border: none;
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
    width: 250px;
}

.submit-btn:hover {
    background-color: #047857;
    box-shadow: 0 6px 8px -1px rgba(16, 185, 129, 0.3);
    transform: translateY(-1px);
}

/* ==========================================================================
   Data Tables
   ========================================================================== */

.results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid #e5e7eb;
}

.results-table th, .results-table td {
    padding: 1rem;
    text-align: center;
    font-size: 0.95rem;
    border-bottom: 1px solid #e5e7eb;
}

.results-table th {
    background-color: #f3f4f6;
    font-weight: 600;
    color: #374151;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
}

.results-table tbody tr {
    background-color: #ffffff;
    transition: background-color 0.2s ease;
}

.results-table tbody tr:hover {
    background-color: #f9fafb;
}

/* Panchayat Table Specifics */
.panchayat-table-container {
    background-color: #ffffff; 
    border-radius: 8px; 
    box-shadow: none;
    border: 1px solid #e5e7eb;
    overflow: hidden;
}

.panchayat-table {
    width: 100%; 
    border-collapse: collapse;
}

.panchayat-table thead {
    background-color: #f8fafc; 
    color: #475569; 
    text-align: left; 
}

.panchayat-table th {
    padding: 1rem;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    border-bottom: 1px solid #e2e8f0;
}

.panchayat-table td {
    padding: 1rem;
    font-size: 0.95rem;
    border-bottom: 1px solid #f1f5f9;
}

.panchayat-table tbody tr:last-child td {
    border-bottom: none;
}

.panchayat-table tbody tr:hover {
    background-color: #f8fafc;
}

/* ==========================================================================
   Cards & Grids
   ========================================================================== */

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    width: 100%;
}

/* Crop Stage Analysis Cards */
.crop-stage-card-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.crop-stage-card {
    background-color: #ffffff;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    padding: 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}

.crop-stage-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.card-header {
    display: flex;
    align-items: center;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: 1rem;
}

.card-header .icon {
    font-size: 2rem;
    margin-right: 1rem;
}

.card-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #111827;
}

.card-header p {
    margin: 0.25rem 0 0;
    font-size: 0.85rem;
    color: #6b7280;
}

.card-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.card-body .data-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
}

.card-body .data-label {
    font-weight: 500;
    color: #4b5563;
    display: flex;
    align-items: center;
    font-size: 0.95rem;
}

.card-body .data-label i {
    margin-right: 0.5rem;
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
    color: #9ca3af;
}

.card-body .data-value {
    font-size: 1rem;
    font-weight: 600;
    color: #111827;
}

/* Card Type Colors */
.card-forecast .icon, .card-forecast .data-value { color: #2563eb; }
.card-normal .icon, .card-normal .data-value { color: #059669; }
.card-observed .icon, .card-observed .data-value { color: #7c3aed; }

/* Water & Weather Threshold Cards */
.water-card-container,
.weather-threshold-card-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
}

.water-card,
.weather-threshold-card {
    background-color: #ffffff;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.2s ease;
}

.water-card:hover,
.weather-threshold-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
}

.water-card .icon,
.weather-threshold-card .icon {
    font-size: 2.25rem;
    margin-bottom: 1rem;
}

.water-card h4,
.weather-threshold-card h4 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.water-card p,
.weather-threshold-card p {
    margin: 0.75rem 0 0;
    font-size: 1.75rem;
    font-weight: 700;
    color: #111827;
}

/* Threshold Value Boxes */
.threshold-values {
    display: flex;
    justify-content: space-around;
    width: 100%;
    margin-top: 15px;
    gap: 10px;
}

.value-box {
    text-align: center;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    flex: 1;
}

/* Specific Value Box Colors */
.value-normal { background: #eff6ff; color: #1d4ed8; }
.value-forecast { background: #fff7ed; color: #c2410c; }
.value-threshold { background: #fef2f2; color: #b91c1c; }

/* Specific Icon/Text Colors */
.water-card.demand .icon, .water-card.demand p { color: #3b82f6; }
.water-card.deficit .icon, .water-card.deficit p { color: #ef4444; }
.weather-threshold-card.maxtemp .icon, .weather-threshold-card.maxtemp p { color: #f97316; }
.weather-threshold-card.mintemp .icon, .weather-threshold-card.mintemp p { color: #0ea5e9; }
.weather-threshold-card.rainfall .icon, .weather-threshold-card.rainfall p { color: #10b981; }

/* ==========================================================================
   Tooltips (Info Container)
   ========================================================================== */

.info-container {
    position: relative;
    display: inline-block;
    margin-left: 6px;
}

.info-icon {
    color: #9ca3af;
    cursor: pointer;
    font-size: 1rem;
    vertical-align: middle;
    transition: color 0.2s ease;
}

.info-icon:hover {
    color: #4b5563;
}

.info-popup {
    display: none;
    position: absolute;
    top: 28px;
    left: 50%;
    transform: translateX(-50%);
    width: 250px;
    padding: 1rem;
    background-color: #1f2937;
    border-radius: 6px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); /* Made shadow a bit stronger for popups */
    /* CHANGED: Boosted Z-index significantly */
    z-index: 9999; 
    color: #f9fafb;
    font-size: 0.85rem;
    line-height: 1.5;
    text-align: center;
}

.info-popup::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-bottom-color: #1f2937;
}

.info-container:hover .info-popup {
    display: block;
}

/* ==========================================================================
   UI Components (Tabs, Pagination, Charts, Alerts)
   ========================================================================== */

/* Tabs */
.tab-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 20px 0;
}

.tab-button {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background-color: #ffffff;
    color: #4b5563;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.tab-button.active {
    background-color: #2563eb;
    color: white;
    border-color: #2563eb;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.tab-button:hover:not(.active) {
    background-color: #f3f4f6;
}

/* Charts */
#chartContainer, #waterChartContainer {
    width: 100%;
    height: 500px;
    margin-top: 20px;
}

.canvasjs-chart-credit {
    display: none !important;
}

/* Search & Pagination */
.search-container {
    padding: 0 1.5rem 1.5rem;
}

#panchayat-search {
    background-color: #f9fafb;
}

#panchayat-search:focus {
    background-color: #ffffff;
}

.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem 0 0.5rem;
    gap: 8px;
    flex-wrap: wrap;
}

.pagination-container button {
    padding: 0.5rem 1rem;
    border: 1px solid #d1d5db;
    background-color: #ffffff;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    font-weight: 500;
    color: #374151;
}

.pagination-container button:hover:not(:disabled) {
    background-color: #f3f4f6;
}

.pagination-container button.active {
    background-color: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
}

.pagination-container button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.pagination-container button.ellipsis:hover {
    background-color: #ffffff;
    cursor: default;
}

/* Alert Messages Section */
#msg-section {
    display: flex;
    flex-direction: column; 
    gap: 1rem; 
}

/* .bottom-message {
    margin-top: 1rem;
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: #991b1b; 
    background: #fef2f2; 
    border: 1px solid #fecaca;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
} */

/* --- Base Layout Structure for All Alerts --- */
.bottom-message {
    margin-top: 1rem;
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 8px;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Subtle interactive lift on hover */
.bottom-message:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

/* Icon custom sizing inside text container */
.bottom-message i {
    font-size: 1.15rem;
    flex-shrink: 0;
}

/* --- Type Specific Themes --- */

/* 1. Diseases: Crimson Alert (High Urgency) */
.bottom-message.disease-warning {
    background: #fef2f2; 
    border-color: #fecaca;
    color: #991b1b; 
    border-left: 5px solid #dc2626;
}
.bottom-message.disease-warning i {
    color: #dc2626;
}

/* 2. Pests: Rust Orange Alert (Moderate Warning) */
.bottom-message.pest-warning {
    background: #fff7ed; 
    border-color: #ffedd5;
    color: #c2410c; 
    border-left: 5px solid #ea580c;
}
.bottom-message.pest-warning i {
    color: #ea580c;
}

/* 3. Threshold Metrics: Amber Notice (Technical Metric Condition) */
.bottom-message.pest-threshold-warning {
    background: #fefce8; 
    border-color: #fef08a;
    color: #a16207; 
    border-left: 5px solid #eab308;
}
.bottom-message.pest-threshold-warning i {
    color: #eab308;
}

/* Image Display Section */
#crop-image-section {
    display: none;
    text-align: center;
}

#crop-image-section img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin: 0 auto;
    border: 1px solid #e5e7eb;
}

.crop-stage-image {
    width: 100%;
    height: 220px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

/* ==========================================================================
   Responsive Utilities
   ========================================================================== */

@media (max-width: 992px) {
    .content { padding: 1.5rem; }
    .form-section-body-crop-details { flex-direction: column; align-items: stretch; }
    .submit-btn { width: 100%; }
}

@media (max-width: 768px) {
    .container { flex-direction: column; }
    .sidebar { width: 100%; height: auto; }
    .form-section-body, .form-sub-section-body-crop-details, .info-grid { grid-template-columns: 1fr; }
    .tab-buttons { flex-direction: column; }
}
/* =========================================
   Horizontal Threshold Container & Header
========================================= */

/* Main outer grouping box card */
.stage-threshold-container {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1.25rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    margin-top: 1rem;
}

/* Stage Context Banner Area */
.stage-context-header {
    border-bottom: 1px dashed #cbd5e1;
    padding-bottom: 1rem;
    margin-bottom: 1.25rem;
}

.stage-badge-wrapper {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 0.35rem;
}

.stage-badge-wrapper .leaf-icon {
    color: #16a34a; /* Agriculture Green Color */
    font-size: 1.25rem;
}

.stage-badge-wrapper h3 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: #1e293b;
    font-family: 'Roboto', sans-serif;
}

/* Dynamic Stage string highlight state */
.highlight-stage {
    color: #1e40af; /* Government Navy Blue Accent */
    background: #eff6ff;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid #bfdbfe;
    font-weight: 800;
}

/* Informative description explanation message text */
.stage-context-msg {
    margin: 0;
    font-size: 0.88rem;
    color: #64748b;
    line-height: 1.5;
}

/* --- Horizontal Grid/Flex Matrix Strip Row --- */
.horizontal-threshold-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    width: 100%;
}

/* Mini Cards Metrics Styling Rules */
.horizontal-thr-card {
    flex: 1;
    min-width: 155px;
    background: #ffffff;
    border: 1px solid #f1f5f9;
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
    transition: all 0.2s ease;
}

.horizontal-thr-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(148, 163, 184, 0.12);
}

.thr-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    flex-shrink: 0;
}

.thr-card-details {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.thr-param-title {
    font-size: 0.75rem;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.thr-param-value {
    font-size: 1.15rem;
    font-weight: 700;
    margin-top: 2px;
}

.thr-param-value small {
    font-size: 0.78rem;
    font-weight: 500;
    color: #475569;
    margin-left: 1px;
}

/* --- Card Active/Unset Condition Themes --- */
.horizontal-thr-card.status-active {
    border-left: 4px solid #dc2626;
    background: #ffffff;
}
.horizontal-thr-card.status-active .thr-card-icon {
    background: #fef2f2;
    color: #dc2626;
}
.horizontal-thr-card.status-active .thr-param-value {
    color: #0f172a;
}

.horizontal-thr-card.status-unset {
    border-left: 4px solid #cbd5e1;
    background: #f8fafc;
}
.horizontal-thr-card.status-unset .thr-card-icon {
    background: #e2e8f0;
    color: #94a3b8;
}
.horizontal-thr-card.status-unset .thr-param-value {
    color: #94a3b8;
    font-weight: 500;
    font-size: 0.95rem;
    font-style: italic;
}

.tool-name {
    margin-top: 1rem;
    padding-top: 0.8rem;

    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;

    border-top: 2px solid rgba(255,255,255,0.25);
}