/* ===== 기본 스타일 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: #f5f7fa;
    min-height: 100vh;
    padding: 20px;
    color: #333;
    overflow-x: hidden;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    padding: 16px 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    max-width: 900px;
}

.page-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: #667eea;
}

.page-subtitle {
    font-size: 0.85rem;
    color: #999;
    margin-top: 2px;
    text-align: center;
}

/* ===== 봇 카드 ===== */
.bot-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
}

.bot-accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.bot-accordion-header:hover {
    background: #f8f9ff;
    border-color: #667eea;
}

.bot-accordion-header.active {
    border-color: #667eea;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-bottom: 0;
}

.bot-accordion-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bot-accordion-toggle {
    font-size: 0.8rem;
    color: #667eea;
    transition: transform 0.2s;
}

.bot-accordion-header.active .bot-accordion-toggle {
    transform: rotate(90deg);
}

.bot-name {
    font-weight: 700;
    color: #333;
    font-size: 1rem;
}

.bot-market-badge {
    background: #667eea;
    color: #fff;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.bot-market-badge.kr {
    background: #e53935;
}

.bot-accordion-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.position-counter {
    font-size: 0.9rem;
    font-weight: 700;
    color: #333;
}

.progress-bar-wrap {
    width: 90px;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    border-radius: 4px;
    transition: width 0.3s;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ccc;
}

.status-dot.active {
    background: #4caf50;
    box-shadow: 0 0 6px rgba(76, 175, 80, 0.5);
}

/* ===== 아코디언 바디 ===== */
.bot-accordion-body {
    display: none;
    background: #fff;
    border: 1px solid #667eea;
    border-top: none;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    padding: 20px;
}

.bot-accordion-body.open {
    display: block;
}

/* ===== 설정 그리드 ===== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.setting-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-field label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.setting-field input[type="number"],
.setting-field input[type="text"] {
    padding: 10px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: #fafafa;
    color: #333;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.setting-field input:focus {
    outline: none;
    border-color: #667eea;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* ===== Toggle ===== */
.toggle-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 6px;
}

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc;
    border-radius: 24px;
    transition: 0.2s;
}

.toggle-slider:before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}

.toggle input:checked + .toggle-slider {
    background: #667eea;
}

.toggle input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #555;
}

/* ===== 액션 버튼 ===== */
.action-row {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

.btn-save {
    padding: 10px 24px;
    background: #667eea;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-save:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* ===== 트레이드 테이블 ===== */
.trade-section {
    margin-top: 20px;
    border-top: 1px solid #f0f0f0;
    padding-top: 16px;
}

.trade-section-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #555;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.trade-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.trade-table th {
    text-align: left;
    padding: 8px 10px;
    color: #888;
    font-weight: 600;
    border-bottom: 1px solid #eee;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.trade-table td {
    padding: 10px 10px;
    border-bottom: 1px solid #f5f5f5;
    color: #333;
}

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

.trade-table tr:hover td {
    background: #f8f9ff;
}

.ticker-badge {
    background: #f0f0f0;
    color: #333;
    padding: 3px 8px;
    border-radius: 5px;
    font-weight: 700;
    font-size: 0.82rem;
}

.time-stopped {
    color: #e53935;
    font-weight: 600;
}

.time-ok {
    color: #4caf50;
    font-weight: 600;
}

.btn-remove-trade {
    padding: 4px 12px;
    background: none;
    border: 1px solid #e53935;
    color: #e53935;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-remove-trade:hover {
    background: #e53935;
    color: #fff;
}

.empty-trades {
    color: #bbb;
    font-size: 0.88rem;
    padding: 12px 0;
    text-align: center;
}

/* ===== 토스트 ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #333;
    color: #fff;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0;
    transition: all 0.3s;
    z-index: 9999;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success { background: #4caf50; }
.toast.error   { background: #e53935; }

/* ===== 빠른 실행 버튼 ===== */
.quick-actions {
    max-width: 900px;
    margin: 0 auto 16px;
    display: flex;
    gap: 10px;
}

.btn-qa {
    flex: 1;
    padding: 14px 16px;
    border: none;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.btn-qa.kr {
    background: linear-gradient(135deg, #e53935, #c62828);
    color: #fff;
    box-shadow: 0 3px 10px rgba(229, 57, 53, 0.28);
}
.btn-qa.kr:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(229, 57, 53, 0.38);
}

.btn-qa.us {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.28);
}
.btn-qa.us:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.38);
}

.btn-qa.report {
    background: linear-gradient(135deg, #4a5568, #2d3748);
    color: #fff;
    box-shadow: 0 3px 10px rgba(74, 85, 104, 0.25);
}
.btn-qa.report:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(74, 85, 104, 0.35);
}

.btn-qa:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* ===== 트레이드 인라인 편집 ===== */
.inline-edit {
    display: flex;
    align-items: center;
    gap: 2px;
}

.trade-input {
    width: 58px;
    padding: 3px 5px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.8rem;
    text-align: right;
    background: #f8fafc;
    color: #333;
}

.trade-input:focus {
    outline: none;
    border-color: #667eea;
    background: #fff;
}

.timestop-cell {
    position: relative;
}

.d-day-label {
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: #f0f4ff;
    white-space: nowrap;
}

.d-day-label:hover {
    background: #e0e7ff;
}

.hidden-date-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
    top: 0;
    left: 0;
}

.trade-actions {
    display: flex;
    gap: 4px;
}

.btn-save-trade {
    padding: 3px 8px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
}

.btn-save-trade:hover { background: #5a67d8; }

.btn-force-sell {
    padding: 3px 8px;
    background: #e53e3e;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
}
.btn-force-sell:hover { background: #c53030; }
.btn-force-sell:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== 수익률 ===== */
.profit-pos { color: #e53e3e; font-weight: 600; }
.profit-neg { color: #3182ce; font-weight: 600; }
.loading-cell { color: #a0aec0; font-size: 0.85em; }

/* ===== 히스토리 섹션 ===== */
.history-section {
    max-width: 900px;
    margin: 24px auto 40px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.history-section > *:first-child {
    border-radius: 12px 12px 0 0;
}

.history-section > *:last-child {
    border-radius: 0 0 12px 12px;
    overflow: hidden;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    flex-wrap: wrap;
    gap: 10px;
}

.history-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #444;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-tabs {
    display: flex;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    overflow: hidden;
}

.history-tab {
    padding: 5px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    background: #fff;
    color: #888;
    cursor: pointer;
}

.history-tab.active {
    background: #667eea;
    color: #fff;
}

.custom-select {
    position: relative;
    min-width: 120px;
}

.custom-select-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    font-size: 0.82rem;
    color: #444;
    cursor: pointer;
    white-space: nowrap;
}

.custom-select-btn:hover { border-color: #667eea; }

.custom-select-arrow {
    font-size: 0.7rem;
    color: #999;
    transition: transform 0.15s;
}

.custom-select.open .custom-select-arrow { transform: rotate(180deg); }

.custom-select-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    z-index: 1000;
    overflow: hidden;
}

.custom-select.open .custom-select-dropdown { display: block; }

.custom-select-option {
    padding: 9px 14px;
    font-size: 0.83rem;
    color: #333;
    cursor: pointer;
    white-space: nowrap;
}

.custom-select-option:hover { background: #f0f4ff; }
.custom-select-option.selected { background: #667eea; color: #fff; }

.history-empty {
    padding: 32px;
    text-align: center;
    color: #aaa;
    font-size: 0.88rem;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.history-table th {
    padding: 10px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 1px solid #eee;
}

.history-table td {
    padding: 11px 16px;
    border-bottom: 1px solid #f5f5f5;
    color: #333;
}

.history-summary-row {
    cursor: pointer;
}

.history-summary-row:hover td {
    background: #f8f9ff;
}

.history-total-row td {
    font-weight: 700;
    color: #444;
    border-top: 2px solid #eee;
    border-bottom: none;
    background: #fafafa;
}

.history-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83rem;
    background: #f8f9ff;
}

.history-detail-table th {
    padding: 7px 16px;
    color: #aaa;
    font-size: 0.72rem;
    text-transform: uppercase;
    font-weight: 600;
    border-bottom: 1px solid #eee;
}

.history-detail-table td {
    padding: 8px 16px;
    border-bottom: 1px solid #eef0f8;
    color: #444;
}

.reason-badge {
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.reason-손절 { background: #fff0f0; color: #e53e3e; }
.reason-익절 { background: #f0fff4; color: #38a169; }
.reason-타임스탑 { background: #fffaf0; color: #dd6b20; }

/* ===== 반응형 ===== */
@media (max-width: 640px) {
    body { padding: 10px; }

    .settings-grid {
        grid-template-columns: 1fr 1fr;
    }

    .progress-bar-wrap {
        display: none;
    }

    /* 테이블 → 카드 변환 */
    .trade-table thead {
        display: none;
    }

    .trade-table,
    .trade-table tbody,
    .trade-table tr {
        display: block;
        width: 100%;
    }

    .trade-table tr {
        border: 1px solid #e8ecf0;
        border-radius: 8px;
        margin-bottom: 10px;
        padding: 4px 0;
        background: #fff;
    }

    .trade-table tr:hover td {
        background: transparent;
    }

    .trade-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 7px 14px;
        border-bottom: 1px solid #f5f5f5;
        font-size: 0.85rem;
    }

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

    .trade-table td::before {
        content: attr(data-label);
        color: #999;
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        flex-shrink: 0;
        margin-right: 8px;
    }

    .trade-table td[data-label=""]::before {
        display: none;
    }

    .trade-table td[data-label=""] {
        justify-content: flex-end;
        padding-top: 8px;
    }

    .trade-input {
        width: 52px;
    }

    .quick-actions {
        flex-wrap: wrap;
    }
    .btn-qa {
        flex: 1 1 calc(50% - 5px);
        min-width: 120px;
        padding: 12px 10px;
        font-size: 0.82rem;
    }
    .btn-qa.report {
        flex: 1 1 100%;
    }

    .history-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .history-controls {
        width: 100%;
        flex-wrap: wrap;
    }

    .custom-select {
        flex: 1;
        min-width: 0;
    }
}
