@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

:root {
    /* Color Palette */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #e0e7ff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --bg-body: #f1f5f9;
    --bg-surface: #ffffff;
    --border-color: #e2e8f0;

    /* Dimensions */
    --header-height: 70px;
    --sidebar-width: 50%;
    /* Slightly narrower form by default for better map view */

    /* Effects */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    color: var(--text-main);
    background-color: var(--bg-body);
}

/* Header */
header {
    height: var(--header-height);
    background-color: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    z-index: 50;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.0em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    flex: 1;
    justify-content: flex-start;
}

.mobile-br {
    display: none;
}


.login-btn {
    background-color: var(--primary);
    color: white;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2);
}

.login-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(79, 70, 229, 0.3);
}

.login-btn:active {
    transform: translateY(0);
}


/* Header Right Section */
.header-right {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
    justify-content: flex-end;
}

/* Filters Container */
.filters-container {
    display: none;
}

.location-filter-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.4rem 1.5rem;
    height: 38px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: white;
    color: #64748b;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    margin-right: 0.5rem;
}

.location-filter-btn:hover {
    background: #f8fafc;
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.12);
}

.location-filter-btn.active {
    background: #e0e7ff;
    border-color: var(--primary);
    color: var(--primary);
}

.location-filter-btn.has-selection {
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    color: white;
    border: none;
    max-width: 200px;
    padding: 0.5rem 1.25rem;
}

.location-filter-btn.has-selection:hover {
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.3);
    color: white;
    filter: brightness(1.1);
}

.location-filter-btn i {
    font-style: normal;
    font-size: 1.1rem;
}

/* Summary Period Badge */
.summary-period-badge {
    font-size: 0.82rem;
    font-weight: 700;
    color: #4f46e5;
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
    padding: 0.4rem 1.2rem;
    border-radius: 999px;
    border: 1px solid #c7d2fe;
    box-shadow: 0 0 15px rgba(79, 70, 229, 0.1);
    white-space: nowrap;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.location-filter-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 220px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.75rem;
    z-index: 110;
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.location-filter-dropdown.show {
    display: flex;
}

.location-filter-dropdown .filters-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
    margin: 0;
}

.location-filter-dropdown .filter-select {
    width: 100%;
    min-width: unset;
    flex: unset;
}

.location-show-btn {
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.25rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: background 0.2s;

    order: 99;
}

.location-show-btn:hover {
    background: var(--primary-hover);
}

/* Filter Selects */
.filter-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 0.45rem 2rem 0.45rem 0.65rem;
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-main);
    cursor: pointer;
    font-family: var(--font-sans);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%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 0.75rem center;
    background-size: 1rem;
    transition: all 0.2s;
    min-width: 110px;
}

.filter-select:hover:not(:disabled) {
    background-color: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-select:disabled {
    opacity: 0.6;
    background-color: #f1f5f9;
    cursor: not-allowed;
    color: #94a3b8;
}

/* User Profile */
.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    transition: background-color 0.2s;
    user-select: none;
}

.user-profile:hover,
.user-profile.active {
    background-color: #f1f5f9;
}

.avatar {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary), #818cf8);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.25);
    border: 2px solid white;
}

.username {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.95rem;
}

/* Dropdown Menu */
.dropdown-menu {
    position: absolute;
    top: 120%;
    right: 0;
    width: 160px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    display: none;
    flex-direction: column;
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

.dropdown-menu.show {
    display: flex;
}

.dropdown-item {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dropdown-item:hover {
    background-color: #f1f5f9;
}

.dropdown-item.danger {
    color: #ef4444;
}

.dropdown-item.danger:hover {
    background-color: #fee2e2;
}

.plot-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.plot-nav-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: var(--shadow-md);
}

.plot-nav-btn:active {
    transform: scale(0.95);
}

/* Form Header (Selected Point Info) */
.form-header {
    padding: 0.6rem 1.25rem;
    background-color: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-height: 55px;
    /* Compact height */
    transition: background-color 0.4s ease, border-color 0.4s ease;
}

/* Section-specific header colors */
.form-header.farm-info-mode {
    background-color: #fef2f2 !important;
    /* Rose 50 */
    border-bottom-color: #fee2e2 !important;
}

.form-header.weekly-survey-mode {
    background-color: #eff6ff !important;
    /* Blue 50 */
    border-bottom-color: #dbeafe !important;
}

.header-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    flex: 1;
    text-align: center;
    align-items: center;
}

.harvest-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.45rem 0.75rem;
    background-color: #d97706;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(217, 119, 6, 0.2);
}

.harvest-btn.harvested {
    background-color: #94a3b8;
    cursor: default;
    box-shadow: none;
    pointer-events: none;
}

.form-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
    transition: color 0.3s ease;
}

.farm-info-mode .section-title-text {
    color: #b91c1c;
    /* Red 700 */
}

.weekly-survey-mode .section-title-text {
    color: #1d4ed8;
    /* Blue 700 */
}

.form-header .subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.farm-info-summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.1rem;
}

#summary-text {
    font-size: 0.75rem;
    color: var(--primary);
    font-weight: 600;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
}



.harvest-btn:hover {
    background-color: #b45309;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(217, 119, 6, 0.3);
}

.harvest-btn:active {
    transform: translateY(0);
}

.harvest-btn span {
    white-space: nowrap;
}

/* Main Content Area (Split View) */
main {
    flex: 1;
    display: flex;
    width: 100%;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
    position: relative;
}

/* Left Panel - Map */
#map-container {
    flex: 1;
    height: 100%;
    position: relative;
    z-index: 10;
}

#map {
    width: 100%;
    height: 100%;
    outline: none;
}

.map-control-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1001;
    background-color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-main);
}

.map-control-btn:hover {
    background-color: #f8fafc;
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.map-control-btn.active {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 0 0 4px var(--primary-light), 0 4px 12px rgba(79, 70, 229, 0.3);
}

.map-control-btn:active {
    transform: translateY(0);
}

/* Right Panel - Form */
#form-container {
    width: 100%;
    height: 100%;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 20;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.05);
}

iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    /* Removes inline gap */
}


/* Responsive adjustments */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 50%;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(15, 23, 42, 0.6);
    /* Slate 900 with opacity */
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal[style*="display: flex"] {
    opacity: 1;
}

.modal-content {
    background-color: var(--bg-surface);
    padding: 2.5rem;
    width: 90%;
    max-width: 420px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    position: relative;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal[style*="display: flex"] .modal-content {
    transform: scale(1);
}

.close-btn {
    color: var(--text-muted);
    position: absolute;
    right: 24px;
    top: 24px;
    font-size: 1.5rem;
    font-weight: 500;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
    background: transparent;
    border: none;
    padding: 4px;
    border-radius: 4px;
}

.close-btn:hover {
    color: var(--text-main);
    background-color: #f1f5f9;
}

.modal h2 {
    margin-bottom: 2rem;
    color: var(--text-main);
    font-weight: 700;
    font-size: 1.75rem;
    text-align: center;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-main);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    color: var(--text-main);
    background-color: #f8fafc;
    transition: all 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    background-color: #fff;
    box-shadow: 0 0 0 4px var(--primary-light);
}

.submit-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    padding: 0.875rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 0.5rem;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}

.submit-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 12px -2px rgba(79, 70, 229, 0.3);
}

.submit-btn:active {
    transform: translateY(0);
}

.register-prompt {
    margin-top: 1.5rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.register-prompt span {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.register-link-btn {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    width: 100%;
    transition: all 0.2s;
}

.register-link-btn:hover {
    background-color: var(--primary-light);
}

/* =========================================
   Survey Form Improvements (v2)
   ========================================= */


#survey-form-wrapper {
    background-color: var(--bg-surface);
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Placeholder State */
#survey-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
    background-color: #f8fafc;
}

#survey-placeholder::before {
    content: '📍';
    font-size: 3rem;
    margin-bottom: 1rem;
    filter: grayscale(100%) opacity(0.5);
}

/* The Form Itself */
#survey-form {
    padding: 2rem;
    flex-direction: column;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* Form Styling */
.form-group-modern {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-label-modern {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-input-modern,
.form-select-modern {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    color: var(--text-main);
    background-color: #fff;
    transition: all 0.2s ease;
    font-family: var(--font-sans);
}

.form-input-modern:focus,
.form-select-modern:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-input-modern:disabled {
    background-color: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}

/* Thai Date Overlay */
input[type="date"][data-thai-init] {
    color: transparent;
}

input[type="date"][data-thai-init]::-webkit-datetime-edit {
    color: transparent;
}

.thai-date-overlay {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: 0.95rem;
    color: var(--text-main);
    white-space: nowrap;
}

/* Custom Select Arrow */
.form-select-modern {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%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 1rem center;
    background-size: 1rem;
    padding-right: 2.5rem;
    cursor: pointer;
}

/* Save Button Row */
.save-btn-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin: 1.5rem auto 1rem auto;
    width: 100%;
}

.save-btn-row .save-btn-modern {
    margin: 0;
}

.dekad-coverage {
    font-size: 0.85rem;
    font-weight: 700;
    color: #15803d;
    background: #dcfce7;
    border: 1px solid #86efac;
    border-radius: 999px;
    padding: 0.3rem 0.75rem;
    white-space: nowrap;
}

.harvest-summary {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.3;
}

.harvest-summary span:first-child {
    color: #0369a1;
}

.harvest-summary span:last-child {
    color: #15803d;
}

/* Save Button */
.save-btn-modern {
    margin: 1.5rem auto 1rem auto;
    width: 100%;
    display: block;
    padding: 0.85rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}

.save-btn-modern:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 12px -2px rgba(79, 70, 229, 0.3);
}

.save-btn-modern:active {
    transform: translateY(0);
}

.save-btn-modern:disabled {
    background: #cbd5e1;
    color: #64748b;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.save-btn-modern.next-iteration {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%) !important;
    box-shadow: 0 4px 6px -1px rgba(22, 163, 74, 0.3) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.save-btn-modern.next-iteration:hover {
    box-shadow: 0 6px 12px -2px rgba(22, 163, 74, 0.4);
}

/* Status Messages */
.form-status-msg {
    min-height: 1.5rem;
    margin-top: 0.5rem;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 500;
}

.sheet-handle {
    display: none;
}

/* ===============================
   🖥 Desktop: Keep Original Split View
   =============================== */

.bottom-sheet {
    position: static;
    width: var(--sidebar-width);
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    border-radius: 0;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.05);
    transform: none;
    z-index: auto;
}

/* ============================
   📱 Improved Mobile Layout
   ============================ */

@media (max-width: 768px) {

    body {
        overflow: auto;
    }

    header {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        height: auto;
        padding: 10px 16px;
        gap: 6px 8px;
        background-color: #ffffff !important;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .logo {
        flex: 1;
        order: 1;
        font-size: 0.85rem;
        white-space: normal;
    }


    .header-right {
        order: 2;
        position: relative;
    }

    .filters-container {
        order: 3;
        width: 100%;
        margin: 0;
        flex-wrap: wrap;
        gap: 8px;
    }

    .filter-select {
        flex: 1 1 30%;
        min-width: 100px;
        font-size: 0.8rem;
    }

    .user-profile {
        padding: 0.2rem 0.4rem;
        gap: 0.35rem;
    }

    .avatar {
        width: 26px;
        height: 26px;
        font-size: 0.65rem;
    }

    .username {
        font-size: 0.75rem;
    }

    .login-btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
}

/* ===============================
   📱 Google Maps Style Bottom Sheet
   =============================== */

@media (max-width: 768px) {

    main {
        height: calc(100vh - 120px);
    }

    #map-container {
        position: relative;
        height: 100%;
    }

    .bottom-sheet {
        position: fixed;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 50vh;
        background: white;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.15);
        display: flex;
        flex-direction: column;
        z-index: 999;
        /* Default visible at 50% height */
    }

    .sheet-handle {
        display: block;
        width: 40px;
        height: 5px;
        background: #cbd5e1;
        border-radius: 5px;
        margin: 8px auto 4px auto;
        cursor: ns-resize;
        touch-action: none;
    }

    #form-container {
        width: 100%;
        flex: 1;
        min-height: 0;
        border: none;
        box-shadow: none;
    }

    #survey-form {
        padding: 0.75rem;
        padding-top: 0.25rem;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        gap: 0.75rem;
    }

    .form-section-modern {
        padding: 0.75rem;
        gap: 0.75rem;
        margin-bottom: 0.5rem;
    }
}

/* ===============================
   Survey Form v2 Groups & Upload
   =============================== */
.form-section-modern {
    background: #f8fafc;
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.form-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.weekly-row-grid {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.weekly-row-grid .form-group-modern {
    flex: 1;
    margin-bottom: 0;
}

/* Weekly Timeline */
.timeline-container {
    width: 100%;
    overflow-x: auto;
    padding: 0.5rem 0.25rem 1rem 0.25rem;
    scrollbar-width: none;
}

.timeline-container::-webkit-scrollbar {
    display: none;
}

.timeline-wrapper {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 0.75rem 0.5rem;
    min-width: auto;
    position: relative;
    padding: 0.5rem 0;
    justify-items: center;
}

.timeline-wrapper::before,
.timeline-wrapper::after {
    content: '';
    position: absolute;
    left: 8%;
    right: 8%;
    height: 2px;
    background-color: #e2e8f0;
    z-index: 1;
}

/* Row 1 Connector */
.timeline-wrapper::before {
    top: calc(0.5rem + 16px);
}

/* Row 2 Connector */
.timeline-wrapper::after {
    bottom: calc(0.5rem + 16px);
}

.week-item {
    position: relative;
    z-index: 2;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: white;
    border: 2px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.week-item::before {
    display: none;
}

.week-item:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.week-item.out-of-range {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
    color: #cbd5e1;
    cursor: default;
    pointer-events: none;
}

.week-item.no-data {
    background-color: #fee2e2;
    border-color: #fca5a5;
    color: #b91c1c;
}

.week-item.has-data {
    background-color: #bbf7d0;
    border-color: #22c55e;
    color: #15803d;
}

.week-item.active {
    background-color: var(--primary);
    border-color: var(--primary);
    color: white;
    transform: scale(1.2);
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.25);
}

/* Section Backgrounds */
#farm-info-section {
    background-color: #fef2f2;
    /* Rose 50 */
    padding: 0.6rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
}

#weekly-survey-section {
    background-color: #eff6ff;
    /* Blue 50 */
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
}

.farm-grid-modern {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.full-width {
    grid-column: span 2;
}

.farm-actions-modern {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* Star Rating System */
.star-rating-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    background: #ffffff;
    border-radius: 12px;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.stars {
    display: flex;
    gap: 0.5rem;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

@media (max-width: 768px) {
    .stars {
        font-size: 1.5rem;
        gap: 0.35rem;
    }

    .star-rating-container {
        padding: 0.5rem 0.75rem;
        gap: 0.35rem;
    }

    .star-label {
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .stars {
        font-size: 1.25rem;
        gap: 0.25rem;
    }

    .star-rating-container {
        padding: 0.4rem 0.6rem;
    }

    .star-label {
        font-size: 0.8rem;
    }
}

.star {
    color: #e2e8f0;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.star:hover {
    transform: scale(1.2);
    color: #ffca28;
}

.star.active {
    color: #ffca28;
    text-shadow: 0 0 15px rgba(255, 202, 40, 0.4);
}

.star-label {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
}


@media (max-width: 480px) {
    .form-header.weekly-survey-mode {
        padding: 1rem 1.25rem;
        min-height: 80px;
    }

    .farm-info-summary {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
        margin-top: 0.25rem;
    }

    #summary-text {
        max-width: none;
        white-space: normal;
        line-height: 1.3;
    }

    .form-section-modern {
        background: white;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        border-radius: 8px;
        padding: 1.25rem;
    }

    .farm-grid-modern {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .farm-actions-modern {
        justify-content: center;
    }

    .weekly-row-grid {
        display: flex;
        flex-direction: row;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .weekly-row-grid .form-group-modern {
        flex: 1;
        min-width: 0;
        /* Prevent overflow */
    }

    #weekly-survey-section {
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .timeline-container {
        padding: 0.25rem 0.25rem 0.5rem 0.25rem;
    }

    .timeline-wrapper {
        gap: 0.4rem 0.5rem;
    }

    .week-item {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    .timeline-wrapper::before {
        top: calc(0.25rem + 14px);
    }

    .timeline-wrapper::after {
        bottom: calc(0.25rem + 14px);
    }

    .save-btn-modern {
        margin: 0.75rem auto 0.75rem auto;
        padding: 0.65rem;
    }

    .section-title {
        font-size: 0.8rem;
        padding-bottom: 0.25rem;
        margin-bottom: 0.15rem;
    }

    .form-group-modern {
        gap: 0.25rem;
    }

    .farm-row-1 .form-input-modern,
    .farm-row-1 .form-select-modern,
    .farm-row-2 .form-input-modern,
    .farm-row-2 .form-select-modern {
        padding: 0.5rem 0.25rem;
        font-size: 0.75rem;
    }

    .thai-date-overlay {
        left: 0.25rem;
        font-size: 0.75rem;
    }

    .save-farm-btn-small {
        padding: 0.5rem 0.5rem;
        font-size: 0.7rem;
    }
}

.section-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    border-bottom: 1px solid var(--primary-light);
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}

/* Row wrapper used in Dekad Survey to place lap tabs on the right */
.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    border-bottom: 1px solid var(--primary-light);
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}

.section-title-row .section-title {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

/* Lap tabs inside Dekad Survey */
.dekad-lap-tabs {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.dekad-lap-tab {
    padding: 0.2rem 0.6rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: color 0.15s, background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.dekad-lap-tab:hover {
    color: var(--primary);
    background: var(--primary-light);
    border-color: var(--primary);
}

.dekad-lap-tab.active {
    color: white;
    background: var(--primary);
    border-color: var(--primary);
}

.upload-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.upload-btn-modern {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background-color: white;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-btn-modern:hover {
    border-color: var(--primary);
    color: var(--primary);
    background-color: var(--primary-light);
}

.upload-status-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

.save-farm-btn-small {
    margin-top: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    width: fit-content;
    align-self: flex-end;
}

.save-farm-btn-small:hover {
    background-color: var(--primary);
    color: white;
}

.save-farm-btn-small:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* =========================================
   Tab Navigation (Survey / Summary)
   ========================================= */

.form-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    background: #f8fafc;
    flex-shrink: 0;
    padding: 0 0.25rem;
    gap: 0.25rem;
}

.form-tab {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    font-family: var(--font-sans);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s ease;
    letter-spacing: 0.01em;
}

.form-tab:hover {
    color: var(--primary);
    background: #f0f4ff;
}

.form-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: white;
}

/* =========================================
   Summary Verification UI
   ========================================= */

.summary-verify-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.25rem 0;
}

.verify-radios {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-items: flex-start;
}

.verify-radio-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: var(--text-main);
    cursor: pointer;
}

.verify-radio-item input {
    cursor: pointer;
    width: 14px;
    height: 14px;
}

.summary-stars-container {
    display: none;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.4rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-top: 0.25rem;
    width: fit-content;
}

.summary-stars-container.show {
    display: flex;
}

.summary-stars {
    display: flex;
    gap: 0.2rem;
    font-size: 1.15rem;
    cursor: pointer;
    color: #e2e8f0;
}

.summary-star {
    transition: transform 0.1s ease;
}

.summary-star:hover {
    transform: scale(1.1);
}

.summary-star.active {
    color: #ffca28;
}

.summary-star-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
}


.summary-footer {
    padding: 1rem;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: center;
}

.save-all-summary-btn {
    padding: 0.75rem 1.5rem;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.1);
    min-width: 150px;
}

.save-all-summary-btn:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(16, 185, 129, 0.2);
}

.save-all-summary-btn svg {
    flex-shrink: 0;
}

.refresh-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    color: #64748b;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}

.refresh-btn:hover {
    background: #f1f5f9;
    color: var(--primary);
    border-color: var(--primary-light);
}

.summary-count-badge {
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
    background: var(--primary);
    border-radius: 999px;
    padding: 0.25rem 0.75rem;
    white-space: nowrap;
}

@media (max-width: 768px) {

    header {
        background: rgba(255, 255, 255, 0.2) !important;
        border-bottom: none !important;
        box-shadow: none !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 1000;
        pointer-events: none;
        padding: 0 0.5rem !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    header>* {
        pointer-events: auto !important;
    }

    main {
        height: 100vh !important;
    }

    #pin-mode-btn {
        top: 80px !important;
    }

    #my-location-btn {
        top: 134px !important;
    }

    .leaflet-top.leaflet-left {
        top: 10% !important;
    }

    .summary-period-wrapper {
        display: flex !important;
        flex: 0 0 35%;
        width: 35%;
        justify-content: center;
        order: 2;
        margin: 0;
        z-index: 5;
    }

    .summary-period-badge {
        display: inline-flex !important;
        font-size: 0.65rem !important;
        padding: 0.50rem !important;
        border-radius: 999px;
        box-shadow: 0 2px 8px rgba(79, 70, 229, 0.1);
        width: 95%;
        justify-content: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #summary-container {
        position: relative;
        padding-bottom: 50px;
        /* Space so table doesn't get covered by floating button */
    }

    #summary-container>div {
        padding: 0.4rem !important;
    }

    .summary-footer {
        padding: 0.5rem;
    }

    .save-all-summary-btn {
        position: fixed;
        bottom: 12px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 1010;
        padding: 0.8rem 1.5rem;
        font-size: 0.85rem;
        font-weight: 700;
        border-radius: 999px;
        box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
        width: auto;
        min-width: 240px;
        justify-content: center;
        border: 2px solid white;
    }

    .save-all-summary-btn svg {
        width: 16px;
        height: 16px;
    }

    .form-header .header-info {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        text-align: center;
        width: 100%;
        padding: 0.1rem 1rem;
    }

    .form-header .section-title-text {
        font-size: 1rem !important;
        margin-bottom: 0.15rem !important;
        color: var(--primary) !important;
    }

    .form-header .subtitle {
        font-size: 0.75rem !important;
        color: var(--text-muted) !important;
    }

    .form-header .farm-info-summary {
        font-size: 0.8rem !important;
        margin-top: 0.25rem !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 0.2rem !important;
    }

    .form-header {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding: 0.25rem 0.5rem !important;
        min-height: auto !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }

    .plot-nav-btn {
        position: fixed !important;
        top: 75% !important;
        transform: translateY(-50%) !important;
        width: 44px !important;
        height: 44px !important;
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(4px);
        border: 1px solid #cbd5e1 !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
        z-index: 2000 !important;
        display: flex !important;
    }

    .plot-nav-btn.prev {
        left: 0.5rem !important;
    }

    .plot-nav-btn.next {
        right: 0.5rem !important;
    }

    .plot-nav-btn svg {
        width: 22px !important;
        height: 22px !important;
    }

    .form-tabs {
        margin-top: -6px !important;
    }

    .form-tab {
        padding: 0.35rem 0.6rem !important;
        font-size: 0.9rem !important;
    }

    /* Mobile Header: Hide username and move avatar to right */
    .username {
        display: none !important;
    }

    .header-right {
        flex: 0 0 40%;
        width: 40%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0;
        min-width: 0;
        order: 3;
        position: relative;
    }

    .location-filter-btn {
        flex: 0 0 75% !important;
        width: 75% !important;
        padding: 0.35rem 0.2rem !important;
        font-size: 0.75rem !important;
        height: 34px !important;
        max-width: none !important;
        white-space: nowrap !important;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-right: 0 !important;
        gap: 0.25rem !important;
    }

    .location-filter-btn i {
        font-size: 0.8rem !important;
        flex-shrink: 0;
    }

    .location-filter-btn span {
        white-space: nowrap;
    }

    .login-btn {
        flex: 0 0 25% !important;
        width: 25% !important;
        padding: 0 !important;
        font-size: 0.5rem !important;
        border-radius: 8px !important;
        min-width: 0 !important;
        box-shadow: none !important;
        height: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
    }

    .user-profile {
        flex: 0 0 25% !important;
        width: 25% !important;
        padding: 0 !important;
        background: transparent !important;
        justify-content: center;
    }

    .logo-full-text {
        display: none !important;
    }

    .mobile-br {
        display: block !important;
    }

    .logo {
        font-size: 0.95rem !important;
        font-weight: 800 !important;
        letter-spacing: -0.01em;
        display: flex !important;
        flex: 0 0 25%;
        width: 25%;
        justify-content: center;
        align-items: center;
        min-width: 0;
        margin: 0 !important;
        padding: 0.4rem 0 !important;
        order: 1;
        overflow: hidden;
        background: white !important;
        border-radius: 10px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
        color: var(--primary) !important;
    }

    /* Mobile: Hide original filters row in header, but allow it in dropdown */
    header>.filters-container {
        display: none !important;
    }

    .location-filter-dropdown .filters-container {
        display: flex !important;
    }

    .location-filter-dropdown {
        display: none;
        position: absolute !important;
        top: calc(100% + 8px) !important;
        right: 0 !important;
        left: auto !important;
        width: 180px !important;
        max-width: 90vw !important;
        background: white !important;
        border: 1px solid var(--border-color) !important;
        border-radius: 12px !important;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2) !important;
        padding: 1rem !important;
        z-index: 10000 !important;
        pointer-events: auto !important;
    }

    .location-filter-dropdown.show {
        display: flex !important;
        flex-direction: column !important;
    }

    /* Mobile Location: Three rows */
    .summary-location-container {
        display: block !important;
    }

    .loc-part {
        display: block !important;
    }


    /* Reduce table padding on mobile */
    #summary-tbody td {
        padding: 0.25rem 0.2rem !important;
    }

    #summary-table {
        table-layout: fixed !important;
        font-size: 0.88rem !important;
    }

    #summary-table th,
    #summary-table td {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    #summary-table th:nth-child(1),
    #summary-table td:nth-child(1) {
        width: 24% !important;
    }

    #summary-table th:nth-child(2),
    #summary-table td:nth-child(2) {
        width: 38% !important;
    }

    #summary-table th:nth-child(3),
    #summary-table td:nth-child(3) {
        width: 38% !important;
    }

    #summary-table th {
        padding: 0.35rem 0.2rem !important;
        font-size: 0.72rem !important;
    }
}