/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Custom Properties for responsive button scaling */
:root {
    --bg-image-width: 100vw;
    --bg-image-max-width: 750px;
    --button-scale-factor: 1;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    line-height: 1.6;
    color: #333;
    background: white;
    min-height: 100vh;
}

/* Landing Page Styles */
.landing-container {
    position: relative;
    min-height: 100vh;
    width: 100%;
    /* Dynamic padding based on button height + bottom margin + breathing animation space */
    padding-bottom: calc(var(--button-height, 44px) + 40px + 10px);
}

/* Background Image Container */
.bg-image-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.bg-image {
    width: 100%;
    max-width: 750px;
    height: auto;
    display: block;
}

/* Fixed Bottom Button */
.fixed-bottom-button {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;

    /* Dynamic width matching bg.png */
    width: 100%;
    max-width: 750px; /* Match bg.png max-width */
    margin: 0 20px; /* Side margins for mobile */
    box-sizing: border-box;

    /* Default styling - will be overridden by inline styles from environment variables */
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;

    /* Breathing animation */
    animation: breathe 2s ease-in-out infinite;
}

/* Breathing animation keyframes */
@keyframes breathe {
    0%,
    100% {
        transform: translateX(-50%) scale(0.95);
        opacity: 1;
    }
    50% {
        transform: translateX(-50%) scale(1);
        opacity: 0.9;
    }
}

.fixed-bottom-button:hover {
    transform: translateX(-50%) scale(1.02);
    animation-play-state: paused;
}

.fixed-bottom-button:active {
    transform: translateX(-50%) scale(0.93);
}

/* Admin Login Styles */
.admin-login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-form-wrapper {
    background: white;
    border-radius: 10px;
    padding: 40px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    width: 100%;
}

.login-form-wrapper h2 {
    text-align: center;
    margin-bottom: 30px;
    color: #333;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: #555;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    transition: border-color 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.login-button {
    width: 100%;
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 12px;
    font-size: 16px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.login-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.error-message {
    background: #ffebee;
    color: #c62828;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 20px;
    text-align: center;
}

/* Admin Dashboard Styles */
.admin-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: white;
    min-height: 100vh;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.admin-header h1 {
    color: #333;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.timezone-info {
    font-size: 14px;
    color: #666;
}

.logout-btn {
    background: #f44336;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 5px;
    transition: background 0.3s ease;
}

.logout-btn:hover {
    background: #d32f2f;
}

.stats-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
}

.stat-card h3 {
    font-size: 14px;
    margin-bottom: 10px;
    opacity: 0.9;
}

.stat-number {
    font-size: 32px;
    font-weight: bold;
}

/* Filter Section Styles */
.filter-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
}

.filter-section h2 {
    margin-bottom: 20px;
    color: #333;
    font-size: 18px;
}

.filter-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.filter-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group label {
    font-size: 14px;
    font-weight: 500;
    color: #555;
    margin-bottom: 5px;
}

.filter-group input,
.filter-group select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: #667eea;
}

.filter-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    margin-top: 10px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd8;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

/* Table Section Styles */
.table-section h2 {
    margin-bottom: 20px;
    color: #333;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.table-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.table-controls label {
    font-size: 14px;
    color: #555;
}

.table-controls select {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.visits-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

.visits-table th,
.visits-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.visits-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
}

.device-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.device-badge.mobile {
    background: #e3f2fd;
    color: #1976d2;
}

.device-badge.desktop {
    background: #f3e5f5;
    color: #7b1fa2;
}

.device-info {
    max-width: 200px;
    word-break: break-word;
    font-size: 12px;
}

.referer a {
    color: #1976d2;
    text-decoration: none;
}

.referer a:hover {
    text-decoration: underline;
}

.status-yes {
    color: #4caf50;
    font-weight: 500;
}

.status-no {
    color: #999;
}

.no-data {
    text-align: center;
    padding: 40px;
    color: #999;
    font-style: italic;
}

/* Pagination Styles */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    margin-top: 30px;
    padding: 20px 0;
}

.page-btn {
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    color: #333;
    text-decoration: none;
    border-radius: 5px;
    transition: all 0.3s ease;
    font-size: 14px;
}

.page-btn:hover {
    background: #f8f9fa;
    border-color: #667eea;
}

.page-btn.current {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.page-ellipsis {
    padding: 8px 4px;
    color: #999;
}

/* Heatmap Styles */
.heatmap-section {
    padding: 20px 0;
}

.heatmap-filter-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
}

.heatmap-filter-section h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 16px;
}

.heatmap-filter-form .filter-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    align-items: end;
}

.heatmap-stats-section {
    margin-bottom: 30px;
}

.heatmap-stats-section h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 16px;
}

.element-stats {
    margin-top: 20px;
}

.element-stats h4 {
    margin-bottom: 10px;
    color: #555;
    font-size: 14px;
}

.element-stats-list {
    list-style: none;
    padding: 0;
}

.element-stats-list li {
    padding: 5px 0;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.element-stats-list li:last-child {
    border-bottom: none;
}

.heatmap-display-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
}

.heatmap-display-section h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 16px;
}

.heatmap-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.heatmap-controls label {
    font-size: 14px;
    color: #555;
    font-weight: 500;
}

.heatmap-controls input[type="range"] {
    width: 100px;
}

.heatmap-controls span {
    font-size: 12px;
    color: #666;
    min-width: 40px;
}

.heatmap-container {
    position: relative;
    width: 100%;
    min-height: 400px;
    height: auto;
    background: white;
    border: 2px solid #ddd;
    border-radius: 10px;
    overflow: auto;
}

#pagePreview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: white;
    transform-origin: top left;
}

.heatmap-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.heatmap-point {
    position: absolute;
    background: radial-gradient(
        circle,
        rgba(255, 0, 0, 0.8) 0%,
        rgba(255, 0, 0, 0.4) 50%,
        transparent 100%
    );
    border-radius: 50%;
    pointer-events: auto;
    cursor: pointer;
    transition: all 0.3s ease;
}

.heatmap-point:hover {
    transform: scale(1.2);
    z-index: 10;
}

/* Heatmap Legend Styles */
.heatmap-legend {
    margin: 15px 0;
    padding: 15px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
}

.heatmap-legend h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #495057;
}

.legend-items {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

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

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #ccc;
}

.legend-item span {
    font-size: 13px;
    color: #495057;
}

.heatmap-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #666;
    font-size: 14px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 5px;
    z-index: 20;
    max-width: 80%;
    word-wrap: break-word;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Landing page responsive adjustments */
    .landing-container {
        /* Dynamic padding for mobile: button height + reduced margins + breathing space */
        padding-bottom: calc(var(--button-height, 44px) + 30px + 8px);
    }

    .fixed-bottom-button {
        margin: 0 15px; /* Reduce side margins on mobile */
    }

    .admin-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .header-actions {
        flex-direction: column;
        gap: 10px;
    }

    .stats-section {
        grid-template-columns: repeat(2, 1fr);
    }

    .heatmap-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .heatmap-container {
        height: 400px;
    }

    .filter-row {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .table-header {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }

    .table-controls {
        align-self: stretch;
        justify-content: space-between;
    }

    .visits-table {
        font-size: 12px;
    }

    .visits-table th,
    .visits-table td {
        padding: 8px 4px;
    }

    .device-info {
        max-width: 120px;
    }

    .pagination {
        flex-wrap: wrap;
        gap: 3px;
    }

    .page-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
}

/* Tab Navigation Styles */
.tab-navigation {
    display: flex;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
    margin-bottom: 0;
    border-bottom: 2px solid #e9ecef;
}

.tab-btn {
    flex: 1;
    padding: 15px 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    color: #6c757d;
    transition: all 0.3s ease;
    border-radius: 8px 8px 0 0;
    position: relative;
}

.tab-btn:hover {
    background: #e9ecef;
    color: #495057;
}

.tab-btn.active {
    background: white;
    color: #1976d2;
    border-bottom: 2px solid #1976d2;
    margin-bottom: -2px;
}

.tab-btn.active::before {
    content: "";
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: #1976d2;
}

/* Tab Content Styles */
.tab-content {
    display: none;
    background: white;
    border-radius: 0 0 8px 8px;
    padding: 20px 0;
}

.tab-content.active {
    display: block;
}

/* URL Generator Tool Styles */
.url-generator-section {
    background: #f0f8ff;
    padding: 30px;
    border-radius: 12px;
    margin: 20px;
    border: 2px solid #e3f2fd;
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
}

.url-generator-section h2 {
    margin-bottom: 20px;
    color: #1976d2;
    font-size: 18px;
    display: flex;
    align-items: center;
}

.url-generator-section h2:before {
    content: "🔗";
    margin-right: 8px;
    font-size: 20px;
}

.generator-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.generator-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.generator-group {
    flex: 1;
    min-width: 250px;
}

.generator-group.full-width {
    flex: 1 1 100%;
}

.generator-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.generator-group input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-sizing: border-box;
}

.generator-group input:focus {
    outline: none;
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}

.generator-group input::placeholder {
    color: #999;
    font-style: italic;
}

.generator-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.generator-result {
    margin-top: 20px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.generator-result label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.url-output-container {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.url-output-container textarea {
    flex: 1;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    font-family: "Courier New", monospace;
    resize: vertical;
    min-height: 80px;
    background: #fafafa;
    transition: border-color 0.3s ease;
}

.url-output-container textarea:focus {
    outline: none;
    border-color: #1976d2;
    background: white;
}

.btn-copy {
    padding: 12px 16px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    min-width: 80px;
    justify-content: center;
}

.btn-copy:hover:not(:disabled) {
    background: #218838;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.btn-copy:disabled {
    background: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

.copy-icon {
    font-size: 16px;
}

.url-info {
    margin-top: 10px;
    padding: 8px 12px;
    background: #e8f5e8;
    border-radius: 4px;
    border-left: 4px solid #28a745;
}

.url-info small {
    color: #155724;
    font-size: 12px;
    line-height: 1.4;
}

/* Responsive adjustments for tabs and URL generator */
@media (max-width: 768px) {
    .tab-btn {
        padding: 12px 15px;
        font-size: 14px;
    }

    .url-generator-section {
        margin: 10px;
        padding: 20px;
    }

    .generator-row {
        flex-direction: column;
        gap: 15px;
    }

    .generator-group {
        min-width: unset;
    }

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

    .btn-copy {
        align-self: flex-start;
        min-width: 120px;
    }

    .generator-actions {
        flex-direction: column;
        gap: 10px;
    }

    .generator-actions .btn {
        width: 100%;
    }
}

/* Additional responsive design for button scaling */
@media (max-width: 480px) {
    :root {
        --button-scale-factor: 0.8;
    }

    .landing-container {
        /* Extra small screens: tighter spacing */
        padding-bottom: calc(var(--button-height, 44px) + 25px + 6px);
    }

    .fixed-bottom-button {
        margin: 0 10px;
        transform: translateX(-50%) scale(var(--button-scale-factor));
    }

    @keyframes breathe {
        0%,
        100% {
            transform: translateX(-50%)
                scale(calc(var(--button-scale-factor) * 0.95));
            opacity: 1;
        }
        50% {
            transform: translateX(-50%) scale(var(--button-scale-factor));
            opacity: 0.9;
        }
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    :root {
        --button-scale-factor: 0.9;
    }

    .fixed-bottom-button {
        transform: translateX(-50%) scale(var(--button-scale-factor));
    }

    @keyframes breathe {
        0%,
        100% {
            transform: translateX(-50%)
                scale(calc(var(--button-scale-factor) * 0.95));
            opacity: 1;
        }
        50% {
            transform: translateX(-50%) scale(var(--button-scale-factor));
            opacity: 0.9;
        }
    }
}

@media (min-width: 769px) {
    :root {
        --button-scale-factor: 1;
    }
}
