/* 房地產案場 CRM 系統 - 現代商務設計系統與高階視覺樣式規範 (Design System & Tokens) */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;600;700&display=swap');

:root {
    /* 品牌與商務主色系 (Slate & Royal Sapphire) */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --primary-ring: rgba(37, 99, 235, 0.15);
    
    /* 輔助與語意色彩 */
    --secondary: #0f172a;
    --secondary-surface: #1e293b;
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --purple: #8b5cf6;
    --purple-light: #f5f3ff;

    /* 表面底色與邊框 */
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --border-subtle: #e2e8f0;
    --border-card: #e2e8f0;

    /* iOS 安全邊界適配 (Safe Area Insets) */
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
}

* {
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}

html {
    min-height: 100%;
    -webkit-text-size-adjust: 100%;
    touch-action: pan-y manipulation;
    scroll-behavior: smooth;
    overflow-x: hidden;
    overflow-y: auto;
    width: 100%;
    max-width: 100%;
}

body {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: var(--bg-main);
    color: #1e293b;
    min-height: 100%;
    min-height: 100dvh;
    width: 100%;
    max-width: 100%;
    padding-left: var(--sal);
    padding-right: var(--sar);
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y manipulation;
}

#app-shell {
    width: 100%;
    max-width: 100%;
    min-height: 100%;
}

.view-container {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

/* ========================================================================= */
/* 行動裝置與全螢幕響應式排版架構 (Mobile Layout Architecture & Zero Overflow) */
/* ========================================================================= */

/* 全域防止水平溢位：確保任何子元件均不超出手機螢幕寬度 */
html, body {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

#app-shell,
main,
.view-container,
#view-list,
#view-form,
#view-schedule,
#view-dashboard {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

/* 專業行動客戶卡片 (Professional Mobile Customer Card) */
.mobile-customer-card {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.mobile-customer-card:active {
    transform: scale(0.995);
}

/* 手機版卡片容器與間距優化 */
#customer-cards-container {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
}

/* 斷點架構：平板與手機 (< 1024px) 優先呈現卡片，桌機 (>= 1024px) 呈現大表格 */
@media screen and (max-width: 1023px) {
    #customer-table-wrap {
        display: none !important;
    }
    #customer-cards-container {
        display: block !important;
    }
}

@media screen and (min-width: 1024px) {
    #customer-table-wrap {
        display: block !important;
    }
    #customer-cards-container {
        display: none !important;
    }
}

/* 表格水平捲動容器保護 (避免即便在桌機或平板也撐爆頁面) */
#customer-table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    width: 100% !important;
    max-width: 100% !important;
}

/* 手機端專用間距與表單底欄高度適配 */
@media screen and (max-width: 768px) {
    /* 來訪登記表浮動底部按鈕：精準浮在手機底部導航列上方，不遮擋也不重疊 */
    .form-floating-bottom-bar {
        bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px)) !important;
    }
    
    /* 確保所有按鈕具有人體工學觸控範圍 (HIG / Material Design) */
    button, a.btn, input, select {
        touch-action: manipulation;
    }

    /* 手機端快速標籤橫向滑動提示陰影 */
    .quick-filters-scroll-wrap {
        mask-image: linear-gradient(to right, black 90%, transparent 100%);
        -webkit-mask-image: linear-gradient(to right, black 90%, transparent 100%);
    }
}

/* 數字與電話使用等寬字型優化對齊感 */
.font-mono, td.font-mono, span.font-mono {
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-feature-settings: "tnum" 1, "zero" 1;
}

/* 避免 iOS Safari 在聚焦表單輸入框時強制放大畫面 (Font-size >= 16px) */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="password"],
    input[type="tel"],
    input[type="email"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
        line-height: 1.35;
    }
}

/* PWA Standalone 全螢幕模式專屬優化 */
@media (display-mode: standalone) {
    header {
        padding-top: var(--sat);
    }
}

/* 自訂精緻滑動捲軸 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.no-scrollbar::-webkit-scrollbar {
    display: none;
}
.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* 橫向分頁標籤導航欄與隱藏捲軸優化 */
.settings-tab-nav {
    flex-shrink: 0 !important;
    min-height: 48px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
}

/* ========================================================================= */
/* 表單與控制項互動美化 (Interactive Form Controls & Pills) */
/* ========================================================================= */

/* 表單卡片統一風格 */
.form-section-card {
    background: #ffffff;
    border-radius: 1rem;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.04), 0 1px 2px -1px rgba(0, 0, 0, 0.04);
    padding: 1.5rem;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.form-section-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.06);
}

/* 輸入框聚焦光暈與微互動 */
input[type="text"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
    transition: all 0.15s ease-in-out;
}

input:focus,
select:focus,
textarea:focus {
    outline: none !important;
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15) !important;
}

/* 標籤雲微互動按鈕 (抗性與未成交理由) */
.tag-btn {
    transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    touch-action: manipulation;
    user-select: none;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #475569;
    border-radius: 0.5rem;
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
}
.tag-btn:hover {
    transform: translateY(-1px);
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
    box-shadow: 0 2px 5px rgba(37, 99, 235, 0.08);
}
.tag-btn:active {
    transform: scale(0.96);
}

/* 快捷篩選標籤 (Quick Filter Chips) */
.quick-filter-chip {
    transition: all 0.15s ease-in-out;
    cursor: pointer;
    border: 1px solid #e2e8f0;
    font-weight: 600;
}
.quick-filter-chip:hover {
    border-color: #cbd5e1;
    transform: translateY(-1px);
}
.quick-filter-chip.active {
    background-color: #2563eb !important;
    color: #ffffff !important;
    border-color: #2563eb !important;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25) !important;
}

/* ========================================================================= */
/* 狀態與意向評級徽章 (Status & Rating Badges) */
/* ========================================================================= */
.badge-status-初訪 {
    background-color: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}
.badge-status-深度洽談二訪,
.badge-status-二訪 {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}
.badge-status-追蹤中 {
    background-color: #e0e7ff;
    color: #4338ca;
    border: 1px solid #c7d2fe;
}
.badge-status-已下訂 {
    background-color: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}
.badge-status-已簽約 {
    background-color: #059669;
    color: #ffffff;
    border: 1px solid #047857;
    box-shadow: 0 1px 3px rgba(5, 150, 105, 0.2);
}
.badge-status-暫緩,
.badge-status-無效客 {
    background-color: #f1f5f9;
    color: #64748b;
    border: 1px solid #e2e8f0;
}
.badge-status-結案 {
    background-color: #334155;
    color: #ffffff;
    border: 1px solid #1e293b;
}

/* 急迫性指示色彩標籤 */
.urgency-high {
    color: #dc2626;
    background-color: #fef2f2;
    border: 1px solid #fecaca;
}
.urgency-medium {
    color: #d97706;
    background-color: #fffbeb;
    border: 1px solid #fde68a;
}
.urgency-low {
    color: #2563eb;
    background-color: #eff6ff;
    border: 1px solid #bfdbfe;
}

/* ========================================================================= */
/* 跟進時間軸 (Timeline) */
/* ========================================================================= */
.timeline-line {
    position: absolute;
    top: 18px;
    bottom: 0;
    left: 17px;
    width: 2px;
    background-color: #e2e8f0;
}

/* 玻璃擬態質感 */
.glass-panel {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* 動畫效果 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUpMobile {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
    animation: fadeIn 0.24s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* 響應式彈窗 (手機版採用 Bottom Sheet 體驗，桌機版置中) */
@media screen and (max-width: 640px) {
    .modal-content-container {
        border-bottom-left-radius: 0 !important;
        border-bottom-right-radius: 0 !important;
        margin-top: auto !important;
        margin-bottom: 0 !important;
        max-height: calc(100vh - 1.5rem) !important;
        animation: slideUpMobile 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
        -webkit-overflow-scrolling: touch;
    }
}

.modal-content-container [class*="overflow-y-auto"] {
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* 手機底部導航欄高亮樣式 */
.mobile-nav-btn.active {
    color: #2563eb !important;
    font-weight: 700;
}
.mobile-nav-btn.active .nav-icon-wrap {
    background-color: #eff6ff;
    border-radius: 12px;
}

/* KPI 統計卡片細緻邊框裝飾 */
.kpi-card-top-accent {
    position: relative;
    overflow: hidden;
}
.kpi-card-top-accent::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #2563eb, #3b82f6);
}

/* ========================================================================= */
/* 列印專用樣式 (Print-Friendly A4) */
/* ========================================================================= */
@media print {
    body {
        background-color: #ffffff !important;
        color: #000000 !important;
        font-size: 10.5pt;
        padding-bottom: 0 !important;
    }
    .no-print {
        display: none !important;
    }
    .print-only {
        display: block !important;
    }
    
    header, nav, #update-banner, #offline-banner, #install-banner, #ios-install-banner, #toast-container {
        display: none !important;
    }

    #view-list .bg-white.rounded-2xl.p-5 {
        display: none !important;
    }
    #customer-cards-container {
        display: none !important;
    }
    .hidden.md\:block, .md\:block {
        display: block !important;
    }
    
    table th:last-child, table td:last-child {
        display: none !important;
    }

    table {
        width: 100% !important;
        border-collapse: collapse !important;
    }
    table th, table td {
        border: 1px solid #cbd5e1 !important;
        padding: 8px !important;
        font-size: 10pt !important;
        white-space: nowrap !important;
    }
    table th {
        background-color: #f1f5f9 !important;
        color: #000 !important;
    }

    .print-card {
        box-shadow: none !important;
        border: 1px solid #000000 !important;
        padding: 1.5cm !important;
    }
    @page {
        margin: 1cm;
        size: A4 landscape;
    }
}

/* 即時同步微光閃爍動畫 (WebSocket Real-time Highlight Pulse) */
@keyframes ws-pulse-highlight {
    0% {
        background-color: rgba(59, 130, 246, 0.25);
        box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4);
    }
    50% {
        background-color: rgba(59, 130, 246, 0.15);
    }
    100% {
        background-color: transparent;
        box-shadow: none;
    }
}

.ws-highlight-pulse {
    animation: ws-pulse-highlight 2s ease-out;
}

/* ========================================================================= */
/* 深色暗黑主題樣式規範 (Dark Theme Specification) */
/* ========================================================================= */
html.dark {
    color-scheme: dark;
}

html.dark body {
    background-color: #0b1120 !important;
    color: #e2e8f0 !important;
}

html.dark .bg-white {
    background-color: #1e293b !important;
}

html.dark .bg-slate-50 {
    background-color: #0f172a !important;
}

html.dark .bg-slate-100 {
    background-color: #0b1120 !important;
}

html.dark .bg-slate-200 {
    background-color: #334155 !important;
    color: #e2e8f0 !important;
}

html.dark .border-slate-100 {
    border-color: #1e293b !important;
}

html.dark .border-slate-200,
html.dark .border-slate-200\/90 {
    border-color: #334155 !important;
}

html.dark .border-slate-300 {
    border-color: #475569 !important;
}

html.dark .text-slate-900,
html.dark .text-slate-800 {
    color: #f8fafc !important;
}

html.dark .text-slate-700 {
    color: #e2e8f0 !important;
}

html.dark .text-slate-600,
html.dark .text-slate-500 {
    color: #94a3b8 !important;
}

html.dark .text-slate-400 {
    color: #64748b !important;
}

/* 深色表單輸入框美化 */
html.dark input[type="text"],
html.dark input[type="password"],
html.dark input[type="tel"],
html.dark input[type="email"],
html.dark input[type="number"],
html.dark input[type="date"],
html.dark input[type="time"],
html.dark input[type="url"],
html.dark select,
html.dark textarea {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    border-color: #334155 !important;
}

html.dark input::placeholder,
html.dark textarea::placeholder {
    color: #64748b !important;
}

html.dark input:focus,
html.dark select:focus,
html.dark textarea:focus {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25) !important;
}

/* 深色表單卡片與彈窗 */
html.dark .form-section-card {
    background: #1e293b !important;
    border-color: #334155 !important;
}

html.dark .form-section-card:hover {
    border-color: #475569 !important;
}

html.dark .modal-content-container {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #f8fafc !important;
}

html.dark .settings-tab-nav {
    background-color: #0f172a !important;
    border-color: #334155 !important;
}

html.dark .settings-tab-btn {
    color: #94a3b8 !important;
}

html.dark .settings-tab-btn:hover {
    color: #f8fafc !important;
}

html.dark .settings-tab-btn.active,
html.dark .settings-tab-btn.text-blue-600 {
    color: #60a5fa !important;
    border-color: #3b82f6 !important;
}

/* 深色資料表格與列 */
html.dark table thead,
html.dark table thead th {
    background-color: #0f172a !important;
    color: #94a3b8 !important;
    border-color: #334155 !important;
}

html.dark table tbody tr {
    border-color: #334155 !important;
}

html.dark table tbody tr:hover {
    background-color: rgba(51, 65, 85, 0.45) !important;
}

html.dark .divide-slate-100 > * + *,
html.dark .divide-slate-200 > * + * {
    border-color: #334155 !important;
}

/* 手機底部導航列 */
html.dark #bottom-nav {
    background-color: #0f172a !important;
    border-color: #1e293b !important;
}

/* 標籤雲與過濾晶片 */
html.dark .tag-btn {
    background: #0f172a !important;
    border-color: #334155 !important;
    color: #cbd5e1 !important;
}

html.dark .tag-btn:hover {
    background: #1e293b !important;
    border-color: #3b82f6 !important;
    color: #60a5fa !important;
}

html.dark .quick-filter-chip {
    background: #1e293b !important;
    border-color: #334155 !important;
    color: #cbd5e1 !important;
}

html.dark .quick-filter-chip:hover {
    border-color: #64748b !important;
}

/* 深色模式捲軸 */
html.dark ::-webkit-scrollbar-track {
    background: #0f172a;
}

html.dark ::-webkit-scrollbar-thumb {
    background: #334155;
}

html.dark ::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

/* 危險區域卡片深色適配 */
html.dark #admin-database-clear-card {
    background-color: rgba(136, 19, 55, 0.2) !important;
    border-color: rgba(244, 63, 94, 0.35) !important;
}

html.dark #admin-database-clear-card .text-rose-900 {
    color: #fecdd3 !important;
}

html.dark #admin-database-clear-card .text-rose-700 {
    color: #fda4af !important;
}

/* 深色模式行動客戶卡片 */
html.dark .mobile-customer-card {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #e2e8f0 !important;
}

html.dark .mobile-customer-card .border-slate-100 {
    border-color: #334155 !important;
}

html.dark .mobile-customer-card .bg-slate-50\/80,
html.dark .mobile-customer-card .bg-slate-50 {
    background-color: #0f172a !important;
    border-color: #334155 !important;
}

html.dark #mobile-actions-menu {
    background-color: #1e293b !important;
    border-color: #334155 !important;
}

html.dark #mobile-actions-menu button {
    color: #cbd5e1 !important;
}

html.dark #mobile-actions-menu button:hover {
    background-color: #334155 !important;
    color: #f8fafc !important;
}



