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

:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --text-primary: #333333;
    --text-secondary: #7f8c8d;
    --border-color: #e0e0e0;
    --header-bg: #2c3e50;
    --header-text: #ffffff;
    --output-bg: #f8f8f8;
    --btn-primary: #3498db;
    --btn-primary-hover: #2980b9;
    --btn-success: #27ae60;
    --btn-success-hover: #229954;
    --btn-danger: #e74c3c;
    --btn-danger-hover: #c0392b;
    --btn-warning: #f39c12;
    --btn-warning-hover: #d68910;
    --highlight-match: #ffeb3b;
    --highlight-match-dark: #ffc107;
    --regex-valid: #27ae60;
    --regex-invalid: #e74c3c;
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #404040;
    --header-bg: #1f1f1f;
    --header-text: #e0e0e0;
    --output-bg: #1f1f1f;
    --highlight-match: #ffc107;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 1.5rem 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

main {
    flex: 1;
    width: 100%;
}


.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    gap: 2rem;
    align-items: center;
    justify-content: space-between;
}

.header-content > div:first-child {
    flex: 0 1 auto;
}

header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

header p {
    font-size: 1rem;
    opacity: 0.9;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.fixit-link {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 0.4rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: var(--header-text);
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s ease;
    line-height: 1.2;
}

.fixit-link:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.more-tools {
    font-size: 0.7rem;
    opacity: 0.8;
}

.fixit-name {
    font-size: 0.9rem;
    font-weight: 600;
}

.theme-toggle {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--header-text);
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 20px;
}

.regex-section {
    margin-bottom: 2rem;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    border: 1px solid var(--border-color);
}

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

.section-header h2 {
    font-size: 1.3rem;
    color: var(--text-primary);
}

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

.regex-input-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#regexInput {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.3s ease;
}

#regexInput:focus {
    outline: none;
    border-color: var(--btn-primary);
}

#regexInput.valid {
    border-color: var(--regex-valid);
}

#regexInput.invalid {
    border-color: var(--regex-invalid);
}

.regex-flags {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.regex-flags label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.regex-flags input[type="checkbox"] {
    margin: 0;
}

.regex-status {
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    min-height: 1.5rem;
}

.regex-status.valid {
    background: rgba(39, 174, 96, 0.1);
    color: var(--regex-valid);
}

.regex-status.invalid {
    background: rgba(231, 76, 60, 0.1);
    color: var(--regex-invalid);
}

.mode-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    justify-content: center;
}

.mode-btn {
    padding: 0.8rem 2rem;
    border: 2px solid var(--btn-primary);
    background: transparent;
    color: var(--btn-primary);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

.mode-btn.active,
.mode-btn:hover {
    background: var(--btn-primary);
    color: white;
}

.mode-content {
    display: none;
}

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

.test-section,
.results-section,
.file-section,
.file-content-section,
.file-results-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    border: 1px solid var(--border-color);
}

#testText {
    width: 100%;
    min-height: 200px;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    background: var(--bg-secondary);
    color: var(--text-primary);
    resize: vertical;
    transition: border-color 0.3s ease;
}

#testText:focus {
    outline: none;
    border-color: var(--btn-primary);
}

.results-container {
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--output-bg);
    overflow: hidden;
}

.match-info {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-weight: 500;
    font-size: 0.9rem;
}

.highlighted-output {
    padding: 16px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
    background: var(--output-bg);
}

.match-highlight {
    background-color: var(--highlight-match);
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
}

[data-theme="dark"] .match-highlight {
    background-color: var(--highlight-match-dark);
    color: #000;
}

.matches-list {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    max-height: 200px;
    overflow-y: auto;
}

.match-item {
    padding: 8px 12px;
    margin-bottom: 8px;
    background: var(--output-bg);
    border-radius: 6px;
    border-left: 4px solid var(--btn-primary);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    word-break: break-all;
}

.match-item:last-child {
    margin-bottom: 0;
}

.match-index {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.file-upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 3rem 2rem;
    text-align: center;
    transition: border-color 0.3s ease, background-color 0.3s ease;
    cursor: pointer;
    margin-bottom: 1rem;
}

.file-upload-area:hover,
.file-upload-area.dragover {
    border-color: var(--btn-primary);
    background-color: rgba(52, 152, 219, 0.05);
}

.file-upload-label {
    cursor: pointer;
    display: block;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.file-upload-area p {
    margin: 0.5rem 0;
}

.file-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.file-info-display {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--output-bg);
    border-radius: 8px;
    display: none;
}

.file-info-display.show {
    display: block;
}

.file-action-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

button {
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

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

.clear-btn:hover {
    background: var(--btn-danger-hover);
    transform: translateY(-2px);
}

.history-btn {
    background: #3498db;
    color: white;
}

.history-btn:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

.copy-btn,
.process-btn {
    background: var(--btn-success);
    color: white;
}

.copy-btn:hover,
.process-btn:hover {
    background: var(--btn-success-hover);
    transform: translateY(-2px);
}

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

.download-btn:hover {
    background: var(--btn-primary-hover);
    transform: translateY(-2px);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

button:disabled:hover {
    transform: none !important;
}

footer {
    background-color: var(--header-bg);
    color: var(--header-text);
    text-align: center;
    padding: 2rem 0;
    margin-top: auto;
}

footer p {
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

footer a {
    color: var(--header-text);
    text-decoration: none;
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

footer a:hover {
    opacity: 1;
    text-decoration: underline;
}

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

.modal-overlay.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

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

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

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

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

.history-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0;
}

.clear-history-btn {
    background: var(--btn-danger);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.history-item {
    padding: 1rem;
    background: var(--output-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s ease;
}

.history-item:hover {
    background: var(--btn-primary);
    color: white;
    transform: translateY(-2px);
}

.history-regex {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-weight: 600;
    margin-bottom: 0.5rem;
    word-break: break-all;
}

.history-flags {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.history-item:hover .history-flags {
    color: rgba(255, 255, 255, 0.8);
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }

    .container {
        padding: 1rem 15px;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .button-group {
        justify-content: center;
    }

    .regex-flags {
        justify-content: center;
    }


    .mode-selector {
        flex-direction: column;
        max-width: 300px;
        margin: 0 auto 2rem;
    }

    .file-upload-area {
        padding: 2rem 1rem;
    }

    .modal-content {
        width: 95%;
        margin: 20px;
    }
}