/* =========================================================
   Curves 自動更新後台 - 主題樣式 (Bootstrap 5.3 自訂)
   品牌色集中在 :root 的 --brand-*，要換正式色碼只改這裡
   ========================================================= */
:root {
    --brand-900: #2E0E41;
    --brand-800: #3F1559;
    --brand-700: #561E7A;
    --brand-600: #6B2C91;   /* 主色 */
    --brand-500: #8441AD;
    --brand-200: #DCC8EA;
    --brand-100: #F1E8F7;
    --brand-50:  #F8F3FB;

    --app-bg: #F6F5F9;
    --app-surface: #FFFFFF;
    --app-border: #E6E3EE;
    --app-text: #1F1A2E;
    --app-muted: #5B5670;
    --app-radius: 12px;
    --app-shadow: 0 1px 2px rgba(31, 26, 46, .04), 0 1px 3px rgba(31, 26, 46, .06);
    --app-sidebar-width: 248px;

    --bs-body-font-family: "Noto Sans TC", system-ui, -apple-system, "Segoe UI", "Microsoft JhengHei", sans-serif;
    --bs-body-font-size: .9375rem;
    --bs-body-line-height: 1.6;
    --bs-body-color: var(--app-text);
    /* 輸入框、卡片、表格沿用 --bs-body-bg，維持白色；頁面底色另外設定在 body */
    --bs-body-bg: #FFFFFF;
    --bs-secondary-color: var(--app-muted);
    --bs-border-color: var(--app-border);
    --bs-primary: var(--brand-600);
    --bs-primary-rgb: 107, 44, 145;
    --bs-link-color: var(--brand-600);
    --bs-link-color-rgb: 107, 44, 145;
    --bs-link-hover-color: var(--brand-800);
    --bs-link-hover-color-rgb: 63, 21, 89;
    --bs-focus-ring-color: rgba(107, 44, 145, .25);
}

body { background-color: var(--app-bg); -webkit-font-smoothing: antialiased; }
@media (max-width: 575.98px) {
    /* 手機上輸入框至少 16px，避免 iOS 自動放大 */
    :root { --bs-body-font-size: 1rem; }
    .form-control, .form-select { font-size: 1rem; }
}

a { text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .82em; word-break: break-all; }
.nowrap { white-space: nowrap; }
.min-w-0 { min-width: 0; }
.text-muted, .form-text { color: var(--app-muted) !important; }

/* ---------- 按鈕、表單 ---------- */
.btn { border-radius: 8px; font-weight: 500; transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s; }
.btn-primary {
    --bs-btn-bg: var(--brand-600); --bs-btn-border-color: var(--brand-600);
    --bs-btn-hover-bg: var(--brand-700); --bs-btn-hover-border-color: var(--brand-700);
    --bs-btn-active-bg: var(--brand-800); --bs-btn-active-border-color: var(--brand-800);
    --bs-btn-disabled-bg: var(--brand-500); --bs-btn-disabled-border-color: var(--brand-500);
    --bs-btn-focus-shadow-rgb: 107, 44, 145;
}
.btn-outline-primary {
    --bs-btn-color: var(--brand-600); --bs-btn-border-color: var(--brand-200);
    --bs-btn-hover-bg: var(--brand-50); --bs-btn-hover-color: var(--brand-700); --bs-btn-hover-border-color: var(--brand-500);
    --bs-btn-active-bg: var(--brand-100); --bs-btn-active-color: var(--brand-800); --bs-btn-active-border-color: var(--brand-500);
    --bs-btn-focus-shadow-rgb: 107, 44, 145;
}
.btn-light { --bs-btn-bg: #fff; --bs-btn-border-color: var(--app-border); --bs-btn-hover-bg: var(--brand-50); --bs-btn-hover-border-color: var(--brand-200); }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; padding: 0; }
.btn-icon.btn-sm { width: 2rem; height: 2rem; }
.btn .bi { line-height: 1; }

.form-control, .form-select { border-radius: 8px; border-color: #D9D5E3; }
.form-control:focus, .form-select:focus, .form-check-input:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 .2rem rgba(107, 44, 145, .18);
}
.form-check-input:checked { background-color: var(--brand-600); border-color: var(--brand-600); }
.form-label { font-weight: 500; margin-bottom: .35rem; }
:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.btn:focus-visible, .form-control:focus-visible, .form-select:focus-visible { outline: none; }

/* ---------- 版型：側欄 + 主內容 ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
    --bs-offcanvas-width: var(--app-sidebar-width);
    --bs-offcanvas-bg: var(--brand-900);
    background: linear-gradient(180deg, var(--brand-800) 0%, var(--brand-900) 100%);
    color: #fff;
}
@media (min-width: 992px) {
    .app-sidebar { position: sticky; top: 0; height: 100vh; width: var(--app-sidebar-width); flex-shrink: 0; display: flex; flex-direction: column; }
}
.app-sidebar .offcanvas-body { display: flex; flex-direction: column; padding: 0; height: 100%; }
.sidebar-brand { display: flex; align-items: center; gap: .75rem; padding: 1.25rem 1.25rem 1rem; }
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem;
    border-radius: 10px; background: rgba(255, 255, 255, .14); font-size: 1.15rem; color: #fff;
}
.brand-title { font-weight: 700; letter-spacing: .02em; line-height: 1.2; }
.brand-sub { font-size: .78rem; color: rgba(255, 255, 255, .72); }
.sidebar-nav { display: flex; flex-direction: column; gap: .15rem; padding: .5rem .75rem; flex: 1; }
.sidebar-section { font-size: .72rem; letter-spacing: .08em; color: rgba(255, 255, 255, .6); padding: 1rem .75rem .35rem; }
.sidebar-link {
    display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border-radius: 8px;
    color: rgba(255, 255, 255, .82); font-weight: 500; transition: background-color .15s, color .15s;
}
.sidebar-link .bi { font-size: 1.05rem; }
.sidebar-link:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.sidebar-link.active { background: rgba(255, 255, 255, .16); color: #fff; box-shadow: inset 3px 0 0 #fff; }
.sidebar-user { border-top: 1px solid rgba(255, 255, 255, .12); padding: 1rem 1.25rem; }
.sidebar-user .user-name { font-weight: 500; line-height: 1.3; }
.sidebar-user .user-account { font-size: .78rem; color: rgba(255, 255, 255, .7); }
.sidebar-user .btn { --bs-btn-color: rgba(255,255,255,.88); --bs-btn-border-color: rgba(255,255,255,.28); --bs-btn-hover-bg: rgba(255,255,255,.12); --bs-btn-hover-color: #fff; --bs-btn-hover-border-color: rgba(255,255,255,.4); }

.avatar {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 2.25rem; height: 2.25rem; border-radius: 50%; font-weight: 600; font-size: .9rem;
    background: var(--brand-100); color: var(--brand-700);
}
.app-sidebar .avatar { background: rgba(255, 255, 255, .18); color: #fff; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
    padding: 1.25rem 1.75rem .5rem;
}
.app-topbar h1 { font-size: 1.4rem; font-weight: 700; margin: 0; line-height: 1.3; }
.page-subtitle { color: var(--app-muted); margin: .15rem 0 0; font-size: .9rem; }
.page-back { display: inline-flex; align-items: center; gap: .25rem; font-size: .85rem; color: var(--app-muted); margin-bottom: .2rem; }
.page-actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.app-content { padding: .75rem 1.75rem 2rem; max-width: 1440px; width: 100%; }
@media (max-width: 575.98px) {
    .app-topbar { padding: 1rem 1rem .25rem; }
    .app-content { padding: .5rem 1rem 6rem; }
}

/* ---------- 卡片 ---------- */
.card { border: 1px solid var(--app-border); border-radius: var(--app-radius); box-shadow: var(--app-shadow); margin-bottom: 1.25rem; }
.card-header { background: transparent; border-bottom: 1px solid var(--app-border); padding: .9rem 1.25rem; font-weight: 600; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.card-header .bi { color: var(--brand-600); }
.card-header .card-hint { font-weight: 400; color: var(--app-muted); font-size: .85rem; }
.card-body { padding: 1.25rem; }
.card > .table-responsive:last-child .table { margin-bottom: 0; }
.step-no {
    display: inline-flex; align-items: center; justify-content: center; width: 1.6rem; height: 1.6rem;
    border-radius: 50%; background: var(--brand-600); color: #fff; font-size: .8rem; font-weight: 700;
}

/* 資訊欄位 (標籤 + 值) */
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem 1.5rem; }
.info-grid .info-label { font-size: .8rem; color: var(--app-muted); margin-bottom: .15rem; }
.info-grid .info-value { font-weight: 500; word-break: break-word; }
.info-grid .info-wide { grid-column: 1 / -1; }

/* ---------- 摘要卡片 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
@media (min-width: 1200px) { .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 575.98px) {
    .stat-grid { gap: .75rem; }
    .stat-card { padding: .85rem; gap: .65rem; }
    .stat-icon { width: 2.25rem; height: 2.25rem; font-size: 1.05rem; }
    .stat-value { font-size: 1.3rem; }
}
.stat-card {
    display: flex; align-items: center; gap: 1rem; padding: 1.1rem 1.25rem; background: var(--app-surface);
    border: 1px solid var(--app-border); border-radius: var(--app-radius); box-shadow: var(--app-shadow);
    color: inherit; transition: border-color .15s, box-shadow .15s;
}
a.stat-card:hover { text-decoration: none; border-color: var(--brand-200); box-shadow: 0 4px 12px rgba(31, 26, 46, .08); }
.stat-icon { display: inline-flex; align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem; border-radius: 10px; font-size: 1.3rem; flex-shrink: 0; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .85rem; color: var(--app-muted); }
.tone-brand .stat-icon { background: var(--brand-100); color: var(--brand-700); }
.tone-slate .stat-icon { background: #F1F5F9; color: #475569; }
.tone-blue .stat-icon { background: #EFF6FF; color: #1D4ED8; }
.tone-red .stat-icon { background: #FEF2F2; color: #B91C1C; }
.tone-red.is-alert { border-color: #FECACA; background: #FFFBFB; }
.tone-red.is-alert .stat-value { color: #B91C1C; }

/* ---------- 表格 ---------- */
.table { --bs-table-hover-bg: var(--brand-50); --bs-table-border-color: var(--app-border); margin-bottom: 0; }
.table > thead th {
    font-size: .78rem; font-weight: 600; color: var(--app-muted); background: #FAF9FC;
    border-bottom-width: 1px; padding: .65rem .75rem; white-space: nowrap;
}
.table > tbody td { padding: .7rem .75rem; vertical-align: middle; }
.table > :not(caption) > * > *:first-child { padding-left: 1.25rem; }
.table > :not(caption) > * > *:last-child { padding-right: 1.25rem; }
/* 文字較長的欄位 (錯誤、註記、說明)：窄螢幕時維持可讀寬度，表格改為橫向捲動 */
.table .col-text { min-width: 180px; }
tr.row-link { cursor: pointer; }
tr.row-link:focus-visible { outline: 2px solid var(--brand-500); outline-offset: -2px; }
.table-scroll { max-height: 440px; overflow: auto; }
.table-scroll thead th { position: sticky; top: 0; z-index: 1; }

/* ---------- 狀態標籤 (顏色 + 圓點 + 文字，不只靠顏色辨識) ---------- */
.pill {
    display: inline-flex; align-items: center; gap: .4rem; padding: .18rem .6rem; border-radius: 999px;
    font-size: .78rem; font-weight: 500; line-height: 1.45; white-space: nowrap; border: 1px solid transparent;
}
.pill::before { content: ""; width: .42rem; height: .42rem; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.pill-new, .pill-pending { background: #F1F5F9; color: #475569; border-color: #E2E8F0; }
.pill-updating { background: #EFF6FF; color: #1D4ED8; border-color: #DBEAFE; }
.pill-done { background: #ECFDF5; color: #047857; border-color: #D1FAE5; }
.pill-failed { background: #FEF2F2; color: #B91C1C; border-color: #FEE2E2; }
.pill-stop { background: #F4F4F5; color: #3F3F46; border-color: #E4E4E7; }
.pill-superseded { background: #FFFBEB; color: #B45309; border-color: #FEF3C7; }
.pill-skipped { background: #ECFEFF; color: #0E7490; border-color: #CFFAFE; }
.pill-role { background: var(--brand-100); color: var(--brand-700); border-color: var(--brand-200); }
.pill-plain::before { display: none; }

/* 進度條 (各狀態分店數) */
.progress-stack { display: flex; height: .5rem; border-radius: 999px; overflow: hidden; background: #EEECF3; min-width: 120px; }
.progress-stack > span { display: block; height: 100%; }
.seg-done { background: #10B981; }
.seg-closed { background: #A1A1AA; }
.seg-updating { background: #3B82F6; }
.seg-failed { background: #EF4444; }
.progress-caption { font-size: .78rem; color: var(--app-muted); margin-top: .3rem; white-space: nowrap; }

/* 篩選按鈕 */
.filter-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.filter-chip {
    border: 1px solid var(--app-border); background: #fff; border-radius: 999px; padding: .25rem .75rem;
    font-size: .82rem; color: var(--app-muted); cursor: pointer; transition: background-color .15s, color .15s, border-color .15s;
}
.filter-chip:hover { border-color: var(--brand-200); color: var(--brand-700); }
.filter-chip.active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.filter-chip .count { opacity: .8; margin-left: .25rem; }

.dropdown-menu { --bs-dropdown-link-active-bg: var(--brand-600); border-color: var(--app-border); border-radius: 10px; padding: .35rem; font-size: .9rem; }
.dropdown-item { border-radius: 6px; padding: .45rem .75rem; }

/* ---------- 提示 ---------- */
.alert { border-radius: 10px; display: flex; gap: .65rem; align-items: flex-start; }
.alert > .bi { font-size: 1.1rem; line-height: 1.4; }
.toast-container { z-index: 1090; }
.app-toast { border: 0; border-radius: 10px; box-shadow: 0 8px 24px rgba(31, 26, 46, .16); }
.app-toast .toast-body { display: flex; gap: .6rem; align-items: center; font-weight: 500; }

/* 空狀態 */
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--app-muted); }
.empty-state .bi { font-size: 2rem; color: var(--brand-200); display: block; margin-bottom: .5rem; }

/* ---------- 建立需求 ---------- */
.item-card { border: 1px solid var(--app-border); border-radius: 10px; background: #fff; padding: .9rem 1rem 1rem; }
.item-card + .item-card { margin-top: .75rem; }
.item-card .item-title { font-weight: 600; font-size: .9rem; }
.items-wrap { background: #FAF9FC; }
.action-bar {
    position: sticky; bottom: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
    background: rgba(255, 255, 255, .96); backdrop-filter: blur(6px); border: 1px solid var(--app-border);
    border-radius: var(--app-radius); box-shadow: 0 -4px 16px rgba(31, 26, 46, .06); padding: .85rem 1.25rem; margin-top: .5rem;
}
.action-bar .summary { color: var(--app-muted); }
.action-bar .summary b { color: var(--app-text); }

/* ---------- 登入 ---------- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: radial-gradient(1200px 600px at 10% -10%, var(--brand-100), transparent), var(--app-bg); }
.auth-card { display: grid; grid-template-columns: 1fr 1fr; max-width: 820px; width: 100%; background: #fff; border-radius: 16px; overflow: hidden; box-shadow: 0 20px 48px rgba(46, 14, 65, .14); }
.auth-brand { background: linear-gradient(160deg, var(--brand-600), var(--brand-900)); color: #fff; padding: 2.5rem; display: flex; flex-direction: column; justify-content: space-between; gap: 2rem; }
.auth-brand h2 { font-size: 1.5rem; font-weight: 700; margin: 0 0 .5rem; }
.auth-brand p { color: rgba(255, 255, 255, .8); margin: 0; }
.auth-brand ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; color: rgba(255, 255, 255, .88); font-size: .9rem; }
.auth-form { padding: 2.5rem; }
.auth-form h1 { font-size: 1.35rem; font-weight: 700; margin-bottom: .25rem; }
@media (max-width: 767.98px) {
    .auth-card { grid-template-columns: 1fr; }
    .auth-brand { padding: 1.5rem; }
    .auth-brand ul { display: none; }
    .auth-form { padding: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation-duration: .01ms !important; }
}
