/* ===== Variables ===== */
:root {
    --color-primary: #6366f1;
    --color-primary-hover: #4f46e5;
    --color-primary-light: rgba(99, 102, 241, 0.08);
    --color-accent: #06b6d4;
    --color-success: #10b981;
    --color-error: #ef4444;
    --color-error-bg: #fef2f2;
    --color-warning: #f59e0b;
    --color-bg: #0f172a;
    --color-bg-card: #1e293b;
    --color-bg-input: #0f172a;
    --color-border: #334155;
    --color-border-focus: #6366f1;
    --color-text: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-text-muted: #64748b;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
    --transition: 200ms ease;
}

/* Light theme */
[data-theme="light"] {
    --color-bg: #f8fafc;
    --color-bg-card: #ffffff;
    --color-bg-input: #f1f5f9;
    --color-border: #e2e8f0;
    --color-border-focus: #6366f1;
    --color-text: #1e293b;
    --color-text-secondary: #475569;
    --color-text-muted: #94a3b8;
    --color-primary-light: rgba(99, 102, 241, 0.06);
    --color-error-bg: #fef2f2;
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* ===== Reset ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    font-size: 15px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===== App Container ===== */
.app-container {
    max-width: 860px;
    margin: 0 auto;
    padding: 32px 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.app-header {
    text-align: center;
    margin-bottom: 32px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 8px;
}

.btn-theme {
    position: absolute;
    right: 0;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-theme:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.logo-icon {
    font-size: 2rem;
}

.logo h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.5px;
}

.logo .highlight {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--color-text-secondary);
    font-size: 0.95rem;
}

/* ===== Main ===== */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ===== Cards ===== */
.card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-card);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}

/* ===== Textarea ===== */
textarea {
    width: 100%;
    min-height: 160px;
    padding: 16px;
    font-family: var(--font-family);
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--color-text);
    background: var(--color-bg-input);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    resize: vertical;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

textarea:focus {
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

textarea::placeholder {
    color: var(--color-text-muted);
}

/* ===== Input Footer ===== */
.input-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.char-counter {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.limit-message {
    font-size: 0.75rem;
    color: var(--color-warning);
    font-weight: 500;
}

.attach-area {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), #818cf8);
    color: #fff;
    font-weight: 600;
    padding: 12px 24px;
    font-size: 0.9rem;
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    padding: 8px 14px;
}

.btn-ghost:hover {
    background: var(--color-primary-light);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.btn-attach {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px dashed var(--color-border);
    padding: 6px 12px;
    font-size: 0.8rem;
    cursor: pointer;
}

.btn-attach:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-primary-light);
}

.btn-attach input[type="file"] {
    display: none;
}

.btn-icon {
    font-size: 1rem;
}

/* ===== Remove File ===== */
.remove-file-btn {
    display: none;
    background: none;
    border: none;
    color: var(--color-error);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.remove-file-btn:hover {
    background: var(--color-error-bg);
}

.upload-status {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* ===== Options Bar ===== */
.options-bar {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
    padding: 16px 20px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 140px;
}

.option-group label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
}

.option-group select {
    padding: 10px 12px;
    font-family: var(--font-family);
    font-size: 0.85rem;
    background: var(--color-bg-input);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.option-group select:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* ===== Output Card ===== */
.output-card {
    min-height: 200px;
}

.output-area {
    min-height: 120px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--color-text-muted);
}

.empty-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.6;
}

.empty-state p {
    max-width: 360px;
    font-size: 0.9rem;
    line-height: 1.6;
}

/* ===== Loading ===== */
.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Error ===== */
.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    color: #fca5a5;
    font-size: 0.9rem;
}

/* ===== Markdown Output ===== */
#output-area h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 16px;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 10px;
}

#output-area h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 24px 0 10px;
    color: var(--color-text);
}

#output-area h2:first-child {
    margin-top: 0;
}

#output-area h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 18px 0 8px;
    color: var(--color-text-secondary);
}

#output-area p {
    margin: 0 0 12px;
    line-height: 1.7;
    color: var(--color-text);
}

#output-area strong {
    color: var(--color-text);
    font-weight: 600;
}

#output-area ul, #output-area ol {
    margin: 8px 0 16px;
    padding-left: 24px;
}

#output-area ul { list-style-type: disc; }
#output-area ul ul { list-style-type: circle; padding-left: 20px; margin: 4px 0; }

#output-area li {
    margin-bottom: 6px;
    line-height: 1.6;
    color: var(--color-text);
}

#output-area li input[type="checkbox"] {
    margin-right: 8px;
    accent-color: var(--color-primary);
}

#output-area table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.85rem;
}

#output-area th, #output-area td {
    border: 1px solid var(--color-border);
    padding: 8px 12px;
    text-align: left;
}

#output-area th {
    background: var(--color-bg-input);
    font-weight: 600;
    color: var(--color-text-secondary);
}

#output-area code {
    background: var(--color-bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: 'Fira Code', 'SF Mono', monospace;
}

#output-area pre {
    background: var(--color-bg-input);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
}

#output-area pre code {
    background: none;
    padding: 0;
}

#output-area a {
    color: var(--color-primary);
    text-decoration: none;
}

#output-area a:hover {
    text-decoration: underline;
}

/* ===== Footer ===== */
.app-footer {
    text-align: center;
    padding: 24px 0 8px;
    margin-top: 24px;
    border-top: 1px solid var(--color-border);
}

.app-footer p {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.app-footer a {
    color: var(--color-primary);
    text-decoration: none;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .app-container {
        padding: 16px 12px;
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    .card {
        padding: 16px;
        border-radius: var(--radius-md);
    }

    .options-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .option-group {
        min-width: 100%;
    }

    .btn-primary {
        width: 100%;
        justify-content: center;
    }

    textarea {
        min-height: 120px;
    }

    .input-footer {
        flex-direction: column;
        align-items: flex-start;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}

/* ===== Output Actions ===== */
.output-actions {
    display: none;
    gap: 8px;
    align-items: center;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.78rem;
}
