:root {
    --primary-color: #4361ee;
    --secondary-color: #3f37c9;
    --accent-color: #4895ef;
    --success-color: #4cc9f0;
    --text-color: #ffffff;
    --text-muted: #e2e8f0;
    /* UPDATED: Brighter for contrast */
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --glass-bg: rgba(255, 255, 255, 0.15);
    /* UPDATED: More opaque for contrast */
    --glass-border: rgba(255, 255, 255, 0.2);
    /* UPDATED: Stronger border */
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --input-bg: rgba(255, 255, 255, 0.15);
    /* UPDATED: Slightly brighter input bg */
    --danger-color: #ef476f;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html {
    font-size: 17px;
    /* UPDATED: Base font size increased */
}

body {
    background: var(--bg-gradient);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

/* Background Animation */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(67, 97, 238, 0.1) 0%, transparent 60%);
    animation: pulse 15s infinite;
    z-index: -1;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.container {
    width: 100%;
    max-width: 800px;
    /* Wider for form */
    padding: 20px;
    perspective: 1000px;
}

/* Glassmorphism Card */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    /* Increased blur */
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px;
    box-shadow: var(--glass-shadow);
    transition: transform 0.4s ease, opacity 0.4s ease;
}

@media (max-width: 600px) {
    .glass-card {
        padding: 20px;
        /* UPDATED: Mobile padding */
    }
}

.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typography */
h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    background: linear-gradient(to right, #4cc9f0, #4361ee);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
}

h2 {
    font-size: 1.8rem;
    /* Use rem relative to new base */
    margin-bottom: 1.2rem;
    color: var(--text-color);
    font-weight: 700;
}

h3 {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    margin-top: 1.5rem;
}

p {
    line-height: 1.6;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 1.05rem;
    /* Ensure readable body text */
}

/* Form Elements */
.form-group {
    margin-bottom: 24px;
    position: relative;
    /* Fixed: Context for absolute feedback */
}

label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 1.1rem;
}

input[type="email"],
input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 16px 20px;
    /* UPDATED: Increased padding */
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text-color);
    font-size: 1.2rem;
    /* UPDATED: Larger text */
    font-weight: 500;
    transition: all 0.3s ease;
    height: 56px;
    /* UPDATED: Ensure touch target height */
}

input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
    background: rgba(255, 255, 255, 0.2);
}

/* Buttons */
.btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    font-size: 1.2rem;
    /* Larger text */
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    height: 56px;
    /* Ensure touch target height */
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    box-shadow: 0 4px 15px rgba(67, 97, 238, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(67, 97, 238, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    margin-top: 10px;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: rgba(239, 71, 111, 0.2);
    color: #ffadb8;
    width: auto;
    padding: 0 20px;
    /* Adjust padding */
    font-size: 1rem;
}

.btn-danger:hover {
    background: rgba(239, 71, 111, 0.4);
}

/* Checkbox specific */
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 14px;
    /* More gap */
    cursor: pointer;
    min-height: 48px;
    /* Touch target */
}

input[type="checkbox"] {
    appearance: none;
    width: 28px;
    /* Larger */
    height: 28px;
    background: var(--input-bg);
    border: 2px solid var(--glass-border);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

input[type="checkbox"]:checked {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 20px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Location Card Styles */
.location-card {
    background: rgba(255, 255, 255, 0.05);
    /* Slightly brighter */
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
    position: relative;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.location-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.animal-groups {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.animal-category {
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: 12px;
}

.category-title {
    font-size: 0.9rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 12px;
    letter-spacing: 1px;
    font-weight: 700;
}

/* UPDATED: Animal Option as Tiles */
.animal-option {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    margin-bottom: 8px;
    font-size: 1.1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 12px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    font-weight: 500;
}

/* Hide the native radio button but keep it logically there */
.animal-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* Hover State */
.animal-option:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
}

/* Selected State - Using :has() */
.animal-option:has(input:checked) {
    background: rgba(30, 58, 138, 0.8);
    /* Dark Blue */
    border: 2px solid #60a5fa;
    /* Bold Blue Border */
    color: white;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(60, 100, 250, 0.3);
}

/* Legacy support for JS adding span */
.animal-option span {
    margin-left: 0 !important;
    /* Override default margin */
    text-align: center;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(16, 185, 129, 0.95);
    color: white;
    padding: 16px 32px;
    border-radius: 40px;
    font-weight: 600;
    font-size: 1.1rem;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 4000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Helper text */
.helper-text {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 6px;
}

/* --- New Styles for V2 --- */
/* .input-popup removed */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.modal-content {
    background: #1e293b;
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Advanced List Items */
.location-card {
    cursor: default;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.location-card.dragging {
    opacity: 0.7;
    background: rgba(67, 97, 238, 0.2);
    border: 2px dashed var(--accent-color);
    transform: scale(0.98);
}

.location-header {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    gap: 12px;
}

/* Sort Handle */
.sort-handle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-muted);
    width: 40px;
    /* Touch target */
    height: 40px;
    border-radius: 8px;
    cursor: grab;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s;
    user-select: none;
    touch-action: none;
    font-size: 1.2rem;
}

.sort-handle-btn:active {
    cursor: grabbing;
    background: var(--primary-color);
    color: white;
}

.location-title-box {
    flex-grow: 1;
    overflow: hidden;
}

.location-title {
    font-weight: 700;
    color: white;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.location-coords {
    font-size: 0.9rem;
    color: var(--success-color);
    font-family: monospace;
    margin-top: 4px;
}

.location-map-container {
    width: 100%;
    height: 220px;
    margin-top: 15px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    overflow: hidden;
    background: #000;
}

/* Red X Button */
.btn-delete-x {
    background: rgba(239, 71, 111, 0.2);
    color: #ffadb8;
    border: none;
    width: 40px;
    /* Touch target */
    height: 40px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}

.btn-delete-x:hover {
    background: #ef476f;
    color: white;
    transform: rotate(90deg);
}

.address-input-wrapper {
    position: relative;
    gap: 10px;
    margin-bottom: 25px;
}

/* Mobile specific for input wrapper */
@media (max-width: 600px) {

    /* 1. Remove Glass Card (Edge-to-Edge) */
    .glass-card {
        border: none;
        box-shadow: none;
        border-radius: 0;
        background: transparent;
        /* Or nice gentle gradient if needed */
        padding: 30px 0;
        /* Vertical breathing room, no horizontal padding from card */
    }

    /* 2. Expand Container */
    .container {
        padding: 0 15px;
        /* Minimal side padding */
    }

    /* 3. Compensate Contrast */
    input[type="email"],
    input[type="text"],
    input[type="number"],
    .location-card,
    .animal-option {
        background: rgba(0, 0, 0, 0.4);
        /* Darker background to pop against body */
        border-color: rgba(255, 255, 255, 0.1);
    }

    /* 4. Vertical Breathing Room */
    .form-group,
    .location-card {
        margin-bottom: 30px;
    }

    /* Legacy: Input wrapper fix */
    .address-input-wrapper {
        display: flex;
        flex-direction: column;
    }

    #btn-convert {
        width: 100% !important;
        margin-top: 10px;
        /* More space */
    }
}

/* Feedback Box */
.feedback-box {
    position: absolute;
    bottom: 100%;
    left: 0;
    /* Align left */
    right: 0;
    /* Full width if needed, or stick to left/right bounds */
    width: max-content;
    max-width: 100%;
    margin-bottom: 12px;
    /* More space */
    background: rgba(15, 23, 42, 0.95);
    /* #0f172a nice dark blue */
    backdrop-filter: blur(8px);
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 1rem;
    /* Larger text */
    font-weight: 600;
    /* Bolder */
    pointer-events: none;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Bouncy pop */
    z-index: 100;
    white-space: normal;
    /* Allow wrapping on mobile */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    /* Default border */
}

.feedback-box:not(:empty) {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.feedback-box::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 20px;
    border-width: 8px;
    border-style: solid;
    border-color: rgba(0, 0, 0, 0.9) transparent transparent transparent;
}

.feedback-error {
    color: #ff6b6b;
    border: 1px solid rgba(255, 107, 107, 0.4);
}

.feedback-warning {
    color: #ffd166;
    border: 1px solid rgba(255, 209, 102, 0.4);
}

.feedback-suggestion {
    cursor: pointer;
    text-decoration: underline;
    font-weight: 800;
    color: #ffd166;
}

/* Suggestions Dropdown */
.suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: rgba(30, 41, 59, 0.98);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    margin-top: 8px;
    padding: 0;
    list-style: none;
    z-index: 2000;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    max-height: 280px;
    overflow-y: auto;
}

.suggestion-item {
    padding: 16px 20px;
    /* Larger touch area */
    color: var(--text-color);
    font-size: 1.05rem;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover,
.suggestion-item.active {
    background: rgba(67, 97, 238, 0.3);
    color: white;
}

.suggestion-highlight {
    color: var(--accent-color);
    font-weight: 700;
}

/* --- Livestock Grid Styles --- */
.livestock-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 10px;
}

.livestock-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 15px 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    font-weight: 500;
    text-align: center;
    min-height: 60px;
}

.livestock-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.livestock-option:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
}

.livestock-option:has(input:checked) {
    background: rgba(30, 58, 138, 0.8);
    border: 2px solid #60a5fa;
    color: white;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(60, 100, 250, 0.3);
}

/* Validation Error State */
.livestock-option.input-error {
    border-color: var(--danger-color);
    background: rgba(239, 71, 111, 0.1);
}

/* Minor Livestock Popup */
.livestock-popup {
    background: rgba(30, 41, 59, 0.98);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 20px;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    z-index: 2000;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    margin-top: 10px;
}

.livestock-popup h4 {
    margin: 0 0 15px 0;
    color: var(--text-color);
    text-align: center;
}

.minor-livestock-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.btn-minor-option {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 10px;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-minor-option:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: white;
}

.btn-minor-option.active {
    background: var(--primary-color);
    border-color: var(--accent-color);
    font-weight: bold;
}

/* Mobile Responsive */
@media (max-width: 600px) {
    .livestock-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .minor-livestock-list {
        grid-template-columns: repeat(2, 1fr);
    }
}