:root {
    /* Brand Colors */
    --color-primary: #ff8859;
    --color-primary-hover: #ff743d;
    --color-primary-light: rgba(255, 136, 89, 0.1);
    /* UIUX #4: 主色當文字 / icon 時用較深版本 (滿足 WCAG AA 4.5:1) */
    --color-primary-text: #c44e1c;
    --color-primary-text-strong: #9a3a13;

    --color-surface: #ffffff;
    --color-background: #f4f6f8;

    --color-success: #22946e;
    --color-success-hover: #1a7556;
    --color-success-light: rgba(34, 148, 110, 0.1);

    /* UIUX #4: warning 提高對比度 (原 b8871f = 3.95:1 → 9c6f0c ~4.7:1) */
    --color-warning: #b8871f;            /* 背景 / icon 用 */
    --color-warning-hover: #946a17;
    --color-warning-text: #9c6f0c;        /* 文字版本 */
    --color-warning-light: rgba(184, 135, 31, 0.12);

    --color-danger: #b13535;
    --color-danger-hover: #8e2a2a;
    --color-danger-light: rgba(177, 53, 53, 0.1);

    --color-info: #1e56a3;
    --color-info-hover: #16447f;
    --color-info-light: rgba(30, 86, 163, 0.1);

    /* 報表頁專用 — warm neutral surface + 細邊框 (取代彩色 accent / gradient) */
    --surface-warm: #fafaf7;
    --surface-sunken: #f4f2ed;
    --border-soft: #ececec;

    /* Text Colors */
    --text-main: #1a1c23;
    --text-muted: #6b7280;
    --text-secondary: #475569;  /* 中等強度，介於 main 跟 muted 之間 */
    --text-inverse: #ffffff;

    /* Background hierarchy */
    --bg-secondary: #f8fafc;     /* 卡片內次級區塊背景 */
    --bg-tertiary: #f1f5f9;      /* 表格 header / 更次級背景 */

    /* Borders & Shadows */
    --border-color: #e7e9ee;
    --border-strong: #d6dae1;
    --shadow-sm: 0 1px 2px 0 rgba(17, 24, 39, 0.04);
    --shadow-md: 0 4px 10px -2px rgba(17, 24, 39, 0.06), 0 2px 4px -2px rgba(17, 24, 39, 0.04);
    --shadow-lg: 0 12px 24px -8px rgba(17, 24, 39, 0.10), 0 6px 12px -6px rgba(17, 24, 39, 0.04);
    --shadow-hover: 0 20px 30px -10px rgba(17, 24, 39, 0.10), 0 8px 12px -6px rgba(17, 24, 39, 0.04);
    --shadow-focus: 0 0 0 3px var(--color-primary-light);

    /* UIUX #4: focus ring 統一 — 任何 focus-visible 都套這個 */
    --focus-ring: 0 0 0 3px rgba(255, 136, 89, 0.45);
    --focus-outline: 2px solid var(--color-primary-text);

    /* UIUX #4: 字級階梯 (rem) — 別再混 0.6rem / 0.65rem / 0.68rem 等奇怪數字 */
    --text-2xs: 0.6875rem;   /* 11px - 小 badge / 小提示 */
    --text-xs:  0.75rem;     /* 12px - 表頭 / pill / sub text */
    --text-sm:  0.8125rem;   /* 13px - 表格內容 / button */
    --text-base:0.875rem;    /* 14px - 一般 UI 文字 */
    --text-md:  1rem;        /* 16px - input / 主要描述 */
    --text-lg:  1.125rem;    /* 18px - card title */
    --text-xl:  1.375rem;    /* 22px - section title */
    --text-2xl: 1.75rem;     /* 28px - metric 數字 */
    --text-3xl: 2.25rem;     /* 36px - hero / page title */

    /* Radii */
    --radius-sm: 0.375rem;
    --radius-md: 0.625rem;
    --radius-lg: 1rem;
    --radius-xl: 1.25rem;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    /* Sidebar */
    --sidebar-width: 260px;
    --sidebar-width-collapsed: 76px;
    --sidebar-bg: #ffffff;
    --sidebar-border: #ececf1;
    --sidebar-item-color: #5b6473;
    --sidebar-item-hover-bg: #f6f7f9;
    /* UIUX #4: section label 原本 #9aa1ad on 白 = 2.82:1 過低 → 拉深到 #6b7280 = 4.7:1 */
    --sidebar-section-color: #6b7280;

    /* Topbar */
    --topbar-height: 54px;

    /* Chart palette — dashboard + reports 共用，改色只改這裡
       字面值 (不用 var(...)) — Chart.js v4.5 動畫引擎吃到 getPropertyValue 拿到
       未解析的 var() 字串會炸 this._fn is not a function */
    --chart-income: #22946e;                              /* = color-success */
    --chart-expense: #b13535;                             /* = color-danger */
    --chart-fill-income: rgba(34, 148, 110, 0.10);
    --chart-fill-expense: rgba(177, 53, 53, 0.08);
    --chart-grid: rgba(15, 23, 42, 0.06);                /* 介於 dashboard 0.05 跟 reports #cbd5e1 之間 */
    --chart-axis-text: #6b7280;                          /* = text-muted */
    /* 住房一覽 sticky 左欄底色 — 不同列狀態用不同色，sticky cell 必須不透明才不會透出底層
       (P0-4 audit: 把寫死的 hex 抽到 token) */
    --occ-sticky-bg-default: var(--color-surface);
    --occ-sticky-bg-vacant: #f1f3f5;        /* = rgba(148,163,184,0.10) over white 等效 */
    --occ-sticky-bg-terminated: #f8f9fa;    /* 跟 terminated 漸層底一致 */
    --occ-sticky-bg-stripe-b: #fafbfa;      /* = rgba(0,0,0,0.02) over white 等效 */

    /* Categorical — 多館 / 分類 / pie 用，取代 BUILDING_COLOR_PALETTE / PIE_COLORS 兩套 */
    --chart-cat-1: #ff8859;  /* brand */
    --chart-cat-2: #3f7c8a;
    --chart-cat-3: #d4a574;
    --chart-cat-4: #7a9a6a;
    --chart-cat-5: #b67d7d;
    --chart-cat-6: #9c8aaa;
    --chart-cat-7: #c4a486;
    --chart-cat-8: #7a7c80;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', 'Noto Sans TC', sans-serif;
    background-color: var(--color-background);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* UIUX #4: 全域 focus-visible fallback —
   任何 button/a/input/textarea/select 沒自己處理 focus 時都套這個樣式。
   用 :focus-visible 避免滑鼠 hover 也顯示 ring (鍵盤才出現) */
:focus-visible {
    outline: 2px solid var(--color-primary-text);
    outline-offset: 2px;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[role="button"]:focus-visible {
    outline: 2px solid var(--color-primary-text);
    outline-offset: 2px;
}

/* UIUX #4 + 報告 P2: 尊重 prefers-reduced-motion (前庭功能障礙 / 暈眩使用者) */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* === Sidebar === */
.sidebar {
    position: relative;
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 30;
    transition: width var(--transition-normal);
    flex-shrink: 0;
}

.sidebar.is-collapsed {
    width: var(--sidebar-width-collapsed);
}

/* --- Header / Logo --- */
.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem 0 1.25rem;
    border-bottom: 1px solid var(--sidebar-border);
    gap: 0.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--text-main);
    min-width: 0;
    flex: 1;
}

/* Sidebar logo — 展開時 icon + 標準字 (聚空間) 併排；收合時只剩 icon */
.logo {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.logo-img-icon {
    width: 34px;
    height: 34px;
    object-fit: contain;
    flex-shrink: 0;
}
.logo-img-wordmark {
    height: 22px;
    width: auto;
    max-width: 110px;
    object-fit: contain;
    flex-shrink: 0;
}
/* 收合時隱藏標準字，只剩 icon */
.sidebar.is-collapsed .logo-img-wordmark { display: none; }
.sidebar.is-collapsed .logo {
    gap: 0;
    justify-content: center;
    width: 100%;
}
.sidebar.is-collapsed .logo-img-icon {
    width: 38px;
    height: 38px;
}

/* 舊 .logo-mark / .logo-wordmark — 留 fallback 不刪，給 .ph icon 用 (萬一改回) */
.logo-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.logo-mark img { width: 100%; height: 100%; object-fit: contain; }

.logo-wordmark {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    min-width: 0;
    overflow: hidden;
}

.logo-name {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: 0.02em;
}

.logo-sub {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--color-primary);
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.sidebar-toggle {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.125rem;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background-color: var(--sidebar-item-hover-bg);
    color: var(--color-primary);
}

.sidebar.is-collapsed .logo-wordmark { display: none; }
.sidebar.is-collapsed .sidebar-header {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 0;
    padding: 0 0.5rem;
    height: var(--topbar-height);
    min-height: auto;
}
.sidebar.is-collapsed .logo {
    justify-content: center;
    flex: 0 0 auto;
}
/* 收合時：toggle 變成右側邊緣懸停才出現的圓形小 tab (Notion / VSCode 風格) */
.sidebar.is-collapsed .sidebar-toggle {
    position: absolute;
    top: 22px;
    right: -13px;
    width: 26px;
    height: 26px;
    font-size: 0.85rem;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    opacity: 0;
    z-index: 32;
    transition: opacity 0.18s ease, background 0.15s, color 0.15s;
}
.sidebar.is-collapsed:hover .sidebar-toggle,
.sidebar.is-collapsed .sidebar-toggle:focus-visible {
    opacity: 1;
}
.sidebar.is-collapsed .sidebar-toggle i {
    transform: rotate(180deg);
}

/* --- Nav --- */
.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 3px;
}
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.nav-section-label {
    display: block;
    padding: 0 0.875rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--sidebar-section-color);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    user-select: none;
}

.sidebar.is-collapsed .nav-section-label {
    height: 1px;
    background-color: var(--sidebar-border);
    padding: 0;
    margin: 0.25rem 0.75rem;
    overflow: hidden;
    text-indent: -9999px;
    color: transparent;
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    text-decoration: none;
    color: var(--sidebar-item-color);
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.9rem;
    transition: background-color var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
}

.nav-item i {
    font-size: 1.25rem;
    flex-shrink: 0;
    transition: transform var(--transition-fast);
}

.nav-item:hover {
    background-color: var(--sidebar-item-hover-bg);
    color: var(--text-main);
}

.nav-item:hover i {
    color: var(--color-primary);
}

.nav-item.active {
    background-color: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--color-primary);
    padding-left: calc(0.875rem + 3px);
}

.nav-item:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

/* === 巢狀子項 (展開時) === */
.nav-children {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    margin-left: 1.25rem;
    padding-left: 0.625rem;
    border-left: 1px solid var(--sidebar-border);
    margin-top: 0.125rem;
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.2s ease, opacity 0.15s, margin-top 0.2s;
    opacity: 1;
}
.nav-children.is-collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    pointer-events: none;
}

/* 父項收合按鈕 (右側 caret) */
.nav-item-parent {
    position: relative;
}
.nav-collapse-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: inherit;
    opacity: 0.55;
    cursor: pointer;
    padding: 0.2rem 0.35rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: transform 0.2s, opacity 0.15s, background-color 0.15s;
}
.nav-collapse-btn:hover { opacity: 1; background: rgba(255, 255, 255, 0.06); }
.nav-collapse-btn.is-collapsed { transform: rotate(-90deg); }
.sidebar.is-collapsed .nav-collapse-btn { display: none; }

.nav-item-child {
    font-size: 0.825rem;
    padding: 0.5rem 0.75rem;
}

.nav-item-child i {
    font-size: 1.05rem;
}

.nav-item-child.active::before,
.sidebar.is-collapsed .nav-item-child.active {
    /* 子項用較細的左條 */
}

/* 收合 sidebar 時：子項退掉縮排，變回一般 icon-only */
.sidebar.is-collapsed .nav-children {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
    margin-top: 0;
}

.sidebar.is-collapsed .nav-item-child {
    font-size: inherit;
    padding: 0.7rem 0;
    justify-content: center;
}

.sidebar.is-collapsed .nav-item-child i {
    font-size: 1.25rem;
}

/* legacy divider — keep harmless if any view still uses it */
.nav-divider {
    height: 1px;
    background-color: var(--sidebar-border);
    margin: 0.5rem 0.75rem;
}

/* Collapsed: icon only + tooltip */
.sidebar.is-collapsed .nav-item {
    justify-content: center;
    padding: 0.7rem 0;
    gap: 0;
}

.sidebar.is-collapsed .nav-item .nav-label { display: none; }
/* 通用 is-hidden 切換 (P2-4 audit: 替代 markup inline style="display:none") */
.nav-item.is-hidden { display: none; }

.sidebar.is-collapsed .nav-item.active {
    /* 收合狀態下沒有左 padding 文字，indicator 還是用 inset shadow */
    padding-left: 0;
}

.sidebar.is-collapsed .nav-item[data-label]:hover::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 0.625rem);
    top: 50%;
    transform: translateY(-50%);
    background-color: var(--text-main);
    color: var(--text-inverse);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.375rem 0.625rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    pointer-events: none;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

/* --- Footer / User profile --- */
.sidebar-footer {
    padding: 0.4rem 0.5rem;
    border-top: 1px solid var(--sidebar-border);
}

/* --- Auth (Login) Overlay --- */
#auth-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.auth-card {
    width: 100%;
    max-width: 380px;
    background: white;
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    padding: 2.25rem 2rem 1.5rem;
}
.auth-brand {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    margin-bottom: 1.75rem;
}
.auth-logo {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.4rem;
    flex-shrink: 0;
}
.auth-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.auth-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}
.auth-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: 0.02em;
}
.auth-sub {
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 0.15rem;
}
/* --- 各館收入報表 --- */
.reports-page { display: flex; flex-direction: column; gap: 1rem; }

.reports-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}
.month-switcher {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.month-switcher .btn {
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
}
.month-switcher__label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
}
.month-switcher__label-eyebrow {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
.month-switcher__label strong {
    font-size: 1.1rem;
}
.month-switcher__right {
    display: flex;
    gap: 0.5rem;
}

.report-grand-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

.reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 1rem;
}

.report-card { padding: 1.25rem; }

.report-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border-color);
}
.report-card-title {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.report-card-title h3 {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.3;
    color: var(--text-main);
}
.report-card-title p {
    margin: 0;
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.report-export-btn {
    flex-shrink: 0;
    padding: 0.42rem 0.85rem;
    font-size: 0.78rem;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.report-export-btn i { font-size: 0.95rem; }

.report-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
}
.report-cell {
    padding: 0.75rem 0.85rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.report-cell .cell-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}
.report-cell .cell-value {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.1;
}
.report-cell .cell-value.income { color: var(--color-success); }
.report-cell .cell-value.expense { color: var(--color-danger); }
.report-cell .cell-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
}
.report-cell-net {
    background: rgba(255, 136, 89, 0.08);
    border: 1px solid rgba(255, 136, 89, 0.25);
}
.report-cell-warning {
    background: rgba(184, 135, 31, 0.06);
    border: 1px dashed rgba(184, 135, 31, 0.35);
}

.report-expense-detail {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--border-color);
}
.report-expense-detail summary {
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 0.35rem 0;
}
.report-expense-detail summary:hover { color: var(--color-warning); }
.report-expense-table {
    width: 100%;
    font-size: 0.8rem;
    margin-top: 0.5rem;
}
.report-expense-table td {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
}
.report-expense-table tfoot td {
    border-top: 2px solid var(--border-color);
    border-bottom: none;
    padding-top: 0.5rem;
}

/* --- 首頁 metric 卡片：可點擊跳轉 --- */
.metric-card.metric-link {
    display: block;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s;
    position: relative;
}
.metric-card.metric-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: rgba(255, 136, 89, 0.4);
}
.metric-card.metric-link::after {
    content: '→';
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    opacity: 0;
    transition: opacity 0.15s, transform 0.15s;
    color: var(--color-warning);
    font-weight: 700;
}
.metric-card.metric-link:hover::after {
    opacity: 1;
    transform: translateX(3px);
}

/* --- Flatpickr 日期選擇器 — 質感重做 --- */
.flatpickr-calendar {
    width: 312px !important;
    padding: 0.85rem !important;
    border-radius: 14px !important;
    box-shadow: 0 12px 36px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.05) !important;
    border: 1px solid #f1f5f9 !important;
    font-family: 'Noto Sans TC', 'Microsoft JhengHei', sans-serif !important;
    background: white !important;
}
.flatpickr-calendar::before, .flatpickr-calendar::after { display: none !important; }

/* 月份標題列 — flex 讓箭頭跟標題完美對齊 */
.flatpickr-months {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0.25rem 0 0.5rem !important;
    border-bottom: none !important;
    gap: 0.25rem !important;
}
.flatpickr-current-month {
    position: static !important;
    flex: 1 !important;
    text-align: center !important;
    font-size: 0.95rem !important;
    font-weight: 700 !important;
    color: #0f172a !important;
    padding: 0 !important;
    height: 32px !important;
    line-height: 32px !important;
    left: auto !important;
    width: auto !important;
}
.flatpickr-current-month .flatpickr-monthDropdown-months {
    font-weight: 700 !important;
    color: #0f172a !important;
    background: transparent !important;
    border-radius: 6px !important;
    padding: 0 0.4rem !important;
}
.flatpickr-current-month input.cur-year {
    font-weight: 700 !important;
    color: #0f172a !important;
    padding: 0 0.3rem !important;
    margin-left: 0.25rem !important;
}
/* 拿掉年份 spinner */
.numInputWrapper span.arrowUp,
.numInputWrapper span.arrowDown { display: none !important; }
.numInputWrapper { padding-right: 0 !important; }

/* 月份左右箭頭 */
.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
    position: static !important;
    float: none !important;
    flex-shrink: 0 !important;
    width: 32px !important;
    height: 32px !important;
    padding: 0 !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: #64748b !important;
    transition: background-color 0.15s, color 0.15s !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
}
.flatpickr-months .flatpickr-prev-month svg,
.flatpickr-months .flatpickr-next-month svg {
    width: 14px !important;
    height: 14px !important;
    fill: currentColor !important;
}
.flatpickr-months .flatpickr-prev-month:hover,
.flatpickr-months .flatpickr-next-month:hover {
    background: #f1f5f9 !important;
    color: var(--color-primary) !important;
}
.flatpickr-months .flatpickr-prev-month:hover svg,
.flatpickr-months .flatpickr-next-month:hover svg {
    fill: var(--color-primary) !important;
}

/* 星期表頭 */
.flatpickr-weekdays {
    background: transparent !important;
    margin-top: 0.25rem !important;
    height: 32px !important;
}
.flatpickr-weekdaycontainer { display: flex; gap: 0; }
.flatpickr-weekday {
    color: #94a3b8 !important;
    font-weight: 600 !important;
    font-size: 0.72rem !important;
    letter-spacing: 0.04em !important;
    height: 32px !important;
    line-height: 32px !important;
    flex: 1 !important;
}

/* 日期方塊 */
.dayContainer {
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 2px !important;
}
.flatpickr-days { width: 100% !important; }
.flatpickr-day {
    width: 38px !important;
    max-width: 38px !important;
    height: 38px !important;
    line-height: 38px !important;
    border-radius: 50% !important;
    font-size: 0.88rem !important;
    color: #334155 !important;
    border: none !important;
    margin: 0 auto !important;
    transition: background-color 0.12s, color 0.12s !important;
}
.flatpickr-day:hover {
    background: #fff7ed !important;
    color: #c2410c !important;
}
/* 今天 — 永遠只是底下小點，不論是否選中 */
.flatpickr-day.today {
    color: #334155 !important;
    font-weight: 600 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    position: relative;
}
.flatpickr-day.today::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #94a3b8;
}
.flatpickr-day.today:hover {
    background: #fff7ed !important;
    color: #c2410c !important;
}
/* 選中 — 橘色實心圓，但 today 不套這個 (下方覆蓋) */
.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange,
.flatpickr-day.selected:focus,
.flatpickr-day.selected:hover {
    background: var(--color-primary) !important;
    color: white !important;
    font-weight: 700 !important;
    box-shadow: 0 4px 10px rgba(255, 136, 89, 0.35) !important;
}
/* today + selected → 不顯示橘色背景，僅用粗體 + 點 表示 */
.flatpickr-day.today.selected {
    background: transparent !important;
    color: var(--color-primary) !important;
    font-weight: 700 !important;
    box-shadow: none !important;
}
.flatpickr-day.today.selected::after {
    background: var(--color-primary) !important;
}
.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay {
    color: #cbd5e1 !important;
}

/* --- 合約管理表格：固定欄寬，避免換 filter 後表頭跑掉 --- */
.data-table.contracts-table {
    table-layout: fixed;
    width: 100%;
}
.data-table.contracts-table th {
    white-space: nowrap;
}

/* --- 帳務管理表格：固定欄寬，避免排序時欄位寬度抖動 --- */
.data-table.finance-table {
    table-layout: fixed;
    width: 100%;
}
.data-table.finance-table th {
    white-space: nowrap;
    overflow: hidden;
}
.data-table.finance-table td {
    word-break: break-word;
    white-space: normal;
    vertical-align: middle;
}
/* 日期欄位永遠不換行 */
.data-table.finance-table tbody td:first-child {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-size: 0.82rem;
}
/* 館別 / 實收實付 / 折扣 / 付款 / 操作 也不換行 */
.data-table.finance-table tbody td:nth-child(2),
.data-table.finance-table tbody td:nth-child(5),
.data-table.finance-table tbody td:nth-child(6),
.data-table.finance-table tbody td:nth-child(7),
.data-table.finance-table tbody td:last-child {
    white-space: nowrap;
}
/* 類別徽章：欄寬已夠寬，badge 不截斷 */
.data-table.finance-table tbody td:nth-child(3) {
    overflow: visible;
    white-space: nowrap;
}
.data-table.finance-table tbody td:nth-child(3) .status-badge {
    display: inline-block;
    vertical-align: middle;
    white-space: nowrap;
}

/* --- 帳務管理：收入綠 / 支出紅 row 底色 --- */
.finance-row-in {
    background-color: rgba(34, 148, 110, 0.06) !important;
    border-left: 3px solid rgba(34, 148, 110, 0.5);
}
.finance-row-in:hover {
    background-color: rgba(34, 148, 110, 0.13) !important;
}
.finance-row-out {
    background-color: rgba(239, 68, 68, 0.06) !important;
    border-left: 3px solid rgba(239, 68, 68, 0.5);
}
.finance-row-out:hover {
    background-color: rgba(239, 68, 68, 0.13) !important;
}

/* --- 入住表單：舊客建議列 --- */
.tenant-suggest-strip {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(0, 0, 0, 0.02);
    padding: 0.5rem;
    border-radius: 6px;
}
.tenant-suggest-strip:empty {
    display: none;
}
.tenant-suggest-strip .ts-header {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0 0.25rem 0.15rem;
    letter-spacing: 0.05em;
}
.tenant-suggest-strip .ts-header-new {
    font-size: 0.8rem;
    color: var(--color-success);
    background: color-mix(in srgb, var(--color-success) 8%, transparent);
    border: 1px dashed color-mix(in srgb, var(--color-success) 35%, transparent);
    border-radius: 6px;
    padding: 0.45rem 0.7rem;
    margin-bottom: 0.4rem;
    letter-spacing: 0;
    font-weight: 500;
}
.tenant-suggest-strip .ts-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.tenant-suggest-strip .ts-item:hover {
    background: rgba(255, 136, 89, 0.08);
    border-color: rgba(255, 136, 89, 0.5);
    box-shadow: 0 1px 4px rgba(255, 136, 89, 0.15);
}
.tenant-suggest-strip .ts-item[data-blocked="1"] {
    cursor: not-allowed;
    opacity: 0.55;
}
.tenant-suggest-strip .ts-item[data-blocked="1"]:hover {
    background: rgba(255, 136, 89, 0.06);
    border-color: rgba(255, 136, 89, 0.2);
}
.tenant-suggest-strip .ts-name {
    font-weight: 600;
    display: inline-flex;
    align-items: baseline;
    gap: 0.5rem;
}
.tenant-suggest-strip .ts-phone {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 400;
}
.tenant-suggest-strip .ts-source {
    font-size: 0.68rem;
    padding: 0.15rem 0.55rem;
    background: rgba(255, 136, 89, 0.15);
    color: #b45309;
    border-radius: 999px;
    font-weight: 500;
}
.tenant-suggest-strip .ts-load,
.tenant-suggest-strip .ts-warn,
.tenant-suggest-strip .ts-hint {
    font-size: 0.7rem;
    font-weight: 500;
}
.tenant-suggest-strip .ts-load { color: var(--color-info, #2563eb); }
.tenant-suggest-strip .ts-warn { color: var(--color-danger); }
.tenant-suggest-strip .ts-hint { color: var(--color-warning, #d97706); }
.tenant-suggest-strip .ts-loaded {
    padding: 0.4rem 0.6rem;
    background: rgba(34, 148, 110, 0.1);
    border: 1px solid rgba(34, 148, 110, 0.3);
    border-radius: 4px;
    color: var(--color-success);
    font-size: 0.8rem;
}

/* --- Password show/hide toggle (登入畫面 + 帳號設定共用) --- */
.password-field-wrap {
    position: relative;
    display: block;
}
.password-field-wrap input {
    padding-right: 2.5rem !important;
    width: 100%;
}
.password-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    font-size: 1.1rem;
    padding: 0.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.15s, background-color 0.15s;
}
.password-toggle:hover {
    color: #475569;
    background: rgba(0, 0, 0, 0.04);
}

.auth-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #1f2937;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
    margin-bottom: 1.25rem;
}
.auth-google:hover {
    background: #f8fafc;
    border-color: #94a3b8;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.auth-google svg { flex-shrink: 0; }

.auth-divider {
    position: relative;
    text-align: center;
    margin: 0 0 1.25rem;
    font-size: 0.7rem;
    color: #94a3b8;
    letter-spacing: 0.1em;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: calc(50% - 1.5rem);
    height: 1px;
    background: #e2e8f0;
}
.auth-divider::before { left: 0; }
.auth-divider::after  { right: 0; }
.auth-divider span { background: white; padding: 0 0.5rem; position: relative; }

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.auth-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.auth-field > span {
    font-size: 0.75rem;
    font-weight: 600;
    color: #475569;
    letter-spacing: 0.02em;
}
.auth-field input {
    padding: 0.65rem 0.85rem;
    font-size: 0.95rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #f8fafc;
    color: #0f172a;
}
.auth-field input:focus {
    outline: none;
    border-color: var(--color-primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(255, 136, 89, 0.15);
}
.auth-submit {
    margin-top: 0.5rem;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-hover));
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
}
.auth-submit:hover:not(:disabled) {
    box-shadow: 0 8px 16px -4px rgba(255, 136, 89, 0.4);
    transform: translateY(-1px);
}
.auth-submit:disabled {
    opacity: 0.6;
    cursor: wait;
}
.auth-submit .ph-circle-notch {
    animation: sync-spin 0.8s linear infinite;
}
.auth-error {
    padding: 0.6rem 0.85rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    border-radius: 6px;
    font-size: 0.8rem;
}
.auth-footer {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
    font-size: 0.7rem;
    color: #94a3b8;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}

/* --- Occupancy 住房一覽矩陣表 --- */
.occ-section { margin-bottom: 1.25rem; }

/* 備註欄 — 最多 2 行，超過顯示 …，hover 看全文 */
/* 房客欄 / 備註欄 — 長英文名 / 長字串自動換行不溢出 */
.occ-table td:nth-child(2),
.occ-table td:nth-child(3) {
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

.occ-note-btn {
    background: transparent;
    border: 1px dashed transparent;
    border-radius: 6px;
    padding: 0.2rem 0.4rem;
    margin: -0.2rem -0.4rem;
    cursor: pointer;
    text-align: center;
    font-family: inherit;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.35;
    width: 100%;
    transition: border-color 0.15s, background 0.15s;
}
.occ-note-btn:hover {
    border-color: var(--border-color);
    background: rgba(255, 136, 89, 0.05);
}
.occ-note-empty {
    color: var(--text-muted);
    font-size: 0.7rem;
    opacity: 0.55;
}
.occ-note-btn:hover .occ-note-empty { opacity: 1; }
.occ-note-clamp {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
    line-height: 1.35;
    max-height: 2.7em;
    cursor: help;
}

/* 縮減 occupancy 介紹卡內距 */
.occ-intro {
    padding: 0.65rem 0.85rem !important;
    margin-bottom: 0.75rem !important;
}

/* Tabs — 各館切換 */
.occ-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.occ-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
    background: var(--bg-secondary, #f8fafc);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text-secondary, #475569);
}
.occ-tab:hover {
    background: var(--bg-tertiary, #f1f5f9);
    border-color: var(--border-color-strong, #cbd5e1);
}
/* P1-5 audit: active 樣式對齊 .bldg-subtab 的柔 active (橘 light + 橘字 + 軟邊)，不要漸層 + 白字
   reports 各館 sub-tab 跟 occupancy 各館 tab 是同一個意圖，視覺應一致 */
.occ-tab.active {
    background: rgba(255, 136, 89, 0.12);
    color: var(--color-primary-text);
    border-color: rgba(255, 136, 89, 0.35);
    box-shadow: none;
}
.occ-tab-count {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 999px;
    font-weight: 600;
}
.occ-tab.active .occ-tab-count {
    background: rgba(255, 136, 89, 0.18);
    color: var(--color-primary-text);
}

/* Room group header — 房間分隔列 */
.occ-room-header td {
    background: linear-gradient(to right, rgba(255, 136, 89, 0.12), rgba(255, 136, 89, 0.04));
    padding: 0.5rem 0.85rem !important;
    border-top: 2px solid rgba(255, 136, 89, 0.35);
    border-bottom: 1px solid rgba(255, 136, 89, 0.2);
    text-align: left !important;
    white-space: nowrap;
}
.occ-room-title {
    color: #b45309;
    font-weight: 700;
    font-size: 0.95rem;
    margin-right: 0.85rem;
}
.occ-room-type {
    color: var(--text-secondary, #475569);
    font-weight: 500;
    font-size: 0.8rem;
    padding: 0.1rem 0.55rem;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 999px;
    margin-right: 0.6rem;
}
.occ-room-meta {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-right: 0.85rem;
}
.occ-room-rent {
    float: right;
    font-weight: 600;
    color: var(--color-success, #16a34a);
    font-size: 0.85rem;
}
.occ-room-rent small {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.7rem;
    margin-left: 2px;
}

/* 同房間床位交替底色 (整個房間統一色) — 只用在「有人住」的 row，留白 / 極淺 */
.occ-table tr.occ-room-stripe-a:not(.occ-row-vacant):not(.occ-row-terminated) > td:not(.occ-bed-label) {
    background: white;
}
.occ-table tr.occ-room-stripe-b:not(.occ-row-vacant):not(.occ-row-terminated) > td:not(.occ-bed-label) {
    background: rgba(0, 0, 0, 0.02);
}

/* Row 狀態 — 用單一明顯底色，覆蓋 stripe (用不透明 hex 避免 sticky 透過去看到底層) */
.occ-table tr.occ-row-vacant > td {
    background: var(--occ-sticky-bg-vacant) !important;
}
.occ-table tr.occ-row-terminated > td {
    background: repeating-linear-gradient(
        45deg,
        rgba(148, 163, 184, 0.06),
        rgba(148, 163, 184, 0.06) 8px,
        rgba(148, 163, 184, 0.12) 8px,
        rgba(148, 163, 184, 0.12) 16px
    ) !important;
    opacity: 0.6;
}
.occ-table-wrap { overflow-x: hidden; }
.data-table.occ-table {
    table-layout: fixed; /* 固定欄寬，月份欄自動平分剩餘空間 */
    width: 100%;
}

/* 可點擊元素：床位 / 租客 button */
.occ-link {
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
    padding: 0;
    text-decoration: none;
    border-bottom: 1px dashed transparent;
    transition: color 0.15s, border-color 0.15s;
}
.occ-link:hover {
    color: var(--color-primary-hover);
    border-bottom-color: currentColor;
}
/* 「+ 入住」按鈕 — 空床/退房後出現在退房欄 */
.occ-checkin-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.12rem 0.35rem;
    font-size: 0.65rem;
    font-weight: 500;
    line-height: 1;
    max-width: 100%;
    white-space: nowrap;
    color: var(--color-success, #16a34a);
    background: rgba(34, 148, 110, 0.08);
    border: 1px solid rgba(34, 148, 110, 0.3);
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
}
.occ-checkin-btn:hover {
    background: rgba(34, 148, 110, 0.18);
    border-color: rgba(34, 148, 110, 0.5);
}
.occ-checkin-btn i {
    font-size: 0.75rem;
}

/* 可點擊日期格 */
.occ-clickable {
    cursor: pointer;
    transition: filter 0.1s;
}
.occ-clickable:hover {
    filter: brightness(0.92);
    outline: 1px solid rgba(255, 136, 89, 0.6);
    outline-offset: -1px;
}
/* 高 specificity 強制置中，蓋過 .data-table 預設 left-align */
.data-table.occ-table th,
.data-table.occ-table td {
    text-align: center;
    padding: 0.4rem 0.35rem;
    font-size: 0.75rem;
    white-space: nowrap;
    border-right: 1px solid var(--border-color, #e5e7eb);
}
.occ-table th { background: var(--bg-secondary); font-weight: 600; }
.occ-table td.occ-bed-label { font-weight: 700; background: var(--bg-secondary); }
.occ-table th.occ-this-month-header {
    background: rgba(255, 136, 89, 0.2);
    color: var(--text-primary);
}
.occ-table td.occ-this-month {
    background: rgba(255, 136, 89, 0.15);
    font-weight: 600;
    color: #b45309;
}
/* 日期顏色 — 過去灰、當前合約期/未來都用藍色 */
.occ-table td.occ-today {
    background: rgba(37, 99, 235, 0.18);   /* 藍底 highlight 今天 */
    color: #1d4ed8;
    font-weight: 700;
}
.occ-table td.occ-this-month {
    color: #2563eb;
    font-weight: 500;
}
.occ-table td.occ-future {
    color: #2563eb;
    font-weight: 500;
}
.occ-table td.occ-past {
    color: #94a3b8;     /* 灰色 */
    font-weight: 400;
    /* 不要刪除線、不要 opacity */
}

/* 繳費狀態 badge (顯示在月份格的日期旁邊) */
.occ-pay-badge {
    display: inline-block;
    margin-left: 3px;
    padding: 0 4px;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1.2;
    vertical-align: middle;
}
/* QW5: 飽和度降一半，用 token + 淡底色，視覺重心回到日期跟床位 */
.occ-pay-paid {
    background: rgba(34, 148, 110, 0.18);
    color: var(--color-success);
}
.occ-pay-partial {
    background: rgba(184, 135, 31, 0.18);
    color: var(--color-warning-text, #9c6f0c);
}
.occ-pay-unpaid {
    background: rgba(177, 53, 53, 0.18);
    color: var(--color-danger);
}
/* === 雙列堆疊：同床位的接續合約 === */
/* 接續列（同床位第 2 列以後）— 淡淡的左邊條 + 縮排視覺 */
.occ-row-continuation td.occ-bed-label {
    background: var(--bg-secondary);
    padding-left: 1.5rem;
}
.occ-bed-label-cont {
    color: var(--text-muted);
    font-size: 0.85rem;
}
/* 未來合約 — 不加任何視覺提示，跟其他列一樣 */
.occ-future-tenant {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    color: var(--text-main);
    font-weight: 500;
}

/* 合約到期標記 — 沿用收租日的藍色，小字區分用途 */
.occ-table td.occ-end-marker {
    background: transparent !important;
    color: #2563eb;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    cursor: help;
}
.occ-table td.occ-end-marker:hover {
    background: var(--bg-tertiary) !important;
}
.occ-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-muted);
}
.occ-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
}
.occ-swatch.occ-today { background: rgba(34, 148, 110, 0.5); }
.occ-swatch.occ-this-month { background: rgba(255, 136, 89, 0.4); }
.occ-swatch.occ-past { background: rgba(0, 0, 0, 0.15); }

/* --- Boot Loading Overlay --- */
#boot-loading {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.boot-loading-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: white;
}
.boot-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: sync-spin 0.8s linear infinite;
}
.boot-loading-text {
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.85);
    letter-spacing: 0.02em;
}

/* --- Sync Indicator (放在 user-profile 內，作為 username 下方副標題) --- */
.sync-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 2px;
    padding: 0;
    font-size: 0.65rem;
    color: var(--text-muted);
    cursor: pointer;
    background: transparent;
    border: none;
    line-height: 1;
}
.sync-indicator:hover .sync-label {
    text-decoration: underline;
}
.sync-indicator i {
    font-size: 0.85rem;
    flex-shrink: 0;
}
.sync-indicator .sync-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sync-indicator.status-idle    { color: var(--color-success); }
.sync-indicator.status-pulling i,
.sync-indicator.status-pushing i {
    animation: sync-spin 0.8s linear infinite;  /* A-M-2: 1.5s 太慢，看不出進行中 */
}
.sync-indicator.status-pulling { color: var(--color-info, #3b82f6); }
.sync-indicator.status-pushing { color: var(--color-info, #3b82f6); }
.sync-indicator.status-error   { color: var(--color-danger); }
.sync-indicator.status-offline { color: var(--color-warning); }
.sync-indicator.status-disabled { opacity: 0.55; }
@keyframes sync-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}
.sidebar.is-collapsed .sync-indicator { display: none; }

/* === Sidebar footer v2 — 雙行 + 分隔線 (2026-06-03 redesign) === */
.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.4rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--transition-fast);
    position: relative;
}
.user-profile:hover {
    background-color: var(--sidebar-item-hover-bg);
}
.user-profile:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.avatar-wrap {
    position: relative;
    flex-shrink: 0;
}
.avatar {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    overflow: hidden;
}
/* avatar icon 模式：font-size 比字母再大一點，更有存在感 */
.avatar[data-avatar-mode="icon"] {
    font-size: 1rem;
    font-weight: 400;
}
.avatar[data-avatar-mode="icon"] i {
    line-height: 1;
}

/* === Avatar picker (帳號設定 modal) === */
.avatar-picker {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-top: 0.4rem;
}
.avatar-preview-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.avatar-preview {
    width: 56px !important;
    height: 56px !important;
    font-size: 1.5rem !important;
}
.avatar-picker-rows {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-width: 0;
}
.avatar-picker-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.avatar-picker-label {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.avatar-icon-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.3rem;
}
.avatar-icon-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--color-surface);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.avatar-icon-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    transform: translateY(-1px);
}
.avatar-icon-btn.is-active {
    background: var(--color-primary);
    color: var(--text-inverse);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2);
}
.avatar-color-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.3rem;
}
.avatar-color-btn {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-full);
    border: 2px solid var(--color-surface);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 0 0 1px var(--border-color);
}
.avatar-color-btn:hover {
    transform: translateY(-1px) scale(1.05);
}
.avatar-color-btn.is-active {
    box-shadow: 0 0 0 2px var(--text-main);
    transform: scale(1.08);
}
.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.75rem;
}
.avatar-status {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 9px;
    height: 9px;
    border-radius: var(--radius-full);
    background-color: var(--color-success);
    border: 1.5px solid var(--color-surface);
}

.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
    flex: 1;
    gap: 0.1rem;
}
.user-name {
    font-weight: 600;
    font-size: var(--text-xs);
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* user-profile 內三顆 action — 常駐顯示 (不 hover-only) */
.user-actions {
    display: flex;
    align-items: center;
    gap: 0.1rem;
    flex-shrink: 0;
}
.profile-action {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.profile-action:hover {
    background-color: var(--color-background);
    color: var(--color-primary);
}
.profile-action-danger:hover {
    background-color: var(--color-danger-light, rgba(177, 53, 53, 0.1));
    color: var(--color-danger);
}

/* 第二行：聚空間 PMS vX.Y.Z / © 2026 聚空間租賃管理顧問有限公司 — 細線分隔，上下兩行排版 */
.brand-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    margin-top: 0.4rem;
    padding: 0.4rem 0.4rem 0.15rem;
    border-top: 1px solid var(--sidebar-border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: var(--text-2xs);
    line-height: 1.3;
    border-radius: 0;
    transition: color var(--transition-fast);
    text-align: center;
}
.brand-row:hover {
    color: var(--text-main);
}
.brand-row:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}
.brand-text {
    font-weight: 500;
    white-space: nowrap;
}
.brand-text #app-version-num {
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    margin-left: 0.15rem;
    letter-spacing: 0.02em;
}
.brand-copy {
    opacity: 0.75;
    font-size: 0.6rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* sidebar collapsed mode：只剩 avatar，brand row 隱藏 */
.sidebar.is-collapsed .user-profile {
    justify-content: center;
    padding: 0.4rem 0;
}
.sidebar.is-collapsed .user-info,
.sidebar.is-collapsed .user-actions,
.sidebar.is-collapsed .brand-row {
    display: none;
}

.sidebar.is-collapsed .sidebar-footer {
    padding: 0.5rem 0.4rem;
}

/* 「關於」彈窗 */
.about-hero {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}
.about-logo {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.about-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.about-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-main);
}
.about-version {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}
.about-section {
    margin-top: 0.5rem;
}
.about-section-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.625rem;
}
.changelog-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 280px;
    overflow-y: auto;
    padding-right: 0.5rem;
}
.changelog-item {
    padding: 0.625rem 0.75rem;
    background: var(--bg-secondary, var(--color-background));
    border-radius: 8px;
}
.changelog-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.25rem;
}
.changelog-head strong {
    color: var(--text-main);
    font-size: 0.875rem;
}
.changelog-date {
    font-size: 0.7rem;
    color: var(--text-muted);
}
.changelog-notes {
    font-size: 0.8rem;
    color: var(--text-main);
    line-height: 1.5;
    opacity: 0.85;
}
.about-footer {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.about-manual-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.85rem;
    background: var(--bg-secondary, var(--color-background));
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.about-manual-link:hover {
    background: rgba(255, 136, 89, 0.08);
    border-color: var(--brand, #ff8859);
    transform: translateY(-1px);
}
.about-manual-link > .ph:first-child {
    font-size: 1.4rem;
    color: var(--brand, #ff8859);
    flex-shrink: 0;
}
.about-manual-link > span {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.about-manual-link > span > strong {
    font-size: 0.9rem;
    font-weight: 600;
}
.about-manual-link > span > small {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.4;
}
.about-manual-link > .ph:last-child {
    color: var(--text-muted);
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar.is-collapsed .user-profile {
    justify-content: center;
    padding: 0.375rem;
}

.sidebar.is-collapsed .user-info,
.sidebar.is-collapsed .user-actions {
    display: none;
}

.sidebar.is-collapsed .user-profile[data-label]:hover::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 0.625rem);
    bottom: 50%;
    transform: translateY(50%);
    background-color: var(--text-main);
    color: var(--text-inverse);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.375rem 0.625rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    pointer-events: none;
    z-index: 100;
    box-shadow: var(--shadow-md);
}


/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* === Topbar === */
.topbar {
    height: var(--topbar-height);
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    z-index: 5;
    gap: 1rem;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.topbar-title {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.page-eyebrow {
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.topbar-left h1 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: -0.01em;
    margin: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.search-bar {
    position: relative;
    width: 320px;
}

.search-bar i {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-bar input {
    width: 100%;
    padding: 0.5625rem 2.5rem 0.5625rem 2.375rem;
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    background-color: var(--color-background);
    outline: none;
    font-family: inherit;
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

.search-bar input:hover {
    background-color: #eef0f3;
}

.search-bar input:focus {
    border-color: var(--color-primary);
    background-color: var(--color-surface);
    box-shadow: var(--shadow-focus);
}

.search-kbd {
    position: absolute;
    right: 0.625rem;
    top: 50%;
    transform: translateY(-50%);
    font-family: 'Outfit', monospace;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    background-color: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.0625rem 0.375rem;
    line-height: 1.4;
    pointer-events: none;
}

.search-bar input:focus ~ .search-kbd { display: none; }

.icon-btn {
    position: relative;
    background: none;
    border: none;
    font-size: 1.125rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
}

.icon-btn:hover {
    color: var(--color-primary);
    background-color: var(--color-primary-light);
}

.icon-btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background-color: var(--color-danger);
    color: var(--text-inverse);
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border: 2px solid var(--color-surface);
    box-sizing: content-box;
}

@media (max-width: 768px) {
    .topbar {
        padding: 0 1rem;
        height: 56px;   /* QW4: 從 54 拉到 56，給 H1 喘息 */
    }
    /* QW4: 手機重新拿掉 breadcrumb (空間珍貴、視覺更乾淨)，反正 sidebar nav 跟 H1 就告訴你在哪 */
    .page-eyebrow {
        display: none !important;
    }
    /* QW4: H1 放大 + 加 weight */
    .topbar-left h1 {
        font-size: 1.125rem;
        font-weight: 600;
        letter-spacing: -0.01em;
    }
    .search-bar {
        width: 180px;
    }
    .search-kbd {
        display: none;
    }
}

@media (max-width: 560px) {
    .search-bar {
        display: none;
    }
}

/* View Container */
.view-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.5rem 2rem;
}

@media (max-width: 768px) {
    .view-container {
        padding: 1rem;
    }
}

.view-section {
    display: none;
    animation: fadeIn var(--transition-normal);
}

.view-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Common Components */

/* Cards */
/* QW3: 卡片改成「無 border + 強化 shadow」，立體感大幅提升 */
.card {
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04), 0 4px 16px -8px rgba(15, 23, 42, 0.08);
    padding: 1.5rem;
    border: none;
    transition: box-shadow var(--transition-normal), transform var(--transition-normal);
}

.card:hover {
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06), 0 8px 24px -8px rgba(15, 23, 42, 0.12);
}

/* A-M-1: 拿掉 metric-card 額外 translateY，避免 dashboard 一片 card 同步抖
   .card:hover 的 shadow + border 已足夠 feedback */

/* card-title — UIUX_AUDIT_CONSISTENCY P1-2: 三處覆寫 + 兩個 !important 整併到這一條
   font-size 走階梯 token (--text-md = 1rem)，原 0.9375rem 太小、L5280 的 !important 1rem 也順勢併入；
   nowrap/ellipsis 從 L6540 拉上來；mobile 額外縮小拿掉，1rem 在手機上仍 OK */
.card-title {
    font-size: var(--text-md);
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
    letter-spacing: -0.005em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-title i {
    color: var(--color-primary);
}

/* Metric Cards */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metric-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.metric-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

/* QW1: metric-icon 統一中性化（取消飽和色塊，色彩留給數字本身）*/
.metric-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    background: var(--bg-tertiary, #f1f5f9);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
/* primary/success/warning/danger/info 變體保留，但只微微染色（避免完全失去語意） */
.metric-icon.primary { color: var(--color-primary); }
.metric-icon.success { color: var(--color-success); }
.metric-icon.warning { color: var(--color-warning); }
.metric-icon.danger  { color: var(--color-danger);  }
.metric-icon.info    { color: var(--color-info);    }

.metric-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.015em;
    font-variant-numeric: tabular-nums;
}

.metric-subtext {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0.01em;
    border: 1px solid transparent;
}

.status-badge.success { background-color: var(--color-success-light); color: var(--color-success); }
/* UIUX #4: badge 文字用較深的 *-text 版本確保 WCAG AA 對比 */
.status-badge.warning { background-color: var(--color-warning-light); color: var(--color-warning-text); }
.status-badge.danger { background-color: var(--color-danger-light); color: var(--color-danger); }
.status-badge.info { background-color: var(--color-info-light); color: var(--color-info); }
.status-badge.primary { background-color: var(--color-primary-light); color: var(--color-primary-text); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5625rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    line-height: 1.25;
    min-height: 38px;
    white-space: nowrap;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.btn:disabled,
.btn.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-primary {
    background-color: var(--color-primary);
    color: var(--text-inverse);
    box-shadow: 0 1px 2px 0 rgba(255, 116, 61, 0.20);
}

.btn-primary:hover {
    background-color: var(--color-primary-hover);
    box-shadow: 0 8px 16px -6px rgba(255, 116, 61, 0.45);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px 0 rgba(255, 116, 61, 0.20);
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: var(--color-background);
    border-color: var(--border-strong);
}

.btn-outline.btn-danger-outline,
.btn-danger-outline {
    background-color: transparent;
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.btn-danger-outline:hover {
    background-color: var(--color-danger-light);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    min-height: 32px;
}

/* Tables */
.table-container {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    text-align: left;
}

.data-table th {
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-color);
    background-color: #fafbfc;
    text-align: left;
    white-space: nowrap;
}

.data-table th:first-child { border-top-left-radius: var(--radius-md); }
.data-table th:last-child { border-top-right-radius: var(--radius-md); }

/* 可點擊排序的表頭 */
.data-table th.sortable-col {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.1s;
}
.data-table th.sortable-col:hover {
    background-color: #f1f5f9;
    color: var(--text-main);
}

.data-table td {
    padding: 0.875rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    color: var(--text-main);
}

.data-table tbody tr {
    transition: background-color var(--transition-fast);
}

.data-table tbody tr:hover {
    background-color: var(--sidebar-item-hover-bg);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table .empty-state {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.data-table .empty-state i {
    font-size: 2rem;
    display: block;
    margin-bottom: 0.5rem;
    color: var(--border-strong);
}

/* Flex utilities */
.flex { display: flex; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }

/* Grid layouts for specific views */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.dashboard-grid .chart-card {
    grid-column: span 2;
}

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .dashboard-grid .chart-card {
        grid-column: span 1;
    }
}

/* === Segmented control (canonical) ===
   .filter-tab 是基準樣式；.chart-mode-btn / .property-filter-btn 視覺一樣，
   一起共用同條規則 (P0-3 audit) — 之後改一處所有 segmented 都跟著走 */
.filter-tabs,
.chart-mode-toggle {
    display: flex;
    gap: 0.375rem;
    flex-wrap: wrap;
    padding: 0.25rem;
    background-color: var(--color-background);
    border-radius: var(--radius-md);
    width: fit-content;
}

.filter-tab,
.chart-mode-btn,
.property-filter-btn {
    background: none;
    border: none;
    padding: 0.4375rem 0.875rem;
    border-radius: calc(var(--radius-md) - 2px);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    line-height: 1.4;
    white-space: nowrap;
}

.filter-tab:hover,
.chart-mode-btn:hover,
.property-filter-btn:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.6);
}

.filter-tab.active,
.chart-mode-btn.active,
.property-filter-btn.active {
    background-color: var(--color-surface);
    color: var(--color-primary);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* 手機：filter-tabs 改水平捲動，不要 wrap 成多行擠醜
   (P1-mobile-#1, #2) tabs 太多時直接橫滑，符合手機資料表 pattern */
@media (max-width: 768px) {
    .filter-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        max-width: 100%;
        width: 100%;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .filter-tabs::-webkit-scrollbar { display: none; }
    .filter-tab,
    .chart-mode-btn,
    .property-filter-btn,
    .filter-tab-label {
        flex-shrink: 0;
        white-space: nowrap;
    }
}

/* 篩選列前面的「館別 / 狀態」標籤 */
.filter-tab-label {
    display: inline-flex;
    align-items: center;
    padding: 0 0.5rem;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    user-select: none;
}

/* 該館 0 筆 → 淡化 chip */
.filter-tab.is-empty {
    opacity: 0.45;
    cursor: default;
}
.filter-tab.is-empty:hover {
    background: transparent;
    color: var(--text-muted);
}

/* === 小幫手 (helper) — 唯讀模式：隱藏所有寫入按鈕 ===
   邏輯：app.js boot 拿到 role 後 set body[data-role]，這層 CSS 純視覺隱藏
   被隱藏範圍：建立/新增 主按鈕、表格列尾的編輯/刪除/匯出/付款按鈕、FAB
   注意：依然能瀏覽、開詳細視窗（檢視類按鈕保留）*/
body[data-role="helper"] [data-fab] { display: none !important; }
body[data-role="helper"] .mobile-fab { display: none !important; }
body[data-role="helper"] [id^="btn-new-"] { display: none !important; }
body[data-role="helper"] [id^="btn-add-"] { display: none !important; }
body[data-role="helper"] [id^="btn-import"] { display: none !important; }
body[data-role="helper"] [id^="btn-export"] { display: none !important; }
body[data-role="helper"] [id^="btn-ask-"] { display: none !important; }
body[data-role="helper"] [id^="btn-gen-"] { display: none !important; }
body[data-role="helper"] [id^="btn-bulk-"] { display: none !important; }
/* 表格列尾的 操作 td 整欄隱藏 (含編輯/刪除/付款/匯出/查驗)
   ⚠ 住房一覽 (.occ-table) 排除 — 它的最後一欄是月份格 (本月橘色)，不能誤刪
   ⚠ 住房一覽的「退房」欄 = 第 4 欄，另外針對 .occ-table 處理 */
body[data-role="helper"] .data-table:not(.occ-table) thead th:last-child,
body[data-role="helper"] .data-table:not(.occ-table) tbody td:last-child {
    display: none !important;
}
/* 住房一覽 退房欄 = 第 4 欄，hide for helper (床位/房客/備註/月份 都保留) */
body[data-role="helper"] .occ-table thead th:nth-child(4),
body[data-role="helper"] .occ-table tbody td:nth-child(4) {
    display: none !important;
}
/* 顯式標 data-write="1" 的按鈕 (其他地方寫入按鈕的逃生口) */
body[data-role="helper"] [data-write] { display: none !important; }
/* 住房一覽 — 入住按鈕 + 退房 checkbox 隱藏 (helper 不能寫入這些) */
body[data-role="helper"] .occ-checkin-btn,
body[data-role="helper"] .occ-terminate-check { display: none !important; }
/* 床位 / 租客 link / 備註 都還是可點 — 備註可編輯、床位/租客是 read-only 詳細視窗 */
/* === 續租意願通知 banner === */
.renew-intent-banner {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1.1rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, rgba(34, 148, 110, 0.08), rgba(34, 148, 110, 0.03));
    border: 1px solid rgba(34, 148, 110, 0.25);
    border-left: 3px solid var(--color-success);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}
.renew-intent-banner:hover {
    background: linear-gradient(135deg, rgba(34, 148, 110, 0.12), rgba(34, 148, 110, 0.06));
    transform: translateX(2px);
}
.renew-intent-banner-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(34, 148, 110, 0.15);
    color: var(--color-success);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.renew-intent-banner-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.renew-intent-banner-body strong {
    font-size: 0.92rem;
    color: var(--text-main);
}
.renew-intent-banner-body small {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* === filter-bar：tabs 左、進階篩選 chip 右 === */
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.3rem 0.75rem;
    background: transparent;
    border: 1px dashed rgba(184, 135, 31, 0.45);
    border-radius: 999px;
    font-size: 0.78rem;
    color: var(--color-warning);
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.filter-chip:hover {
    background: rgba(184, 135, 31, 0.08);
    border-style: solid;
}
.filter-chip.active {
    background: rgba(184, 135, 31, 0.12);
    border-color: var(--color-warning);
    border-style: solid;
    font-weight: 600;
}
.filter-chip-count {
    background: rgba(184, 135, 31, 0.18);
    color: var(--color-warning-text);
    font-size: var(--text-xs);
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    font-weight: 600;
    min-width: 1.2rem;
    text-align: center;
}
.filter-chip.active .filter-chip-count {
    background: var(--color-warning);
    color: white;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* UIUX #1: 帳務管理 sub-tabs (3 個子頁共用) */
.finance-sub-tabs {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}
.finance-sub-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-muted);
    font-size: var(--text-base);
    font-weight: 500;
    transition: background-color 0.15s, color 0.15s;
    white-space: nowrap;
}
.finance-sub-tab:hover:not(.is-active) {
    background: rgba(0,0,0,0.04);
    color: var(--text-main);
}
.finance-sub-tab.is-active {
    background: white;
    color: var(--color-primary-text);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}
.finance-sub-tab i {
    font-size: 1.05rem;
}
@media (max-width: 640px) {
    .finance-sub-tab .fst-label { display: none; }
    /* 手機: 跟其他 filter 列一致改水平捲動 (P1-3 audit)
       3 個 sub-tab 一般會 fit，但有 icon-only / label 切換時防擠掉 */
    .finance-sub-tabs {
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .finance-sub-tabs::-webkit-scrollbar { display: none; }
    .finance-sub-tab {
        flex-shrink: 0;
        flex-basis: auto;
    }
}

/* 升級版分頁 (P1-9) */
.pg-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
    font-size: 0.85rem;
    color: var(--text-main);
}
.pg-info {
    color: var(--text-muted);
    margin-right: 0.5rem;
}
.pg-arrow, .pg-num {
    min-width: 32px;
    height: 32px;
    padding: 0 0.5rem;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    color: var(--text-main);
    transition: background 0.1s;
}
.pg-arrow:hover:not(:disabled), .pg-num:hover:not(.pg-active) {
    background: #f1f5f9;
}
.pg-arrow:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.pg-num.pg-active {
    background: var(--color-primary, #4f46e5);
    color: white;
    border-color: var(--color-primary, #4f46e5);
    font-weight: 600;
    cursor: default;
}
.pg-ellipsis {
    color: var(--text-muted);
    padding: 0 0.25rem;
}
.pg-size {
    margin-left: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}
.pg-size select {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 0.8rem;
    background: white;
    cursor: pointer;
}

.pagination-info {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(17, 24, 39, 0.55);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    animation: modalOverlayIn var(--transition-normal);
}

@keyframes modalOverlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* === 區間選擇器 (報表頁頂部) === */
.range-picker {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    background: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.55rem 0.85rem;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}
.range-picker-presets {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    position: relative;
}
.range-picker-icon {
    color: var(--color-primary);
    font-size: 1.15rem;
}
.range-picker-preset-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.7rem;
    border-radius: 8px;
    background: var(--bg-secondary, #f6f8fa);
    color: var(--text-main);
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.range-picker-preset-trigger:hover {
    background: rgba(255, 136, 89, 0.08);
}
.range-picker-preset-trigger .ph-caret-down {
    font-size: 0.7rem;
    color: var(--text-muted);
}
.range-picker-preset-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    background: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    padding: 0.35rem;
    z-index: 50;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.2rem;
    min-width: 240px;
}
/* 重要: HTML hidden 屬性預設是 display:none，被上面的 display:grid 蓋掉 → 強制覆寫 */
.range-picker-preset-panel[hidden] {
    display: none !important;
}
.rp-preset-option {
    background: none;
    border: none;
    text-align: left;
    padding: 0.45rem 0.7rem;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-main);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.12s;
}
.rp-preset-option:hover {
    background: rgba(255, 136, 89, 0.1);
}
.rp-preset-option.is-active {
    background: var(--color-primary, #ff8859);
    color: white;
    font-weight: 600;
}
.range-picker-dates {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding-left: 0.85rem;
    border-left: 1px solid var(--border-color);
}
.rp-date {
    border: 1px solid var(--border-color);
    border-radius: 7px;
    padding: 0.32rem 0.55rem;
    font-size: 0.85rem;
    background: var(--color-surface);
    color: var(--text-main);
    font-family: inherit;
}
.rp-date:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(255, 136, 89, 0.12);
}
.rp-sep {
    color: var(--text-muted);
    font-size: 0.85rem;
}
/* 手機: 上下排列 + 寬度限縮 (P1-mobile-#4) */
@media (max-width: 640px) {
    .range-picker {
        gap: 0.5rem;
        padding: 0.5rem 0.7rem;
        max-width: 100%;
        box-sizing: border-box;
    }
    .range-picker-presets {
        flex-wrap: wrap;
        max-width: 100%;
    }
    .range-picker-dates {
        padding-left: 0;
        border-left: none;
        border-top: 1px dashed var(--border-color);
        padding-top: 0.5rem;
        width: 100%;
        justify-content: center;
        gap: 0.5rem;
    }
    .rp-date {
        flex: 0 1 auto;
        min-width: 0;
        font-size: 0.8rem;
        padding: 0.32rem 0.45rem;
    }
    .range-picker-preset-panel {
        grid-template-columns: 1fr 1fr;     /* 2 欄而非 3 欄，避免溢出 */
        min-width: 0;
        width: max-content;
        max-width: calc(100vw - 2rem);
        left: 0;
    }
}

/* === 報表 hub Tab 列 (monochrome — 唯一 brand 色保留給「active 文字」) === */
.reports-hub-tabs {
    display: flex;
    gap: 0.15rem;
    margin: 1rem 0 1rem;
    background: var(--surface-warm);
    border-radius: 12px;
    padding: 0.25rem;
    border: 1px solid var(--border-soft);
    box-shadow: none;
    overflow-x: auto;
    scrollbar-width: none;
}
.reports-hub-tabs::-webkit-scrollbar { display: none; }
.reports-hub-tab {
    flex: 1 1 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    border: none;
    background: none;
    font-family: inherit;
    cursor: pointer;
}
.reports-hub-tab:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text-main);
}
.reports-hub-tab.is-active {
    background: var(--color-surface);
    color: var(--color-primary-text);
    box-shadow: 0 1px 2px rgba(17,24,39,0.06);
}
.reports-hub-tab i { font-size: 1rem; }
@media (max-width: 640px) {
    .reports-hub-tab {
        padding: 0.55rem 0.65rem;
        font-size: 0.8rem;
    }
}

/* === 總覽 KPI 卡片組 === */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}
@media (max-width: 900px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
.kpi-card {
    background: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1rem 1.15rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.15s;
}
.kpi-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.kpi-card-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.04em;
    margin-bottom: 0.35rem;
}
.kpi-card-label .ph {
    font-size: 0.95rem;
}
.kpi-card-value {
    font-size: 1.65rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
}
.kpi-card-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}
.kpi-card-accent {
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
}
.kpi-accent-income { background: var(--color-success, #22946e); }
.kpi-accent-paid { background: var(--color-primary, #ff8859); }
.kpi-accent-net { background: #3b82f6; }
.kpi-accent-occ { background: #8b5cf6; }

/* === 報表圖表卡片 === */
.report-chart-card {
    background: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1rem 1.15rem 1.25rem;
    box-shadow: var(--shadow-sm);
}
.report-chart-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}
.report-chart-title .ph {
    color: var(--color-primary);
    font-size: 1.05rem;
}
.report-chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
@media (max-width: 900px) {
    .report-chart-grid { grid-template-columns: 1fr; }
}

/* 水平條形圖（用 div 拼 — 不引入 Chart.js） */
.bar-chart-row {
    display: grid;
    grid-template-columns: 90px 1fr 100px;
    align-items: center;
    gap: 0.6rem;
    padding: 0.35rem 0;
    font-size: 0.83rem;
}
.bar-chart-label {
    color: var(--text-secondary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bar-chart-bar-wrap {
    background: var(--bg-tertiary, #f1f5f9);
    border-radius: 99px;
    height: 14px;
    overflow: hidden;
    position: relative;
}
.bar-chart-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), #ffb985);
    border-radius: 99px;
    transition: width 0.4s ease-out;
}
.bar-chart-value {
    text-align: right;
    color: var(--text-main);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Donut 圖（純 CSS conic-gradient） */
.donut-chart-wrap {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}
.donut-chart {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.donut-chart::after {
    content: '';
    position: absolute;
    width: 78px;
    height: 78px;
    background: var(--color-surface);
    border-radius: 50%;
}
.donut-chart-center {
    position: relative;
    z-index: 2;
    text-align: center;
    line-height: 1.1;
}
.donut-chart-center-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
}
.donut-chart-center-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.donut-chart-legend {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
}
.donut-legend-item {
    display: grid;
    grid-template-columns: 14px 1fr auto;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}
.donut-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}
.donut-legend-label {
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.donut-legend-value {
    color: var(--text-main);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* === 各館子標籤列 (monochrome — active = 深底白字) === */
.bldg-subtab-row {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    padding-bottom: 0.4rem;
    margin-bottom: 1rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.bldg-subtab-row::-webkit-scrollbar { display: none; }
.bldg-subtab {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    background: var(--color-surface);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
}
.bldg-subtab:hover {
    background: var(--surface-warm);
    color: var(--text-main);
}
.bldg-subtab.is-active {
    background: rgba(255, 136, 89, 0.12);
    color: var(--color-primary-text);
    border-color: rgba(255, 136, 89, 0.35);
    box-shadow: none;
}
.bldg-subtab i { font-size: 1rem; }

/* === 館別 Hero (單館頁面上方) — 純白 + brand 細左邊條 === */
.bldg-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.15rem;
    background: var(--color-surface);
    border: 1px solid var(--border-soft);
    border-left: 3px solid var(--color-primary);
    border-radius: 12px;
    margin-bottom: 1rem;
    box-shadow: none;
}
.bldg-hero-info h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.01em;
}
.bldg-hero-info p {
    margin: 0.2rem 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* === 大數字 stat tile — flat / monochrome / 數字黑色 === */
.stat-tile-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}
@media (max-width: 900px) {
    .stat-tile-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
}
.stat-tile {
    background: var(--color-surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 1rem 1.15rem;
    box-shadow: none;
    position: relative;
    overflow: hidden;
    transition: background 0.15s, border-color 0.15s;
}
/* P1-5 audit: stat-tile / connector-card / report-chart-card hover 跟全站 .card:hover 對齊
   (原本 reports 系列用 surface-warm 背景，其他頁用 shadow，視覺不一致) */
.stat-tile:hover {
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06), 0 8px 24px -8px rgba(15, 23, 42, 0.12);
    border-color: var(--border-strong);
}
.stat-tile-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}
.stat-tile-label .ph {
    font-size: 0.9rem;
    color: var(--text-muted);
}
.stat-tile-value {
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    letter-spacing: -0.015em;
}
.stat-tile-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.45rem;
}
@media (max-width: 640px) {
    .stat-tile-value { font-size: 1.4rem; }
    .stat-tile { padding: 0.85rem 0.95rem; }
}

/* === 收入 vs 支出 對照卡片 — flat / monochrome / 數字黑色 / 細 6px bar === */
.io-compare-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
@media (max-width: 900px) {
    .io-compare-grid { grid-template-columns: 1fr; }
}
.io-card {
    background: var(--color-surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 1rem 1.15rem;
    box-shadow: none;
    position: relative;
    overflow: hidden;
}
.io-card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-soft);
}
.io-card-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.io-card-title .ph { color: var(--text-muted); }
.io-card-total {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.015em;
}

.io-row {
    display: grid;
    grid-template-columns: 110px 1fr 110px;
    align-items: center;
    gap: 0.6rem;
    padding: 0.35rem 0;
}
@media (max-width: 480px) {
    .io-row { grid-template-columns: 80px 1fr 90px; gap: 0.4rem; }
}
.io-row-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.io-row-bar {
    background: var(--surface-sunken);
    border-radius: 99px;
    height: 6px;
    overflow: hidden;
}
.io-row-bar-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.4s ease-out;
}
.io-row-bar-fill.is-income { background: var(--color-success); }
.io-row-bar-fill.is-expense { background: var(--color-danger); }

/* === Stacked bar (Tab 1: 各館應收 vs 已收) === */
.stacked-bar-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.stacked-bar-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.stacked-bar-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.stacked-bar-label {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-main);
}
.stacked-bar-rate {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    font-variant-numeric: tabular-nums;
}
.stacked-bar-rate.good { background: rgba(34, 148, 110, 0.1); color: var(--color-success); }
.stacked-bar-rate.mid { background: rgba(184, 135, 31, 0.12); color: var(--color-warning-text); }
.stacked-bar-rate.bad { background: rgba(177, 53, 53, 0.1); color: var(--color-danger); }
.stacked-bar-track {
    background: var(--surface-sunken);
    border-radius: 99px;
    height: 10px;
    overflow: hidden;
    min-width: 60px;
}
.stacked-bar-paid {
    background: var(--color-success);
    height: 100%;
    border-radius: 99px;
    transition: width 0.5s ease-out;
}
.stacked-bar-vals {
    display: flex;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    flex-wrap: wrap;
}
.sb-val-paid { color: var(--text-main); font-weight: 600; }
.sb-val-out { color: var(--color-danger); font-weight: 600; }
.sb-val-total { color: var(--text-muted); }

/* === 左右並排圖表容器 (Tab 3: 圓餅 + 柱狀) === */
.charts-side-by-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
@media (max-width: 900px) {
    .charts-side-by-side { grid-template-columns: 1fr; }
}

/* === 圓餅圖 (Tab 3 支出結構，Chart.js doughnut) === */
.pie-chart-wrap {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}
.pie-chart-canvas-wrap {
    width: 220px;
    height: 220px;
    flex-shrink: 0;
    position: relative;
}
.pie-chart-legend {
    flex: 1;
    min-width: 160px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 220px;
    overflow-y: auto;
}
.pie-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.pie-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}
.pie-legend-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    min-width: 0;
}
.pie-legend-label {
    font-size: 0.82rem;
    color: var(--text-main);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pie-legend-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* 圖表 hover tooltip 已下架 — Chart.js 內建 tooltip 取代 (dashboard + reports 共用) */

/* === Pareto Tiles (Tab 3) — 寬度依金額比例 === */
.pareto-summary-mini {
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
    letter-spacing: 0.02em;
}
.pareto-summary-mini strong {
    color: var(--color-primary-text);
    font-size: 1.05rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin: 0 0.15rem;
}
.pareto-tiles {
    display: flex;
    gap: 4px;
    width: 100%;
    border-radius: 10px;
    overflow: hidden;
    min-height: 110px;
}
.pareto-tile {
    flex: 1 1 0;
    min-width: 70px;
    padding: 0.7rem 0.65rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.3rem;
    background: var(--surface-sunken);
    color: var(--text-secondary);
    overflow: hidden;
    transition: filter 0.15s, transform 0.15s;
    border-radius: 6px;
}
.pareto-tile:hover { transform: translateY(-1px); filter: brightness(0.97); }
.pareto-tile.is-key {
    background: linear-gradient(135deg, var(--color-primary), #ff743d);
    color: #fff;
}
.pareto-tile-pct {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}
.pareto-tile-label {
    font-size: 0.78rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pareto-tile.is-key .pareto-tile-label { color: rgba(255,255,255,0.95); }
.pareto-tile-amount {
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
    opacity: 0.8;
}
@media (max-width: 640px) {
    .pareto-tiles { flex-wrap: wrap; }
    .pareto-tile { min-width: 100px; flex-basis: calc(50% - 2px); }
    .pareto-tile-pct { font-size: 1.2rem; }
}

/* === Connector card (Tab 2: 引導到其他頁面) === */
.connector-card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1.1rem;
    background: var(--color-surface);
    border: 1px solid var(--border-soft);
    border-left: 3px solid var(--color-warning);
    border-radius: 10px;
    margin-bottom: 1rem;
    transition: background 0.15s;
}
.connector-card:hover {
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06), 0 8px 24px -8px rgba(15, 23, 42, 0.12);
    border-color: var(--border-strong);
}
.connector-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(184, 135, 31, 0.12);
    color: var(--color-warning-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}
.connector-card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}
.connector-card-body strong {
    font-size: 0.9rem;
    color: var(--text-main);
}
.connector-card-body small {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.connector-card-link {
    color: var(--color-primary-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    transition: background 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.connector-card-link:hover { background: rgba(255, 136, 89, 0.1); }

/* === 報表警告卡 (Tab 3: 房東租金 0% 偵測) === */
.report-warning-card {
    display: flex;
    gap: 0.85rem;
    padding: 1rem 1.15rem;
    background: rgba(184, 135, 31, 0.08);
    border: 1px solid rgba(184, 135, 31, 0.3);
    border-left: 3px solid var(--color-warning);
    border-radius: 10px;
    margin-bottom: 1rem;
}
.report-warning-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(184, 135, 31, 0.2);
    color: var(--color-warning-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.report-warning-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
}
.report-warning-body strong {
    font-size: 0.92rem;
    color: var(--color-warning-text);
}
.report-warning-body small {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.5;
}
.report-warning-types {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.4rem;
}
.report-warning-type {
    padding: 0.2rem 0.55rem;
    background: var(--color-surface);
    border: 1px solid var(--border-soft);
    border-radius: 99px;
    font-size: 0.72rem;
    color: var(--text-main);
    font-weight: 500;
}

/* === 報表資訊條 (房東租金偵測成功時) — 極簡 1 行 === */
.report-info-card {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.85rem;
    background: rgba(34, 148, 110, 0.06);
    border: 1px solid rgba(34, 148, 110, 0.2);
    border-left: 3px solid var(--color-success);
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
}
.report-info-icon-inline {
    color: var(--color-success);
    font-size: 1rem;
    flex-shrink: 0;
}
.report-info-card strong {
    color: var(--text-main);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.report-info-type {
    display: inline-block;
    padding: 0.08rem 0.4rem;
    background: var(--color-surface);
    border: 1px solid var(--border-soft);
    border-radius: 99px;
    font-size: 0.7rem;
    color: var(--text-main);
    font-weight: 500;
    margin: 0 0.15rem;
}

/* === Bar 目標虛線 (Tab 2: 出租率 95% 目標) === */
.bar-target-line {
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 2px;
    border-left: 2px dashed var(--text-muted);
    opacity: 0.5;
    transform: translateX(-1px);
}

/* === 月度入住/退租圖跟一般 trend 共用 .trend-chart-wrap === */

/* === 報表表格 (Tab 2 床位 / 即將到期 / Tab 3 P&L) === */
.report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.report-table thead th {
    text-align: left;
    padding: 0.55rem 0.7rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-soft);
    background: var(--surface-warm);
}
.report-table tbody td {
    padding: 0.6rem 0.7rem;
    border-bottom: 1px solid var(--border-soft);
    color: var(--text-main);
}
.report-table tbody tr:hover { background: var(--surface-warm); }
.report-table tbody tr:last-child td { border-bottom: none; }
.report-pnl-table .pnl-total-row td {
    border-top: 2px solid var(--text-main);
    border-bottom: none;
    background: var(--surface-warm);
}
/* 手機: P&L 表 7 欄硬塞會把館別名字擠成直行
   做法: 整個表撐成 max-content 走外層 overflow-x scroll，cell 一律 nowrap (P1-mobile-#6) */
@media (max-width: 768px) {
    .report-pnl-table {
        width: max-content;
        min-width: 100%;
    }
    .report-pnl-table th,
    .report-pnl-table td {
        white-space: nowrap;
        padding: 0.55rem 0.7rem;
    }
}

/* 床位狀態 badge */
.bed-status {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 600;
}
.bed-status.is-rented { background: rgba(34, 148, 110, 0.1); color: var(--color-success); }
.bed-status.is-vacant { background: rgba(184, 135, 31, 0.12); color: var(--color-warning-text); }

/* report-chart-card title 加 flex 排版 */
.report-chart-card {
    background: var(--color-surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 1rem 1.15rem 1.15rem;
    box-shadow: none;
    margin-bottom: 1rem;
}
.report-chart-title {
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.45rem;
}
.report-chart-title > span:first-child {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}
.report-chart-title .ph {
    color: var(--text-muted);
    font-size: 1rem;
}
.io-row-amount {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.15;
}
.io-row-amount strong {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
}
.io-row-pct {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}
.io-empty {
    padding: 1.5rem 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* 月度趨勢折線圖 (Chart.js canvas — 需要明確高度) */
.trend-chart-wrap {
    width: 100%;
    height: 260px;
    position: relative;
}

.modal-content {
    background-color: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    /* dvh = 動態 viewport，鍵盤彈出時自動縮，避免 modal 內 input 被遮到拉不回 (P1 mobile follow-up #4) */
    max-height: 85dvh;
    /* 改成 flex 容器 — 讓 header / body / footer 分層，只有 body 內部捲動 */
    display: flex;
    flex-direction: column;
    overflow: hidden;     /* 圓角不會被 scrollbar 切掉 */
    animation: modalContentIn var(--transition-normal);
}

@keyframes modalContentIn {
    from { opacity: 0; transform: translateY(8px) scale(0.99); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* 折扣 / 加收 分段切換按鈕（取代醜醜的 native <select>) */
.adj-kind-toggle {
    display: inline-flex;
    background: var(--bg-tertiary, #f1f5f9);
    border-radius: 6px;
    padding: 2px;
    gap: 0;
    border: 1px solid var(--border-color);
}
.adj-kind-btn {
    border: none;
    background: transparent;
    padding: 0.32rem 0.5rem;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    font-family: inherit;
    white-space: nowrap;
    flex: 1;
    text-align: center;
}
.adj-kind-btn:hover {
    color: var(--text-main);
    background: rgba(0,0,0,0.03);
}
.adj-kind-btn.is-active {
    color: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.adj-kind-btn.is-active[data-kind="sub"] {
    background: var(--color-danger, #b13535);
}
.adj-kind-btn.is-active[data-kind="add"] {
    background: var(--color-success, #22946e);
}

/* 編輯中誤點外面：modal 震動提醒 + 邊框閃一下橘色 (lockOutsideClose) */
.modal-content.modal-shake {
    animation: modalShake 0.4s cubic-bezier(.36,.07,.19,.97) both;
    box-shadow: 0 0 0 3px rgba(255, 136, 89, 0.35), 0 18px 48px -12px rgba(0,0,0,0.25);
}
@keyframes modalShake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-6px); }
    40%, 60% { transform: translateX(6px); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    gap: 1rem;
    flex-shrink: 0;   /* header 不被擠壓 */
}

.modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

/* modal subtitle — 動態插在 h3 之後 (例: 新增合約 "將建立合約編號 C100·...")
   audit QW-5: 拆 inline style 到 CSS class */
.modal-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-weight: 400;
    line-height: 1.4;
}
.modal-subtitle .mono {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-secondary);
    font-weight: 600;
    letter-spacing: 0.02em;
}
.modal-subtitle__faded {
    opacity: 0.7;
}

.modal-close {
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.modal-close:hover {
    background-color: var(--color-background);
    color: var(--text-main);
}

.modal-body {
    padding: 1.5rem;
    flex: 1 1 auto;       /* 吃掉剩餘高度 */
    overflow-y: auto;     /* 只有 body 捲動 */
    min-height: 0;        /* flex 子元素能正確壓縮 */
}
/* 細緻一點的捲動條樣式 */
.modal-body::-webkit-scrollbar {
    width: 8px;
}
.modal-body::-webkit-scrollbar-track {
    background: transparent;
}
.modal-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

.property-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.detail-item label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detail-item span {
    font-size: 0.875rem;
    color: var(--text-main);
}

/* Form Styles */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.form-input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--color-surface);
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--text-main);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.form-input:hover:not(:focus):not(:disabled) {
    border-color: var(--border-strong);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--shadow-focus);
}

.form-input:disabled {
    background-color: var(--color-background);
    color: var(--text-muted);
    cursor: not-allowed;
}

.form-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.form-section h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Todo Cards Grid - Three columns for contracts, finance, maintenance */
.todo-cards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-top: 0;
}

@media (max-width: 1024px) {
    .todo-cards-grid {
        grid-template-columns: 1fr;
    }
}

/* === Settings page === */
.settings-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0;
}

.settings-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all var(--transition-fast);
}

.settings-tab:hover {
    color: var(--text-main);
}

.settings-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.settings-tab i {
    font-size: 1.1rem;
}

.settings-content {
    animation: fadeIn 0.2s ease;
}

/* === 房間/床位管理 modal === */
.rooms-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 0.75rem;
}

.rooms-stats {
    font-size: 0.875rem;
    color: var(--text-main);
}

.rooms-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.room-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    overflow: hidden;
}

.room-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--color-background);
    border-bottom: 1px solid var(--border-color);
    gap: 0.75rem;
    flex-wrap: wrap;
}

.bed-list {
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.bed-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: background-color var(--transition-fast);
}

.bed-row:hover {
    background-color: var(--color-background);
}

.bed-letter {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background-color: var(--color-primary-light);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.bed-main {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex-wrap: wrap;
}

.bed-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: none;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    transition: all var(--transition-fast);
}

.bed-add-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background-color: var(--color-primary-light);
}

/* 停用館別整列降低不透明度 */
.inactive-row {
    opacity: 0.5;
}

.inactive-row strong {
    text-decoration: line-through;
    text-decoration-color: var(--text-muted);
}

/* === 查帳橫條 (dashboard) === */
.check-banner {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid;
}

.check-banner.urgent {
    background: linear-gradient(135deg, rgba(255, 136, 89, 0.08), rgba(255, 116, 61, 0.04));
    border-color: var(--color-primary);
}

.check-banner.soft {
    background-color: var(--color-background);
    border-color: var(--border-color);
}

.check-banner-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background-color: var(--color-primary);
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.check-banner.soft .check-banner-icon {
    background-color: var(--color-surface);
    color: var(--color-primary);
    border: 1px solid var(--border-color);
}

.check-banner-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    line-height: 1.4;
    min-width: 0;
}

.check-banner-body strong {
    font-size: 1rem;
}

.check-banner-body span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* === 銀行末 5 碼徽章 === */
.bank-last5-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.55rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid;
}

.bank-last5-badge.pending {
    background-color: var(--color-warning-light);
    color: var(--color-warning);
    border-color: rgba(184, 135, 31, 0.3);
}

.bank-last5-badge.verified {
    background-color: var(--color-success-light);
    color: var(--color-success);
    border-color: rgba(34, 148, 110, 0.3);
}

.bank-last5-badge i {
    font-size: 0.9rem;
}

.bank-last5-badge strong {
    letter-spacing: 0.1em;
}

/* 待核對列 hover 強調 */
tr.is-await-verify-row {
    background-color: rgba(184, 135, 31, 0.03);
}
tr.is-await-verify-row:hover {
    background-color: rgba(184, 135, 31, 0.08);
}

/* metric 卡黃色強調 */
.metric-card.highlight-warning {
    border: 1px solid var(--color-warning);
    background: linear-gradient(180deg, rgba(184, 135, 31, 0.04) 0%, transparent 100%);
}

/* === 合約生命週期視覺 === */
.is-decision-row {
    background-color: rgba(177, 53, 53, 0.04);
}
.is-decision-row:hover {
    background-color: rgba(177, 53, 53, 0.08);
}
.is-archived-row {
    opacity: 0.65;
}
.is-archived-row strong {
    color: var(--text-muted);
}

/* metric 卡片紅色強調 (待決策) */
.metric-card.highlight-danger {
    border: 1px solid var(--color-danger);
    background: linear-gradient(180deg, rgba(177, 53, 53, 0.04) 0%, transparent 100%);
}

/* === 本月分類分析交叉表 === */
.matrix-wrap {
    overflow-x: auto;
}

.matrix-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
}

.matrix-table th,
.matrix-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    text-align: right;
    white-space: nowrap;
}

.matrix-table thead th {
    background-color: var(--color-background);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.matrix-table th.m-type,
.matrix-table td.m-type {
    text-align: left;
    color: var(--text-main);
    font-weight: 500;
    position: sticky;
    left: 0;
    background-color: var(--color-surface);
}

.matrix-table th.m-total,
.matrix-table td.m-total {
    background-color: var(--color-background);
    font-weight: 600;
    color: var(--text-main);
    border-left: 1px solid var(--border-color);
}

/* 收入區段 header — 綠色帶 */
.matrix-table tr.m-section-row.is-income td {
    background-color: rgba(34, 148, 110, 0.10);
    color: var(--color-success);
    font-weight: 700;
    font-size: 0.78rem;
    text-align: left;
    padding: 0.55rem 0.85rem;
    letter-spacing: 0.04em;
    border-top: 2px solid rgba(34, 148, 110, 0.35);
    border-bottom: 1px solid rgba(34, 148, 110, 0.25);
}
/* 支出區段 header — 紅色帶 */
.matrix-table tr.m-section-row.is-expense td {
    background-color: rgba(177, 53, 53, 0.08);
    color: var(--color-danger);
    font-weight: 700;
    font-size: 0.78rem;
    text-align: left;
    padding: 0.55rem 0.85rem;
    letter-spacing: 0.04em;
    border-top: 3px solid rgba(177, 53, 53, 0.35);
    border-bottom: 1px solid rgba(177, 53, 53, 0.25);
}
/* 收入小計 */
.matrix-table tr.m-subtotal.is-income td {
    background-color: rgba(34, 148, 110, 0.05);
    border-top: 1px dashed rgba(34, 148, 110, 0.4);
    border-bottom: 2px solid rgba(34, 148, 110, 0.45);
}
/* 支出小計 */
.matrix-table tr.m-subtotal.is-expense td {
    background-color: rgba(177, 53, 53, 0.05);
    border-top: 1px dashed rgba(177, 53, 53, 0.4);
    border-bottom: 2px solid rgba(177, 53, 53, 0.45);
}
/* fallback (沒有 is-income/is-expense class 時) */
.matrix-table tr.m-section-row td {
    background-color: var(--color-background);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-align: left;
    padding: 0.5rem 0.75rem;
    letter-spacing: 0.05em;
}
.matrix-table tr.m-subtotal td {
    background-color: var(--color-background);
    border-top: 2px solid var(--border-strong);
}

/* 淨收益 — 冷色調 slate，跟收入綠 / 支出紅做出清楚區隔 */
.matrix-table tr.m-net-row td {
    background-color: rgba(51, 65, 85, 0.08);
    border-top: 2px solid rgb(71, 85, 105);
    border-bottom: 2px solid rgb(71, 85, 105);
    font-size: 1rem;
    padding-top: 0.85rem;
    padding-bottom: 0.85rem;
}
.matrix-table tr.m-net-row td.m-type {
    color: rgb(30, 41, 59);
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* 率類 — 不再加底色，純素淨灰字 */
.matrix-table tr.m-margin-row td {
    background-color: transparent;
    font-size: 0.82rem;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.matrix-table tr.m-margin-row td.m-type {
    color: var(--text-muted);
    font-weight: 500;
}

/* sticky 類型欄底色要跟隨 row 變化（覆蓋通用 m-type 背景） */
.matrix-table tr.m-section-row.is-income td.m-type { background-color: rgba(34, 148, 110, 0.10); }
.matrix-table tr.m-section-row.is-expense td.m-type { background-color: rgba(177, 53, 53, 0.08); }
.matrix-table tr.m-subtotal.is-income td.m-type { background-color: rgba(34, 148, 110, 0.05); }
.matrix-table tr.m-subtotal.is-expense td.m-type { background-color: rgba(177, 53, 53, 0.05); }
.matrix-table tr.m-net-row td.m-type { background-color: rgba(51, 65, 85, 0.08); }

/* .chart-mode-toggle / .chart-mode-btn 已合併到 L2584 canonical .filter-tab 規則 (P0-3) */

/* === 各館收支總覽 (帳務管理頁) === */
.building-finance-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.bf-row {
    display: grid;
    grid-template-columns: 200px 1fr auto;
    gap: 1rem;
    align-items: center;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.bf-row:hover {
    border-color: var(--color-primary);
    background-color: var(--color-primary-light);
}

.bf-row.is-selected {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-focus);
}

.bf-name {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.bf-name strong {
    font-size: 0.95rem;
}

.bf-rate {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.5rem;
    border-radius: var(--radius-full);
    align-self: flex-start;
}

.bf-rate.good { background-color: var(--color-success-light); color: var(--color-success); }
.bf-rate.fair { background-color: var(--color-warning-light); color: var(--color-warning); }
.bf-rate.low { background-color: var(--color-danger-light); color: var(--color-danger); }

.bf-bar {
    height: 6px;
    background-color: var(--color-background);
    border-radius: 3px;
    overflow: hidden;
}

.bf-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-primary-hover));
    border-radius: 3px;
    transition: width 0.4s ease;
}

.bf-stats {
    display: flex;
    gap: 1.25rem;
    font-size: 0.8rem;
    white-space: nowrap;
}

.bf-stats > span {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.bf-label {
    color: var(--text-muted);
    font-size: 0.7rem;
}

@media (max-width: 880px) {
    .bf-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    .bf-stats {
        flex-wrap: wrap;
    }
}

/* Gender chips (dashboard 空床性別分布) */
.gender-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.gender-chip i {
    font-size: 0.95rem;
}

.gender-chip strong {
    font-size: 0.875rem;
    margin-left: 0.1rem;
}

.gender-chip.male {
    background-color: var(--color-info-light);
    color: var(--color-info);
}

.gender-chip.female {
    background-color: var(--color-danger-light);
    color: var(--color-danger);
}

.gender-chip.mixed {
    background-color: var(--color-primary-light);
    color: var(--color-primary);
}

/* Clickable tenant name link */
.tenant-link {
    background: none;
    border: none;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    font-weight: 600;
    color: var(--color-primary);
    cursor: pointer;
    text-decoration: none;
    border-bottom: 1px dashed transparent;
    transition: border-color var(--transition-fast);
}

.tenant-link:hover {
    border-bottom-color: var(--color-primary);
}

/* Area Filter Row (for properties: 館別篩選) */
.area-filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--border-color);
}

.area-filter-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    background: var(--color-surface);
    color: var(--text-main);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition-fast);
    min-width: 110px;
}

.area-filter-btn:hover {
    border-color: var(--color-primary);
    background-color: var(--color-primary-light);
}

.area-filter-btn.active {
    border-color: var(--color-primary);
    background-color: var(--color-primary-light);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.area-filter-btn .area-name {
    font-size: 0.875rem;
    font-weight: 600;
}

.area-filter-btn .area-stats {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.area-filter-btn.active .area-stats {
    color: var(--color-primary);
}

.area-filter-btn.is-full .area-stats {
    color: var(--color-danger);
}

/* .property-filter-btn 已合併到 L2584 canonical .filter-tab 規則 (P0-3)，原本 !important 全拆 */

/* Modal Footer */
.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--color-background);
    flex-shrink: 0;   /* footer 不被擠壓 */
    /* border-radius 不需要：modal-content 用 overflow:hidden 已自動帶圓角 */
}

/* Form Grid (used in modals) */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-grid .form-group {
    margin-bottom: 0;
}

/* 斷點 768 不是 640 — 涵蓋 iPad mini portrait + 大手機橫拿，跟其他 mobile rule 同 (audit QW-2) */
@media (max-width: 768px) {
    /* 手機: form-grid 直接改 block，每個 form-group 自然成一行
       不用 grid 1fr 是因為 stepper sticky / form-section-divider grid-column 1/-1
       會跟 grid layout 互相打架 (P1 mobile follow-up #2/#3/#5) */
    .form-grid {
        display: block;
    }
    .form-grid > * {
        margin-bottom: 1rem;
    }
    .form-grid > *:last-child {
        margin-bottom: 0;
    }
    .form-grid > .form-section-divider {
        margin-top: 1rem;
        margin-bottom: 0.75rem;
    }
}

.form-hint {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.form-input.input-error,
select.form-input.input-error,
textarea.form-input.input-error {
    border-color: var(--color-danger);
    background-color: var(--color-danger-light);
}

select.form-input {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%236b7280' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    padding-right: 2.25rem;
}

/* === Custom Select (取代原生下拉，方便美化) === */
.custom-select {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--color-surface);
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--text-main);
    cursor: pointer;
    text-align: left;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.custom-select-trigger:hover {
    border-color: var(--color-primary);
}

.custom-select-trigger:focus,
.custom-select.is-open .custom-select-trigger {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.custom-select.input-error .custom-select-trigger {
    border-color: var(--color-danger);
    background-color: var(--color-danger-light);
}

.custom-select-value {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-select-value.placeholder {
    color: var(--text-muted);
}

.custom-select-icon {
    color: var(--text-muted);
    font-size: 1rem;
    transition: transform var(--transition-fast), color var(--transition-fast);
    flex-shrink: 0;
}

.custom-select.is-open .custom-select-icon {
    transform: rotate(180deg);
    color: var(--color-primary);
}

.custom-select-panel {
    position: fixed;
    background-color: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 2100;
    max-height: 280px;
    overflow-y: auto;
    padding: 0.375rem;
    min-width: 180px;
    animation: csFadeIn 0.12s ease;
}

@keyframes csFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.custom-select-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--text-main);
    cursor: pointer;
    border-radius: var(--radius-sm);
    text-align: left;
    transition: background-color var(--transition-fast);
}

.custom-select-option > i {
    opacity: 0;
    color: var(--color-primary);
    font-size: 1rem;
    transition: opacity var(--transition-fast);
}

.custom-select-option:hover {
    background-color: var(--color-primary-light);
}

.custom-select-option.is-selected {
    color: var(--color-primary);
    font-weight: 600;
    background-color: var(--color-primary-light);
}

.custom-select-option.is-selected > i {
    opacity: 1;
}

/* 自訂滾動條（下拉面板內） */
.custom-select-panel::-webkit-scrollbar {
    width: 6px;
}
.custom-select-panel::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 3px;
}

/* 搜尋框 */
.custom-select.is-searchable .custom-select-panel {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* hidden 屬性必須蓋過 display: flex (否則收不回去) */
.custom-select-panel[hidden] {
    display: none !important;
}

/* ============================================================
 * Audit Quick Wins (2026-06-03)
 * 對應 UIUX_AUDIT_REPORT_2026-06-03.md 的快速改善
 * ============================================================ */

/* QW-P11: 金額/數字欄使用 tabular-nums，欄位對齊不抖動 */
.data-table td,
.data-table th,
.metric-value,
.cell-value,
#app-version-num,
.brand-text {
    font-variant-numeric: tabular-nums;
}

/* QW-AM4: 表單欄位 required 沒填時，input-error 加 shake 一次 */
@keyframes input-shake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-4px); }
    75%      { transform: translateX(4px); }
}
.input-error {
    animation: input-shake 0.3s ease-out;
}
@media (prefers-reduced-motion: reduce) {
    .input-error { animation: none; }
}

/* QW-AP7: modal 退場動畫 (對稱於進場) */
.modal-overlay.is-closing {
    animation: modalOverlayOut 0.18s ease-in forwards;
}
.modal-overlay.is-closing .modal-content {
    animation: modalContentOut 0.18s ease-in forwards;
}
@keyframes modalOverlayOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}
@keyframes modalContentOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to   { opacity: 0; transform: translateY(8px) scale(0.99); }
}

/* QW: undo toast 底部 5 秒倒數進度條 */
.undo-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(0, 0, 0, 0.06);
    overflow: hidden;
    border-radius: 0 0 var(--radius-md, 8px) var(--radius-md, 8px);
}
.undo-progress-fill {
    display: block;
    height: 100%;
    width: 100%;
    background: var(--color-primary);
    transform-origin: left center;
}
.toast.toast-undo {
    position: relative;
    padding-bottom: 0.65rem;  /* 多留一點空間給進度條 */
}

/* row-flash 顏色從 hardcoded 改用 token */
@keyframes row-flash-anim-tokenized {
    0%   { background-color: rgba(255, 136, 89, 0); }
    20%  { background-color: rgba(255, 136, 89, 0.18); }
    100% { background-color: rgba(255, 136, 89, 0); }
}

/* ============================================================
 * 響應式 Quick Wins (2026-06-03)
 * 對應 UIUX_AUDIT_REPORT_2026-06-03.md Part 4 響應式 QW 1-5
 * ============================================================ */

/* R-C-1: sidebar 在 ≤ 1100 強制自動收合（icon-only 模式） */
@media (max-width: 1100px) {
    .sidebar:not(.is-collapsed) {
        width: var(--sidebar-width-collapsed, 76px);
    }
    .sidebar:not(.is-collapsed) .nav-label,
    .sidebar:not(.is-collapsed) .nav-section-label,
    .sidebar:not(.is-collapsed) .logo-img-wordmark,
    .sidebar:not(.is-collapsed) .user-info,
    .sidebar:not(.is-collapsed) .user-actions,
    .sidebar:not(.is-collapsed) .brand-row,
    .sidebar:not(.is-collapsed) .nav-item-toggle {
        display: none;
    }
    .sidebar:not(.is-collapsed) .nav-item,
    .sidebar:not(.is-collapsed) .user-profile {
        justify-content: center;
    }
}

/* R-C-2 / M-C-2: 所有 data-table 操作欄 sticky right
   T3 修正：排除 occupancy 矩陣（.occ-table）+ 排除 colspan 列（空狀態） */
.data-table:not(.occ-table) thead th:last-child,
.data-table:not(.occ-table) tbody td:last-child:not([colspan]) {
    position: sticky;
    right: 0;
    background: var(--color-surface);
    box-shadow: -4px 0 6px -4px rgba(0, 0, 0, 0.06);
    z-index: 1;
}
.data-table:not(.occ-table) tbody tr:hover td:last-child {
    background: var(--bg-secondary, #fafbfc);
}

/* M-C-3: modal 在 ≤ 600px 改 bottom sheet (全螢幕貼底) */
@media (max-width: 600px) {
    .modal-overlay {
        padding: 0;
        align-items: flex-end;
    }
    .modal-content {
        max-width: 100% !important;
        width: 100%;
        max-height: 95vh;
        border-radius: 16px 16px 0 0;
        position: relative;
        padding-top: 0.5rem;   /* 給 drag handle 留空間 */
    }
    /* drag handle 視覺提示：頂端一條小灰條，暗示「這是可下拉的 sheet」 */
    .modal-content::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        border-radius: 4px;
        background: var(--border-color, #d1d5db);
        opacity: 0.7;
    }
    .modal-header { padding-top: 0.5rem; }
    .modal-footer {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* R-M-1: page-level toolbar 在 ≤ 900 自動換行 (properties / contracts / finance / maintenance / tenants 共 5 頁) */
@media (max-width: 900px) {
    .card > .flex.justify-between {
        flex-wrap: wrap;
        gap: 0.75rem;
    }
    .card > .flex.justify-between > .flex {
        flex: 1 1 auto;
        flex-wrap: wrap;
    }
    .card > .flex.justify-between .search-bar {
        width: auto !important;
        flex: 1 1 180px;
        min-width: 160px;
    }
}

/* R-M-4: settings-tabs 在 ≤ 720 改橫向捲動，不再爆排版 */
@media (max-width: 720px) {
    .settings-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .settings-tabs::-webkit-scrollbar { display: none; }
    .settings-tab {
        flex-shrink: 0;
    }
}

/* T3R-#2: toast 在手機補 safe-area-inset-top (toast 容器是 top-right，原本擋 Dynamic Island)
   bottom 那條無效，移除 */
#toast-container {
    padding-top: env(safe-area-inset-top, 0);
}

/* M-P-5 + T3R-#4: 觸控設備觸控目標 ≥ 44×44 (擴大涵蓋) */
@media (max-width: 768px) {
    .icon-btn,
    .profile-action,
    .pg-btn,
    .filter-tab,
    .area-filter-btn,
    .data-table:not(.occ-table) .btn-outline,
    .data-table:not(.occ-table) .btn-sm,
    .data-table:not(.occ-table) td button,
    .omn-back,
    .omn-bed-actions .btn,
    .modal-close,
    .chart-mode-btn,
    .month-switcher .btn,
    .report-export-btn,
    .occ-tab,
    .settings-tab,
    .fst-link,
    .tenant-link,
    .password-toggle {
        min-width: 44px;
        min-height: 44px;
    }
    .data-table:not(.occ-table) .btn-outline,
    .data-table:not(.occ-table) .btn-sm {
        padding: 0.55rem 0.8rem;
    }
    /* .omn-back 是 inline 字 + icon，要確保有 padding 撐高 */
    .omn-back {
        padding: 0.6rem 0.5rem;
        font-size: 0.875rem;
    }
}

/* 手機 metric-card: 2x2 grid (audit QW-4 還原)
   原本改成水平 snap scroll 但右邊兩張不會被注意到，重要 KPI 看不到
   改回 2x2 跟 reports .stat-tile-grid 同手感，跨頁面一致 */
@media (max-width: 768px) {
    .metrics-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
        margin-bottom: 1.25rem;
    }
    .metric-value {
        font-size: 1.5rem;
        letter-spacing: -0.02em;
    }
    .metric-icon {
        width: 28px;
        height: 28px;
        font-size: 0.95rem;
    }
    .metric-card {
        padding: 0.85rem 0.9rem;
    }
    .metric-card .metric-subtext {
        font-size: 0.7rem;
    }
}

/* card-title 補丁已整併到 L2306 base rule (P1-2)，原 QW !important 移除 */

/* T3R-#6: finance/analysis/unsettled sub-tabs 改保留 label 但縮短 */
@media (max-width: 640px) {
    .finance-sub-tab .fst-label {
        display: inline !important;
        font-size: 0.7rem;
        margin-left: 0.25rem;
    }
    .finance-sub-tab {
        padding: 0.55rem 0.6rem;
    }
}

/* T3R-#8: area-filter-row 改橫向 scroll (≤768)，省垂直空間 */
@media (max-width: 768px) {
    .area-filter-row {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    .area-filter-row::-webkit-scrollbar { height: 4px; }
    .area-filter-btn {
        flex-shrink: 0;
        scroll-snap-align: start;
        min-width: auto;
        padding: 0.6rem 0.85rem;
    }
}

/* T3R-#9 v2 (P1-mobile-#1 follow-up): month-switcher 手機 3 欄按鈕一條水平
   layout:
     [          2026 年 6 月          ]  ← label spanning, eyebrow above
     [ ◀ 上個月 | 本月 | 下個月 ▶ ]  ← 3 buttons equal width 1 row */
@media (max-width: 640px) {
    .month-switcher {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 0.4rem;
        padding: 0.6rem 0.7rem;
        align-items: center;
    }
    .month-switcher__label {
        grid-column: 1 / -1;
        order: -1;
        align-items: center;
        gap: 0.1rem;
    }
    .month-switcher__label-eyebrow { font-size: 0.65rem; }
    .month-switcher__label strong { font-size: 1.05rem; }
    /* __right 是 wrapper div 沒實際視覺含義 — display: contents 讓 this/next 直接參與 parent grid */
    .month-switcher__right {
        display: contents;
    }
    .month-switcher .btn {
        padding: 0.42rem 0.4rem !important;
        font-size: 0.78rem !important;
        white-space: nowrap;
        text-align: center;
        justify-content: center;
    }
    .month-switcher .btn .ph { font-size: 0.85rem; }
}

/* finance-toolbar: 已結帳目 header row (P1-mobile-#1 follow-up)
   desktop: title 左 + 搜尋 + 3 顆按鈕 右
   mobile : title 一行、搜尋一行、3 顆按鈕一行 (等分水平對齊) */
.finance-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 0.75rem;
}
.finance-toolbar__title {
    margin-bottom: 0 !important;
}
.finance-toolbar__actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.finance-toolbar__search {
    width: 250px;
}
@media (max-width: 768px) {
    .finance-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .finance-toolbar__search {
        width: 100%;
    }
    .finance-toolbar__actions {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 0.4rem;
    }
    .finance-toolbar__search {
        grid-column: 1 / -1;
    }
    .finance-toolbar__actions .btn {
        padding: 0.5rem 0.35rem !important;
        font-size: 0.75rem !important;
        white-space: nowrap;
        justify-content: center;
    }
    .finance-toolbar__actions .btn .ph { font-size: 0.85rem; }
}

/* ============================================================
 * 合約管理 — Row Card 設計 (方案 B)
 * 表格架構保留 (給 tableFilter.js)，視覺改成卡片列
 * ============================================================ */
.contracts-card-list { border: none; }
.contracts-card-list tbody { display: block; }
.contracts-card-list tr.contract-row {
    display: block;
    border: none;
    background: transparent;
    margin-bottom: 0.6rem;
    padding: 0;
}
.contracts-card-list tr.contract-row td.contract-row-cell {
    display: block;
    padding: 0;
    border: none;
    background: transparent;
}
/* 蓋掉桌面 ≥601 對 .data-table 的全域 sticky right (對 row card 不適用) */
.contracts-card-list thead th:last-child,
.contracts-card-list tbody td:last-child {
    position: static;
    box-shadow: none;
}

/* 排序 bar */
.contract-sort-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.contract-sort-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-weight: 500;
}
.contract-sort-select {
    padding: 0.35rem 0.6rem;
    font-size: var(--text-xs);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--text-main);
    cursor: pointer;
}

/* 主卡片 */
.contract-row-card {
    display: flex;
    background: var(--color-surface, #fff);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    overflow: hidden;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    min-height: 76px;
}
.contract-row-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.08);
}

/* 左側 6px 狀態 rail */
.crc-rail {
    width: 6px;
    flex-shrink: 0;
    background: var(--text-muted);
}
.crc-state-active .crc-rail { background: var(--color-success); }
.crc-state-awaiting_decision .crc-rail,
.crc-state-expired .crc-rail { background: var(--color-danger); }
.crc-state-expiring_soon .crc-rail { background: var(--color-warning); }
.crc-state-snoozed .crc-rail { background: var(--color-info, #3b82f6); }
.crc-state-renewed .crc-rail { background: var(--text-muted); opacity: 0.6; }
.crc-state-terminated .crc-rail { background: var(--text-muted); opacity: 0.4; }

/* 卡片內容區 */
.crc-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0.7rem 1rem;
    gap: 0.4rem;
    min-width: 0;
}

/* 上排：id / 物件 / 租客 / 租金 — 四欄等距 */
.crc-top {
    display: grid;
    grid-template-columns: 1.5fr 2fr 1.2fr 1.2fr;
    gap: 0.85rem;
    align-items: center;
}
.crc-id {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
}
.crc-id strong {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
}
.crc-parent {
    font-size: var(--text-2xs);
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    white-space: nowrap;
}
.crc-signed-flag {
    color: var(--color-success);
    font-size: 0.95rem;
    line-height: 1;
}
.crc-property {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.crc-tenant {
    font-size: var(--text-xs);
    color: var(--text-main);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.crc-tenant i { color: var(--text-muted); }
.crc-amount {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
    text-align: right;
}
.crc-term {
    font-size: var(--text-2xs);
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 0.2rem;
}

/* 下排：狀態文字 + 日期 + 倒數 */
.crc-bottom {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    align-items: center;
    font-size: var(--text-2xs);
    color: var(--text-muted);
    padding-top: 0.35rem;
    border-top: 1px dashed var(--border-color);
}
.crc-state {
    font-weight: 600;
    color: var(--text-secondary);
}
.crc-state-active .crc-state { color: var(--color-success); }
.crc-state-awaiting_decision .crc-state,
.crc-state-expired .crc-state { color: var(--color-danger); }
.crc-state-expiring_soon .crc-state { color: var(--color-warning); }
.crc-state-snoozed .crc-state { color: var(--color-info, #3b82f6); }

.crc-dates {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.crc-countdown {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.crc-countdown i { font-size: 0.55rem; }
.crc-countdown-danger { color: var(--color-danger); }
.crc-countdown-warn { color: var(--color-warning); }
.crc-countdown-normal { color: var(--text-muted); }
.crc-snooze { color: var(--color-info, #3b82f6); font-weight: 500; }

/* 右側動作區 */
.crc-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.7rem 0.8rem 0.7rem 0;
    flex-shrink: 0;
}
.crc-cta {
    padding: 0.45rem 0.85rem !important;
    font-size: var(--text-xs);
    white-space: nowrap;
}

/* ⋯ kebab menu */
.crc-more {
    position: relative;
}
.crc-more-trigger {
    background: none;
    border: 1px solid transparent;
    cursor: pointer;
    padding: 0.45rem;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    font-size: 1rem;
    line-height: 1;
}
.crc-more-trigger:hover {
    background: var(--bg-secondary);
    color: var(--text-main);
    border-color: var(--border-color);
}
.crc-more-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    min-width: 200px;
    padding: 0.3rem;
    z-index: 50;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.crc-more.is-open .crc-more-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.crc-more-item {
    background: none;
    border: none;
    padding: 0.5rem 0.7rem;
    text-align: left;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: var(--text-xs);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    font-family: inherit;
}
.crc-more-item:hover {
    background: var(--bg-secondary);
}
.crc-more-item.is-danger { color: var(--color-danger); }
.crc-more-item.is-danger:hover { background: var(--color-danger-light, rgba(177, 53, 53, 0.08)); }
.crc-more-item.is-success { color: var(--color-success); }
.crc-more-item i {
    font-size: 0.95rem;
    flex-shrink: 0;
}
.crc-more-sep {
    height: 1px;
    background: var(--border-color);
    margin: 0.25rem 0;
}

/* 已歸檔淡化 */
.contract-row-card.crc-state-renewed,
.contract-row-card.crc-state-terminated {
    opacity: 0.7;
}

/* 響應式：手機把上排改 2 欄 */
@media (max-width: 768px) {
    .crc-top {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto auto;
        gap: 0.3rem 0.5rem;
    }
    .crc-id { grid-column: 1 / -1; }
    .crc-property {
        grid-column: 1 / -1;
        font-size: var(--text-2xs);
    }
    .crc-tenant { grid-column: 1; }
    .crc-amount {
        grid-column: 2;
        text-align: right;
        align-self: center;
        font-size: 0.85rem;
    }
    .crc-actions {
        flex-direction: column;
        gap: 0.3rem;
        padding: 0.5rem;
    }
    .crc-cta {
        width: 100%;
        justify-content: center;
        padding: 0.45rem !important;
        font-size: 0.7rem;
    }
    .crc-more-menu {
        right: 0;
        min-width: 180px;
    }
}

/* ============================================================
 * Audit 第二輪 (2026-06-03)
 * 對應 UIUX_AUDIT_REPORT 的 C-2/C-3/C-4/M-2/M-4 + M-R-1/M-R-5
 * ============================================================ */

/* C-2: data-table 加 sticky thead — 滾下去仍能看欄位 (純樣式，不強制 max-height) */
.data-table:not(.occ-table) thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-secondary, #fafbfc);
}
/* 修正 sticky-right action 欄跟 sticky thead 交疊時的層級 */
.data-table:not(.occ-table) thead th:last-child { z-index: 3; }

/* opt-in 才開內部捲動：在需要的 view 用 .table-container--scroll
   全域不再強制 max-height，避免小表也吃內部捲動軸 */
.table-container--scroll {
    max-height: calc(100vh - 320px);
    overflow: auto;
}

/* C-4: 抽 6 個基礎 utility class 打底，未來分批替換 inline style */
.text-2xs   { font-size: var(--text-2xs); }
.text-xs    { font-size: var(--text-xs); }
.text-sm    { font-size: var(--text-sm); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
.text-primary { color: var(--color-primary); }
.cell-stack { display: flex; flex-direction: column; gap: 0.25rem; }
.cell-primary { font-weight: 600; color: var(--text-main); }
.cell-sub { font-size: var(--text-2xs); color: var(--text-muted); }
.flex-1 { flex: 1; }
.gap-1 { gap: 0.25rem; }
.gap-3 { gap: 0.75rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.tabular-nums { font-variant-numeric: tabular-nums; }

/* M-4: 空狀態通用樣式 (給 dashboard 待辦 / 列表空無資料) */
.empty-state-friendly {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.5rem 1rem;
    color: var(--text-muted);
    text-align: center;
}
.empty-state-friendly .esf-icon {
    font-size: 2rem;
    color: var(--color-success);
    opacity: 0.7;
    /* T3-P-1: 進場輕輕上移再回位 (一次性，不再無限循環)，避免三張卡同時抖 */
    animation: esf-enter 0.6s ease-out;
}
@keyframes esf-enter {
    from { transform: translateY(6px); opacity: 0; }
    to   { transform: translateY(0); opacity: 0.7; }
}
.empty-state-friendly .esf-title {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
}
.empty-state-friendly .esf-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
}
@media (prefers-reduced-motion: reduce) {
    .empty-state-friendly .esf-icon { animation: none; }
}

/* M-2: topbar breadcrumb 樣式 (取代寫死「聚空間」eyebrow) */
.page-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--text-muted);
    font-size: var(--text-xs);
}
.page-eyebrow .pb-sep {
    opacity: 0.5;
    font-size: 0.65rem;
}
.page-eyebrow .pb-current {
    color: var(--text-secondary);
    font-weight: 500;
}

/* M-R-1: 手機 sidebar → drawer
   ≤ 768：sidebar 變 fixed drawer (預設藏在 -100%)，點漢堡 → 展開
   桌面：照常 (上面的 ≤1100 規則 + 預設 260px) */
.topbar-hamburger {
    display: none;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    margin-right: 0.5rem;
    transition: background var(--transition-fast);
}
.topbar-hamburger:hover {
    background: var(--bg-secondary);
    color: var(--color-primary);
}

/* backdrop: 改用 visibility 切換 (display 切換不能 transition opacity)
   桌面始終看不見、不可點；手機 .is-open 才出現 */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.sidebar-backdrop.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

@media (max-width: 768px) {
    .topbar-hamburger { display: inline-flex; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        /* dvh = dynamic viewport height，把 mobile Safari URL bar 算進去，避免 footer 被切到 (P1-mobile-#2) */
        height: 100dvh;
        width: 280px !important;
        transform: translateX(-100%);
        transition: transform 0.25s ease, width 0.2s ease;
        z-index: 999;
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.15);
        /* drawer 關閉狀態完全不接受互動，避免「隱形 sidebar 擋住主內容左邊」 */
        pointer-events: none;
        visibility: hidden;
        /* drawer 自身是 flex column (繼承 .sidebar)，nav 已 flex:1 自動撐開 + 滾動，
           footer 在 column 最後自然 stick 在底部，不需要再 sticky */
        overflow: hidden;
    }
    /* drawer 內 nav 撐滿、自己 scrollable；footer 永遠停在底部可見 */
    .sidebar.is-mobile-open .sidebar-nav {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
    }
    .sidebar.is-mobile-open .sidebar-footer {
        flex-shrink: 0;
        background: var(--sidebar-bg);
        border-top: 1px solid var(--sidebar-border);
        /* iOS safe-area 補底 padding 避免被 home indicator 蓋 */
        padding-bottom: calc(0.4rem + env(safe-area-inset-bottom)) !important;
    }
    .sidebar.is-mobile-open {
        transform: translateX(0);
        pointer-events: auto;
        visibility: visible;
    }
    /* 手機：原 sidebar-toggle 收合功能在 drawer 內無意義，直接隱藏；用 backdrop / 漢堡 / nav-item 切頁來關 */
    .sidebar-toggle { display: none; }
    /* 手機 drawer 內回到完整版面 (蓋掉 ≤1100 的 icon-only 規則) */
    .sidebar.is-mobile-open:not(.is-collapsed) {
        width: 280px !important;
    }
    /* drawer 內回到完整顯示 — 用顯式 display 不要 revert (.user-info / .user-actions 是 flex，revert 變 block 會破版) */
    .sidebar.is-mobile-open .nav-label,
    .sidebar.is-mobile-open .nav-section-label,
    .sidebar.is-mobile-open .logo-img-wordmark {
        display: inline;
    }
    .sidebar.is-mobile-open .user-info {
        display: flex !important;
        flex-direction: column;
    }
    .sidebar.is-mobile-open .user-actions {
        display: flex !important;
        align-items: center;
    }
    .sidebar.is-mobile-open .brand-row {
        display: flex !important;
    }
    /* 確認 footer 不被收合相關規則蓋掉 */
    .sidebar.is-mobile-open .sidebar-footer {
        display: block !important;
        padding: 0.4rem 0.5rem !important;
    }
    .sidebar.is-mobile-open .user-profile {
        display: flex !important;
        align-items: center;
        gap: 0.5rem;
        padding: 0.5rem !important;
    }
    .sidebar.is-mobile-open .nav-item,
    .sidebar.is-mobile-open .user-profile {
        justify-content: flex-start;
    }
    /* main-content 不再被 sidebar push */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

/* M-R-5: 手機「新增」FAB (fixed bottom-right) */
.mobile-fab {
    display: none;
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    border: none;
    box-shadow: 0 6px 16px rgba(249, 115, 22, 0.35);
    font-size: 1.6rem;
    cursor: pointer;
    z-index: 100;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}
.mobile-fab:hover,
.mobile-fab:active {
    transform: scale(1.05);
    box-shadow: 0 8px 20px rgba(249, 115, 22, 0.45);
}
@media (max-width: 768px) {
    .mobile-fab { display: inline-flex; }
    /* 同時讓桌面版有 data-fab 的「新增」按鈕在手機上隱藏（避免重複） */
    .btn[data-fab] { display: none; }
}

/* M-R-3 v3 (2026-06-13): 住房一覽手機 redesign — 給月份格喘息空間
   依 OCCUPANCY_MOBILE_REDESIGN_2026-06-13.md
   原則: sticky 左 2 欄(床位+房客) + sticky thead + 月份欄固定 68px (不 fixed-layout 平分) */
@media (max-width: 768px) {
    /* 1. 表格改 auto + width: max-content，自然撐寬靠 wrap 橫捲 (不再被 fixed 平分擠死) */
    .data-table.occ-table {
        table-layout: auto;
        width: max-content;
        min-width: 100%;
    }

    /* 2. 字級/padding 比原本寬鬆 */
    .occ-table { font-size: 0.75rem; }
    .occ-table thead th,
    .occ-table tbody td {
        padding: 0.5rem 0.4rem;
        line-height: 1.3;
    }

    /* 3. 固定前 4 欄寬度 */
    .occ-table thead th:nth-child(1),
    .occ-table tbody td:nth-child(1) {
        width: 56px !important; min-width: 56px;
    }
    .occ-table thead th:nth-child(2),
    .occ-table tbody td:nth-child(2) {
        width: 96px !important; min-width: 96px;
        text-align: left !important;
        padding-left: 0.55rem;
        word-break: break-word;
    }
    .occ-table thead th:nth-child(3),
    .occ-table tbody td:nth-child(3) {
        width: 72px !important; min-width: 72px;
    }
    .occ-table thead th:nth-child(4),
    .occ-table tbody td:nth-child(4) {
        width: 36px !important; min-width: 36px;
        padding: 0.4rem 0.2rem;
    }

    /* 4. 月份欄 (第 5 欄之後) 統一 68px */
    .occ-table thead th:nth-child(n+5),
    .occ-table tbody td:nth-child(n+5) {
        width: 68px !important;
        min-width: 68px;
        padding: 0.5rem 0.3rem;
    }

    /* 5. sticky 左側雙欄: 床位 + 房客 */
    .occ-table td:nth-child(1),
    .occ-table th:nth-child(1) {
        position: sticky;
        left: 0;
        z-index: 2;
        background: var(--bg-secondary, #fafbfc);
    }
    .occ-table td:nth-child(2),
    .occ-table th:nth-child(2) {
        position: sticky;
        left: 56px;
        z-index: 2;
        background: var(--color-surface, #fff);
        box-shadow: 4px 0 6px -4px rgba(0, 0, 0, 0.10);
    }
    .occ-table thead th:nth-child(1),
    .occ-table thead th:nth-child(2) { z-index: 4; }
    /* 房間 header (R1 女生6人房 ...) 橫滑時 sticky 在左
       Safari 對 <td> 套 sticky 行為不穩 → 改成 td 純維持底色，sticky 套到內 div */
    .occ-table tr.occ-room-header td {
        position: static !important;
        padding: 0 !important;
        background-color: var(--color-surface);
        background-image: linear-gradient(to right, rgba(255, 136, 89, 0.12), rgba(255, 136, 89, 0.04));
    }
    .occ-table tr.occ-room-header .occ-room-header-inner {
        position: sticky;
        left: 0;
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.5rem 0.85rem;
        z-index: 3;
        max-width: 100vw;
    }
    /* sticky 雙欄在 vacant / terminated 列要跟著該列底色不透明 (P1 mobile follow-up #1)
       否則橫滾時底層的 +入住 button / 月份格 會透出來，視覺髒 */
    .occ-table tr.occ-row-vacant > td:nth-child(1),
    .occ-table tr.occ-row-vacant > td:nth-child(2) {
        background: var(--occ-sticky-bg-vacant) !important;
    }
    .occ-table tr.occ-row-terminated > td:nth-child(1),
    .occ-table tr.occ-row-terminated > td:nth-child(2) {
        background: var(--occ-sticky-bg-terminated) !important;
    }
    /* stripe-b 列的 sticky 房客欄底色要跟列底色一致 (本身是 rgba(0,0,0,0.02) 半透明，sticky 漏底) */
    .occ-table tr.occ-room-stripe-b:not(.occ-row-vacant):not(.occ-row-terminated) > td:nth-child(2) {
        background: var(--occ-sticky-bg-stripe-b) !important;
    }

    /* 防禦規則: 防範未來再加新全域 thead 規則時把矩陣表 clip 掉 (V2 designer 建議) */
    .occ-table thead {
        position: static !important;
        width: auto !important;
        height: auto !important;
        clip: auto !important;
        overflow: visible !important;
        margin: 0 !important;
        padding: 0;
    }

    /* 6. sticky thead — 全域規則排除了 occ-table，這裡單獨補回 */
    .occ-table thead th {
        position: sticky;
        top: 0;
        z-index: 3;
        background: var(--bg-secondary, #fafbfc);
    }
    /* sticky thead × sticky 左欄交叉處要最高層 */
    .occ-table thead th:nth-child(1),
    .occ-table thead th:nth-child(2) { z-index: 5; }

    /* 7. 月份格內容 + tabular-nums */
    .occ-table td.occ-cell {
        white-space: nowrap;
        font-variant-numeric: tabular-nums;
    }
    .occ-table td.occ-end-marker {
        font-size: 0.68rem;
        white-space: normal;
        line-height: 1.25;
    }
    .occ-table .occ-pay-badge {
        display: inline-block;
        margin-left: 2px;
        font-size: 0.6rem;
    }

    /* 8. 退房 checkbox 視覺降權 */
    .occ-terminate-check {
        transform: scale(0.9);
        opacity: 0.7;
    }

    /* 9. wrap 右側漸層 — absolute 取代原 sticky (iOS Safari 行為一致) */
    .occ-table-wrap {
        position: relative;
        overflow-x: auto !important;
        /* 寫 hidden 不是 visible — CSS spec 規定一軸 hidden/auto 時，visible 那邊會被強制改 auto，sticky thead 縱向會失靈 */
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }
    .occ-table-wrap::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to left, var(--color-surface, #fff) 0%, transparent 100%);
        pointer-events: none;
        opacity: 0.8;
    }

    /* 各館 tab 列橫向捲動 (留用) */
    .occ-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }
    .occ-tab {
        flex-shrink: 0;
        scroll-snap-align: start;
    }
}

/* 月份 label 兩種版本: desktop 顯示 `2026/5`，mobile 顯示 `5月` */
.occ-month-short { display: none; }
@media (max-width: 768px) {
    .occ-month-full { display: none; }
    .occ-month-short { display: inline; font-weight: 600; }
}

/* ============================================================
 * M-R-3：垂直導航三層 drilldown (CSS 留著，但 occupancy.js 暫不渲染)
 * 用戶偏好矩陣表 — 手機改靠橫向捲動 + sticky 床位欄解決
 * ============================================================ */
.occ-mobile-nav { display: none; }

.omn-level-header {
    background: var(--color-surface, #fff);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 5;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}
.omn-back {
    background: none;
    border: none;
    color: var(--color-primary);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.2rem 0;
    margin-bottom: 0.35rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 500;
}
.omn-back:hover {
    color: var(--color-primary-hover);
    text-decoration: underline;
}
.omn-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0 0 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.omn-sub {
    color: var(--text-muted);
    font-size: var(--text-2xs);
    display: block;
}

.omn-cards {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.omn-card {
    background: var(--color-surface, #fff);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    padding: 0.85rem 1rem;
    cursor: pointer;
    text-align: left;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform 0.15s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
button.omn-card { font-family: inherit; }
.omn-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 3px 8px rgba(249, 115, 22, 0.1);
}
.omn-card:active {
    transform: scale(0.98);
}
.omn-card-main {
    flex: 1;
    min-width: 0;
}
.omn-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.15rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.omn-card-title i { color: var(--color-primary); }
.omn-card-sub {
    font-size: var(--text-2xs);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    line-height: 1.4;
}
.omn-card-stats {
    display: flex;
    gap: 0.85rem;
    flex-shrink: 0;
}
.omn-stat {
    text-align: center;
    line-height: 1.1;
}
.omn-stat strong {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
}
.omn-stat small {
    color: var(--text-muted);
    font-size: 0.6rem;
}
.omn-chevron {
    color: var(--text-muted);
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* 床位卡片 (level 3) — 含底部 action 按鈕，不是 button 本身 */
.omn-bed-card {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    cursor: default;
}
.omn-bed-card .omn-card-main {
    flex: none;
}
.omn-bed-card.is-rented {
    border-left: 3px solid var(--color-success);
}
.omn-bed-card.is-vacant {
    border-left: 3px solid var(--color-warning);
}
.omn-bed-meta {
    margin-top: -0.2rem;
}
.omn-bed-actions {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--border-color);
}
.omn-bed-actions .btn {
    flex: 1;
    justify-content: center;
    padding: 0.55rem 0.8rem;
    font-size: var(--text-xs);
}

/* ============================================
   M-C-4 (2026-06-13): 新增入住 / 建立合約 modal 手機 redesign
   依 CONTRACT_MODAL_MOBILE_REDESIGN_2026-06-13.md
   桌面樣式不動 — 全包在 @media (max-width: 600px) 內
   ============================================ */
@media (max-width: 600px) {
    /* 1. Modal Header: 取消 flex 搶寬度，標題 / 副標 / close 各自獨立流 */
    .modal-header {
        display: block;
        position: relative;
        padding: 1rem 3rem 0.85rem 1.25rem;
    }
    .modal-header h3 {
        font-size: 1rem;
        line-height: 1.35;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .modal-header .modal-subtitle {
        display: block;
        margin-top: 0.3rem;
        font-size: 0.7rem;
        line-height: 1.4;
        white-space: normal;
    }
    .modal-header .modal-close {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
    }

    /* 2. Wizard Stepper: 緊湊水平條 + sticky 在 modal-body 頂 */
    .wizard-stepper {
        gap: 0.3rem !important;
        padding: 0.6rem 1rem 0.7rem !important;
        margin-bottom: 0.5rem !important;
        position: sticky;
        top: -1.5rem;
        background: var(--color-surface);
        z-index: 5;
        margin-left: -1.5rem !important;
        margin-right: -1.5rem !important;
    }
    .wizard-stepper .wiz-step {
        flex-shrink: 0;
        gap: 0.3rem !important;
    }
    .wizard-stepper .wiz-step-num {
        width: 24px !important;
        height: 24px !important;
        font-size: 0.7rem !important;
    }
    .wizard-stepper .wiz-step-label {
        white-space: nowrap;
        font-size: 0.7rem !important;
        max-width: 0;
        overflow: hidden;
        opacity: 0;
        transition: max-width 0.2s, opacity 0.2s, margin 0.2s;
        margin-left: 0;
    }
    /* 當前步驟 (JS 加 .is-current) 才展開 label */
    .wizard-stepper .wiz-step.is-current .wiz-step-label {
        max-width: 6em;
        opacity: 1;
        margin-left: 0.1rem;
    }
    .wizard-stepper .wiz-step-bar {
        min-width: 12px;
        max-width: 40px;
        flex: 1 1 auto;
    }

    /* 3. 額外床位卡片: label / 增加按鈕 / hint 各自獨立 block */
    #ph-extraBeds > div {
        padding: 0.85rem !important;
    }
    #ph-extraBeds > div > div:first-child {
        display: block !important;
        margin-bottom: 0.6rem !important;
    }
    #ph-extraBeds > div > div:first-child > label {
        display: block;
        margin-bottom: 0.5rem;
        font-size: 0.875rem;
        line-height: 1.5;
    }
    #ph-extraBeds > div > div:first-child > label small {
        display: block;
        margin-top: 0.15rem;
        font-size: 0.7rem;
        line-height: 1.4;
    }
    #ph-extraBeds #add-extra-bed-btn {
        display: block;
        width: 100%;
        font-size: 0.8rem !important;
        padding: 0.55rem 0.7rem !important;
        min-height: 40px;
    }
    #ph-extraBeds .form-hint {
        font-size: 0.7rem !important;
        line-height: 1.5 !important;
        margin-top: 0.5rem !important;
    }

    /* 4. Footer 按鈕 3 顆平分寬度，不擠到換行 */
    .modal-footer {
        gap: 0.4rem;
        padding: 0.75rem 1rem;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }
    .modal-footer .btn {
        flex: 1 1 0;
        min-width: 0;
        font-size: 0.825rem;
        padding: 0.6rem 0.4rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .modal-footer .btn i {
        font-size: 0.85rem;
    }

    /* 5. Form Group label 防止飄移 (grid item 預設 min-width: auto 會撐爆) */
    .modal-body .form-grid .form-group {
        min-width: 0;
    }
    .modal-body .form-grid .form-group label {
        text-align: left;
    }

    /* 6. modal-body 加底 padding，避免最後一個欄位被 footer 蓋 */
    .modal-body {
        padding-bottom: 1rem;
    }
}

/* M-C-4-tiny: 超窄螢幕 ≤360px (iPhone SE 1) 再細修 */
@media (max-width: 360px) {
    .modal-header h3 {
        font-size: 0.9rem;
    }
    .wizard-stepper .wiz-step.is-current .wiz-step-label {
        max-width: 5em;
        font-size: 0.65rem !important;
    }
    .modal-footer .btn {
        font-size: 0.75rem;
        padding: 0.55rem 0.3rem;
    }
    .modal-footer .btn i {
        display: none;
    }
}

.omn-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
}

/* ============================================================
 * M-R-2: data-table → card list 在 ≤ 600px 自動轉換
 * 配合 js/utils/tableDataLabels.js 自動加的 data-label 屬性
 * ============================================================ */
@media (max-width: 600px) {
    /* 取消 sticky thead / overflow，table 改 block flow */
    .table-container {
        max-height: none;
        overflow: visible;
    }
    .data-table {
        border: none;
        background: transparent;
    }
    .data-table:not(.occ-table) thead {
        /* 表頭視覺上隱藏，但仍要存在給 data-label 邏輯用 — 排除矩陣表 (.occ-table)
           不然會把月份 header 整列 clip 掉 (designer V2 報告根因) */
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
    }
    .data-table:not(.occ-table),
    .data-table:not(.occ-table) tbody,
    .data-table:not(.occ-table) tr,
    .data-table:not(.occ-table) td {
        display: block;
        width: 100%;
    }
    /* tr = 卡片容器，內部用 grid 2-col 排版 (方案 A: stacked-2-col)
       label 在上灰小字、值在下強調，雙欄並排 → 解決「太分散」痛點 */
    .data-table:not(.occ-table) tbody tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 1rem;
        row-gap: 0.85rem;
        background: var(--color-surface, #fff);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 1rem;
        margin-bottom: 0.75rem;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    }
    .data-table:not(.occ-table) tbody tr:hover {
        background: var(--color-surface, #fff);
    }
    /* 一般 td: label 在上、值在下 (mini stacked block) */
    .data-table:not(.occ-table) td {
        display: block;
        padding: 0;
        border: none;
        text-align: left;
        font-size: 0.92rem;
        font-weight: 600;
        color: var(--text-main);
        line-height: 1.3;
        word-wrap: break-word;
        min-width: 0;
    }
    .data-table:not(.occ-table) td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.68rem;
        color: var(--text-muted);
        font-weight: 500;
        letter-spacing: 0.01em;
        margin-bottom: 0.2rem;
        text-transform: none;
    }
    /* 第一個 td (主名 / 編號) = 卡片標題，跨整列 */
    .data-table:not(.occ-table) td:first-child {
        grid-column: 1 / -1;
        font-size: 1.02rem;
        font-weight: 700;
        padding-bottom: 0.7rem;
        margin-bottom: 0;
        border-bottom: 1px solid var(--border-soft);
    }
    .data-table:not(.occ-table) td:first-child::before {
        display: none;
    }
    /* 最後一個 td (操作) = 跨整列、右靠 */
    .data-table:not(.occ-table) th:last-child,
    .data-table:not(.occ-table) td:last-child {
        position: static;
        box-shadow: none;
    }
    .data-table:not(.occ-table) td:last-child {
        grid-column: 1 / -1;
        display: flex;
        justify-content: flex-end;
        gap: 0.5rem;
        padding-top: 0.85rem;
        margin-top: 0;
        border-top: 1px solid var(--border-soft);
    }
    .data-table:not(.occ-table) td:last-child::before {
        display: none;
    }
    /* 空狀態 row 跨欄不適用卡片 */
    .data-table:not(.occ-table) tr.empty-row,
    .data-table:not(.occ-table) tr:has(td[colspan]) {
        display: block;
    }
    .data-table:not(.occ-table) tr.empty-row td,
    .data-table:not(.occ-table) td[colspan] {
        display: block;
        text-align: center;
        grid-column: auto;
    }
    .data-table:not(.occ-table) tr.empty-row td::before,
    .data-table:not(.occ-table) td[colspan]::before { display: none; }

    /* === 方案 v3: cards-with-hero 表用 dual-row 法
       桌面 row-desktop 顯、row-mobile-card 隱
       手機 row-desktop 隱、row-mobile-card 顯 (skip M-R-2 grid 2-col 完全自管 layout) === */
    .data-table.cards-with-hero tbody tr.row-desktop {
        display: none;
    }
    .data-table.cards-with-hero tbody tr.row-mobile-card {
        display: block !important;
        grid-template-columns: none !important;
        padding: 0 !important;
        margin-bottom: 0.85rem !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }
    .data-table.cards-with-hero tbody tr.row-mobile-card > td {
        display: block !important;
        padding: 0 !important;
        grid-column: auto !important;
        border: none !important;
        font-size: inherit;
        font-weight: 400;
        color: inherit;
        margin: 0 !important;
        text-align: left !important;  /* 蓋掉 td[colspan] 的 text-align: center (那條是給空狀態訊息用) */
    }
    .data-table.cards-with-hero tbody tr.row-mobile-card > td::before {
        display: none !important;
    }
}

/* 桌面: row-mobile-card 隱 (cards-with-hero 才有這個 row) */
.data-table tr.row-mobile-card {
    display: none;
}
@media (min-width: 601px) {
    .data-table.cards-with-hero tbody tr.row-mobile-card { display: none !important; }
}

/* ============================================================
 * 手機 finance / unsettled card v3 — designer mockup
 * 在 .row-mobile-card > td > .entity-mobile-card 容器內
 * ============================================================ */
@media (max-width: 600px) {
    .entity-mobile-card {
        background: var(--color-surface);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 0.95rem 1rem;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    }
    .entity-mobile-card .c-hero-equal {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 0.65rem;
    }
    .entity-mobile-card .c-hero-who {
        flex: 1 1 auto;
        min-width: 0;
    }
    .entity-mobile-card .c-hero-tenant {
        font-size: 1.1rem;
        font-weight: 700;
        color: var(--text-main);
        line-height: 1.25;
    }
    .entity-mobile-card .c-hero-tags {
        display: flex;
        align-items: center;
        gap: 0.45rem;
        margin-top: 0.3rem;
        flex-wrap: wrap;
    }
    .entity-mobile-card .c-hero-place {
        font-size: 0.78rem;
        color: var(--text-muted);
    }
    .entity-mobile-card .c-hero-tags .dot {
        width: 3px;
        height: 3px;
        background: var(--text-muted);
        border-radius: 50%;
        opacity: 0.6;
    }
    .entity-mobile-card .c-hero-side {
        flex: 0 0 auto;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 0.35rem;
    }
    .entity-mobile-card .c-hero-amt {
        font-size: 1.1rem;
        font-weight: 700;
        line-height: 1.2;
        letter-spacing: -0.01em;
        font-variant-numeric: tabular-nums;
    }
    .entity-mobile-card .c-hero-amt.income { color: var(--color-success); }
    .entity-mobile-card .c-hero-amt.expense { color: var(--color-danger); }
    .entity-mobile-card .badge {
        display: inline-flex;
        align-items: center;
        padding: 0.18rem 0.6rem;
        border-radius: 999px;
        font-size: 0.72rem;
        font-weight: 600;
    }
    .entity-mobile-card .badge.success {
        background: rgba(34, 148, 110, 0.12);
        color: var(--color-success);
    }
    .entity-mobile-card .badge.danger {
        background: rgba(177, 53, 53, 0.10);
        color: var(--color-danger);
    }
    /* type-chip 語意色 */
    .entity-mobile-card .type-chip {
        display: inline-flex;
        align-items: center;
        gap: 0.2rem;
        padding: 0.15rem 0.5rem;
        border-radius: 999px;
        font-size: 0.7rem;
        font-weight: 600;
    }
    .entity-mobile-card .type-chip i { font-size: 0.78rem; }
    .entity-mobile-card .type-chip.rent     { background: rgba(255, 136, 89, 0.15); color: var(--color-primary-text); }
    .entity-mobile-card .type-chip.deposit  { background: rgba(34, 148, 110, 0.12); color: var(--color-success); }
    .entity-mobile-card .type-chip.utility  { background: rgba(156, 111, 12, 0.12); color: var(--color-warning-text); }
    .entity-mobile-card .type-chip.misc     { background: rgba(107, 114, 128, 0.10); color: var(--text-muted); }
    /* 分隔 */
    .entity-mobile-card .c-divider {
        height: 1px;
        background: var(--border-soft);
        margin: 0.65rem 0 0.7rem;
    }
    /* chip 列 (日期 / 期間 / 合約) */
    .entity-mobile-card .c-chips {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
        margin-bottom: 0.75rem;
    }
    .entity-mobile-card .c-chip {
        display: inline-flex;
        align-items: center;
        gap: 0.25rem;
        padding: 0.3rem 0.6rem;
        border-radius: 999px;
        background: var(--bg-tertiary);
        font-size: 0.72rem;
        color: var(--text-secondary);
        font-weight: 500;
    }
    .entity-mobile-card .c-chip i { font-size: 0.85rem; }
    .entity-mobile-card .c-chip.danger {
        background: rgba(177, 53, 53, 0.10);
        color: var(--color-danger);
    }
    .entity-mobile-card .c-chip.warn {
        background: rgba(156, 111, 12, 0.12);
        color: var(--color-warning-text);
    }
    .entity-mobile-card .c-chip.success {
        background: rgba(34, 148, 110, 0.12);
        color: var(--color-success);
    }
    /* 折扣 / 付款 2x2 grid */
    .entity-mobile-card .c-meta-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.6rem 1rem;
        margin-bottom: 0.65rem;
    }
    .entity-mobile-card .c-meta-cell {
        text-align: left;
    }
    .entity-mobile-card .c-meta-cap {
        display: block;
        font-size: 0.68rem;
        color: var(--text-muted);
        font-weight: 500;
        margin-bottom: 0.15rem;
        text-align: left;
    }
    .entity-mobile-card .c-meta-val {
        display: block;
        font-size: 0.85rem;
        color: var(--text-main);
        font-weight: 600;
        text-align: left;
    }
    .entity-mobile-card .c-meta-val-sub {
        font-size: 0.68rem;
        color: var(--text-muted);
        font-weight: 400;
        margin-left: 0.25rem;
    }
    .entity-mobile-card .c-meta-val-muted {
        color: var(--text-muted);
        font-weight: 400;
    }
    /* 備註區 (獨立、左 border 強調) */
    .entity-mobile-card .c-note {
        background: var(--bg-secondary);
        border-left: 3px solid var(--border-strong);
        border-radius: 0 6px 6px 0;
        padding: 0.5rem 0.7rem;
        margin-bottom: 0.85rem;
    }
    .entity-mobile-card .c-note .c-meta-cap { margin-bottom: 0.2rem; }
    .entity-mobile-card .c-note-text {
        font-size: 0.82rem;
        color: var(--text-main);
        line-height: 1.45;
        word-break: break-word;
    }
    /* actions 列 (純靠右) */
    .entity-mobile-card .c-actions {
        display: flex;
        justify-content: flex-end;
        gap: 0.5rem;
        padding-top: 0.7rem;
        border-top: 1px solid var(--border-soft);
    }
    .entity-mobile-card .c-actions .btn-icon {
        width: 36px;
        height: 36px;
        border-radius: 8px;
        border: 1px solid var(--border-color);
        background: white;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        font-size: 1rem;
        cursor: pointer;
        font-family: inherit;
    }
    .entity-mobile-card .c-actions .btn-icon:active { background: var(--bg-secondary); }
    .entity-mobile-card .c-actions .btn-icon.danger { color: var(--color-danger); }
    /* primary 按鈕 (unsettled 用「核對結帳」/「結帳」) — 撐滿剩餘空間 */
    .entity-mobile-card .c-actions .btn-primary {
        flex: 1 1 auto;
        height: 36px;
        padding: 0 0.9rem;
        border-radius: 8px;
        background: var(--color-success);
        color: white;
        border: none;
        font-size: 0.85rem;
        font-weight: 600;
        font-family: inherit;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.3rem;
        cursor: pointer;
    }
    .entity-mobile-card .c-actions .btn-primary:active {
        background: var(--color-success-hover);
    }
    .entity-mobile-card .c-actions .btn-primary i { font-size: 0.9rem; }
}


.custom-select-search {
    position: sticky;
    top: 0;
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 1;
}

.custom-select-search i {
    color: var(--text-muted);
    font-size: 1rem;
    flex-shrink: 0;
    margin-left: 0.25rem;
}

.custom-select-search-input {
    flex: 1;
    border: none;
    outline: none;
    background: none;
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--text-main);
    padding: 0.25rem;
}

.custom-select-search-input::placeholder {
    color: var(--text-muted);
}

.custom-select-options-wrap {
    overflow-y: auto;
    padding: 0.375rem;
    max-height: 240px;
}

.custom-select-empty {
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

textarea.form-input {
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
}

/* Danger / Success buttons */
.btn-danger {
    background-color: var(--color-danger);
    color: var(--text-inverse);
}

.btn-danger:hover {
    background-color: #8e2929;
    box-shadow: var(--shadow-md);
}

.btn-success {
    background-color: var(--color-success);
    color: var(--text-inverse);
}

.btn-success:hover {
    background-color: #1c7758;
    box-shadow: var(--shadow-md);
}

/* Toast */
#toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 99999;  /* 永遠在最上層 (modal 1000+20×depth 也壓不過) */
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background-color: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    border-left-width: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    min-width: 240px;
    transform: translateX(120%);
    transition: transform var(--transition-normal);
}

.toast.show {
    transform: translateX(0);
}

.toast i {
    font-size: 1.25rem;
}

.toast-success { border-left-color: var(--color-success); }
.toast-success i { color: var(--color-success); }
.toast-danger { border-left-color: var(--color-danger); }
.toast-danger i { color: var(--color-danger); }
.toast-warning { border-left-color: var(--color-warning); }
.toast-warning i { color: var(--color-warning); }
.toast-info { border-left-color: var(--color-info); }
.toast-info i { color: var(--color-info); }

/* UIUX #3: undo toast — 包含「復原」按鈕 + 倒數秒數 */
.toast-undo {
    border-left-color: var(--color-warning);
    align-items: center;
}
.toast-undo i { color: var(--color-warning); }
.toast-undo .undo-msg {
    flex: 1;
    min-width: 0;
}
.toast-undo .undo-btn {
    margin-left: 0.5rem;
    padding: 0.3rem 0.7rem;
    background: var(--color-warning);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.1s;
}
.toast-undo .undo-btn:hover {
    background: #946a17;
}
.toast-undo .undo-countdown {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5em;
    height: 1.5em;
    margin-left: 0.4rem;
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-muted);
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
}

/* Dropdown menu */
.dropdown-menu {
    position: absolute;
    background-color: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    z-index: 100;
    overflow: hidden;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    color: var(--text-main);
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.dropdown-item:hover {
    background-color: var(--color-background);
}

.dropdown-item.danger {
    color: var(--color-danger);
}

.dropdown-item.danger:hover {
    background-color: var(--color-danger-light);
}

.dropdown-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.25rem 0;
}

/* Notification Panel */
.notification-panel {
    position: absolute;
    top: 64px;
    right: 1.75rem;
    width: 360px;
    max-height: 480px;
    overflow-y: auto;
    background-color: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    animation: csFadeIn 0.15s ease;
}

.notification-header {
    padding: 0.875rem 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background-color: var(--color-surface);
    z-index: 1;
}

.notification-item {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.notification-item:hover {
    background-color: var(--color-background);
}

.notification-item:last-child {
    border-bottom: none;
}

.notification-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-main);
}

.notification-item-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Global search results */
.global-search-results {
    position: absolute;
    top: 64px;
    width: 480px;
    background-color: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    max-height: 480px;
    overflow-y: auto;
    animation: csFadeIn 0.15s ease;
}

.search-result-group {
    padding: 0.5rem 0;
}

.search-result-group-title {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background-color: var(--color-background);
}

.search-result-item {
    display: block;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.search-result-item:hover {
    background-color: var(--color-background);
}

/* UIUX #2: 帳單從搜尋/儀表板點過來後高亮閃爍 (2.2s 內) */
@keyframes row-flash-anim {
    0%   { background-color: rgba(255, 136, 89, 0.35); }
    50%  { background-color: rgba(255, 136, 89, 0.20); }
    100% { background-color: transparent; }
}
tr.row-flash > td {
    animation: row-flash-anim 2.2s ease-out;
}

.search-result-item-title {
    font-size: 0.875rem;
    font-weight: 500;
}

.search-result-item-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.search-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Checkin task checkbox visual */
.task-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.125rem;
    line-height: 0;
    transition: transform var(--transition-fast);
}

.task-icon-btn:hover {
    transform: scale(1.15);
}

/* card-title nowrap/ellipsis 已整併到 L2306 base rule (P1-2)，原 !important 移除 */

.metric-header {
    white-space: nowrap !important;
}

.metric-value {
    white-space: nowrap !important;
}

.status-badge {
    white-space: nowrap !important;
}
