/* CSS Variables for theming */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --error-color: #ef4444;
    --error-bg: #fef2f2;
    --warning-color: #f59e0b;
    --warning-bg: #fffbeb;
    --suggestion-color: #3b82f6;
    --suggestion-bg: #eff6ff;
    --success-color: #10b981;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #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;
}

/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

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

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

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.tagline {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main content */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    flex: 1;
    padding-bottom: 2rem;
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr 400px;
    }
}

/* Editor section */
.editor-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon {
    font-size: 1rem;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

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

.btn:active {
    transform: translateY(0);
}

/* Editor container */
.editor-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.editor {
    min-height: 400px;
    max-height: 600px;
    overflow-y: auto;
    padding: 1.25rem;
    font-size: 1rem;
    line-height: 1.8;
    outline: none;
    border: 2px solid transparent;
    transition: border-color 0.2s ease;
}

.editor:focus {
    border-color: var(--primary-color);
}

.editor:empty::before {
    content: attr(placeholder);
    color: var(--text-secondary);
    pointer-events: none;
}

.char-count {
    padding: 0.75rem 1.25rem;
    background: var(--background);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    border-top: 1px solid var(--border-color);
}

/* Highlighted errors in editor */
.highlight-error {
    background: var(--error-bg);
    border-bottom: 2px wavy var(--error-color);
    cursor: pointer;
    transition: background 0.2s ease;
}

.highlight-error:hover {
    background: #fecaca;
}

.highlight-warning {
    background: var(--warning-bg);
    border-bottom: 2px wavy var(--warning-color);
    cursor: pointer;
    transition: background 0.2s ease;
}

.highlight-warning:hover {
    background: #fde68a;
}

.highlight-suggestion {
    background: var(--suggestion-bg);
    border-bottom: 2px dashed var(--suggestion-color);
    cursor: pointer;
    transition: background 0.2s ease;
}

.highlight-suggestion:hover {
    background: #bfdbfe;
}

/* Results section */
.results-section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 600px;
}

.results-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.results-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.stats {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.stat {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
}

.stat-errors {
    background: var(--error-bg);
    color: var(--error-color);
}

.stat-warnings {
    background: var(--warning-bg);
    color: var(--warning-color);
}

.stat-suggestions {
    background: var(--suggestion-bg);
    color: var(--suggestion-color);
}

/* Issues list */
.issues-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

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

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

/* Issue card */
.issue-card {
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.issue-card:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

.issue-card.error {
    background: var(--error-bg);
    border-left: 3px solid var(--error-color);
}

.issue-card.warning {
    background: var(--warning-bg);
    border-left: 3px solid var(--warning-color);
}

.issue-card.suggestion {
    background: var(--suggestion-bg);
    border-left: 3px solid var(--suggestion-color);
}

.issue-type {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.375rem;
}

.issue-card.error .issue-type { color: var(--error-color); }
.issue-card.warning .issue-type { color: var(--warning-color); }
.issue-card.suggestion .issue-type { color: var(--suggestion-color); }

.issue-text {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--text-primary);
}

.issue-text .original {
    text-decoration: line-through;
    opacity: 0.7;
}

.issue-explanation {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.issue-suggestion {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--success-color);
    font-weight: 500;
}

.apply-fix {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-left: 0.5rem;
    transition: background 0.2s ease;
}

.apply-fix:hover {
    background: #059669;
}

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

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

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

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

/* Toast notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

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

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--error-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1001;
    padding: 1rem;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.show .modal-content {
    transform: scale(1);
}

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

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s ease;
}

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

.saved-list {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.empty-saved {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
}

.saved-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem;
    background: var(--background);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
}

.saved-item-info {
    flex: 1;
    min-width: 0;
}

.saved-item-title {
    font-weight: 500;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.saved-item-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.saved-item-actions {
    display: flex;
    gap: 0.5rem;
}

.saved-item-actions button {
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: background 0.2s ease;
}

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

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

.btn-delete {
    background: var(--error-bg);
    color: var(--error-color);
}

.btn-delete:hover {
    background: #fecaca;
}

/* Responsive design */
@media (max-width: 768px) {
    .header {
        padding: 1.5rem 0.5rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .logo {
        width: 40px;
        height: 40px;
    }

    .toolbar {
        justify-content: center;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .editor {
        min-height: 300px;
    }

    .results-section {
        max-height: none;
    }

    .stats {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .logo-container {
        flex-direction: column;
        gap: 0.5rem;
    }

    .toolbar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .btn {
        justify-content: center;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Focus visible for accessibility */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .toolbar, .footer, .results-section {
        display: none;
    }

    .editor {
        border: 1px solid #000;
    }
}
