* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 50%, #0f1419 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: #1a1f3a;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(247, 147, 26, 0.2);
    overflow: hidden;
    border: 1px solid rgba(247, 147, 26, 0.3);
}

header {
    background: linear-gradient(135deg, #f7931a 0%, #ff9500 50%, #627eea 100%);
    color: white;
    padding: 30px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(247, 147, 26, 0.3);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

header h1 i {
    font-size: 2.5rem;
    margin-right: 10px;
}

.status {
    display: inline-block;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    font-size: 0.9rem;
}

.tabs {
    display: flex;
    background: #0f1419;
    border-bottom: 2px solid rgba(247, 147, 26, 0.3);
}

.tab-btn {
    flex: 1;
    padding: 15px 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: #8b8fa3;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
}

.tab-btn:hover {
    background: rgba(247, 147, 26, 0.1);
    color: #f7931a;
}

.tab-btn.active {
    background: rgba(247, 147, 26, 0.15);
    color: #f7931a;
    border-bottom: 3px solid #f7931a;
    font-weight: 600;
}

.tab-btn i {
    font-size: 1rem;
}

.tab-content {
    display: none;
    padding: 30px;
    background: #1a1f3a;
}

.tab-content.active {
    display: block;
}

.section {
    margin-bottom: 30px;
    padding: 20px;
    background: #0f1419;
    border-radius: 8px;
    border: 1px solid rgba(247, 147, 26, 0.2);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.section h2 {
    color: #f7931a;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

input[type="text"],
input[type="number"],
textarea {
    width: 100%;
    padding: 12px;
    margin: 8px 0;
    border: 2px solid rgba(247, 147, 26, 0.3);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.3s;
    background: #0f1419;
    color: #e0e0e0;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
    outline: none;
    border-color: #f7931a;
    box-shadow: 0 0 0 3px rgba(247, 147, 26, 0.1);
}

button {
    background: linear-gradient(135deg, #f7931a 0%, #ff9500 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin: 8px 8px 8px 0;
    box-shadow: 0 2px 8px rgba(247, 147, 26, 0.3);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(247, 147, 26, 0.5);
    background: linear-gradient(135deg, #ff9500 0%, #f7931a 100%);
}

button:active {
    transform: translateY(0);
}

.result {
    margin-top: 15px;
    padding: 15px;
    background: #0f1419;
    border-radius: 6px;
    border: 1px solid rgba(247, 147, 26, 0.3);
    min-height: 50px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #e0e0e0;
}

.result.loading {
    color: #f7931a;
    font-style: italic;
}

/* 骨架屏樣式 */
.skeleton-container {
    padding: 20px;
}

.skeleton-line,
.skeleton-card {
    background: linear-gradient(90deg, #0f1419 25%, #1a1f3a 50%, #0f1419 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

.skeleton-card {
    background: linear-gradient(90deg, #0f1419 25%, #1a1f3a 50%, #0f1419 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border: 1px solid rgba(247, 147, 26, 0.2);
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* 持倉分類按鈕樣式 */
#position-tabs {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    gap: 10px;
    flex-wrap: wrap;
}

.position-tab-btn {
    transition: all 0.3s ease;
}

.position-tab-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.position-tab-btn.active {
    opacity: 1 !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* 響應式設計 */
@media (max-width: 768px) {
    #position-tabs {
        flex-direction: column;
    }
    
    .position-tab-btn {
        width: 100%;
        margin-right: 0 !important;
        margin-bottom: 10px;
    }
    
    /* 手機端持倉卡片查看更多按鈕 */
    #account-info button[onclick*="loadMorePositions"] {
        width: 100%;
        padding: 8px 20px !important;
        font-size: 0.9rem;
        min-height: 36px;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px;
    }
}

/* 查看更多按鈕通用樣式 */
#account-info button[onclick*="loadMorePositions"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
    padding: 8px 20px;
    min-height: 36px;
    transition: all 0.2s ease;
}

#account-info button[onclick*="loadMorePositions"]:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

#account-info button[onclick*="loadMorePositions"] span {
    display: inline-block;
}

.result.error {
    color: #ef5350;
    border-color: #ef5350;
    background: rgba(239, 83, 80, 0.1);
}

.result.success {
    color: #00d9a5;
    border-color: #00d9a5;
    background: rgba(0, 217, 165, 0.1);
}

/* K 線圖表樣式 */
#klines-chart {
    background: #0f1419;
    border-radius: 6px;
    padding: 10px;
    border: 1px solid rgba(247, 147, 26, 0.2);
}

#klines-info {
    padding: 10px;
    background: #0f1419;
    border-radius: 6px;
    border: 1px solid rgba(247, 147, 26, 0.2);
    color: #e0e0e0;
}

select {
    font-size: 1rem;
    cursor: pointer;
    background: #0f1419;
    color: #e0e0e0;
    border: 2px solid rgba(247, 147, 26, 0.3);
    border-radius: 6px;
    padding: 8px;
}

select:focus {
    outline: none;
    border-color: #f7931a;
    box-shadow: 0 0 0 3px rgba(247, 147, 26, 0.1);
}

/* 訂單列表樣式 */
.orders-container {
    max-height: 70vh;
    overflow-y: auto;
    min-height: 100px; /* 確保容器有最小高度 */
    background: transparent; /* 確保背景透明，不會遮擋內容 */
}

/* 確保訂單卡片可見 */
.orders-container .order-item {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* 確保訂單詳情網格可見 */
.order-item .order-details {
    display: grid !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
    overflow: visible !important;
}

/* 訂單分頁樣式 */
.order-tab-btn {
    transition: all 0.3s ease;
}

.order-tab-btn:hover {
    background: #ff9500 !important;
    color: white !important;
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(247, 147, 26, 0.4);
}

.order-tab-btn.active {
    background: #f7931a !important;
    color: white !important;
    box-shadow: 0 2px 4px rgba(247, 147, 26, 0.3);
}

/* AI 分頁按鈕樣式 */
.order-ai-tab-btn {
    transition: all 0.3s ease;
}

.order-ai-tab-btn:hover {
    background: #ff9500 !important;
    color: white !important;
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(247, 147, 26, 0.4);
}

.order-item {
    transition: transform 0.2s, box-shadow 0.2s;
}

.order-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15) !important;
}

.order-item.success {
    border-left-color: #00d9a5 !important;
}

.order-item.error {
    border-left-color: #ef5350 !important;
}

details summary {
    user-select: none;
}

details summary:hover {
    text-decoration: underline;
}

/* 響應式設計 */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        margin: 0;
        border-radius: 8px;
    }

    header {
        padding: 20px 15px;
    }

    header h1 {
        font-size: 1.5rem;
        margin-bottom: 8px;
    }

    header h1 i {
        font-size: 1.5rem;
        margin-right: 8px;
    }

    .status {
        font-size: 0.8rem;
        padding: 6px 12px;
    }

    .tabs {
        flex-direction: column;
        flex-wrap: wrap;
    }

    .tab-btn {
        border-bottom: 1px solid #e0e0e0;
        padding: 12px 15px;
        font-size: 0.9rem;
        flex: 1 1 auto;
        min-width: 0;
    }

    .tab-btn i {
        font-size: 0.9rem;
    }

    .tab-btn.active {
        border-bottom: 3px solid #4A90E2;
    }
    
    .tab-content {
        padding: 15px;
    }

    .section {
        padding: 15px;
        margin-bottom: 20px;
    }

    .section h2 {
        font-size: 1.1rem;
        margin-bottom: 12px;
    }

    input[type="text"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px; /* 防止 iOS 自動縮放 */
        padding: 10px;
        margin: 6px 0;
    }

    button {
        padding: 10px 16px;
        font-size: 0.9rem;
        margin: 6px 6px 6px 0;
        width: 100%;
    }

    .result {
        padding: 12px;
        font-size: 0.85rem;
    }
    
    #klines-chart {
        height: 300px !important;
    }
    
    .orders-container {
        max-height: 50vh;
    }

    /* 訂單列表響應式 */
    .order-tabs {
        flex-wrap: wrap;
        gap: 5px !important;
    }

    .order-tab-btn {
        padding: 8px 12px !important;
        font-size: 0.85rem !important;
        flex: 1 1 auto;
        min-width: calc(50% - 5px);
    }

    .order-ai-tabs-wrapper {
        position: relative;
    }

    .order-ai-tabs-container {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
        padding: 0 40px !important;
    }

    .order-ai-tabs-container::-webkit-scrollbar {
        display: none !important;
    }

    .order-ai-tab-btn {
        padding: 8px 16px !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
        min-width: auto !important;
    }

    .order-ai-scroll-btn {
        display: flex !important;
    }

    .order-ai-scroll-btn:hover {
        background: rgba(255, 255, 255, 1) !important;
        box-shadow: 0 2px 6px rgba(0,0,0,0.15) !important;
    }

    .order-item {
        padding: 12px !important;
        margin-bottom: 10px !important;
        background: #0f1419 !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        min-height: 100px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        color: #e0e0e0 !important;
    }

    /* 只對標題區域應用 flex-direction: column */
    .order-item > div:first-child {
        flex-direction: column !important;
    }

    .order-item > div:first-child > div:first-child {
        margin-bottom: 10px;
    }
    
    /* 確保詳情網格正常顯示（手機端改為單列） */
    .order-item .order-details {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 10px !important;
        visibility: visible !important;
        opacity: 1 !important;
        height: auto !important;
        overflow: visible !important;
    }

    /* 表格響應式 */
    table {
        font-size: 0.8rem;
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table thead,
    table tbody,
    table tr {
        display: block;
    }

    table thead {
        display: none;
    }

    table tr {
        border: 1px solid #ddd;
        margin-bottom: 10px;
        padding: 10px;
        border-radius: 6px;
        background: white;
    }

    table td {
        display: flex;
        justify-content: space-between;
        padding: 8px;
        border: none;
        border-bottom: 1px solid #eee;
    }

    table td:last-child {
        border-bottom: none;
    }

    table td::before {
        content: attr(data-label);
        font-weight: bold;
        margin-right: 10px;
        color: #666;
        flex-shrink: 0;
    }
    
    /* 帳戶資訊響應式 */
    #account-tab .section > div:first-child {
        flex-direction: column !important;
    }
    
    #account-tab #account-info > div {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    #account-tab #account-info > div > div {
        padding: 12px !important;
    }

    /* 分頁按鈕響應式 */
    .pagination {
        flex-wrap: wrap;
        gap: 5px;
    }

    .pagination button {
        padding: 8px 12px;
        font-size: 0.85rem;
        min-width: auto;
    }

    /* 日誌區域響應式 */
    #trading-logs {
        font-size: 0.75rem;
        padding: 10px;
        max-height: 60vh;
    }

    /* 表單元素響應式 */
    label {
        display: block;
        margin-bottom: 5px;
    }

    /* 彈出框響應式 */
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        padding: 20px 15px !important;
        margin: 10px !important;
    }

    .modal-content h3 {
        font-size: 1.2rem !important;
    }

    .modal-content p {
        font-size: 0.95rem !important;
    }

    .modal-buttons {
        flex-direction: column;
        gap: 10px;
    }

    .modal-btn {
        width: 100%;
    }
}

/* 手機端額外優化 */
@media (max-width: 480px) {
    body {
        padding: 5px;
    }

    header {
        padding: 15px 10px;
    }

    header h1 {
        font-size: 1.2rem;
    }

    header h1 i {
        font-size: 1.2rem;
    }

    .tab-content {
        padding: 10px;
    }

    .section {
        padding: 12px;
    }

    .section h2 {
        font-size: 1rem;
    }

    button {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    .order-tab-btn,
    .order-ai-tab-btn {
        padding: 8px 14px !important;
        font-size: 0.8rem !important;
    }

    .order-ai-scroll-btn {
        width: 28px !important;
        height: 28px !important;
    }

    .order-ai-tabs-container {
        padding: 0 35px !important;
    }

    .order-item {
        padding: 10px !important;
    }

    #trading-logs {
        font-size: 0.7rem;
        max-height: 50vh;
    }
}

/* 日誌樣式 */
.log-error {
    color: #f48771;
}

.log-warning {
    color: #dcdcaa;
}

.log-info {
    color: #4ec9b0;
}

.log-debug {
    color: #9cdcfe;
}

#trading-logs {
    font-family: 'Courier New', 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    max-height: 70vh;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 15px;
    border-radius: 6px;
    border: 1px solid #3e3e3e;
}

#trading-logs::-webkit-scrollbar {
    width: 8px;
}

#trading-logs::-webkit-scrollbar-track {
    background: #1e1e1e;
}

#trading-logs::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

#trading-logs::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* AI 交易訂單記錄頁面 - 按鈕分區樣式 */
.order-filter-section {
    margin-bottom: 15px;
}

.filter-section-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #f7931a;
    margin-bottom: 8px;
    padding-left: 2px;
}

.order-filter-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.order-filter-buttons .new-ai-tab,
.order-filter-buttons .new-order-type {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.3s;
    flex: 1 1 auto;
    min-width: calc(25% - 6px);
    text-align: center;
}

/* AI 分類按鈕樣式 */
.ai-filter-buttons .new-ai-tab {
    background: rgba(247, 147, 26, 0.1);
    color: #8b8fa3;
}

.ai-filter-buttons .new-ai-tab.active {
    background: #f7931a;
    color: white;
}

.ai-filter-buttons .new-ai-tab:hover {
    background: #d0d0d0;
}

.ai-filter-buttons .new-ai-tab.active:hover {
    background: #3a7bc8;
}

/* 訂單類型按鈕樣式 */
.type-filter-buttons .new-order-type {
    background: rgba(247, 147, 26, 0.1);
    color: #8b8fa3;
}

.type-filter-buttons .new-order-type.active {
    background: #00d9a5;
    color: white;
}

.type-filter-buttons .new-order-type:hover {
    background: #d0d0d0;
}

.type-filter-buttons .new-order-type.active:hover {
    background: #229954;
}

/* 手機版優化 */
@media (max-width: 768px) {
    .order-filter-section {
        margin-bottom: 12px;
    }
    
    .filter-section-label {
        font-size: 0.85rem;
        margin-bottom: 6px;
        font-weight: 600;
    }
    
    .order-filter-buttons {
        gap: 6px;
    }
    
    .order-filter-buttons .new-ai-tab,
    .order-filter-buttons .new-order-type {
        padding: 6px 12px;
        font-size: 0.8rem;
        min-width: calc(25% - 5px);
        flex: 1 1 auto;
    }
}

/* 小屏幕手機版進一步優化 */
@media (max-width: 480px) {
    .order-filter-section {
        margin-bottom: 10px;
    }
    
    .filter-section-label {
        font-size: 0.8rem;
        margin-bottom: 5px;
    }
    
    .order-filter-buttons {
        gap: 5px;
    }
    
    .order-filter-buttons .new-ai-tab,
    .order-filter-buttons .new-order-type {
        padding: 5px 10px;
        font-size: 0.75rem;
        min-width: calc(25% - 4px);
        flex: 1 1 auto;
    }
}

