/* ========== CSS Variables / Themes ========== */
:root,
[data-theme="dark"] {
    --bg: #0f0a1a;
    --bg-secondary: #1a1230;
    --surface: rgba(255, 255, 255, 0.05);
    --surface-border: rgba(255, 255, 255, 0.08);
    --surface-hover: rgba(255, 255, 255, 0.08);
    --text: #f0eef5;
    --text-secondary: #a09bb5;
    --text-muted: #6b6580;
    --primary: #6366f1;
    --primary-hover: #5558e6;
    --primary-glow: rgba(99, 102, 241, 0.3);
    --secondary: #8b5cf6;
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.12);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.12);
    --input-bg: rgba(255, 255, 255, 0.06);
    --input-border: rgba(255, 255, 255, 0.1);
    --input-focus: rgba(99, 102, 241, 0.5);
    --glass-bg: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-blur: 20px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --gradient-logo: linear-gradient(135deg, #6366f1, #8b5cf6);
}

[data-theme="light"] {
    --bg: #f5f3fa;
    --bg-secondary: #ebe8f3;
    --surface: rgba(255, 255, 255, 0.7);
    --surface-border: rgba(0, 0, 0, 0.06);
    --surface-hover: rgba(255, 255, 255, 0.9);
    --text: #1a1230;
    --text-secondary: #5c5672;
    --text-muted: #8a849c;
    --primary: #6366f1;
    --primary-hover: #5558e6;
    --primary-glow: rgba(99, 102, 241, 0.2);
    --secondary: #8b5cf6;
    --success: #059669;
    --success-bg: rgba(5, 150, 105, 0.1);
    --error: #dc2626;
    --error-bg: rgba(220, 38, 38, 0.08);
    --input-bg: rgba(255, 255, 255, 0.8);
    --input-border: rgba(0, 0, 0, 0.1);
    --input-focus: rgba(99, 102, 241, 0.4);
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(0, 0, 0, 0.06);
    --glass-blur: 20px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --gradient-logo: linear-gradient(135deg, #6366f1, #8b5cf6);
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

/* ========== App Container ========== */
.app-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px;
    min-height: 100dvh;
}

/* ========== Header ========== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid var(--surface-border);
    margin-bottom: 20px;
}

.logo {
    font-size: 1.35rem;
    font-weight: 700;
    background: var(--gradient-logo);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-decoration: none;
    letter-spacing: -0.02em;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--primary);
}

.nav-logout {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ========== Theme Toggle ========== */
.theme-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    transition: color 0.2s;
}

.theme-toggle:hover {
    color: var(--primary);
}

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ========== Glass Card ========== */
.glass-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 20px;
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow);
}

/* ========== Textarea Wrapper ========== */
.textarea-wrapper {
    position: relative;
}

.btn-reset {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    opacity: 0;
    pointer-events: none;
}

.btn-reset.visible {
    opacity: 1;
    pointer-events: auto;
}

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

/* ========== Form Elements ========== */
.textarea {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 14px;
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    line-height: 1.6;
    resize: vertical;
    min-height: 140px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--input-focus);
}

.textarea::placeholder {
    color: var(--text-muted);
}

.input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 14px;
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--input-focus);
}

.input::placeholder {
    color: var(--text-muted);
}

.controls-row {
    display: flex;
    gap: 12px;
    margin: 14px 0;
}

.select-group {
    flex: 1;
}

.select-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.88rem;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6580' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 12px;
    font-family: 'DM Sans', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    padding: 14px 24px;
    box-shadow: 0 2px 12px var(--primary-glow);
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 20px var(--primary-glow);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-full {
    width: 100%;
    margin-top: 4px;
}

.btn-small {
    font-size: 0.8rem;
    padding: 6px 14px;
    border-radius: 8px;
    font-weight: 500;
}

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

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

.btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ========== Result Section ========== */
.result-section {
    margin-top: 16px;
}

.result-section .glass-card {
    margin-bottom: 16px;
}

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

.result-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.corrected-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88rem;
    line-height: 1.7;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

.lang-badge {
    display: inline-block;
    margin-top: 12px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--surface-border);
    padding: 3px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ========== Work On This / Errors ========== */
.section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.errors-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.error-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 14px;
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
}

.error-category {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.error-diff {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.error-diff svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.diff-old {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.84rem;
    color: var(--error);
    background: var(--error-bg);
    padding: 2px 8px;
    border-radius: 6px;
    text-decoration: line-through;
}

.diff-new {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.84rem;
    color: var(--success);
    background: var(--success-bg);
    padding: 2px 8px;
    border-radius: 6px;
}

.error-rule {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ========== No Errors ========== */
.no-errors {
    text-align: center;
    padding: 12px 0;
}

.no-errors-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--success-bg);
    color: var(--success);
    border-radius: 50%;
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.no-errors p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ========== Login Page ========== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
}

.login-card {
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.login-logo {
    font-size: 2rem;
    font-weight: 700;
    background: var(--gradient-logo);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-error {
    background: var(--error-bg);
    color: var(--error);
    font-size: 0.85rem;
    padding: 10px;
    border-radius: 10px;
    margin-bottom: 4px;
}

/* ========== Patterns Page ========== */
.patterns-header {
    margin-bottom: 20px;
}

.page-title {
    font-size: 1.3rem;
    font-weight: 700;
}

.patterns-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 4px;
}

.categories-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.category-card {
    padding: 0;
    overflow: hidden;
}

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    cursor: pointer;
    transition: background 0.2s;
}

.category-header:hover {
    background: var(--surface-hover);
}

.category-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.category-name {
    font-weight: 600;
    font-size: 0.92rem;
}

.category-count {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-glow);
    padding: 2px 8px;
    border-radius: 12px;
}

.category-arrow {
    color: var(--text-muted);
    transition: transform 0.2s;
}

.category-card.expanded .category-arrow {
    transform: rotate(180deg);
}

.category-examples {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.category-card.expanded .category-examples {
    max-height: 600px;
}

.example-item {
    padding: 12px 20px;
    border-top: 1px solid var(--surface-border);
}

.example-diff {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.example-diff svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.example-rule {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.language-card {
    margin-top: 4px;
}

.language-card .section-title {
    margin-bottom: 10px;
}

.language-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.language-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.language-name {
    font-size: 0.9rem;
    font-weight: 500;
}

.language-count {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ========== Empty State ========== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-text {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ========== Button Row (Fix + Translate) ========== */
.btn-row {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

.btn-row .btn-full {
    margin-top: 0;
}

/* ========== Result Actions ========== */
.result-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ========== Translate Button (Home) ========== */
.btn-translate {
    background: linear-gradient(135deg, #d97706, #f59e0b);
    color: #fff;
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 1.1rem;
    line-height: 1;
    box-shadow: 0 2px 12px rgba(217, 119, 6, 0.3);
    flex-shrink: 0;
}

.btn-translate:hover {
    background: linear-gradient(135deg, #b45309, #d97706);
    box-shadow: 0 4px 20px rgba(217, 119, 6, 0.4);
}

.btn-translate:active {
    transform: scale(0.98);
}

/* ========== Translate Button (Result - small) ========== */
.btn-translate-sm {
    background: linear-gradient(135deg, #d97706, #f59e0b);
    color: #fff;
    font-size: 0.8rem;
    padding: 6px 10px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(217, 119, 6, 0.25);
}

.btn-translate-sm:hover {
    background: linear-gradient(135deg, #b45309, #d97706);
}

/* ========== Language Picker Overlay ========== */
.translate-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.translate-overlay-content {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 24px;
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 360px;
}

.btn-back {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 0;
    margin-bottom: 16px;
    transition: color 0.2s;
}

.btn-back:hover {
    color: var(--text);
}

.picker-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 20px;
}

.lang-picker-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.lang-picker-btn {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    color: var(--text);
    padding: 16px;
    border-radius: 14px;
    font-size: 1.05rem;
    font-weight: 600;
    text-align: center;
    transition: all 0.2s;
}

.lang-picker-btn:hover {
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.15), rgba(245, 158, 11, 0.15));
    border-color: #d97706;
    color: var(--text);
}

.lang-picker-btn:active {
    transform: scale(0.98);
}

/* ========== Translate Loading ========== */
.translate-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.spinner-amber {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(217, 119, 6, 0.2);
    border-top-color: #d97706;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.translate-loading-text {
    color: #f59e0b;
    font-size: 1rem;
    font-weight: 600;
}

/* ========== Translate Result ========== */
.translate-result {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px 24px;
}

.translate-result-card {
    border-color: #d97706 !important;
}

.translate-result-title {
    color: #d97706;
}

.btn-amber {
    background: linear-gradient(135deg, #d97706, #f59e0b);
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    margin-top: 16px;
    font-size: 0.9rem;
    box-shadow: 0 2px 12px rgba(217, 119, 6, 0.3);
}

.btn-amber:hover {
    background: linear-gradient(135deg, #b45309, #d97706);
    box-shadow: 0 4px 20px rgba(217, 119, 6, 0.4);
}

.btn-amber:active {
    transform: scale(0.98);
}

/* ========== Copy Feedback ========== */
.btn-copied {
    color: var(--success) !important;
    border-color: var(--success) !important;
}

/* ========== Responsive ========== */
@media (max-width: 480px) {
    .app-container {
        padding: 0 12px;
    }

    .glass-card {
        padding: 16px;
    }
}

/* ========== Scrollbar (dark theme) ========== */
[data-theme="dark"] ::-webkit-scrollbar {
    width: 6px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
    background: transparent;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* ========== Selection ========== */
::selection {
    background: var(--primary);
    color: #fff;
}
