/* 全局樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --panel-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-color: #1e293b;
    --text-secondary: #64748b;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', 'Noto Sans TC', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 標題區 */
header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #3b82f6 100%);
    color: white;
    padding: 2rem;
    text-align: center;
    box-shadow: var(--shadow-md);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* 主要內容區 */
.main-content {
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem;
    flex: 1;
}

/* 控制面板 */
.control-panel {
    width: 320px;
    background: var(--panel-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    height: fit-content;
    position: sticky;
    top: 1.5rem;
    overflow-y: auto;
    max-height: calc(100vh - 3rem);
}

.panel-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.panel-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.panel-section h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-color);
    font-weight: 600;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group select,
.form-group input[type="text"],
.form-group input[type="number"] {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: all 0.2s;
    background: white;
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group input[type="checkbox"] {
    margin-right: 0.5rem;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.form-group label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: 400;
    color: var(--text-color);
}

/* 編輯區域 */
.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.editor-section {
    background: var(--panel-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    flex: 1;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.editor-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

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

textarea {
    width: 100%;
    min-height: 300px;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    resize: vertical;
    background: #fafafa;
    transition: all 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    background: white;
}

#output-text {
    background: #f8f9fa;
}

/* 預覽區域 */
.preview-area {
    width: 100%;
    min-height: 300px;
    padding: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: white;
    overflow: auto;
    line-height: 1.8;
}

.preview-area h1, .preview-area h2, .preview-area h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.8rem;
}

.preview-area h1 { font-size: 2rem; }
.preview-area h2 { font-size: 1.5rem; }
.preview-area h3 { font-size: 1.2rem; }

.preview-area p {
    margin-bottom: 1rem;
}

.preview-area ul, .preview-area ol {
    margin-left: 2rem;
    margin-bottom: 1rem;
}

.preview-area code {
    background: #f1f5f9;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Consolas', monospace;
    font-size: 0.9em;
}

.preview-area pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.preview-area pre code {
    background: none;
    color: inherit;
    padding: 0;
}

.output-toggle {
    margin-top: 1rem;
}

/* 轉換按鈕區 */
.convert-section {
    display: flex;
    justify-content: center;
    padding: 0;
}

/* 按鈕樣式 */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

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

.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: #475569;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.btn-large {
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
}

.btn-icon {
    font-size: 1.2em;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* 訊息區域 */
.messages-area {
    background: var(--panel-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.messages-area h4 {
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 600;
}

#messages-content {
    max-height: 200px;
    overflow-y: auto;
}

.message-item {
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    border-left: 4px solid;
    font-size: 0.9rem;
}

.message-warning {
    background: #fef3c7;
    border-color: var(--warning-color);
    color: #92400e;
}

.message-info {
    background: #dbeafe;
    border-color: var(--primary-color);
    color: #1e40af;
}

.message-error {
    background: #fee2e2;
    border-color: var(--error-color);
    color: #991b1b;
}

/* 連線狀態 */
#connection-status {
    margin-top: 0.8rem;
    padding: 0.6rem;
    border-radius: 6px;
    font-size: 0.85rem;
    text-align: center;
    font-weight: 500;
}

#connection-status.success {
    background: #d1fae5;
    color: #065f46;
}

#connection-status.error {
    background: #fee2e2;
    color: #991b1b;
}

#connection-status.loading {
    background: #e0e7ff;
    color: #3730a3;
}

/* 頁尾 */
footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
}

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

footer a:hover {
    text-decoration: underline;
}

/* 載入動畫 */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-loading .btn-icon {
    animation: spin 1s linear infinite;
}

/* 響應式設計 */
@media (max-width: 1200px) {
    .main-content {
        flex-direction: column;
    }

    .control-panel {
        width: 100%;
        position: static;
        max-height: none;
    }

    textarea {
        min-height: 250px;
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    .main-content {
        padding: 1rem;
    }

    .control-panel,
    .editor-section {
        padding: 1rem;
    }

    .btn-large {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
    }
}

/* 捲軸樣式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

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

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