/* ========================================
   CSS Custom Properties (Theming)
   ======================================== */
:root {
    /* Light Theme */
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8fafc;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #a0aec0;
    --border-color: #e2e8f0;
    --border-focus: #4299e1;
    --accent-primary: #4299e1;
    --accent-secondary: #667eea;
    --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    --success-color: #48bb78;
    --error-color: #f56565;
    --warning-bg: #fff5f5;
    --warning-border: #fed7d7;
    --history-bg: #f7fafc;
    --panel-hover: #edf2f7;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --text-primary: #f7fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #718096;
    --border-color: #4a5568;
    --border-focus: #63b3ed;
    --accent-primary: #63b3ed;
    --accent-secondary: #9f7aea;
    --accent-gradient: linear-gradient(135deg, #9f7aea 0%, #667eea 100%);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
    --warning-bg: #742a2a;
    --warning-border: #c53030;
    --history-bg: #2d3748;
    --panel-hover: #4a5568;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: var(--transition);
}

/* ========================================
   Container
   ======================================== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ========================================
   Header
   ======================================== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin-bottom: 24px;
}

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

.logo-icon {
    font-size: 2rem;
    animation: pulse 2s infinite;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-sub {
    font-size: 0.85rem;
    font-weight: 400;
    opacity: 0.8;
}

.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.25rem;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

/* ========================================
   Language Controls
   ======================================== */
.lang-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 20px;
}

.lang-label {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 8px 20px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    min-width: 100px;
    text-align: center;
    transition: var(--transition);
}

.lang-switch-group {
    display: flex;
    align-items: center;
    justify-content: center;
}

.swap-btn {
    background: var(--accent-gradient);
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.5rem;
    color: white;
    transition: var(--transition);
    box-shadow: var(--shadow-md);
}

.swap-btn:hover {
    transform: rotate(180deg) scale(1.1);
    box-shadow: var(--shadow-lg);
}

/* ========================================
   Panels
   ======================================== */
.panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: var(--transition);
}

.panel:hover {
    box-shadow: var(--shadow-lg);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.panel-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    color: var(--text-secondary);
}

.action-btn:hover {
    background: var(--panel-hover);
    color: var(--accent-primary);
}

.source-input {
    width: 100%;
    min-height: 200px;
    padding: 16px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.6;
    resize: vertical;
    font-family: inherit;
    transition: var(--transition);
}

.source-input:focus {
    outline: none;
}

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

.result-area {
    min-height: 200px;
    padding: 16px;
    position: relative;
}

.result-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.placeholder-text {
    font-size: 0.95rem;
}

.result-text {
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text-primary);
    word-break: break-word;
}

.result-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-secondary);
    gap: 12px;
}

/* Spinner */
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.panel-footer {
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

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

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

/* ========================================
   Translate Button
   ======================================== */
.translate-action {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.translate-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 32px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-md);
}

.translate-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.translate-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-shortcut {
    font-size: 0.75rem;
    opacity: 0.7;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 4px;
}

/* ========================================
   Error Message
   ======================================== */
.error-message {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    border-radius: var(--radius-sm);
    margin-bottom: 24px;
    animation: slideDown 0.3s ease;
}

.error-icon {
    font-size: 1.25rem;
}

.error-text {
    flex: 1;
    color: var(--error-color);
    font-size: 0.9rem;
}

.error-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    transition: var(--transition);
}

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

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   History Section
   ======================================== */
.history-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    margin-bottom: 24px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    cursor: pointer;
    transition: var(--transition);
}

.history-header:hover {
    background: var(--panel-hover);
}

.history-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-muted);
    transition: var(--transition);
}

.history-toggle.expanded .toggle-icon {
    transform: rotate(180deg);
}

.history-content {
    padding: 0 20px 20px;
    border-top: 1px solid var(--border-color);
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 12px 0;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    background: var(--history-bg);
    transition: var(--transition);
    cursor: pointer;
}

.history-item:hover {
    background: var(--panel-hover);
}

.history-source, .history-target {
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-source {
    color: var(--text-secondary);
    padding-right: 12px;
}

.history-target {
    color: var(--text-primary);
    font-weight: 500;
    padding-left: 12px;
    border-left: 2px solid var(--accent-primary);
}

.history-arrow {
    color: var(--accent-primary);
    padding: 0 8px;
    font-size: 1rem;
}

.history-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-actions {
    display: flex;
    justify-content: center;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.clear-history-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
}

.clear-history-btn:hover {
    border-color: var(--error-color);
    color: var(--error-color);
}

/* ========================================
   Footer
   ======================================== */
.footer {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

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

    .header {
        padding: 12px 0;
        margin-bottom: 16px;
    }

    .logo-text {
        font-size: 1.2rem;
    }

    .logo-sub {
        display: none;
    }

    .panels {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .lang-controls {
        gap: 12px;
    }

    .lang-label {
        font-size: 0.95rem;
        padding: 6px 14px;
        min-width: 80px;
    }

    .swap-btn {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }

    .translate-btn {
        padding: 12px 24px;
        font-size: 1rem;
    }

    .btn-shortcut {
        display: none;
    }

    .history-item {
        flex-direction: column;
        gap: 4px;
    }

    .history-arrow {
        display: none;
    }

    .history-source, .history-target {
        padding: 0;
        border-left: none;
    }
}

@media (max-width: 480px) {
    .logo-icon {
        font-size: 1.5rem;
    }

    .logo-text {
        font-size: 1rem;
    }

    .theme-toggle {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .source-input {
        min-height: 150px;
    }

    .result-area {
        min-height: 150px;
    }
}

/* ========================================
   Animations
   ======================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.result-text {
    animation: fadeIn 0.3s ease;
}

/* Copy feedback */
.copy-feedback {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--success-color);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    animation: fadeIn 0.2s ease;
    pointer-events: none;
}

/* Scrollbar styling */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
