/* Theme Variables */
:root {
    color-scheme: light dark;
    --bg-primary: #EAECEA;
    --bg-secondary: #E0E1E2;
    --text-primary: #000;
    --text-secondary: #777;
    --border-color: #E0E1E2;
    --input-bg: #fff;
    --hover-bg: #9FA1A1;
    --hover-text: #fff;
    --error-color: #dc3545;
    --success-color: #28a745;
    --warning-color: #ffc107;
}

/* Dark theme */
[data-theme="dark"] {
    --bg-primary: #2D2D30;
    --bg-secondary: #3C3C3C;
    --text-primary: #CCCCCC;
    --text-secondary: #999;
    --border-color: #404040;
    --input-bg: #404040;
    --hover-bg: #007ACC;
    --hover-text: #fff;
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #e4e4e4;
    --text-primary: #000;
    --text-secondary: #777;
    --border-color: #E0E1E2;
    --input-bg: #fff;
    --hover-bg: #9FA1A1;
    --hover-text: #fff;
}

/* Auto theme (system preference) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-primary: #2D2D30;
        --bg-secondary: #3C3C3C;
        --text-primary: #CCCCCC;
        --text-secondary: #999;
        --border-color: #404040;
        --input-bg: #404040;
        --hover-bg: #007ACC;
        --hover-text: #fff;
    }
}

/* Base Styles */
* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center; /* Always center */
    padding: 2rem 1rem;
    min-height: 100vh;
}

.container {
    max-width: 900px;
    width: 100%;
    background-color: var(--bg-primary);
    border-radius: 12px;
    padding: 2rem 6rem;
    transition: all 0.6s ease;
    transform: translateY(0); /* Initial position */
}

/* Search active state - move container up */
body.search-active .container {
    transform: translateY(-5%); /* Move up by 10% of viewport height */
}

/* Fixed top-right controls */
.fixed-controls {
    position: fixed;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
    z-index: 100;
}

header {
    text-align: center;
    margin-top: 1rem;
    margin-bottom: 3rem;
    transition: all 0.3s ease;
}

header h1 {
    font-size: 3.5rem;
    margin: 0 0 0.5rem 0;
    background: linear-gradient(135deg, #007ACC, #9FA1A1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    /* transition: all 0.3s ease; */
}

header p {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin: 0;
    /* transition: all 0.3s ease; */
}

.search-active header h1 {
    font-size: 2rem;
}

.search-active header p {
    font-size: 1rem;
}

.main-search {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1rem;
    transition: all 0.3s ease; /* Smooth transition for search area */
}

.search-input-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

#urlInput {
    width: 100%;
    min-width: 280px;
    padding: 1rem 6.5rem 1rem 2.5rem; /* Left padding for jump button, right padding for clear + paste buttons */
    font-size: 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background-color: var(--input-bg);
    color: var(--text-primary);
    outline: none;
    transition: all 0.3s ease;
}

#urlInput:focus {
    border-color: var(--hover-bg);
    box-shadow: 0 0 0 3px rgba(159, 161, 161, 0.1);
}

#urlInput::placeholder {
    color: var(--text-secondary);
}

/* Clear button inside input */
.clear-btn {
    position: absolute;
    right: 3rem; /* Position before paste button */
    top: 50%;
    transform: translateY(-50%);
    padding: 0.5rem;
    font-size: 14px;
    border: none;
    border-radius: 8px;
    background-color: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.clear-btn:hover {
    background-color: var(--error-color);
    color: white;
}

.clear-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Paste button inside input */
.paste-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    padding: 0.5rem;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    background-color: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.paste-btn:hover {
    background-color: var(--hover-bg);
    color: var(--hover-text);
}

.paste-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Jump button inside input */
.jump-btn {
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    padding: 0.5rem 0.2rem;
    border: none;
    border-radius: 8px;
    background-color: transparent;
    color: var(--hover-text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.jump-btn:hover {
    background-color: var(--success-color);
    color: white;
}

.jump-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.action-btn {
    padding: 0.75rem;
    font-size: 18px;
    border: none;
    border-radius: 12px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background-color: var(--hover-bg);
    color: var(--hover-text);
    transform: translateY(-1px);
}

/* Button icon styles - unified for all button types */
.btn-icon,
.action-btn > *,
.clear-btn > *,
.paste-btn > *,
.jump-btn > * {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    transition: all 0.3s ease;
}

/* Fine-tuning for jump button */
.jump-btn > * {
    transform: translateY(-0.06rem);
}

/* Icon container - maintains layout during lazy loading */
.icon-maintainer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
}

/* Image icons - unified filter */
.icon-maintainer img {
    filter: brightness(0) saturate(100%);
}

/* SVG icons - unified fill */
.icon-maintainer svg {
    fill: var(--text-primary);
}

/* Text/emoji icons */
.icon-maintainer span {
    font-size: 16px;
    line-height: 1;
    text-align: center;
    /* transform: translateX(-0.125rem); */
}

/* Hover states - unified */
.icon-maintainer:hover img {
    filter: brightness(0) saturate(100%) invert(100%);
}

.icon-maintainer:hover svg {
    fill: var(--hover-text);
}

/* Theme-specific icon adjustments - unified */
[data-theme="dark"] .icon-maintainer img {
    filter: brightness(0) saturate(100%) invert(80%);
}

[data-theme="dark"] .icon-maintainer:hover img {
    filter: brightness(0) saturate(100%) invert(100%);
}

/* Auto theme (system preference) - unified */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .icon-maintainer img {
        filter: brightness(0) saturate(100%) invert(80%);
    }
    
    :root:not([data-theme="light"]) .icon-maintainer:hover img {
        filter: brightness(0) saturate(100%) invert(100%);
    }
}

/* Status */
.status {
    text-align: center;
    margin: 0.5rem 0;
    font-weight: 500;
    min-height: 24px;
}

.status.error {
    color: var(--error-color);
}

.status.success {
    color: var(--success-color);
}

/* Results */
.results-container {
    margin-top: 2rem;
}

.link-group {
    margin-bottom: 2rem;
}

.group-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
    text-align: center;
}

.link-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
}

.link-btn {
    display: block;
    padding: 1rem 1.5rem;
    text-decoration: none;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 12px;
    text-align: center;
    font-weight: 500;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.link-btn:hover {
    background-color: var(--hover-bg);
    color: var(--hover-text);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: var(--hover-bg);
}

.divider {
    border: none;
    height: 1px;
    background-color: var(--border-color);
    margin: 1.5rem 0;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
    font-style: italic;
}

.empty-state p {
    margin: 0.5rem 0;
}

.empty-state strong {
    color: var(--text-primary);
}

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

.modal-content {
    background-color: var(--bg-primary);
    margin: 5% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    
    /* Hide scrollbar but keep scroll functionality */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer and Edge */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.modal-content::-webkit-scrollbar {
    display: none;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    border-radius: 12px 12px 0 0;
}

.modal-header h2 {
    margin: 0;
    color: var(--text-primary);
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background-color: var(--hover-bg);
    color: var(--hover-text);
}

.modal-body {
    padding: 1.5rem;
}

.section {
    margin-bottom: 2rem;
}

.section h3 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-weight: 500;
}

.form-group input, 
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
    color: var(--text-primary);
    font-size: 14px;
}

.form-group input:focus, 
.form-group textarea:focus {
    outline: none;
    border-color: var(--hover-bg);
    box-shadow: 0 0 0 2px rgba(159, 161, 161, 0.1);
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    background-color: var(--hover-bg);
    color: var(--hover-text);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-danger {
    background-color: var(--error-color);
    color: white;
}

#currentRules {
    max-height: 300px;
    overflow-y: auto;
}

.rule-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.rule-info {
    flex: 1;
}

.rule-info strong {
    display: block;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.rule-info small {
    display: block;
    color: var(--text-secondary);
    font-size: 12px;
}

.delete-rule {
    padding: 0.5rem 1rem;
    background-color: var(--error-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

.delete-rule:hover {
    background-color: #c82333;
}

/* Responsive Design - consolidated mobile rules */
@media (max-width: 640px) {
    .container {
        margin-top: 10%;
        padding: 1.5rem 1.5rem;
    }

    header {
        margin-bottom: 2.5rem;
    }
    header h1 { 
        margin: 1rem auto;
        font-size: 2.5rem; 
    }
    header p {
        font-size: 1.2rem;
    }
    .search-active header h1 { 
        font-size: 1.75rem; 
    }
    .search-active header p {
        font-size: 1rem;
    }

    #urlInput {
        min-width: unset;
        padding: 1rem 5rem 1rem 2.5rem; /* Left padding for jump button, right padding for clear + paste buttons */
        font-size: 15px;
    }

    .search-input-container {
        width: 92%;
    }
    
    /* .link-buttons { 
        grid-template-columns: 1fr; 
    } */

    .fixed-controls {
        top: 0.75rem;
        right: 0.75rem;
        gap: 0.25rem;
    }
    .action-btn { 
        padding: 0.5rem; 
    }
    .link-btn { 
        margin: 0 0.5rem; 
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    body { 
        padding: 1rem 0.5rem; 
    }

    .container {
        border-radius: 8px;
        padding: 1rem;
    }
    
    header h1 { 
        font-size: 2rem; 
    }
    header p {
        font-size: 1rem;
    }
    .search-active header h1 { 
        font-size: 1.5rem; 
    }
    .search-active header p {
        font-size: 0.8rem;
    }

    #urlInput { 
        font-size: 14px; 
    }

    .search-input-container {
        width: 98%;
    }

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

    .link-btn { 
        margin: 0 2rem;
        padding: 0.8rem 1rem;
        font-size: 14px;
    }
}

/* Rules display styles */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h3 {
    margin: 0;
}

.toggle-btn {
    background: var(--hover-bg);
    color: var(--hover-text);
    border: none;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.toggle-btn:hover {
    opacity: 0.8;
}

.rules-section-header {
    color: var(--text-secondary);
    font-size: 1rem;
    margin: 1.5rem 0 0.8rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.rules-section-header:first-child {
    margin-top: 0.5rem;
}

.builtin-header {
    color: var(--text-secondary);
    font-style: italic;
}

.rules-divider {
    margin: 1.5rem 0;
    border: none;
    border-top: 2px dashed var(--border-color);
}

.builtin-rule {
    background: var(--bg-secondary);
    opacity: 0.8;
    border-left: 3px solid var(--text-secondary);
}

.custom-rule {
    border-left: 3px solid var(--hover-bg);
}

.builtin-rule .rule-info strong {
    color: var(--text-secondary);
}

/* Responsive adjustments for new styles */
@media (max-width: 768px) {
    .section-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }
    
    .toggle-btn {
        align-self: flex-end;
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
}
