/**
 * Upbit Pro Trader - Mobile & Responsive Stylesheet
 * Optimized for smartphones (iPhone, Galaxy), tablets, and narrow viewports.
 */

/* Root & Global Overflow Prevention */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* ==========================================================================
   TABLET RESPONSIVENESS (max-width: 1100px)
   ========================================================================== */
@media (max-width: 1100px) {
    .header-inner {
        padding: 0 10px;
    }

    .gnb-nav {
        gap: 12px;
    }

    .gnb-link {
        font-size: 13px;
    }

    .exchange-layout-grid {
        grid-template-columns: 1fr;
    }

    .market-sidebar-col {
        position: static;
        width: 100%;
    }

    .market-coin-list {
        max-height: 400px;
    }

    .pos-pro-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 960px) {
    .gnb-nav {
        display: none !important;
    }
}

/* ==========================================================================
   MOBILE RESPONSIVENESS (max-width: 768px)
   ========================================================================== */
@media (max-width: 768px) {
    body {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 15px));
        font-size: 12px;
    }

    /* 1. Header */
    .upbit-header {
        height: 50px;
        width: 100%;
    }

    .header-inner {
        padding: 0 8px;
        gap: 4px;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .gnb-nav, .user-nav {
        display: none !important;
    }

    .header-left {
        gap: 6px;
        flex-shrink: 0;
        display: flex;
        align-items: center;
    }

    .logo-text {
        font-size: 16px;
        font-weight: 800;
    }

    .logo-dot {
        width: 4px;
        height: 4px;
    }

    .logo-sub {
        display: none !important;
    }

    .header-right {
        display: flex;
        align-items: center;
        gap: 4px;
        flex-shrink: 0;
    }

    .header-bot-status {
        display: flex;
        align-items: center;
        gap: 3px;
        flex-shrink: 0;
    }

    /* Hide redundant market badge in top header on mobile (already in account strip & position card) */
    #badgeMarket {
        display: none !important;
    }

    #badgeMode {
        font-size: 10px !important;
        padding: 2px 5px !important;
    }

    #badgeStatus {
        font-size: 10px !important;
        padding: 2px 6px !important;
    }

    .header-actions {
        display: flex;
        align-items: center;
        gap: 3px;
        flex-shrink: 0;
    }

    .upbit-btn-bot,
    #btnToggleBot {
        padding: 3px 6px !important;
        font-size: 11px !important;
        height: 30px !important;
        display: inline-flex !important;
        align-items: center !important;
        gap: 3px !important;
    }

    .icon-btn {
        width: 30px !important;
        height: 30px !important;
        font-size: 12px !important;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .icon-btn.btn-settings {
        width: 30px !important;
        height: 30px !important;
        padding: 0 !important;
        justify-content: center !important;
    }

    .icon-btn.btn-settings .btn-label {
        display: none !important;
    }

    /* 2. Notice Bar */
    .upbit-notice-bar {
        padding: 4px 0;
    }

    .notice-inner {
        padding: 0 10px;
        font-size: 11px;
    }

    /* 3. Mobile Navigation Tabs Bar (Sticky under header) */
    .mobile-nav-tabs {
        display: flex;
        align-items: center;
        overflow-x: auto;
        white-space: nowrap;
        background: #ffffff;
        border-bottom: 1px solid var(--border-card);
        position: sticky;
        top: 50px;
        z-index: 900;
        padding: 0 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .mobile-nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .mobile-nav-tabs .tab-btn {
        background: none;
        border: none;
        padding: 9px 12px;
        font-size: 12px;
        font-weight: 600;
        color: var(--text-secondary);
        cursor: pointer;
        position: relative;
        flex-shrink: 0;
        transition: color 0.15s;
    }

    .mobile-nav-tabs .tab-btn.active {
        color: var(--upbit-navy);
        font-weight: 800;
    }

    .mobile-nav-tabs .tab-btn.active::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 2.5px;
        background: var(--upbit-navy);
    }

    /* 4. Main Container & Layout */
    .upbit-main-container {
        padding: 0 6px;
        margin: 6px auto 16px auto;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    /* 4-B. Top KPI Banner on Mobile */
    .kpi-banner-section {
        margin-bottom: 6px;
        width: 100%;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .kpi-card {
        padding: 9px 10px;
        gap: 4px;
    }

    .kpi-value {
        font-size: 16px;
    }

    .kpi-value.highlight {
        font-size: 13px;
    }

    .kpi-krw {
        font-size: 11px;
    }

    .kpi-footer {
        font-size: 10px;
        flex-wrap: wrap;
        padding-top: 4px;
    }

    .exchange-layout-grid {
        grid-template-columns: 1fr;
        gap: 8px;
        width: 100%;
        max-width: 100%;
    }

    .trading-desk-col {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    /* 5. Coin Summary Header Bar */
    .coin-summary-card {
        padding: 10px 12px;
        width: 100%;
        max-width: 100%;
    }

    .coin-header-top {
        flex-wrap: wrap;
        gap: 6px;
        justify-content: space-between;
    }

    .coin-name-group {
        display: flex;
        align-items: baseline;
        gap: 6px;
    }

    .coin-kr-name {
        font-size: 17px;
    }

    .coin-symbol-pair {
        font-size: 11px;
    }

    .coin-sub-tabs {
        gap: 2px;
    }

    .sub-tab-btn {
        padding: 2px 6px;
        font-size: 11px;
    }

    .coin-price-stats-row {
        flex-direction: column;
        gap: 10px;
    }

    .main-price-box {
        width: 100%;
    }

    .big-price-krw {
        font-size: 24px;
    }

    .market-metrics-grid {
        width: 100%;
        min-width: unset;
        grid-template-columns: 1fr 1fr;
        column-gap: 12px;
        row-gap: 4px;
    }

    .metric-cell {
        font-size: 11px;
        padding: 3px 0;
    }

    .header-account-strip {
        gap: 6px;
        font-size: 10px;
        padding: 6px 8px;
        flex-wrap: wrap;
        line-height: 1.4;
    }

    /* 6. Chart Card */
    .upbit-chart-card {
        padding: 8px 10px;
        width: 100%;
        max-width: 100%;
    }

    .chart-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .tf-btn-group {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 2px;
        justify-content: flex-start;
    }

    .tf-btn-group::-webkit-scrollbar {
        display: none;
    }

    .tf-btn {
        padding: 3px 6px;
        font-size: 10px;
        flex-shrink: 0;
    }

    .chart-tools-group {
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        gap: 4px;
    }

    .ind-pill {
        padding: 2px 6px;
        font-size: 10px;
    }

    .canvas-chart-wrapper {
        height: 290px;
    }

    /* 7. Split Grid (Orderbook & Order Form) */
    .split-trade-grid {
        grid-template-columns: 1fr;
        gap: 8px;
        width: 100%;
        max-width: 100%;
    }

    .orderbook-panel, .orderform-panel {
        width: 100%;
        max-width: 100%;
    }

    .ob-table-header, .ob-row {
        padding: 3px 6px;
        font-size: 11px;
    }

    .order-main-tabs {
        height: 36px;
    }

    .otab-btn {
        padding: 0 8px;
        font-size: 12px;
    }

    .order-form-body {
        padding: 10px 12px;
    }

    .upbit-pct-btn {
        padding: 4px 6px;
        font-size: 11px;
    }

    .btn-order-submit {
        height: 42px;
        font-size: 14px;
    }

    /* 8. Activity & History Section */
    .activity-history-section {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .history-panel {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .history-tab-bar {
        overflow-x: auto;
        white-space: nowrap;
        padding: 0 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        height: 38px;
    }

    .history-tab-bar::-webkit-scrollbar {
        display: none;
    }

    .htab-btn {
        flex-shrink: 0;
        padding: 0 10px;
        font-size: 12px;
        height: 38px;
    }

    .history-extra-actions {
        display: none;
    }

    .history-content-tab {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .positions-list {
        padding: 8px 6px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* 9. Position Pro Card Mobile Optimization (KEY FIX) */
    .position-card-pro {
        padding: 10px;
        gap: 8px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }

    .pos-pro-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        width: 100%;
    }

    .pos-pro-title {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    .pos-symbol-name {
        font-size: 14px;
        font-weight: 800;
    }

    .pos-qty {
        font-size: 11px;
        color: var(--text-muted);
        background: var(--bg-sub);
        padding: 2px 6px;
        border-radius: 3px;
        margin-left: auto;
    }

    .pos-pro-pnl-wrap {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        flex-wrap: wrap;
        text-align: left;
        background: var(--bg-sub);
        padding: 7px 10px;
        border-radius: var(--radius-sm);
        border: 1px solid var(--border-light);
        width: 100%;
        box-sizing: border-box;
    }

    .pos-pro-pnl {
        font-size: 15px;
        font-weight: 800;
    }

    .pos-pro-pnl-krw {
        font-size: 12px;
        font-weight: 700;
    }

    .trade-fee-sub {
        width: 100%;
        text-align: right;
        margin-top: 2px;
        font-size: 10px;
    }

    .pos-reason-banner {
        flex-wrap: wrap;
        gap: 4px;
        padding: 6px 8px;
        font-size: 11px;
        line-height: 1.4;
    }

    .pos-reason-pill {
        font-size: 10px;
    }

    .pos-reason-text {
        word-break: break-word;
    }

    .pos-gauge-section {
        gap: 3px;
    }

    .pos-gauge-labels {
        font-size: 9px;
    }

    .pos-gauge-labels .gauge-sub-krw {
        display: none;
    }

    /* 2-Column Clean Grid on Mobile */
    .pos-pro-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        padding: 8px;
        width: 100%;
        box-sizing: border-box;
    }

    .pos-grid-item {
        background: var(--bg-card);
        padding: 6px 8px;
        border-radius: 3px;
        border: 1px solid var(--border-light);
        min-width: 0;
        overflow: hidden;
    }

    .pos-grid-item:last-child:nth-child(odd) {
        grid-column: span 2;
    }

    .pos-grid-lbl {
        font-size: 10px;
    }

    .pos-grid-val {
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .grid-sub-krw {
        font-size: 10px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Full-width Touch-friendly Close Button */
    .pos-card-close-btn {
        align-self: stretch;
        width: 100%;
        padding: 9px 12px;
        font-size: 12px;
        font-weight: 700;
        text-align: center;
        justify-content: center;
        margin-top: 4px;
        border-radius: 4px;
    }

    /* Empty state */
    .upbit-pos-empty {
        padding: 24px 14px;
    }

    .empty-actions {
        flex-direction: column;
        width: 100%;
        gap: 6px;
    }

    .btn-sub-action {
        width: 100%;
    }

    /* 10. Table Responsiveness */
    .table-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .upbit-table {
        min-width: 520px;
    }

    /* 11. Market Sidebar Column */
    .market-sidebar-col {
        width: 100%;
        max-width: 100%;
        margin-top: 6px;
    }

    .market-tab-bar {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .market-tab-bar::-webkit-scrollbar {
        display: none;
    }

    .mtab-btn {
        flex-shrink: 0;
        padding: 0 10px;
        font-size: 12px;
    }

    .market-coin-list {
        max-height: 350px;
    }

    /* 12. Mobile Bottom Fixed Action Bar */
    .mobile-action-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 52px;
        background: #ffffff;
        border-top: 1px solid var(--border-card);
        display: grid;
        grid-template-columns: 1.2fr 1fr 1fr;
        gap: 6px;
        padding: 6px 8px;
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
    }

    .m-action-btn {
        border: none;
        border-radius: 4px;
        font-size: 12px;
        font-weight: 700;
        color: #ffffff;
        cursor: pointer;
        padding: 0 4px;
    }

    .m-btn-primary { background: var(--upbit-navy); }
    .m-btn-success { background: var(--color-up); }
    .m-btn-danger { background: #dc3545; }

    /* 13. Settings Modal on Mobile */
    .modal-container.upbit-dialog {
        width: 95% !important;
        max-width: 95% !important;
        max-height: 90vh !important;
        margin: 5vh auto;
    }

    .modal-body {
        max-height: calc(90vh - 120px) !important;
        overflow-y: auto;
        padding: 12px !important;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    /* 14. Footer */
    .bot-minimal-footer {
        margin-top: 12px;
        margin-bottom: 56px;
        height: auto;
        padding: 8px 10px;
    }

    .bot-footer-inner {
        flex-wrap: wrap;
        gap: 4px;
        font-size: 10px;
        text-align: center;
        justify-content: center;
    }
}

/* ==========================================================================
   MOBILE DARK MODE OVERRIDES
   ========================================================================== */
@media (max-width: 768px) {
    body.upbit-dark .mobile-nav-tabs {
        background: #131722;
        border-bottom-color: #2a2e39;
    }

    body.upbit-dark .mobile-nav-tabs .tab-btn {
        color: #848e9c;
    }

    body.upbit-dark .mobile-nav-tabs .tab-btn.active {
        color: #38bdf8;
    }

    body.upbit-dark .mobile-nav-tabs .tab-btn.active::after {
        background: #38bdf8;
    }

    body.upbit-dark .pos-pro-pnl-wrap {
        background: #1a202c;
        border-color: #2d3748;
    }

    body.upbit-dark .pos-grid-item {
        background: #181d27;
        border-color: #262f3f;
    }

    body.upbit-dark .pos-qty {
        background: #1e2433;
        color: #9aa7b9;
    }

    body.upbit-dark .pos-card-close-btn {
        background: rgba(235, 77, 75, 0.15);
        color: #ff6b6b;
        border-color: rgba(235, 77, 75, 0.35);
    }

    body.upbit-dark .pos-card-close-btn:hover {
        background: rgba(235, 77, 75, 0.25);
    }

    body.upbit-dark .mobile-action-bar {
        background: #131722;
        border-top-color: #2a2e39;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.4);
    }
}

/* ==========================================================================
   EXTRA NARROW SMARTPHONES (max-width: 480px)
   ========================================================================== */
@media (max-width: 480px) {
    #badgeMode {
        display: none !important;
    }
    .header-inner {
        padding: 0 6px;
    }
    .logo-text {
        font-size: 15px;
    }
    .upbit-btn-bot,
    #btnToggleBot {
        padding: 2px 5px !important;
        font-size: 10px !important;
    }
}

@media (max-width: 768px) {
    .upbit-pos-empty.compact {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .empty-compact-actions {
        width: 100%;
    }
    .empty-compact-actions .btn-sub-action-sm {
        flex: 1;
        text-align: center;
    }
    .pos-panel-redirect-box {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
}


