/* ==========================================================================
   template_manager.css — 共用模板管理外觀（透明玻璃框 + 賽博金屬）
   .tm-* classes 全視口可用，不綁 body.nbm / media query。
   置中框（單張、批次桌面）自帶 .tm-backdrop/.tm-panel 外殼；
   批次手機 sheet 內只用 .tm-row/.tm-list/.tm-edit/.tm-footer 等內容類。
   金屬邊框：透明 border + 雙層背景 padding-box/border-box（保留圓角）。
   ========================================================================== */

:root {
    --tm-ink: #0b1220;
    --tm-head-fill: linear-gradient(180deg, rgba(25, 34, 52, .97), rgba(12, 18, 30, .97));
    --tm-panel-fill: linear-gradient(180deg, rgba(249, 252, 255, .98), rgba(234, 244, 255, .96));
    --tm-scan: repeating-linear-gradient(0deg, rgba(103, 232, 249, .05) 0 1px, transparent 1px 3px);
    --tm-steel-edge: linear-gradient(165deg, rgba(236, 244, 252, .95), rgba(148, 166, 190, .55) 28%, rgba(84, 100, 124, .65) 52%, rgba(214, 226, 240, .90) 74%, rgba(120, 140, 165, .60));
    --tm-gold-edge: linear-gradient(135deg, #f6d38a, #e8a13a 55%, #b97718);
    --tm-neon: #22d3ee;
    --tm-neon-hi: #67e8f9;
    --tm-gold-ink: #241703;
    --tm-text-hi: #eaf3fd;
    --tm-glow-neon: inset 0 0 0 1px rgba(34, 211, 238, .35), 0 0 14px rgba(34, 211, 238, .18);
    --tm-glow-gold: 0 6px 16px rgba(232, 161, 58, .38);
    --tm-bevel-hi: inset 0 1px 0 rgba(255, 255, 255, .14);
    --tm-ease: cubic-bezier(.32, .72, 0, 1);
    --tm-mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---- 置中框外殼 ---- */
.tm-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: radial-gradient(120% 90% at 50% 100%, rgba(34, 211, 238, .10), transparent 55%), rgba(8, 13, 24, .55);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .22s ease, visibility 0s .22s;
}
.tm-backdrop.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity .22s ease;
}
.tm-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 460px;
    max-height: min(80vh, 640px);
    border: 1.5px solid transparent;
    border-radius: 22px;
    overflow: hidden;
    background: var(--tm-panel-fill) padding-box, var(--tm-steel-edge) border-box;
    box-shadow: 0 24px 70px rgba(8, 14, 26, .45), 0 0 0 1px rgba(34, 211, 238, .12);
    transform: translateY(12px) scale(.98);
    transition: transform .24s var(--tm-ease);
}
.tm-backdrop.is-open .tm-panel { transform: none; }

/* ---- 頭部：槍鐵金屬帶 ---- */
.tm-head {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 54px;
    padding: 12px 10px 10px 18px;
    background: var(--tm-scan), var(--tm-head-fill);
    border-bottom: 1px solid rgba(148, 166, 190, .28);
    box-shadow: var(--tm-bevel-hi);
    color: var(--tm-text-hi);
}
.tm-head::after {
    content: "";
    position: absolute;
    left: 18px;
    right: 18px;
    bottom: -1px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(246, 211, 138, .9) 30%, rgba(34, 211, 238, .8) 70%, transparent);
}
.tm-heading {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.tm-kicker {
    font: 600 10px/1 var(--tm-mono);
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--tm-neon-hi);
    opacity: .85;
}
.tm-title {
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tm-close {
    width: 40px;
    height: 40px;
    margin-left: auto;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border: 1px solid rgba(148, 166, 190, .35);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, .10), rgba(255, 255, 255, .02));
    color: var(--tm-text-hi);
    cursor: pointer;
    transition: transform .15s ease;
}
.tm-close svg { width: 18px; height: 18px; }
.tm-close:active { transform: scale(.9); }

/* ---- 主體與搜尋 ---- */
.tm-body {
    flex: 1 1 auto;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 14px 14px 0;
}
.tm-search,
.tm-input {
    width: 100%;
    padding: 9px 14px;
    border-radius: 12px;
    border: 1px solid rgba(148, 166, 190, .4);
    background: rgba(255, 255, 255, .9);
    color: #1e293b;
    font-size: 14px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.tm-search:focus,
.tm-input:focus {
    border-color: var(--tm-neon);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, .18);
}
.tm-textarea { resize: none; line-height: 1.5; }
.tm-search { margin-bottom: 10px; }

.tm-list {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 12px;
}

/* ---- 模板列 ---- */
.tm-row {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(255, 255, 255, .96), rgba(244, 250, 255, .92)) padding-box, var(--tm-steel-edge) border-box;
    padding: 6px 8px 6px 4px;
}
.tm-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    min-height: 44px;
    border: 0;
    background: transparent;
    text-align: left;
    border-radius: 10px;
    cursor: pointer;
}
.tm-main:hover { background: rgba(34, 211, 238, .06); }
.tm-main:active { background: rgba(34, 211, 238, .10); }
.tm-dot {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: currentColor;
    box-shadow: 0 0 8px currentColor;
}
.tm-text { flex: 1 1 auto; min-width: 0; }
.tm-name {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tm-preview {
    display: block;
    font-size: 11px;
    color: #64748b;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tm-icon-btn {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(148, 166, 190, .4);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(255, 255, 255, .9), rgba(240, 247, 255, .8));
    color: #33465e;
    cursor: pointer;
    transition: transform .12s ease;
}
.tm-icon-btn svg { width: 15px; height: 15px; }
.tm-icon-btn:active { transform: scale(.9); }
.tm-icon-btn.is-danger { color: #b91c1c; }

.tm-empty {
    padding: 26px 12px;
    text-align: center;
    font-size: 12px;
    color: #64748b;
}

/* ---- 存新範本列（footer） ---- */
.tm-footer {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 12px 14px;
    border-top: 1px solid rgba(148, 166, 190, .25);
}
.tm-footer-name { flex: 1 1 auto; min-width: 0; }

/* ---- 行內編輯 ---- */
.tm-edit {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 2px 8px;
}
.tm-edit-label {
    font-size: 12px;
    font-weight: 700;
    color: #33465e;
}
.tm-edit-row { display: flex; gap: 8px; align-items: center; }
.tm-edit-row .tm-input { flex: 1 1 auto; }
.tm-edit-check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: #33465e; }
.tm-edit-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ---- 按鈕 ---- */
.tm-btn {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid rgba(148, 166, 190, .4);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, .92), rgba(240, 247, 255, .85));
    color: #33465e;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .12s ease;
}
.tm-btn:active { transform: scale(.96); }
.tm-btn--gold {
    border: 0;
    background: var(--tm-gold-edge);
    color: var(--tm-gold-ink);
    box-shadow: var(--tm-glow-gold), inset 0 1px 0 rgba(255, 255, 255, .5);
}

/* 編輯時收起搜尋 / footer */
.tm-collapsed { display: none !important; }

/* ---- 開啟置中框的入口按鈕（批次桌面用；手機以 nbm-hide 隱藏） ---- */
.tm-open-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 46px;
    padding: 11px 14px;
    border: 1px solid transparent;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(255, 255, 255, .94), rgba(236, 246, 255, .88)) padding-box, var(--tm-steel-edge) border-box;
    box-shadow: 0 4px 14px rgba(56, 116, 186, .10), inset 0 1px 0 rgba(255, 255, 255, .8);
    color: #1e293b;
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}
.tm-open-btn:hover { box-shadow: 0 6px 18px rgba(56, 116, 186, .16), inset 0 1px 0 rgba(255, 255, 255, .8); }
.tm-open-btn:active { transform: scale(.99); }
.tm-open-icon {
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(34, 211, 238, .16), rgba(34, 211, 238, .05));
    box-shadow: var(--tm-glow-neon);
    color: #0891b2;
}
.tm-open-icon svg { width: 16px; height: 16px; }
.tm-open-label { flex: 1 1 auto; min-width: 0; }
.tm-open-chevron {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--tm-gold-edge);
    box-shadow: var(--tm-glow-gold), inset 0 1px 0 rgba(255, 255, 255, .55);
    color: var(--tm-gold-ink);
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

/* ---- 無障礙 ---- */
.tm-search:focus-visible,
.tm-main:focus-visible,
.tm-icon-btn:focus-visible,
.tm-btn:focus-visible,
.tm-close:focus-visible {
    outline: 2px solid var(--tm-neon);
    outline-offset: 2px;
}

/* ≤768px：置中框放寬到近滿寬（單張頁手機） */
@media (max-width: 768px) {
    .tm-panel {
        max-width: none;
        max-height: min(86vh, 720px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .tm-backdrop,
    .tm-panel,
    .tm-close,
    .tm-btn,
    .tm-icon-btn {
        transition: none !important;
    }
    .tm-close:active,
    .tm-btn:active,
    .tm-icon-btn:active { transform: none; }
}
