/* Language switching styles */
[class*="lang-"] {
    display: none;
}

.lang-zh-hant {
    display: inline;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --accent-color: #3498db;
    --background-color: #f5f6fa;
    --text-color: #2c3e50;
    --border-color: #ddd;
    --hover-color: #f8f9fa;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 20px;
    background-color: var(--background-color);
    color: var(--text-color);
    font-size: 16px;
}

/* Base container styles */
.search-form {
    max-width: 800px;
    width: 90%;
    margin: 0.5rem auto;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Responsive padding adjustments */
@media screen and (max-width: 48.75em) {
    .search-form {
        padding: 15px;
        margin: 10px;
    }

    body {
        padding: 10px;
    }
}

.search-form h1 {
    color: var(--primary-color);
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.75rem;
    line-height: 150%;
}

.form-group {
    margin-bottom: 1rem;
    width: 100%;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

/* Responsive select box */
.custom-select-multiple {
    height: 300px;
    min-height: 200px;
    width: 100%;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    background-color: white;
}

.select-item {
    padding: 10px;
    cursor: pointer;
    transition: background-color 0.2s;
    user-select: none;
}

.select-item:hover {
    background-color: #f7fafc;
}

.select-item.selected {
    background-color: #2c5282;
    color: white;
    font-weight: 500;
}

.select-item.selected:hover {
    background-color: #2a4365;
}

.select-help {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 0.5rem;
    font-style: italic;
}

/* Button styles */
.button {
    background-color: var(--accent-color);
    color: white;
    padding: 12px 24px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease-in-out;
    font-weight: 600;
    width: 100%;
    margin-top: 20px;
}

.button:hover {
    background-color: #2980b9;
    transform: translateY(-0.5rem);
}

.button:active {
    transform: translateY(0);
}

/* Error message styles */
.error-message {
    color: #e53e3e;
    font-size: 0.875rem;
    margin-top: 0.5rem;
    display: block;
    padding: 8px;
    background: #fadbd8;
    border-radius: 4px;
}

/* Results section */
.results-section {
    width: 100%;
    max-width: 800px;
    margin: 2rem auto;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

@media screen and (max-width: 48.75em) {
    .results-section {
        margin: 10px;
        padding: 15px;
    }
}

.result-item {
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    background-color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.result-item:last-child {
    border-bottom: none;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.result-header h3 {
    margin: 0;
    color: #2c5282;
    font-size: 1.25rem;
}

.article-number {
    font-weight: 600;
    color: #4a5568;
}

.result-title {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 1rem;
    color: #2d3748;
}

.result-ementa {
    margin-bottom: 1rem;
    padding: 0.5rem;
    background-color: #f7fafc;
    border-radius: 0.25rem;
}

.result-content {
    white-space: pre-wrap;
    line-height: 1.6;
    color: #4a5568;
}

/* Grid layout for larger screens */
@media screen and (min-width: 48.75em) {
    .form-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .form-grid .form-group {
        margin-bottom: 0;
    }

    .form-grid .form-group:last-child {
        grid-column: 1 / -1;
    }
}

/* Scrollbar styling */
.select-multiple::-webkit-scrollbar {
    width: 8px;
}

.select-multiple::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.select-multiple::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

/* Override the error-message div's default styling */
#error-message.error-message {
    border-bottom: none;
    margin: 0;
    padding: 0;
}

.search-title {
    border-bottom: 3px solid #2c5282 !important;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    font-size: clamp(1.5rem, 4vw, 2rem);
    margin-top: 0;
}

/* Add to existing CSS */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.modal-content {
    background-color: white;
    margin: 15% auto;
    padding: 20px;
    border-radius: 5px;
    width: 90%;
    max-width: 500px;
}

/* Responsive design */
@media screen and (max-width: 768px) {
    .search-form {
        padding: 1rem;
        margin: 1rem auto;
    }

    .select-multiple {
        height: 200px;
    }

    .form-control {
        padding: 0.5rem;
    }

    .location-checkboxes {
        gap: 0.5rem;
    }

    .modal-content {
        width: 95%;
        margin: 10% auto;
    }
}

/* Extra small devices */
@media screen and (max-width: 480px) {
    .search-form {
        width: 95%;
        padding: 0.5rem;
    }

    .select-multiple {
        height: 150px;
    }

    .checkbox {
        font-size: 0.9rem;
    }

    .form-control {
        font-size: 0.9rem;
    }
}

/* Button styling */
.button--form {
    width: 100%;
    padding: 0.75rem;
    background-color: #2c5282;
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.button--form:hover {
    background-color: #2d3748;
}

/* Error message styling */
.error-message {
    color: #e53e3e;
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

/* Location checkboxes */
.location-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 8px 0;  /* Add padding for better touch area */
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;  /* iOS minimum touch target size */
    padding: 4px 8px;  /* Add padding for better touch area */
    position: relative;  /* Ensure proper stacking context */
}

.checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin: 0;
    cursor: pointer;
    position: relative;
    z-index: 1;  /* Ensure checkbox is clickable */
}

.checkbox label {
    cursor: pointer;
    padding: 8px;  /* Increase touch target */
    margin: -8px;  /* Offset padding to maintain layout */
    font-size: 16px;  /* Prevent zoom on iOS */
    position: relative;
    z-index: 1;  /* Ensure label is clickable */
}

@supports (-webkit-touch-callout: none) {
    /* iOS-specific styles */
    html,
    body {
        height: 100%;
        overflow-x: hidden;
        -webkit-tap-highlight-color: transparent;  /* Remove tap highlight */
    }

    .main {
        /* Enable scrolling within the main content */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        height: 100%;
        /* Adjust for iOS safe areas */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    /* Handle notch/status bar area */
    .search-form {
        padding-top: max(1rem, env(safe-area-inset-top));
        position: relative;  /* Create stacking context */
        z-index: 0;  /* Lower than checkbox elements */
    }

    /* Improve input accessibility */
    input[type="checkbox"] {
        -webkit-appearance: checkbox !important;  /* Force native checkbox appearance */
        -moz-appearance: checkbox !important;
        appearance: checkbox !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        position: static !important;  /* Reset position */
        width: 22px !important;  /* Slightly larger on iOS */
        height: 22px !important;
        margin: 0 8px 0 0 !important;
    }

    /* Ensure touch targets are large enough */
    .checkbox {
        touch-action: manipulation;  /* Disable double-tap zoom */
        -webkit-user-select: none;  /* Prevent text selection */
        user-select: none;
    }
}

/* Update the result styles */
.article-number {
    font-weight: 600;
    color: #2c5282;
    padding: 0.5rem 0;
    margin: 0.5rem 0;
}

.result-ementa {
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background-color: #f7fafc;
    border-radius: 0.25rem;
}

/* Add styles for the keyword group */
.keyword-group {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.keyword-group .form-control {
    flex: 1;
    margin-bottom: 0;
}

.keyword-group .button--form {
    width: auto;
    min-width: 100px;
}

/* Add to your existing CSS */
@supports (-webkit-touch-callout: none) {

    /* iOS-specific styles */
    html,
    body {
        height: 100%;
        overflow-x: hidden;
    }

    .main {
        /* Enable scrolling within the main content */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        height: 100%;
        /* Adjust for iOS safe areas */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    /* Handle notch/status bar area */
    .search-form {
        padding-top: max(1rem, env(safe-area-inset-top));
    }

    /* Improve input accessibility */
    input,
    textarea,
    select {
        font-size: 16px;
        /* Prevent zoom on focus */
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        border-radius: 0;
    }
}

/* Prevent text size adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
}

/* Add styles for the collapsible law codes section */
.law-codes-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 0.5rem 0;
}

.collapse-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    transition: transform 0.3s ease;
}

.collapse-toggle.collapsed i {
    transform: rotate(-180deg);
}

#lawCodesCollapse {
    transition: height 0.3s ease-out;
    overflow: hidden;
}

#lawCodesCollapse:not(.show) {
    display: none;
}

/* Loading and No Results States */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--secondary-color);
    font-size: 1.1rem;
}

.loading::after {
    content: "...";
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: ""; }
    40% { content: "."; }
    60% { content: ".."; }
    80% { content: "..."; }
}

.no-results {
    text-align: center;
    padding: 2rem;
    background-color: #f8f9fa;
    border-radius: 8px;
    margin: 1rem 0;
}

.no-results p {
    color: var(--secondary-color);
    margin: 0.5rem 0;
    font-size: 1.1rem;
}

.no-results p:first-child {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 1.2rem;
}

.no-results ul {
    list-style-type: none;
    padding: 0;
    margin: 1rem 0;
    text-align: left;
    display: inline-block;
}

.no-results li {
    color: var(--secondary-color);
    padding: 0.3rem 0;
    position: relative;
    padding-left: 1.5rem;
}

.no-results li::before {
    content: "•";
    position: absolute;
    left: 0.5rem;
    color: var(--accent-color);
}

/* Error Message */
.error-message {
    background-color: #fff5f5;
    border: 1px solid #feb2b2;
    color: #c53030;
    padding: 0.75rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-weight: 500;
    display: none;
}

.error-message:not(:empty) {
    display: block;
}