/*=============================================================
  dashboard.css - 경영 대시보드 반응형 스타일
  모바일 우선 (Mobile First) 설계
=============================================================*/

/* 기본 리셋 & 폰트 */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 
                 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f7;
    color: #1d1d1f;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* 전체 컨테이너 */
.dash-wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
}

/* 헤더 */
.dash-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.dash-title {
    font-size: 20px;
    font-weight: 600;
    color: #1d1d1f;
}
.dash-subtitle {
    font-size: 12px;
    color: #86868b;
    margin-top: 2px;
}

/* 기간 필터 버튼 그룹 */
.period-btns {
    display: flex;
    gap: 4px;
    background: #e8e8ed;
    border-radius: 8px;
    padding: 3px;
}
.period-btns button {
    border: none;
    background: transparent;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    color: #636366;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}
.period-btns button.active {
    background: #fff;
    color: #1d1d1f;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.period-btns button:hover:not(.active) {
    color: #1d1d1f;
}

/* 채널 필터 */
.channel-btns {
    display: flex;
    gap: 4px;
    background: #e8e8ed;
    border-radius: 8px;
    padding: 3px;
}
.channel-btns button {
    border: none;
    background: transparent;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    color: #636366;
    cursor: pointer;
    transition: all 0.2s;
}
.channel-btns button.active {
    background: #fff;
    color: #1d1d1f;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* KPI 카드 그리드 */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.kpi-card {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: transform 0.15s;
}
.kpi-card:hover {
    transform: translateY(-1px);
}
.kpi-label {
    font-size: 12px;
    color: #86868b;
    font-weight: 500;
}
.kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: #1d1d1f;
    margin-top: 6px;
    letter-spacing: -0.5px;
}
.kpi-change {
    font-size: 12px;
    margin-top: 4px;
    font-weight: 500;
}
.kpi-change.up { color: #34c759; }
.kpi-change.down { color: #ff3b30; }
.kpi-change .arrow { font-size: 10px; margin-right: 2px; }

/* 차트 카드 */
.chart-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    margin-bottom: 16px;
}
.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.chart-title {
    font-size: 15px;
    font-weight: 600;
    color: #1d1d1f;
}
.chart-legend {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: #86868b;
}
.chart-legend span {
    display: flex;
    align-items: center;
    gap: 5px;
}
.chart-legend .dot {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    display: inline-block;
}

/* 차트 영역 */
.chart-area {
    position: relative;
    width: 100%;
}
.chart-area.trend { height: 240px; }
.chart-area.bar { height: 220px; }
.chart-area.doughnut { height: 180px; }

/* 두 컬럼 그리드 (채널비교 + 주문상태) */
.chart-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

/* 도넛 차트 + 범례 레이아웃 */
.doughnut-wrap {
    display: flex;
    align-items: center;
    gap: 20px;
}
.doughnut-chart {
    width: 160px;
    height: 160px;
    flex-shrink: 0;
    position: relative;
}
.doughnut-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
}
.doughnut-legend span {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #3a3a3c;
}
.doughnut-legend .dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* 제품 순위 테이블 */
.rank-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.rank-table thead th {
    text-align: left;
    padding: 10px 8px;
    color: #86868b;
    font-weight: 500;
    border-bottom: 1px solid #e5e5ea;
    font-size: 12px;
}
.rank-table thead th.right { text-align: right; }
.rank-table tbody td {
    padding: 12px 8px;
    color: #1d1d1f;
    border-bottom: 1px solid #f2f2f7;
}
.rank-table tbody td.right { text-align: right; }
.rank-table tbody td.up { color: #34c759; font-weight: 500; }
.rank-table tbody td.down { color: #ff3b30; font-weight: 500; }
.rank-table tbody tr:last-child td { border-bottom: none; }
.rank-table tbody tr:hover { background: #f9f9fb; }

/* 로딩 스피너 */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #86868b;
    font-size: 13px;
}
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e5ea;
    border-top-color: #007aff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 에러 상태 */
.error-msg {
    text-align: center;
    padding: 30px;
    color: #ff3b30;
    font-size: 13px;
}

/* 마지막 갱신 시간 */
.last-update {
    text-align: center;
    font-size: 11px;
    color: #aeaeb2;
    padding: 16px 0;
}

/*=============================================================
  반응형 - 태블릿 (768px 이하)
=============================================================*/
@media screen and (max-width: 768px) {
    .dash-wrap { padding: 12px; }
    
    .kpi-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    .kpi-card { padding: 14px; }
    .kpi-value { font-size: 20px; }
    
    .chart-row {
        grid-template-columns: 1fr;
    }
    
    .chart-area.trend { height: 200px; }
    .chart-area.bar { height: 200px; }
}

/*=============================================================
  반응형 - 모바일 (480px 이하)
=============================================================*/
@media screen and (max-width: 480px) {
    .dash-wrap { padding: 8px; }
    
    .dash-header { margin-bottom: 14px; }
    .dash-title { font-size: 18px; }
    
    .period-btns button { padding: 5px 10px; font-size: 12px; }
    
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        margin-bottom: 14px;
    }
    .kpi-card { padding: 12px; }
    .kpi-label { font-size: 11px; }
    .kpi-value { font-size: 18px; margin-top: 4px; }
    .kpi-change { font-size: 11px; }
    
    .chart-card { padding: 14px; margin-bottom: 10px; border-radius: 10px; }
    .chart-title { font-size: 14px; }
    .chart-legend { gap: 10px; font-size: 11px; }
    
    .chart-area.trend { height: 180px; }
    .chart-area.bar { height: 180px; }
    
    .doughnut-wrap { 
        flex-direction: column; 
        gap: 12px; 
    }
    .doughnut-chart { width: 140px; height: 140px; }
    .doughnut-legend { 
        flex-direction: row; 
        flex-wrap: wrap; 
        gap: 6px; 
        justify-content: center;
    }
    .doughnut-legend span { font-size: 11px; }
    
    .rank-table { font-size: 12px; }
    .rank-table thead th { padding: 8px 4px; font-size: 11px; }
    .rank-table tbody td { padding: 10px 4px; }
    
    /* 테이블 스크롤 */
    .table-scroll { 
        overflow-x: auto; 
        -webkit-overflow-scrolling: touch; 
    }
}

/* 다크모드 (향후 지원 시) */
/*
@media (prefers-color-scheme: dark) {
    body { background: #1c1c1e; color: #f5f5f7; }
    .chart-card, .kpi-card { background: #2c2c2e; }
    ...
}
*/
