/* ── 歷史變更紀錄頁（兩欄式 app 版面）────────────────────
   沿用 tokens.css 的 TIDC 配色與 layout.css 的 .topbar / .commandbar /
   .panel / .panel-head / .map-shell，本檔只補本頁專屬元件。 */

/* ── Command bar ── */
.hist-commandbar { gap: 16px; align-items: center; }
.hist-commandbar .date-pick { align-items: center; }
/* 統一控件高度，避免統計卡文字被截斷 */
.hist-commandbar .date-pick-field select { height: 44px; }
.hist-commandbar .date-pick-calendar { height: 44px; }
.hist-commandbar .hbtn.ghost { height: 44px; }

.date-pick {
    display: flex;
    align-items: center;
    gap: 10px;
}
.date-pick > label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-700);
    white-space: nowrap;
}
.date-pick > label svg { width: 15px; height: 15px; color: var(--accent); }
.date-pick-field {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.date-pick-field select {
    appearance: none;
    -webkit-appearance: none;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-900);
    background: var(--white);
    border: 1px solid var(--ink-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 8px 34px 8px 13px;
    min-width: 300px;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.date-pick-field select:hover { border-color: var(--ink-300); }
.date-pick-field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,91,172,.16);
}
.date-pick-field select:disabled { color: var(--ink-400); cursor: not-allowed; }
.date-pick-calendar {
    font-family: inherit;
    font-size: 13px;
    color: var(--ink-900);
    background: var(--white);
    border: 1px solid var(--ink-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 8px 10px;
}
.date-pick-calendar:hover { border-color: var(--ink-300); }
.date-pick-calendar:disabled { color: var(--ink-400); cursor: not-allowed; }
.date-pick-calendar:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,91,172,.16);
}
.date-pick-field .chev {
    position: absolute;
    right: 11px;
    width: 14px;
    height: 14px;
    color: var(--ink-400);
    pointer-events: none;
}

/* 摘要統計（連體卡，呼應主頁 .quick-stats） */
.hist-stats {
    display: flex;
    align-items: stretch;
    height: 44px;
    border: 1px solid var(--ink-200);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--white);
    box-shadow: var(--shadow-sm);
}
.hist-stats .stat {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 0 16px;
    border-right: 1px solid var(--ink-100);
}
.hist-stats .stat:last-child { border-right: 0; }
.hist-stats .stat .k {
    font-size: 10.5px;
    color: var(--ink-500);
    letter-spacing: .02em;
    white-space: nowrap;
    line-height: 1;
}
.hist-stats .stat .v {
    font-family: "JetBrains Mono", monospace;
    font-size: 17px;
    font-weight: 600;
    color: var(--ink-900);
    line-height: 1.05;
}
.hist-stats .stat.gold .v { color: #B8820A; }

/* head 通用按鈕（清空紀錄 / 顯示地圖等） */
.hbtn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--ink-200);
    background: var(--white);
    color: var(--ink-700);
    border-radius: var(--radius);
    padding: 8px 13px;
    font-size: 12.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s ease;
    white-space: nowrap;
}
.hbtn svg { width: 15px; height: 15px; flex: none; }
.hbtn:hover { border-color: var(--ink-300); background: var(--paper-2); color: var(--ink-900); }

/* ── Main split ──
   主頁 main 用 --left-w；本頁用獨立 --hist-left-w，預設 52% 給清單。 */
.hist-main {
    grid-template-columns: var(--hist-left-w, 54%) 6px 1fr;
}
.hist-main.map-hidden {
    grid-template-columns: 1fr;
}
.hist-main.map-hidden .panel-right,
.hist-main.map-hidden .resizer { display: none; }

/* ── 左欄：清單面板 ── */
.day-headline {
    display: flex;
    align-items: baseline;
    gap: 9px;
}
.day-headline .d-main {
    font-size: 16px;
    font-weight: 600;
    color: var(--ink-900);
    letter-spacing: .01em;
}
.day-headline .d-week {
    font-size: 11.5px;
    color: var(--ink-400);
    background: var(--paper);
    border: 1px solid var(--ink-100);
    border-radius: 5px;
    padding: 1px 7px;
}

.day-stats {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    margin-left: 4px;
}
.ds-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--ink-500);
    background: var(--paper);
    border: 1px solid var(--ink-100);
    border-radius: 100px;
    padding: 2px 9px;
}
.ds-pill b { color: var(--ink-900); font-weight: 700; }
.ds-pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.ds-pill.active .dot { background: var(--gold); }
.ds-pill.active b { color: #B8820A; }
.ds-pill.done .dot { background: var(--ink-300); }

/* panel-head 的地圖開關按鈕（沿用主頁 .head-toggle 樣式；此處補預設） */
.head-toggle {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    border: 1px solid var(--ink-200);
    background: var(--white);
    color: var(--ink-500);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: all .15s ease;
}
.head-toggle:hover { border-color: var(--ink-300); color: var(--ink-800); background: var(--paper-2); }
.head-toggle.is-on {
    background: var(--accent-soft);
    border-color: #B9D3EC;
    color: var(--accent-deep);
}

/* 子工具列：筆數說明 + 批次復原 */
.hist-subbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    border-bottom: 1px solid var(--ink-100);
    background: var(--paper-2);
}
.hist-subbar .grow { flex: 1; }
.sub-meta { font-size: 12px; color: var(--ink-500); }

.hbtn.batch-restore {
    background: linear-gradient(180deg, #1971C7, var(--accent));
    border-color: var(--accent-deep);
    color: #fff;
    box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 1px 2px rgba(0,91,172,.3);
    padding: 7px 12px;
}
.hbtn.batch-restore:hover:not(:disabled) {
    background: linear-gradient(180deg, var(--accent), var(--accent-deep));
    color: #fff;
}
.hbtn.batch-restore .cnt {
    background: rgba(255,255,255,.25);
    border-radius: 100px;
    padding: 0 7px;
    font-family: "JetBrains Mono", monospace;
    min-width: 18px;
    text-align: center;
}
.hbtn.batch-restore:disabled {
    background: var(--ink-100);
    border-color: var(--ink-200);
    color: var(--ink-400);
    cursor: not-allowed;
    box-shadow: none;
}
.hbtn.batch-restore:disabled .cnt { background: rgba(0,0,0,.06); }

/* ── 表格 ── */
.table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    position: relative;
}
.hist-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.hist-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--paper-2);
    color: var(--ink-500);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: .03em;
    text-transform: uppercase;
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--ink-200);
    white-space: nowrap;
}
.hist-table th.num, .hist-table td.num { text-align: left; }
.hist-table tbody td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--ink-100);
    vertical-align: middle;
}
.hist-table tbody tr { cursor: pointer; transition: background .12s ease; }
.hist-table tbody tr:hover { background: var(--accent-soft); }
.hist-table tbody tr.row-focus { background: var(--gold-soft); }
.hist-table tbody tr.is-restored { background: repeating-linear-gradient(135deg, transparent, transparent 9px, rgba(126,140,151,.05) 9px, rgba(126,140,151,.05) 18px); }
.hist-table tbody tr.is-restored:hover { background: var(--paper-2); }

.col-chk { width: 40px; text-align: center !important; }
.col-chk input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.col-chk input:disabled { cursor: not-allowed; opacity: .4; }

.col-ts { width: 92px; }
.ts-time { font-family: "JetBrains Mono", monospace; font-size: 12.5px; color: var(--ink-700); font-weight: 500; }

.spot-cell { display: flex; flex-direction: column; gap: 1px; align-items: flex-start; }
.spot-code { font-weight: 600; color: var(--ink-900); font-family: "JetBrains Mono", monospace; font-size: 12.5px; }
.spot-sec { font-size: 11px; color: var(--ink-400); }

.coord-before .cv, .coord-after .cv {
    font-family: "JetBrains Mono", monospace;
    font-size: 12px;
    white-space: nowrap;
}
.coord-before .cv { color: var(--ink-500); }
.coord-after .cv { color: var(--accent-deep); font-weight: 600; }
.coord-before i, .coord-after i { color: var(--ink-300); font-style: normal; }

.col-dist { width: 84px; }
.dist-tag {
    display: inline-block;
    font-family: "JetBrains Mono", monospace;
    font-size: 11.5px;
    font-weight: 600;
    color: #B8820A;
    background: var(--gold-soft);
    border-radius: 5px;
    padding: 2px 7px;
}
.is-restored .dist-tag { color: var(--ink-500); background: var(--paper); }

.col-act { width: 108px; text-align: right !important; }
.col-act .btn-restore { margin-left: auto; }
.restored-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--mint);
}
.restored-tag svg { width: 14px; height: 14px; }

/* ── 右欄：地圖面板 ── */
.panel-right .map-shell { flex: 1; position: relative; min-height: 0; }
#hist-map { position: absolute; inset: 0; background: var(--paper-2); z-index: 1; }

.map-legend-inline {
    display: flex;
    gap: 13px;
}
.line-mode-seg button svg { width: 14px; height: 14px; }
.line-mode-seg button.active svg { color: #fff; }
.map-legend-inline .mli {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: var(--ink-600, var(--ink-700));
}
.map-legend-inline .sw {
    width: 11px; height: 11px; border-radius: 50%;
    border: 1.5px solid #fff; box-shadow: 0 0 0 1px var(--ink-200);
}

/* 地圖隱藏時，右欄不顯示，但保留一個「顯示地圖」浮鈕（其實右欄已隱藏，
   此鈕用於需要時 — 預設藏在 map-shell 內，map-hidden 不影響它）。 */
.map-reveal {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 600;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: rgba(255,255,255,.94);
    border: 1px solid var(--ink-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 8px 12px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--accent-deep);
    cursor: pointer;
}
.map-reveal svg { width: 15px; height: 15px; }
.map-reveal[hidden] { display: none; }

/* leaflet popup */
.hist-pin { background: none; border: 0; }
/* components.css 把 Leaflet popup 的內距歸零、由內容自己留白（地圖頁的 .pop 是 14px），這裡比照 */
.hist-popup { font-size: 12px; min-width: 180px; padding: 12px 14px; }
.hist-popup .hp-h {
    font-weight: 700; color: var(--ink-900); font-size: 13px;
    margin-bottom: 6px; padding-bottom: 5px; border-bottom: 1px solid var(--ink-100);
}
.hist-popup .hp-h span { font-weight: 500; color: var(--accent); font-size: 11px; margin-left: 4px; }
.hist-popup .hp-r { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.hist-popup .hp-r span { color: var(--ink-500); }
.hist-popup .hp-r b { font-family: "JetBrains Mono", monospace; color: var(--ink-900); font-weight: 600; }

/* ── 空狀態 ── */
.hist-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: var(--ink-400);
}
.hist-empty[hidden] { display: none; }
.hist-empty svg { width: 46px; height: 46px; color: var(--ink-200); margin-bottom: 14px; }
.hist-empty h3 { margin: 0 0 6px; color: var(--ink-700); font-size: 16px; }
.hist-empty p { margin: 0; font-size: 13px; max-width: 320px; }

/* ── 響應式：窄畫面改上下堆疊 ── */
@media (max-width: 1040px) {
    .hist-commandbar { flex-wrap: wrap; }
    .hist-stats .stat { padding: 4px 12px; }
    .hist-main {
        display: flex;
        flex-direction: column;
        padding: 12px;
    }
    .hist-main .resizer { display: none; }
    .panel-left { min-height: 280px; flex: 1 1 auto; margin-bottom: 12px; }
    .panel-right { min-height: 340px; flex: 1 1 auto; }
    .hist-main.map-hidden .panel-right { display: none; }
}
