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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition: 150ms ease;
}

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

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
header {
    text-align: center;
    padding: 2rem 0;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

header .subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-bottom: 2rem;
}

/* Controls Section */
.controls-section {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    display: grid;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .controls-section {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-color);
}

.input-with-help {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.help-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Input Styles */
input[type="text"],
input[type="url"],
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--surface-color);
}

input[type="text"]:focus,
input[type="url"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Color Picker */
.color-picker-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

input[type="color"] {
    width: 48px;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 2px;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

input[type="color"]::-webkit-color-swatch {
    border-radius: 4px;
    border: none;
}

#highlight-color-text {
    width: 90px;
    text-align: center;
    font-family: 'Courier New', monospace;
}

.preset-colors {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.color-preset {
    width: 28px;
    height: 28px;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform var(--transition), border-color var(--transition);
}

.color-preset:hover {
    transform: scale(1.1);
}

.color-preset:focus {
    outline: none;
    border-color: var(--text-color);
}

/* URL Input */
.url-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.url-input-wrapper input {
    flex: 1;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
}

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

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

.btn-outline {
    background: transparent;
    color: var(--secondary-color);
    border: 1px solid var(--border-color);
}

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

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

/* Text Section */
.text-section {
    display: grid;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .text-section {
        grid-template-columns: 1fr 1fr;
    }
}

.text-input-container,
.text-output-container {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.text-input-container label,
.text-output-container label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-color);
}

textarea#text-input {
    min-height: 300px;
    resize: vertical;
}

.text-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* Text Output */
.text-output {
    min-height: 300px;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--background-color);
    overflow-y: auto;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.text-output .placeholder-text {
    color: var(--text-muted);
    font-style: italic;
}

.text-output .highlight {
    padding: 0.1em 0.2em;
    border-radius: 3px;
    font-weight: 500;
}

.output-stats {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
}

/* Footer */
footer {
    padding: 1.5rem 0;
    text-align: center;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

footer p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition);
}

footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    z-index: 1000;
    max-width: 90vw;
    text-align: center;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.error {
    background: #dc2626;
}

.toast.success {
    background: #16a34a;
}

/* Loading State */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Responsive Adjustments */
@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }

    header .subtitle {
        font-size: 0.95rem;
    }

    .controls-section {
        padding: 1rem;
    }

    .text-input-container,
    .text-output-container {
        padding: 1rem;
    }

    textarea#text-input,
    .text-output {
        min-height: 200px;
    }

    .text-actions {
        flex-direction: column;
    }

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

    .url-input-wrapper {
        flex-direction: column;
    }

    .color-picker-wrapper {
        flex-direction: column;
        align-items: flex-start;
    }

    .preset-colors {
        width: 100%;
        justify-content: flex-start;
    }
}

/* Print Styles */
@media print {
    .controls-section,
    .text-input-container,
    footer {
        display: none;
    }

    .text-output-container {
        box-shadow: none;
        padding: 0;
    }

    .text-output {
        border: none;
        background: white;
    }
}
