:root {
    --primary-color: #4361ee;
    --primary-light: #e0e7ff;
    --secondary-color: #3f37c9;
    --accent-color: #f72585;
    --text-color: #2b2d42;
    --text-light: #8d99ae;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --border-color: #e9ecef;
    --success-color: #4cc9f0;
    --warning-color: #f8961e;
    --danger-color: #ef233c;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --border-radius: 12px;
    --border-radius-sm: 6px;
    --transition: none;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px 24px;
}

.app-header {
    text-align: center;
    margin-bottom: 40px;
}

.app-header h1 {
    font-size: 40px;
    font-weight: 800;
    color: var(--primary-color);
    margin-bottom: 8px;
    line-height: 1.2;
}

.app-header h1 span {
    color: var(--text-color);
    font-weight: 600;
}

.app-header .subtitle {
    font-size: 18px;
    color: var(--text-light);
}

.control-panel {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 24px;
    margin-bottom: 32px;
    box-shadow: var(--shadow-sm);
    overflow: visible !important;
    position: relative;
    z-index: 50;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
}

.toggle-filters {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--border-radius-sm);

}

.toggle-filters:hover {
    background-color: var(--primary-light);
}

.toggle-filters svg {
    width: 20px;
    height: 20px;
    fill: var(--text-color);
    transition: transform 0.3s ease;
}

.toggle-filters.collapsed svg {
    transform: rotate(180deg);
}

.panel-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: 2000px;
    overflow: visible !important;
    opacity: 1;
    transition: max-height 0.5s ease, opacity 0.3s ease, padding 0.3s ease;
    position: relative;
    z-index: 1;
}

.panel-content.collapsed {
    max-height: 0;
    opacity: 0;
    padding: 0;
    overflow: hidden;
}

.action-form {
    margin-bottom: 10px;
}

.action-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border-radius: var(--border-radius-sm);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;

    border: none;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.btn-fetch {
    background-color: var(--primary-color);
    color: white;
}

.btn-fetch:hover {
    background-color: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-clear {
    background-color: #dc143c;
    color: white;
}

.btn-clear:hover {
    background-color: #b00830;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: none;
    opacity: 0;
    position: absolute;
}

.btn.loading .btn-content {
    opacity: 0;
}

.btn.loading .loading-spinner {
    opacity: 1;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.filters-row {
    display: flex;
    gap: 12px;
    align-items: end;
    flex-wrap: nowrap;
    overflow: visible !important;
    padding-bottom: 8px;
    scroll-behavior: smooth;
    position: relative;
    z-index: 100;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 115px;
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.filter-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-color);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.filter-select, .filter-input {
    padding: 10px 11px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 14px;

    background-color: var(--bg-color);
    height: 36px;
    min-height: 36px;
    max-height: 36px;
    display: flex;
    align-items: center;
    line-height: 1;
}

.filter-select:focus, .filter-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

/* Custom Dropdown Styles */
.custom-select {
    position: relative;
    width: 100%;
    min-width: 0;
    z-index: 100;
}

.custom-select-trigger {
    padding: 10px 32px 10px 11px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 14px;
    background-color: var(--bg-color);
    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    position: relative;
    height: 36px;
    min-height: 36px;
    max-height: 36px;
    line-height: 1;
}

.custom-select-trigger:hover {
    border-color: var(--primary-color);
}

.custom-select.open .custom-select-trigger {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

.custom-select-trigger::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid var(--text-color);
    transition: transform 0.3s ease;
}

.custom-select.open .custom-select-trigger::after {
    transform: translateY(-50%) rotate(180deg);
}

.custom-select-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 9999 !important;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-10px);
    transition: max-height 0.4s ease, opacity 0.3s ease, transform 0.3s ease;
}

.custom-select.open .custom-select-options {
    max-height: 300px;
    opacity: 1;
    transform: translateY(0);
    overflow-y: auto;
}

.custom-select-option {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-color);
}

.custom-select-option:hover {
    background-color: var(--primary-light);
    color: var(--primary-color);
}

.custom-select-option.selected {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
}

.custom-select-option.selected:hover {
    background-color: var(--secondary-color);
}

/* Hide original select */
.filter-select.hidden {
    display: none;
}

/* Scrollbar styling for dropdown */
.custom-select-options::-webkit-scrollbar {
    width: 6px;
}

.custom-select-options::-webkit-scrollbar-track {
    background: var(--bg-color);
    border-radius: 3px;
}

.custom-select-options::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

.custom-select-options::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Hide scrollbar for short lists */
.custom-select.short-list .custom-select-options {
    overflow-y: hidden !important;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

.custom-select.short-list .custom-select-options::-webkit-scrollbar {
    display: none; /* Chrome/Safari/Opera */
}

.range-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    min-height: 36px;
    max-height: 36px;
}

.range-inputs span {
    color: var(--text-light);
    font-weight: 500;
}

.range-inputs input {
    height: 36px;
    min-height: 36px;
    max-height: 36px;
    line-height: 1;
}

.filter-input {
    width: 75px;
    font-size: 14px;
    padding: 10px 11px;
    height: 36px;
    min-height: 36px;
    max-height: 36px;
    line-height: 1;
}

.filter-buttons {
    display: flex;
    gap: 8px;
}

.btn-apply {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    cursor: pointer;

    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-apply:hover {
    background-color: var(--secondary-color);
}

.btn-reset {
    background-color: var(--text-light);
    color: white;
    text-decoration: none;
    padding: 10px 15px;
    border-radius: var(--border-radius-sm);
    font-weight: 500;

    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-reset:hover {
    background-color: var(--text-color);
    color: white;
}

.stats-container {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    position: relative;
    z-index: 0;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    background-color: var(--primary-light);
    color: var(--primary-color);
    padding: 6px 12px;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
}

.stat-icon {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.properties-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
    margin-bottom: 48px;
}

.property-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    opacity: 0;
}

.property-card.show {
    animation: cardLoad 0.5s ease-out forwards;
}

.property-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.property-image-container {
    height: 180px;
    overflow: hidden;
    position: relative;
}

.property-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.property-card:hover .property-image {
    transform: scale(1.05);
}

.property-image-placeholder {
    width: 100%;
    height: 100%;
    background-color: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
}

.property-image-placeholder svg {
    width: 48px;
    height: 48px;
    fill: var(--primary-color);
    opacity: 0.5;
}

.property-content {
    padding: 14px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.property-title {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-color);
    line-height: 1.3;
}

.property-meta {
    display: flex;
    gap: 8px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-light);
}

.meta-icon {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.property-details {
    display:flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
}

.detail-row.highlight {
    padding: 3px;
    background-color: var(--primary-light);
    border-radius: var(--border-radius-sm);
}

.detail-label {
    display: flex;
    align-items: center;
    gap: 2px;
    color: var(--text-light);
    font-weight: 500;
}

.detail-icon {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.detail-value {
    font-weight: 600;
    color: var(--text-color);
    text-align: right;
}

.highlight .detail-value {
    color: var(--primary-color);
    font-weight: 700;
}

.property-footer {
    padding: 0 14px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
}

.property-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background-color: var(--primary-color);
    color: white;
    border-radius: var(--border-radius-sm);
    font-weight: 600;
    text-decoration: none;

    font-size: 12px;
}

.property-link:hover {
    background-color: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.link-icon {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

:root {
    --otodom-logo-height: 50px;
    --otodom-logo-width: 80px;
    --nieruchomosci-logo-height: 50px;
    --nieruchomosci-logo-width: 120px;
    --olx-logo-height: 38px;
    --olx-logo-width: 58px;
    --gratka-logo-height: 34px;
    --gratka-logo-width: 85px;
}

.source-logo {
    height: auto;
    object-fit: contain;
    display: block;
}

.source-logo.otodom {
    transform: translateX(-20px);
    height: var(--otodom-logo-height);
    max-width: var(--otodom-logo-width);
}

.source-logo.nieruchomosci {
    height: var(--nieruchomosci-logo-height);
    max-width: var(--nieruchomosci-logo-width);
}

.source-logo.olx {
    transform: translateX(-20px);
    height: var(--olx-logo-height);
    max-width: var(--olx-logo-width);
}

.source-logo.gratka {
    transform: translateX(-20px);
    height: var(--gratka-logo-height);
    max-width: var(--gratka-logo-width);
}

.pagination-container {
    display: flex;
    justify-content: center;
    margin-top: 48px;
}

.pagination {
    display: flex;
    gap: 8px;
    align-items: center;
}

.page-link {
    padding: 8px 16px;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    color: var(--text-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.page-link:hover {
    background-color: var(--primary-light);
    color: var(--primary-color);
}

.page-link.current {
    background-color: var(--primary-color);
    color: white;
}

.page-link svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.empty-state {
    text-align: center;
    padding: 64px 32px;
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.empty-icon {
    width: 48px;
    height: 48px;
    fill: var(--primary-color);
    margin-bottom: 24px;
    opacity: 0.7;
}

.empty-state h3 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--text-color);
}

.empty-state p {
    color: var(--text-light);
    font-size: 17px;
}

@media (max-width: 1024px) {
    .filters-row {
        gap: 12px;
    }

    .filter-group {
        min-width: 100px;
    }

    .filter-input {
        width: 70px;
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: 20px 12px;
    }

    .app-header h1 {
        font-size: 28px;
    }

    .app-header h1 svg {
        width: 28px;
        height: 28px;
    }

    .app-header p {
        font-size: 15px;
    }

    .filters-row {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .filter-group {
        min-width: auto;
        z-index: auto; /* FIX: Allow dropdowns to overflow */
    }

    .custom-select.open {
        z-index: 1000; /* FIX: Bring open dropdown to front */
    }

    .filter-group label {
        font-size: 13px;
    }

    .filter-input, .filter-select {
        width: 100%;
        padding: 10px 12px;
        font-size: 14px;
    }

    .filter-buttons {
        flex-direction: column;
        gap: 10px;
    }

    .filter-buttons .btn {
        width: 100%;
    }

    .action-buttons {
        flex-direction: column;
        gap: 10px;
    }

    .action-buttons .btn {
        width: 100%;
    }

    .stats-container {
        flex-direction: column;
        gap: 10px;
    }

    .stat-item {
        font-size: 14px;
        padding: 8px 12px;
    }

    .properties-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .property-card {
        padding: 15px;
    }

    .property-title {
        font-size: 16px;
    }

    .property-price {
        font-size: 18px;
    }

    .property-details {
        font-size: 13px;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
    }

    .page-link.first, .page-link.last {
        display: none;
    }

    .page-link {
        padding: 6px 10px;
        font-size: 13px;
    }

    .panel-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .toggle-filters {
        align-self: flex-end;
    }

    .control-panel {
        padding: 15px;
        z-index: 100; /* Ensure filter panel is on top */
    }

    .custom-select {
        min-width: 120px;
    }

    .custom-select-trigger {
        font-size: 13px;
        padding: 8px 32px 8px 10px;
    }

    .custom-select-option {
        font-size: 13px;
        padding: 8px 10px;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 15px 8px;
    }

    .app-header {
        margin-bottom: 20px;
    }

    .app-header h1 {
        font-size: 24px;
    }

    .app-header h1 svg {
        width: 24px;
        height: 24px;
    }

    .app-header p {
        font-size: 13px;
    }

    .control-panel {
        padding: 12px;
        margin-bottom: 15px;
    }

    .panel-header h2 {
        font-size: 16px;
    }

    .toggle-filters {
        padding: 6px 10px;
        font-size: 12px;
    }

    .filters-row {
        gap: 10px;
    }

    .filter-group label {
        font-size: 12px;
        margin-bottom: 4px;
    }

    .btn {
        padding: 9px 14px;
        font-size: 12px;
    }

    .custom-select {
        min-width: 100px;
    }

    .custom-select-trigger {
        font-size: 12px;
        padding: 7px 28px 7px 8px;
    }

    .custom-select-trigger::after {
        right: 8px;
        border-left: 4px solid transparent;
        border-right: 4px solid transparent;
        border-top: 4px solid var(--text-color);
    }

    .custom-select-option {
        font-size: 12px;
        padding: 7px 8px;
    }

    .custom-select-options {
        max-height: 200px;
    }

    .btn svg {
        width: 14px;
        height: 14px;
    }

    .filter-select, .filter-input {
        padding: 8px 10px;
        font-size: 13px;
    }

    .filter-buttons {
        gap: 8px;
    }

    .action-buttons {
        gap: 8px;
    }

    .stat-item {
        font-size: 12px;
        padding: 6px 10px;
    }

    .stat-item svg {
        width: 14px;
        height: 14px;
    }

    .properties-grid {
        gap: 12px;
    }

    .property-card {
        padding: 12px;
    }

    .property-title {
        font-size: 14px;
        margin-bottom: 6px;
    }

    .property-price {
        font-size: 16px;
    }

    .property-details {
        font-size: 12px;
        gap: 6px;
    }

    .property-details span {
        padding: 4px 8px;
    }

    .property-actions {
        gap: 6px;
    }

    .property-actions .btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .pagination {
        gap: 4px;
    }

    .page-link {
        padding: 5px 8px;
        font-size: 12px;
        min-width: 32px;
    }

    .empty-state {
        padding: 30px 15px;
    }

    .empty-state svg {
        width: 50px;
        height: 50px;
    }

    .empty-state h3 {
        font-size: 16px;
    }

    .empty-state p {
        font-size: 13px;
    }
}

/* Additional styles for animations and notifications */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes cardLoad {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.btn.loading .btn-content {
    opacity: 0;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: none;
}

#custom-messages-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}

#custom-messages-container > div {
    animation: slideInUp 0.3s ease-out;
    margin-left: auto;
    max-width: 100%;
}

@keyframes refreshSlideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes slideDownMobile {
    from {
        opacity: 0;
        transform: translateY(-100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.refresh-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    background: rgba(76, 201, 240, 0.95);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    z-index: 10000;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: refreshSlideDown 0.4s ease-out forwards;
    width: 95vw;
    max-width: calc(100vw - 20px);
    box-sizing: border-box;
}

.refresh-notification > div {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.refresh-notification .spinner {
    flex-shrink: 0;
    display: block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
    transform-origin: center;
}

.refresh-notification span {
    flex: 1;
    word-wrap: break-word;
}

@media (max-width: 768px) {
    .refresh-notification {
        top: 12px;
        left: 10px !important;
        right: 10px !important;
        padding: 12px 14px;
        font-size: 13px;
        width: calc(100vw - 20px) !important;
        max-width: none !important;
        transform: translateX(0) !important;
        animation: slideDownMobile 0.5s ease-out forwards !important;
    }
    
    .refresh-notification div {
        gap: 10px !important;
        flex-wrap: nowrap;
    }
    
    .refresh-notification .spinner {
        width: 20px !important;
        height: 20px !important;
        border: 2.5px solid rgba(255, 255, 255, 0.3) !important;
        border-top-color: white !important;
        border-right-color: white !important;
        animation: spin 1s linear infinite !important;
        flex-shrink: 0 !important;
        min-width: 20px;
        min-height: 20px;
    }

    .refresh-notification span {
        white-space: normal !important;
        word-break: break-word !important;
        line-height: 1.3;
    }
}
