/* Agriculture Map — marker and popup styles */

.ag-map-container {
    width: 100%;
    height: calc(100vh - 280px);
    min-height: 400px;
    border-radius: 6px;
    border: 1px solid var(--rz-border-color, #dee2e6);
}

/* Base marker pin */
.ag-marker-pin {
    width: 24px;
    height: 24px;
    border-radius: 50% 50% 50% 0;
    position: absolute;
    transform: rotate(-45deg);
    left: 50%;
    top: 50%;
    margin: -15px 0 0 -12px;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Farm markers */
.ag-marker-farm {
    background-color: #1976d2;
}

.ag-marker-farm-inactive {
    background-color: #90a4ae;
}

/* Parcel markers */
.ag-marker-parcel {
    background-color: #388e3c;
    width: 18px;
    height: 18px;
    margin: -11px 0 0 -9px;
}

.ag-marker-parcel-inactive {
    background-color: #bdbdbd;
    width: 18px;
    height: 18px;
    margin: -11px 0 0 -9px;
}

/* Popup */
.ag-map-popup {
    font-size: 0.85rem;
    line-height: 1.5;
    min-width: 180px;
}

.ag-map-popup strong {
    font-size: 0.9rem;
}

.ag-map-popup hr {
    border-color: var(--rz-border-color, #dee2e6);
}

/* Filter bar */
.ag-map-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

/* Collapsible SIGPAC filter panel */
.ag-map-filter-panel {
    background: var(--rz-panel-background-color, #fff);
    border: 1px solid var(--rz-border-color, #dee2e6);
    border-radius: var(--rz-border-radius, 4px);
}

/* Responsive filter field grid: 2 columns on small, 3 on medium, auto on large */
.ag-map-filter-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem 1rem;
}

@media (min-width: 768px) {
    .ag-map-filter-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1200px) {
    .ag-map-filter-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* Legend */
.ag-map-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
}

.ag-map-legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
}

.ag-map-legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

/* Popup action links */
.ag-popup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--rz-border-color, #dee2e6);
}

.ag-popup-action {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    font-size: 0.75rem;
    color: #1976d2;
    text-decoration: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.ag-popup-action:hover {
    background-color: rgba(25, 118, 210, 0.08);
    text-decoration: none;
}

.ag-popup-action-icon {
    font-family: 'Material Icons', 'Material Symbols Outlined', sans-serif;
    font-size: 14px;
    line-height: 1;
}

/* Summary side panel */
.ag-map-layout {
    display: flex;
    gap: 1rem;
}

.ag-map-main {
    flex: 1;
    min-width: 0;
}

.ag-map-side-panel {
    width: 280px;
    flex-shrink: 0;
}

.ag-side-panel-card {
    padding: 0.75rem;
}

.ag-side-panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.ag-side-panel-row {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    font-size: 0.85rem;
}

.ag-side-panel-actions {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--rz-border-color, #dee2e6);
}

/* Alert severity markers — Farm */
.ag-marker-farm-critical {
    background-color: #d32f2f;
}

.ag-marker-farm-warning {
    background-color: #f57c00;
}

.ag-marker-farm-info {
    background-color: #fbc02d;
}

/* Alert severity markers — Parcel */
.ag-marker-parcel-critical {
    background-color: #d32f2f;
    width: 18px;
    height: 18px;
    margin: -11px 0 0 -9px;
}

.ag-marker-parcel-warning {
    background-color: #f57c00;
    width: 18px;
    height: 18px;
    margin: -11px 0 0 -9px;
}

.ag-marker-parcel-info {
    background-color: #fbc02d;
    width: 18px;
    height: 18px;
    margin: -11px 0 0 -9px;
}

/* Cluster overrides */
.ag-cluster-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.ag-cluster-farm {
    background-color: rgba(25, 118, 210, 0.7);
    border: 2px solid #1976d2;
}

.ag-cluster-parcel {
    background-color: rgba(56, 142, 60, 0.7);
    border: 2px solid #388e3c;
}

/* Dashboard mini-map */
.ag-minimap-container {
    width: 100%;
    height: 220px;
    border-radius: 6px;
    border: 1px solid var(--rz-border-color, #dee2e6);
}

.ag-minimap-widget {
    min-height: 300px;
}

.ag-minimap-alert-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0 0;
}

.ag-minimap-alert-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.3rem 0;
    border-bottom: 1px solid var(--rz-border-color, #dee2e6);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background-color 0.15s;
}

.ag-minimap-alert-item:last-child {
    border-bottom: none;
}

.ag-minimap-alert-item:hover {
    background-color: rgba(25, 118, 210, 0.06);
}

.ag-minimap-severity-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.4rem;
    flex-shrink: 0;
}

/* Parcel polygon styles */
.ag-polygon-default {
    fill: #388e3c;
    fill-opacity: 0.25;
    stroke: #388e3c;
    stroke-width: 2.5;
    stroke-opacity: 0.85;
}

.ag-polygon-inactive {
    fill: #bdbdbd;
    fill-opacity: 0.1;
    stroke: #bdbdbd;
    stroke-width: 1.5;
    stroke-opacity: 0.5;
}

.ag-polygon-selected {
    fill: #1565c0;
    fill-opacity: 0.30;
    stroke: #1565c0;
    stroke-width: 3.5;
    stroke-opacity: 0.95;
}

/* Legend section enhancements */
.ag-map-legend-separator {
    width: 1px;
    height: 18px;
    background-color: var(--rz-border-color, #dee2e6);
    margin: 0 0.25rem;
}

.ag-map-legend-section-title {
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--rz-text-secondary-color, #666);
}

/* SIGPAC legend swatch — generic diagonal hatching (used as section header dot) */
.ag-map-legend-sigpac {
    background: repeating-linear-gradient(
        45deg,
        #00e5ff,
        #00e5ff 3px,
        transparent 3px,
        transparent 6px
    );
    opacity: 0.8;
}

/* SIGPAC ortophoto legend swatch */
.ag-map-legend-swatch-ortophoto {
    width: 20px;
    height: 14px;
    display: inline-block;
    border-radius: 2px;
    background: linear-gradient(135deg, #5d8a48 0%, #8aab6f 50%, #6b9955 100%);
    border: 1px solid rgba(0, 0, 0, 0.2);
    opacity: 0.75;
}

/* SIGPAC recinto legend swatch — cyan dashed border matching map style */
.ag-map-legend-swatch-recinto {
    width: 20px;
    height: 14px;
    display: inline-block;
    border-radius: 2px;
    border: 2px dashed #00e5ff;
    background-color: transparent;
    box-shadow: 0 0 2px rgba(0, 229, 255, 0.35);
}

/* SIGPAC live/fallback status indicator */
.ag-sigpac-status {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 9px;
    line-height: 1.6;
    white-space: nowrap;
}

.ag-sigpac-status--live {
    background-color: rgba(0, 229, 255, 0.12);
    color: #00838f;
    border: 1px solid rgba(0, 229, 255, 0.35);
}

.ag-sigpac-status--fallback {
    background-color: rgba(120, 144, 156, 0.12);
    color: #546e7a;
    border: 1px solid rgba(120, 144, 156, 0.35);
}

.ag-sigpac-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.ag-sigpac-status--live .ag-sigpac-status-dot {
    background-color: #00e5ff;
    box-shadow: 0 0 4px rgba(0, 229, 255, 0.7);
    animation: ag-pulse-dot 2s ease-in-out infinite;
}

.ag-sigpac-status--fallback .ag-sigpac-status-dot {
    background-color: #78909c;
}

@keyframes ag-pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Legend swatch for polygon boundaries */
.ag-map-legend-swatch {
    width: 20px;
    height: 14px;
    display: inline-block;
    border: 2px solid #388e3c;
    border-radius: 2px;
    background-color: rgba(56, 142, 60, 0.15);
}

/* SIGPAC recinto vector glow for reference visibility */
.ag-sigpac-recinto-path {
    filter: drop-shadow(0 0 2px rgba(0, 229, 255, 0.4));
}

/* Parcel Form embedded map */
.ag-parcel-form-map-wrapper,
.ag-boundary-preview-wrapper {
    margin-top: 1rem;
    border: 1px solid var(--rz-border-color, #dee2e6);
    border-radius: 6px;
    overflow: hidden;
}

.ag-parcel-form-map-header,
.ag-boundary-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background-color: var(--rz-base-background-color, #f8f9fa);
    border-bottom: 1px solid var(--rz-border-color, #dee2e6);
}

.ag-parcel-form-map-title,
.ag-boundary-preview-title {
    display: inline-flex;
    align-items: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--rz-text-color, #333);
}

.ag-parcel-form-map-container,
.ag-boundary-preview-container {
    width: 100%;
    height: 300px;
    min-height: 200px;
}

/* ============================================================================
   GIS FORM DIALOG — compact layout for Farm / Parcel forms with embedded maps
   Applied via TabDialogOptions CssClass="ag-gis-form-dialog"
                          ContentCssClass="ag-gis-form-content"
   ============================================================================ */

/* Reduce internal body padding for tighter form density */
.ag-gis-form-dialog .ag-gis-form-content {
    padding: 0.5rem 0.75rem;
    padding-top: 0;
}

/* Compact dialog-footer inside GIS forms */
.ag-gis-form-dialog .dialog-footer {
    margin-top: 0.35rem !important;
    margin-bottom: 0.15rem;
}

/* Reduce spacing between form fields and map section */
.ag-gis-form-content .ag-parcel-form-map-wrapper,
.ag-gis-form-content .ag-boundary-preview-wrapper {
    margin-top: 0.5rem;
}

/* Responsive map height inside GIS form dialogs */
.ag-gis-form-content .ag-parcel-form-map-container,
.ag-gis-form-content .ag-boundary-preview-container {
    height: clamp(200px, 28vh, 340px);
}

/* Tighter row gap inside GIS form RadzenRow */
.ag-gis-form-content .rz-stack {
    gap: 0.25rem;
}

/* Reduce Radzen form-field bottom margin inside GIS forms */
.ag-gis-form-content .rz-form-field {
    margin-bottom: 0.15rem;
}

/* ============================================================================
   GIS FORM SIDE-BY-SIDE LAYOUT — form on left, map on right
   Applied via class="ag-gis-side-by-side" on RadzenStack
   ============================================================================ */

.ag-gis-side-by-side {
    width: 100%;
    min-height: 0;
    align-items: stretch;
}

.ag-gis-form-panel {
    flex: 0 0 45%;
    min-width: 320px;
    max-height: 75vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.ag-gis-map-panel {
    flex: 1 1 55%;
    min-width: 340px;
    display: flex;
    flex-direction: column;
}

/* Map container fills its panel when inside the side-by-side layout */
.ag-gis-map-panel .ag-parcel-form-map-container,
.ag-gis-map-panel .ag-boundary-preview-container {
    flex: 1 1 auto;
    height: auto;
    min-height: 350px;
}

/* Map wrapper fills the map panel */
.ag-gis-map-panel .ag-parcel-form-map-wrapper,
.ag-gis-map-panel .ag-boundary-preview-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Responsive: stack vertically on narrow viewports */
@media (max-width: 900px) {
    .ag-gis-side-by-side {
        flex-direction: column !important;
    }

    .ag-gis-form-panel {
        flex: 0 0 auto;
        max-height: none;
        overflow-y: visible;
    }

    .ag-gis-map-panel {
        flex: 0 0 auto;
    }

    .ag-gis-map-panel .ag-parcel-form-map-container,
    .ag-gis-map-panel .ag-boundary-preview-container {
        min-height: 280px;
        height: 300px;
    }
}

/* ============================================================================
   GEOMETRY EDITING TOOLBAR
   ============================================================================ */

.ag-edit-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    background-color: var(--rz-base-background-color, #f8f9fa);
    border-bottom: 1px solid var(--rz-border-color, #dee2e6);
}

.ag-edit-toolbar .rz-button {
    font-size: 0.78rem;
    padding: 0.2rem 0.55rem;
}

.ag-edit-toolbar-separator {
    width: 1px;
    height: 20px;
    background-color: var(--rz-border-color, #dee2e6);
    margin: 0 0.15rem;
}

/* Dirty-state badge shown in header when geometry has unsaved changes */
.ag-dirty-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 9px;
    line-height: 1.6;
    white-space: nowrap;
    background-color: rgba(255, 152, 0, 0.14);
    color: #e65100;
    border: 1px solid rgba(255, 152, 0, 0.4);
}

.ag-dirty-badge-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
    background-color: #ff9800;
    animation: ag-pulse-dot 2s ease-in-out infinite;
}

/* ============================================================================
   GEOMETRY RECONCILIATION
   ============================================================================ */

.ag-recon-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    background-color: rgba(0, 229, 255, 0.06);
    border-bottom: 1px solid rgba(0, 229, 255, 0.2);
}

.ag-recon-toolbar .rz-button {
    font-size: 0.78rem;
    padding: 0.2rem 0.55rem;
}

.ag-recon-status {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--rz-text-secondary-color, #666);
}

.ag-recon-status-icon {
    font-family: 'Material Icons', 'Material Symbols Outlined', sans-serif;
    font-size: 14px;
    line-height: 1;
    color: #00838f;
}

/* Reconciliation legend swatches */
.ag-recon-legend {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    background-color: var(--rz-base-background-color, #f8f9fa);
    border-bottom: 1px solid var(--rz-border-color, #dee2e6);
}

.ag-recon-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.ag-recon-swatch {
    width: 16px;
    height: 10px;
    display: inline-block;
    border-radius: 2px;
}

.ag-recon-swatch--erp {
    background-color: rgba(25, 118, 210, 0.25);
    border: 2px solid #1976d2;
}

.ag-recon-swatch--sigpac {
    background-color: transparent;
    border: 2px dashed #00e5ff;
}

.ag-recon-swatch--edited {
    background-color: rgba(255, 152, 0, 0.25);
    border: 2px solid #ff9800;
}

/* Editing mode status label */
.ag-editing-label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 9px;
    line-height: 1.6;
    white-space: nowrap;
    background-color: rgba(255, 152, 0, 0.14);
    color: #e65100;
    border: 1px solid rgba(255, 152, 0, 0.4);
}
