/* v6.x.4c.2 充電紀錄 (ChargeLog) — 旅程分析版
   承接 v6.x.4b ChargeDetail 的 paper/hairline 系統,主色調沿用 #1f9d3e
   Signature: 時間區段 segmented filter + 充電旅程 sparkline + 動態 count-up KPI
   - 不靠 card-in-card box-shadow,只用髮絲線分段
   - 一個大數字 anchor + 細 eyebrow labels
   - 卡片 hover/active 狀態;sparkline 描繪動畫
   - reduce-motion 自動停用進場動畫 */

:root {
    --paper:        #fbfcf9;
    --paper-card:   #ffffff;
    --paper-shade:  #f4f6f1;
    --ink:          #1a2a1c;
    --ink-mid:      #3a4a3c;
    --ink-soft:     #7a8a7c;
    --ink-faint:    #aab5ac;
    --line:         #d8e2dc;
    --line-soft:    #e9eee9;
    --brand:        #1f9d3e;
    --brand-deep:   #157a2e;
    --brand-tint:   #e9f6ed;
    --brand-mist:   #f1faf3;
    --eco:          #b8821c;
    --eco-tint:     #faf1de;
    --info:         #3b7ddd;
    --info-tint:    #e8f0fc;
    --warn:         #d04545;
    --warn-tint:    #fdecec;

    --type-display: -apple-system, BlinkMacSystemFont, "Helvetica Neue",
                    "PingFang TC", "Microsoft JhengHei", sans-serif;
    --type-mono:    ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono",
                    "Courier New", monospace;

    --radius-sm:    4px;
    --radius-md:    8px;
    --radius-lg:    14px;
    --tnum:         "tnum" 1, "lnum" 1;
    --ease-out:     cubic-bezier(0.22, 0.61, 0.36, 1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--type-display);
    font-feature-settings: var(--tnum);
    background: var(--paper);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    font-size: 14px;
    line-height: 1.5;
}

.mono {
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
    letter-spacing: -0.01em;
}

.eyebrow {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.container {
    max-width: 480px;
    margin: 0 auto;
    background: var(--paper-card);
    min-height: 100vh;
    padding-bottom: 80px;
    overflow-x: hidden;
}

/* ==========================================================
   0. Loading veil — list not rendered yet
   ========================================================== */

.log_loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 22px;
    color: var(--ink-soft);
    font-size: 12px;
}

.log_loading .spinner {
    width: 22px;
    height: 22px;
    border: 2px solid var(--brand-tint);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: log-spin 0.85s linear infinite;
}

@keyframes log-spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================
   1. Summary — hero + 4 mini 統一成一個 panel (減少中段切換感)
   ========================================================== */

.summary {
    padding: 18px 22px 14px;
}

.summary_head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 6px;
}

.summary_head .eyebrow {
    display: block;
}

.summary_head .summary_tip {
    font-size: 11px;
    color: var(--ink-faint);
    letter-spacing: 0.04em;
    text-align: right;
    line-height: 1.3;
    max-width: 50%;
}

/* 大數字 anchor */
.summary_hero {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 2px 0 4px;
}

.summary_hero .unit_lead {
    font-size: 0.5em;
    font-weight: 600;
    color: var(--ink-soft);
    transform: translateY(-0.45em);
}

.summary_hero .hero_num {
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
    font-size: clamp(40px, 11.5vw, 54px);
    font-weight: 800;
    color: var(--brand);
    line-height: 1;
    letter-spacing: -0.04em;
    font-variant-numeric: tabular-nums;
    opacity: 1;
}

.summary_hero .unit_tail {
    font-size: 0.4em;
    font-weight: 600;
    color: var(--ink-soft);
    margin-left: 4px;
    transform: translateY(-0.45em);
}

.summary_sub {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 13px;
    color: var(--ink-mid);
}

.summary_sub .sub_dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--brand);
    flex-shrink: 0;
}

.summary_sub .sub_pay {
    color: var(--ink-soft);
}

/* 4 mini KPI — 跟 hero 同一個 panel,用 dashed 線接起來 */
.summary_mini {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-top: 1px dashed var(--line);
    padding: 12px 0 4px;
    margin-top: 14px;
    gap: 4px;
}

.summary_mini .mini {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 0 6px;
    border-right: 1px solid var(--line-soft);
}

.summary_mini .mini:last-child {
    border-right: 0;
}

.summary_mini .mini_ico {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-tint);
    color: var(--brand);
    flex-shrink: 0;
}

.summary_mini .mini_ico svg {
    width: 12px;
    height: 12px;
}

.summary_mini .mini_ico.eco {
    background: var(--eco-tint);
    color: var(--eco);
}

.summary_mini .mini_eyebrow {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-soft);
    text-align: center;
    line-height: 1.2;
}

.summary_mini .mini_value {
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    text-align: center;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.summary_mini .mini_value .mini_unit {
    font-size: 10px;
    font-weight: 500;
    color: var(--ink-soft);
    margin-left: 1px;
}

/* ==========================================================
   2. 區段切換 segmented filter (獨立於 summary,journey 下方)
   ========================================================== */

.summary_filter {
    display: flex;
    gap: 0;
    margin: 0 22px 18px;
    padding: 3px;
    background: var(--paper-shade);
    border-radius: 999px;
    border: 1px solid var(--line-soft);
    position: relative;
}

.summary_filter button {
    flex: 1;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 0;
    padding: 8px 10px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
    border-radius: 999px;
    cursor: pointer;
    transition: color 0.18s var(--ease-out);
    letter-spacing: 0.02em;
    position: relative;
    z-index: 1;
}

.summary_filter button:hover:not(.active) {
    color: var(--ink-mid);
}

.summary_filter button:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.summary_filter button.active {
    color: var(--paper-card);
}

.summary_filter .seg_indicator {
    position: absolute;
    top: 3px;
    bottom: 3px;
    border-radius: 999px;
    background: var(--brand);
    box-shadow: 0 1px 4px rgba(31, 157, 62, 0.22);
    transition: left 0.28s var(--ease-out), width 0.28s var(--ease-out);
    z-index: 0;
    pointer-events: none;
}

/* ==========================================================
   3. 充電旅程 sparkline strip
   ========================================================== */

.journey {
    padding: 18px 22px 4px;
    border-bottom: 1px solid var(--line);
}

.journey_head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 12px;
}

.journey_head .eyebrow {
    letter-spacing: 0.14em;
}

.journey_legend {
    font-size: 11px;
    color: var(--ink-soft);
    display: flex;
    align-items: center;
    gap: 6px;
}

.journey_legend .legend_dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--brand);
    box-shadow: 0 0 0 3px rgba(31, 157, 62, 0.12);
}

.journey_chart {
    width: 100%;
    height: 84px;
    display: block;
    overflow: visible;
}

.journey_chart .axis {
    stroke: var(--line);
    stroke-width: 1;
    stroke-dasharray: 2 3;
}

.journey_chart .area {
    fill: url(#journey-grad);
    opacity: 0;
    transition: opacity 0.5s var(--ease-out) 0.4s;
}

.journey_chart .line {
    fill: none;
    stroke: var(--brand);
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    /* 進場動畫 — dasharray 由 JS 設為 path 長度 */
}

.journey_chart .dot {
    fill: var(--paper-card);
    stroke: var(--brand);
    stroke-width: 1.8;
    opacity: 0;
    transition: opacity 0.3s var(--ease-out);
}

.journey_chart .dot.peak {
    fill: var(--brand);
}

.journey.is_in .journey_chart .area {
    opacity: 1;
}

.journey.is_in .journey_chart .dot {
    opacity: 1;
}

.journey_meta {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 11px;
    color: var(--ink-faint);
    letter-spacing: 0.04em;
}

/* ==========================================================
   4. 充電紀錄 list — monthly grouped cards
   ========================================================== */

.records {
    padding: 24px 22px 0;
}

.records_head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 14px;
}

.records_head .eyebrow {
    letter-spacing: 0.14em;
}

.records_count {
    font-size: 11px;
    color: var(--ink-soft);
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
}

/* 月份群組 */
.month_group {
    margin-bottom: 22px;
}

.month_label {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 0 0 10px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 2px;
}

.month_label .m_y {
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: 0.04em;
}

.month_label .m_name {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.month_label .m_total {
    margin-left: auto;
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
    font-size: 12px;
    color: var(--ink-soft);
}

.month_label .m_total strong {
    color: var(--brand);
    font-weight: 700;
}

/* 卡片列 */
.log_card {
    display: grid;
    grid-template-columns: 56px 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 14px 4px;
    border-bottom: 1px solid var(--line-soft);
    cursor: pointer;
    transition: background-color 0.15s var(--ease-out),
                transform 0.18s var(--ease-out),
                padding-left 0.18s var(--ease-out);
    border-radius: var(--radius-sm);
    -webkit-user-select: none;
    user-select: none;
    opacity: 0;
    transform: translateY(8px);
}

.log_card.is_in {
    opacity: 1;
    transform: translateY(0);
    transition: background-color 0.15s var(--ease-out),
                transform 0.18s var(--ease-out),
                padding-left 0.18s var(--ease-out),
                opacity 0.4s var(--ease-out);
}

.log_card:hover {
    background: var(--brand-mist);
    padding-left: 8px;
}

.log_card:active {
    background: var(--brand-tint);
    transform: scale(0.985);
    transition-duration: 0.06s;
}

.log_card:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: -2px;
}

/* 日期塊 */
.log_date {
    text-align: center;
    line-height: 1.05;
    padding: 6px 4px;
    border-radius: var(--radius-md);
    background: var(--paper-shade);
    transition: background-color 0.15s var(--ease-out);
}

.log_card:hover .log_date {
    background: var(--brand-tint);
}

.log_date .d_day {
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
    font-size: 18px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1;
}

.log_date .d_mon {
    font-size: 9.5px;
    font-weight: 700;
    color: var(--ink-soft);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    margin-top: 4px;
}

.log_date .d_dow {
    font-size: 9px;
    color: var(--ink-faint);
    margin-top: 2px;
    letter-spacing: 0.06em;
}

/* 中段:時間 + 期間 */
.log_meta {
    min-width: 0;
}

.log_time {
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
    font-size: 12.5px;
    color: var(--ink-mid);
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.log_time .time_dot {
    color: var(--ink-faint);
    margin: 0 5px;
}

.log_dur {
    font-size: 11px;
    color: var(--ink-soft);
    margin-top: 3px;
    letter-spacing: 0.02em;
}

.log_dur .dur_pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    background: var(--paper-shade);
    border-radius: 999px;
    color: var(--ink-mid);
    font-weight: 500;
    font-size: 10.5px;
}

.log_dur .dur_pill svg {
    width: 9px;
    height: 9px;
}

/* 右側:度數 + 費用 */
.log_amt {
    text-align: right;
    line-height: 1.1;
    min-width: 80px;
}

.log_amt .amt_kwh {
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
    font-size: 16px;
    font-weight: 700;
    color: var(--brand);
    letter-spacing: -0.02em;
}

.log_amt .amt_kwh .amt_unit {
    font-size: 10px;
    font-weight: 500;
    color: var(--ink-soft);
    margin-left: 2px;
}

.log_amt .amt_pay {
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
    font-size: 11px;
    color: var(--ink-soft);
    margin-top: 3px;
}

.log_amt .amt_arrow {
    display: inline-block;
    margin-left: 4px;
    color: var(--ink-faint);
    transition: transform 0.18s var(--ease-out), color 0.18s var(--ease-out);
}

.log_card:hover .amt_arrow {
    transform: translateX(2px);
    color: var(--brand);
}

/* 空狀態 */
.log_empty {
    text-align: center;
    padding: 50px 22px 40px;
    color: var(--ink-soft);
}

.log_empty .empty_icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: var(--paper-shade);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-faint);
}

.log_empty .empty_icon svg {
    width: 28px;
    height: 28px;
}

.log_empty .empty_title {
    font-size: 15px;
    font-weight: 700;
    color: var(--ink-mid);
    margin-bottom: 4px;
}

.log_empty .empty_sub {
    font-size: 12px;
    color: var(--ink-soft);
    letter-spacing: 0.02em;
    line-height: 1.55;
}

.log_empty .empty_hint {
    margin-top: 10px;
    font-size: 11px;
    color: var(--ink-faint);
    font-family: var(--type-mono);
    font-feature-settings: var(--tnum);
    letter-spacing: 0.04em;
}

.log_empty .empty_switch {
    appearance: none;
    -webkit-appearance: none;
    background: var(--brand-tint);
    color: var(--brand-deep);
    border: 1px solid var(--brand);
    border-radius: 999px;
    padding: 7px 18px;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    margin-top: 16px;
    cursor: pointer;
    transition: background-color 0.15s var(--ease-out);
}

.log_empty .empty_switch:hover {
    background: var(--brand-mist);
}

.log_empty .empty_switch:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* ==========================================================
   5. 底部小記
   ========================================================== */

.log_footer {
    margin: 30px 22px 10px;
    padding-top: 16px;
    border-top: 1px dashed var(--line);
    font-size: 11px;
    color: var(--ink-faint);
    text-align: center;
    letter-spacing: 0.04em;
}

.log_footer .footer_id {
    font-family: var(--type-mono);
    color: var(--ink-soft);
}

/* ==========================================================
   6. Reduce-motion respect
   ========================================================== */

@media (prefers-reduced-motion: reduce) {
    .summary_hero .hero_num,
    .summary_filter .seg_indicator,
    .log_card,
    .log_card.is_in,
    .journey_chart .area,
    .journey_chart .dot {
        animation: none !important;
        transition: none !important;
    }

    .log_card {
        opacity: 1;
        transform: none;
    }

    .journey_chart .area,
    .journey_chart .dot {
        opacity: 1;
    }

    .summary_hero .hero_num {
        /* count-up 直接顯示最終值,不需 tween */
    }
}

/* ==========================================================
   6. 小螢幕 (< 360px) 安全降級
   ========================================================== */

@media (max-width: 360px) {
    .summary_mini {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px 8px;
    }

    .summary_mini .mini {
        border-right: 0;
    }

    .log_card {
        grid-template-columns: 48px 1fr auto;
        gap: 10px;
    }

    .log_amt {
        min-width: 64px;
    }

    .log_amt .amt_kwh {
        font-size: 14px;
    }
}