
    :root { --bg-main: #f4f7f6; --bg-soft: #f8fbf9; --card-bg: #ffffff; --primary: #2e7d32; --primary-dark: #1b5e20; --primary-soft: #e8f5e9; --accent: #4caf50; --accent-soft: #eef8f0; --orange: #ff9800; --danger: #c62828; --danger-soft: #ffebee; --info: #1976d2; --text-main: #26332a; --text-muted: #66736a; --border: #dfe8e3; --shadow: 0 12px 30px rgba(30, 80, 45, 0.08); --shadow-soft: 0 6px 18px rgba(30, 80, 45, 0.06); --radius: 18px; }
    * { box-sizing: border-box; }
    body { margin: 0; background: radial-gradient(circle at top left, rgba(76, 175, 80, 0.16), transparent 28%), linear-gradient(180deg, #f8fbf9 0%, var(--bg-main) 42%, #ffffff 100%); color: var(--text-main); font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif; min-height: 100vh; overflow-x: hidden; }
    .app-shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }
    .sidebar { background: linear-gradient(180deg, #1b5e20 0%, #2e7d32 56%, #1b5e20 100%); color: #f1fff4; padding: 24px 18px; position: sticky; top: 0; height: 100vh; box-shadow: 12px 0 35px rgba(52, 71, 34, 0.18); z-index: 10; }
    .brand-mark { display: flex; align-items: center; gap: 12px; padding-bottom: 22px; border-bottom: 1px solid rgba(255, 255, 255, 0.14); margin-bottom: 20px; }
    .brand-icon { width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; background: linear-gradient(135deg, #e8f5e9, #81c784); color: #1b5e20; font-size: 1.55rem; box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.28); }
    .brand-title { font-weight: 800; font-size: 1rem; line-height: 1.25; } .brand-subtitle { font-size: 0.75rem; opacity: 0.82; margin-top: 3px; }
    .nav-pill { color: rgba(255, 250, 229, 0.86); display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 12px; border-radius: 14px; text-decoration: none; margin-bottom: 8px; font-weight: 700; font-size: 0.95rem; transition: 0.18s ease; border: 0; background: transparent; text-align: left; cursor: pointer; }
    .nav-pill:focus-visible { outline: 3px solid rgba(255, 244, 203, 0.85); outline-offset: 2px; }
    .nav-pill i { width: 20px; text-align: center; } .nav-pill:hover, .nav-pill.active { background: rgba(232, 245, 233, 0.96); color: #1b5e20; transform: translateX(2px); }
    .sidebar-quote { position: absolute; bottom: 24px; left: 18px; right: 18px; text-align: center; font-size: 0.82rem; line-height: 1.65; color: rgba(255, 250, 229, 0.86); border-top: 1px solid rgba(255, 255, 255, 0.14); padding-top: 18px; }
    .main { padding: 22px 28px 34px; min-width: 0; position: relative; }
    #view-dashboard { display: block; } #view-map, #view-charts-full { display: none; height: calc(100vh - 44px); flex-direction: column; }
    .topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 4px 0 22px; }
    .page-title { display: flex; align-items: center; gap: 14px; } .page-title .logo-leaf { width: 50px; height: 50px; border-radius: 17px; display: grid; place-items: center; background: linear-gradient(135deg, #e8f5e9 0%, #81c784 48%, #2e7d32 100%); color: #ffffff; box-shadow: var(--shadow-soft); font-size: 1.65rem; }
    .page-title h1 { font-size: clamp(1.35rem, 2vw, 1.9rem); margin: 0; font-weight: 900; color: #1f3326; } .page-title p { margin: 4px 0 0; color: var(--text-muted); font-size: 0.92rem; }
    .top-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; } .status-chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 999px; padding: 8px 13px; background: rgba(255, 255, 255, 0.72); box-shadow: var(--shadow-soft); color: var(--text-main); font-size: 0.88rem; font-weight: 700; } .status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px rgba(95,127,50,0.12); }
    .card-clean { background: rgba(255, 255, 255, 0.86); border: 1px solid rgba(234, 223, 202, 0.82); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(8px); }
    .summary-card { padding: 20px; height: 100%; background: linear-gradient(135deg, rgba(255,255,255,0.95), rgba(255,248,231,0.92)), radial-gradient(circle at top right, rgba(126,160,77,0.17), transparent 34%); }
    .section-title { display: flex; align-items: center; gap: 9px; margin-bottom: 15px; font-weight: 900; color: #1f3326; } .section-title .icon-box { width: 32px; height: 32px; border-radius: 11px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-dark); }
    .summary-text { line-height: 1.75; color: #2f4035; font-size: 0.98rem; } .alert-soft { border-radius: 14px; background: var(--danger-soft); color: #c62828; padding: 10px 12px; font-weight: 800; font-size: 0.88rem; display: inline-flex; gap: 8px; align-items: center; margin-top: 12px; }
    .kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; } .kpi-card { padding: 18px; min-height: 112px; display: flex; align-items: center; gap: 14px; position: relative; overflow: hidden; } .kpi-card::after { content: ''; position: absolute; right: -28px; bottom: -32px; width: 96px; height: 96px; border-radius: 50%; background: rgba(217, 164, 65, 0.12); }
    .kpi-icon { width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center; font-size: 1.35rem; flex: 0 0 auto; background: var(--primary-soft); color: var(--primary); } .kpi-icon.gold { background: var(--accent-soft); color: var(--accent); } .kpi-icon.blue { background: #e9f3f7; color: var(--info); } .kpi-icon.red { background: var(--danger-soft); color: var(--danger); }
    .kpi-label { color: var(--text-muted); font-size: 0.82rem; font-weight: 800; margin-bottom: 5px; } .kpi-value { font-size: 1.38rem; font-weight: 900; color: #1f3326; line-height: 1.1; } .kpi-note { font-size: 0.75rem; color: var(--text-muted); margin-top: 5px; }
    .filter-card { padding: 18px 20px; margin-top: 16px; } .filter-grid { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 12px; align-items: end; } .date-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; gap: 12px; align-items: end; margin-top: 12px; }
    label.form-label { color: var(--text-muted); font-size: 0.82rem; font-weight: 900; margin-bottom: 6px; } .form-control, .form-select { border-color: var(--border); border-radius: 11px; color: var(--text-main); min-height: 42px; }
    .btn-main { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); border: none; color: #fff; border-radius: 12px; font-weight: 900; padding: 11px 18px; box-shadow: 0 10px 18px rgba(64, 90, 34, 0.18); } .btn-soft { background: #f8fbf9; border: 1px solid var(--border); color: #52645a; border-radius: 12px; font-weight: 800; padding: 10px 16px; } .btn-chip { border: 1px solid var(--border); color: #52645a; background: #ffffff; border-radius: 11px; font-weight: 800; min-height: 40px; padding: 8px 14px; } .btn-chip.active, .btn-chip:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
    .workspace-grid { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(360px, .92fr); gap: 16px; margin-top: 16px; }
    .chart-card, .form-card, .history-card { padding: 18px 20px; } .chart-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; } .chart-pane { display: none; } .chart-pane.active { display: block; } .chart-container { position: relative; width: 100%; height: 318px; }
    .big-chart-shell { display: flex; flex-direction: column; height: 100%; min-height: 0; }
    .big-chart-toolbar { border-radius: 16px; flex-shrink: 0; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
    .big-chart-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin: 12px 0; flex-shrink: 0; }
    .big-kpi { padding: 14px 16px; min-height: 86px; border-radius: 16px; background: rgba(255,255,255,.9); border: 1px solid var(--border); box-shadow: var(--shadow-soft); }
    .big-kpi .label { color: var(--text-muted); font-size: .78rem; font-weight: 900; }
    .big-kpi .value { color: #1f3326; font-size: 1.25rem; font-weight: 950; margin-top: 5px; line-height: 1.15; }
    .big-chart-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, .75fr); grid-template-rows: minmax(300px, 1fr) minmax(260px, .9fr); gap: 12px; overflow-y: auto; }
    .big-chart-card { padding: 14px 16px; min-height: 0; display: flex; flex-direction: column; }
    .big-chart-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 950; color: #1f3326; }
    .big-chart-canvas { position: relative; flex: 1; min-height: 220px; }
    .big-rank-table { max-height: 100%; overflow: auto; }
    .big-rank-table table { margin-bottom: 0; }
    .big-rank-table thead th { position: sticky; top: 0; background: #f4f7f6 !important; z-index: 2; font-size: .78rem; color: var(--text-muted); }

    .form-section { border: 1px solid var(--border); border-radius: 16px; overflow: hidden; margin-bottom: 14px; background: #ffffff; } .form-section-header { background: linear-gradient(90deg, #e8f5e9, #f4f7f6); padding: 11px 14px; color: #2f4035; font-weight: 900; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--border); } .form-section-body { padding: 14px; }
    .btn-save { width: 100%; border: none; border-radius: 14px; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; min-height: 48px; font-weight: 900; box-shadow: 0 12px 20px rgba(64, 90, 34, .2); } .btn-update { width: 100%; border: none; border-radius: 14px; background: linear-gradient(135deg, #4caf50, #2e7d32); color: white; min-height: 48px; font-weight: 900; box-shadow: 0 12px 20px rgba(231, 123, 24, .18); }
    .receipt-review-panel { border: 1px solid #ffe082; border-radius: 14px; background: #fffdf5; padding: 12px; }
    .receipt-suggestion-row { border-top: 1px dashed #eadfb8; padding: 10px 0; }
    .receipt-suggestion-row:first-child { border-top: 0; }
    .receipt-confidence-high { background: #e8f5e9; color: #1b5e20; }
    .receipt-confidence-medium { background: #fff8e1; color: #e65100; }
    .receipt-confidence-low { background: #ffebee; color: #b71c1c; }
    .receipt-applied-pending { background-color: #fff3cd !important; border-color: #d39e00 !important; }
    .receipt-applied-confirmed { background-color: #e8f5e9 !important; border-color: #2e7d32 !important; }
    .receipt-batch-shell { border: 1px solid #b7dfbd; border-radius: 16px; background: linear-gradient(135deg, #f5fbf6, #ffffff); padding: 14px; margin-bottom: 14px; }
    .receipt-batch-panel { border-top: 1px dashed #b7dfbd; margin-top: 12px; padding-top: 12px; }
    .receipt-batch-items { display: grid; gap: 10px; max-height: 620px; overflow: auto; padding-right: 2px; }
    .receipt-batch-item { border: 1px solid var(--border); border-radius: 14px; background: #fff; padding: 12px; }
    .receipt-batch-file { overflow-wrap: anywhere; font-weight: 900; color: #26332a; }
    .receipt-batch-state { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; background: #eef3f0; color: #52645a; font-size: .74rem; font-weight: 900; }
    .receipt-batch-state.ready, .receipt-batch-state.saved { background: #e8f5e9; color: #1b5e20; }
    .receipt-batch-state.failed { background: #ffebee; color: #b71c1c; }
    .receipt-batch-state.normalizing, .receipt-batch-state.qr-ocr, .receipt-batch-state.saving { background: #fff8e1; color: #e65100; }
    .receipt-batch-state.cancelled { background: #eceff1; color: #546e7a; }
    .receipt-batch-common { border-radius: 13px; background: #f8fbf9; border: 1px solid var(--border); padding: 11px; }
    .table-container { max-height: 420px; overflow-y: auto; } .table thead th { position: sticky; top: 0; background: #f4f7f6 !important; z-index: 2; color: #66736a; font-size: 0.78rem; border-bottom: 1px solid var(--border); }
    .badge-status { border-radius: 999px; padding: 6px 10px; font-weight: 900; font-size: .76rem; } .status-paid { background: #e8f5e9; color: #2e7d32; } .status-unpaid { background: #ffebee; color: #c62828; } .status-partial { background: #fff8e1; color: #ef6c00; } .status-na { background: #eceff1; color: #546e7a; }

    /* 🚀 地圖拖曳標記與面板專用樣式 */
    .map-toolbar-card { border-radius: 16px; flex-shrink: 0; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
    .map-filter-panel { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
    .map-filter-panel.show { display: block; }
    .map-filter-hint { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-dark); font-size: .78rem; font-weight: 900; }
    .custom-marker-icon { background: transparent; border: none; }
    .map-floating-panel { position: absolute; top: 20px; right: 20px; z-index: 1000; width: 360px; background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(12px); padding: 24px; border-radius: 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15); border: 1px solid var(--border); display: none; max-height: calc(100% - 40px); overflow-y: auto; transition: all 0.3s ease; }
    .leaflet-popup-content-wrapper { border-radius: 12px; }

    /* 儲存提示框 (Toast) 動畫 */
    @keyframes toastFade { 0% { opacity: 0; transform: translate(-50%, 20px); } 10% { opacity: 1; transform: translate(-50%, 0); } 90% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -20px); } }
    .global-toast-container { position: fixed; right: 22px; bottom: 22px; z-index: 10020; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
    .global-toast { max-width: min(420px, calc(100vw - 32px)); background: rgba(46, 125, 50, .97); color: white; padding: 13px 18px; border-radius: 14px; box-shadow: 0 10px 34px rgba(0,0,0,.2); font-weight: 800; animation: globalToastFade 4.2s forwards; }
    @keyframes globalToastFade { 0% { opacity: 0; transform: translateY(14px); } 8%, 88% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-8px); } }
    .perf-panel { display: none; position: fixed; right: 22px; top: 84px; z-index: 10010; width: min(390px, calc(100vw - 32px)); background: #fff; border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 18px 55px rgba(20,50,30,.22); padding: 16px; }
    .perf-panel.show { display: block; }
    .perf-output { white-space: pre-wrap; margin: 10px 0; padding: 10px; border-radius: 12px; background: #f4f7f6; color: #26332a; font-size: .8rem; line-height: 1.55; max-height: 260px; overflow: auto; }
    .dependency-error { margin: 16px; padding: 16px; border-radius: 14px; background: #ffebee; color: #9b1c1c; font-weight: 800; text-align: center; }

    #loader, #password-overlay { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; flex-direction: column; background: radial-gradient(circle at top left, rgba(217, 164, 65, 0.22), transparent 32%), linear-gradient(135deg, #f8fbf9, #e8f5e9); }
    #loader { display: none; background: rgba(248, 251, 249, .94); backdrop-filter: blur(6px); }
    .pwd-card { width: min(92vw, 430px); border-radius: 24px; background: rgba(255,255,255,.92); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 36px 30px; text-align: center; }

    /* =========================================================
       響應式修正：避免中小尺寸螢幕側邊欄消失
       原本在 max-width:1180px 直接 display:none，會造成部分筆電/螢幕看不到側邊欄。
       ========================================================= */
    @media (max-width: 1180px) {
      .big-chart-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }

      .big-chart-grid {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(4, minmax(300px, auto));
        overflow-y: auto;
      }

      /* 中小尺寸桌機/筆電：保留左側欄，只縮小寬度 */
      .app-shell {
        grid-template-columns: 190px minmax(0, 1fr);
      }

      .sidebar {
        display: block;
        position: sticky;
        top: 0;
        height: 100vh;
        padding: 20px 12px;
      }

      .brand-mark {
        gap: 9px;
      }

      .brand-icon {
        width: 40px;
        height: 40px;
        border-radius: 13px;
        font-size: 1.35rem;
      }

      .brand-title {
        font-size: 0.9rem;
      }

      .brand-subtitle {
        font-size: 0.7rem;
      }

      .nav-pill {
        font-size: 0.86rem;
        padding: 10px 9px;
        gap: 8px;
      }

      .sidebar-quote {
        left: 12px;
        right: 12px;
        font-size: 0.76rem;
      }

      .main {
        padding: 18px;
      }

      .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }

      .workspace-grid {
        grid-template-columns: 1fr;
      }

      .filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }

      .date-grid {
        grid-template-columns: 1fr;
      }
    }

    /* 平板/手機：側邊欄改為上方選單，不再隱藏 */
    @media (max-width: 768px) {
      .app-shell {
        grid-template-columns: 1fr;
      }

      .sidebar {
        position: relative;
        height: auto;
        width: 100%;
        display: block;
        padding: 14px 12px;
        box-shadow: 0 8px 24px rgba(52, 71, 34, 0.16);
      }

      .brand-mark {
        padding-bottom: 12px;
        margin-bottom: 12px;
      }

      .sidebar nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
      }

      .nav-pill {
        margin-bottom: 0;
        justify-content: center;
        font-size: 0.82rem;
        padding: 10px 8px;
      }

      .nav-pill:hover,
      .nav-pill.active {
        transform: none;
      }

      .sidebar-quote {
        display: none;
      }

      .main {
        padding: 14px;
      }

      #view-map,
      #view-charts-full {
        height: auto;
        min-height: calc(100vh - 120px);
      }
    }

    @media (max-width: 680px) {
      .map-floating-panel {
        width: calc(100% - 40px);
      }

      .kpi-grid,
      .filter-grid {
        grid-template-columns: 1fr;
      }
    }

    /* 桌面側欄：內容不壓縮，空間足夠時footer置底，不足時可捲動。 */
    @media (min-width: 769px) {
      .sidebar {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
      }

      .sidebar > .brand-mark,
      .sidebar > nav,
      .sidebar > .sidebar-quote {
        flex: 0 0 auto;
      }

      .sidebar-quote {
        position: static;
        margin-top: auto;
      }
    }
