/* ===================================================================
   MoneyFlow Pro — ธีมหรูหรามินิมอล (ดำ / ทอง / ขาว) สำหรับเดโม
   =================================================================== */
:root {
    --gold: #C5A572; --gold-light: #D9C29A; --gold-dark: #A6864F;
    --ink: #1A1A1A; --ink-soft: #2B2B2B;
    --gray: #6B6B6B; --gray-light: #E8E8E8;
    --bg: #F7F5F1; --card: #FFFFFF;
    --text: #1A1A1A; --text-muted: #8A8A8A;
    --border: #ECEAE5;
    --success: #2E7D5B; --danger: #C0392B; --warning: #D4A03A; --info: #4A6FA5;
    --sidebar-w: 250px; --radius: 14px;
    --shadow: 0 2px 16px rgba(0,0,0,.06); --shadow-hover: 0 6px 24px rgba(0,0,0,.10);
}
.theme-dark {
    --bg: #121212; --card: #1E1E1E; --text: #EAEAEA; --text-muted: #9A9A9A;
    --border: #2C2C2C; --gray-light: #2C2C2C;
    --shadow: 0 2px 16px rgba(0,0,0,.4); --shadow-hover: 0 6px 24px rgba(0,0,0,.5);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* ====== มือถือ: กัน tap highlight + double-tap zoom + text resize ====== */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }
body { margin:0; font-family:'Sarabun','Inter',system-ui,sans-serif; background:var(--bg); color:var(--text); font-size:15px; line-height:1.6; transition:background .25s,color .25s; }
.app-wrapper { min-height:100vh; }

/* Sidebar */
.sidebar { position:fixed; top:0; left:0; bottom:0; width:var(--sidebar-w); background:var(--ink); color:#C9C9C9; z-index:1040; display:flex; flex-direction:column; transition:transform .25s; }
.sidebar-brand { padding:24px 22px; font-size:20px; font-weight:700; color:#fff; display:flex; align-items:center; gap:10px; border-bottom:1px solid rgba(255,255,255,.08); }
.sidebar-brand i { color:var(--gold); font-size:26px; }
.sidebar-brand em { color:var(--gold); font-style:normal; font-weight:400; }
.sidebar-nav { flex:1; padding:18px 0; overflow-y:auto; }
.sidebar-nav a { display:flex; align-items:center; gap:14px; padding:12px 24px; color:#A8A8A8; text-decoration:none; font-size:15px; font-weight:500; border-left:3px solid transparent; transition:all .18s; }
.sidebar-nav a i { font-size:18px; width:22px; text-align:center; }
.sidebar-nav a:hover { background:rgba(255,255,255,.04); color:#fff; }
.sidebar-nav a.active { background:linear-gradient(90deg, rgba(197,165,114,.18), transparent); color:var(--gold); border-left-color:var(--gold); }
.sidebar-footer { padding:14px 24px; font-size:12px; color:#555; border-top:1px solid rgba(255,255,255,.06); }

.main-content { margin-left:var(--sidebar-w); min-height:100vh; }
.topbar { background:var(--card); border-bottom:1px solid var(--border); padding:0 28px; height:64px; display:flex; align-items:center; gap:18px; position:sticky; top:0; z-index:1030; }
.page-title { font-size:19px; font-weight:600; margin:0; flex:1; color:var(--text); }
.btn-toggle { background:none; border:none; font-size:22px; color:var(--text); cursor:pointer; display:none; }
.topbar-right { display:flex; align-items:center; gap:16px; }
.lang-switch { display:flex; align-items:center; gap:6px; font-weight:600; }
.lang-switch a { color:var(--text-muted); text-decoration:none; font-size:13px; cursor:pointer; }
.lang-switch a.active { color:var(--gold); }
.btn-icon { background:none; border:none; font-size:18px; color:var(--text); cursor:pointer; padding:6px; border-radius:8px; }
.btn-icon:hover { background:var(--gray-light); }
.user-btn { background:none; border:1px solid var(--border); padding:6px 12px; border-radius:30px; display:flex; align-items:center; gap:8px; color:var(--text); font-size:14px; cursor:pointer; }
.user-btn i { color:var(--gold); font-size:18px; }
.content-area { padding:28px; }

/* Cards */
.card { background:var(--card); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow); margin-bottom:22px; }
.card-body { padding:22px; }
.card-title { font-size:15px; font-weight:600; color:var(--text-muted); text-transform:uppercase; letter-spacing:.5px; margin-bottom:4px; }
.stat-card { position:relative; overflow:hidden; }
.stat-card .stat-icon { position:absolute; right:16px; top:50%; transform:translateY(-50%); font-size:42px; opacity:.12; }
.stat-value { font-size:26px; font-weight:700; color:var(--text); margin-top:4px; }
.stat-value.income { color:var(--success); } .stat-value.expense { color:var(--danger); } .stat-value.gold { color:var(--gold); }

/* Buttons */
.btn { border-radius:10px; font-weight:500; padding:9px 18px; }
.btn-gold { background:linear-gradient(135deg, var(--gold), var(--gold-dark)); border:none; color:#fff; }
.btn-gold:hover { color:#fff; box-shadow:0 4px 14px rgba(197,165,114,.4); }
.btn-outline-gold { border-color:var(--gold); color:var(--gold-dark); background:transparent; }
.btn-outline-gold:hover { background:var(--gold); color:#fff; }
.btn-outline-secondary { border-color:var(--border); color:var(--text); background:transparent; }

/* Table */
.table { margin:0; color:var(--text); width:100%; border-collapse:collapse; }
.table thead th { background:var(--bg); color:var(--text-muted); font-weight:600; font-size:13px; text-transform:uppercase; letter-spacing:.4px; border-bottom:2px solid var(--border); padding:14px 16px; text-align:left; }
.table tbody td { padding:13px 16px; border-color:var(--border); vertical-align:middle; }
.table tbody tr { border-bottom:1px solid var(--border); }
.text-income { color:var(--success); font-weight:600; }
.text-expense { color:var(--danger); font-weight:600; }
.text-transfer { color:var(--info); font-weight:600; }
.badge-type { padding:5px 12px; border-radius:20px; font-size:12px; font-weight:600; display:inline-block; }
.badge-income { background:rgba(46,125,91,.14); color:var(--success); }
.badge-expense { background:rgba(192,57,43,.14); color:var(--danger); }
.badge-transfer { background:rgba(74,111,165,.14); color:var(--info); }
.cat-dot { display:inline-block; width:10px; height:10px; border-radius:50%; margin-right:8px; vertical-align:middle; }

/* Business selector */
.biz-selector { position:relative; margin-right:auto; }
.biz-btn { display:flex; align-items:center; gap:8px; background:var(--card); border:1px solid var(--border); border-radius:30px; padding:7px 14px; cursor:pointer; font-size:14px; color:var(--text); font-family:inherit; }
.biz-btn i.bi-diagram-3 { color:var(--gold); }
.biz-btn:hover { border-color:var(--gold); }
.biz-dropdown { display:none; position:absolute; top:calc(100% + 6px); left:0; background:var(--card); border:1px solid var(--border); border-radius:12px; box-shadow:0 8px 30px rgba(0,0,0,.15); min-width:240px; padding:8px; z-index:1050; max-height:400px; overflow-y:auto; }
.biz-dropdown.show { display:block; }
.biz-opt { display:flex; align-items:center; gap:8px; padding:9px 12px; border-radius:8px; cursor:pointer; font-size:14px; color:var(--text); }
.biz-opt:hover { background:var(--bg); }
.biz-opt input { width:16px; height:16px; accent-color:#C5A572; }
.biz-opt-divider { height:1px; background:var(--border); margin:6px 0; }
.biz-manage { display:flex; align-items:center; gap:8px; padding:9px 12px; border-radius:8px; font-size:13px; color:var(--gold-dark); text-decoration:none; }
.biz-manage:hover { background:var(--bg); }

/* Form */
.form-control, .form-select { border-radius:10px; border-color:var(--border); padding:9px 14px; background:var(--card); color:var(--text); }
.form-control:focus, .form-select:focus { border-color:var(--gold); box-shadow:0 0 0 .2rem rgba(197,165,114,.2); outline:none; }
.form-label { font-weight:500; font-size:14px; margin-bottom:6px; color:var(--text); display:block; }

/* Login */
.login-wrapper { min-height:100vh; display:flex; align-items:center; justify-content:center; background:linear-gradient(135deg, #1A1A1A 0%, #2B2620 100%); padding:20px; }
.login-card { background:var(--card); border-radius:20px; padding:44px 38px; width:100%; max-width:400px; box-shadow:0 20px 60px rgba(0,0,0,.4); }
.login-logo { text-align:center; margin-bottom:28px; font-size:26px; font-weight:700; color:var(--ink); }
.login-logo i { color:var(--gold); font-size:34px; display:block; margin-bottom:8px; }

.empty-state { text-align:center; padding:50px 20px; color:var(--text-muted); }
.empty-state i { font-size:48px; opacity:.3; margin-bottom:12px; }
.chart-container { position:relative; height:320px; }
.chart-container.small { height:240px; }
.demo-badge { position:fixed; top:12px; right:12px; background:#C0392B; color:#fff; padding:6px 14px; border-radius:20px; font-size:12px; font-weight:600; z-index:2000; box-shadow:0 4px 12px rgba(0,0,0,.3); }

/* ====== Grid system (เหมือน Bootstrap 12-col) ====== */
.row { display:flex; flex-wrap:wrap; margin-left:-12px; margin-right:-12px; }
.col, .col-auto, .col-md-4, .col-md-6, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-xl-3 { padding-left:12px; padding-right:12px; }
.col { flex:1 1 0%; min-width:0; } .col-auto { flex:0 0 auto; }
.col-md-4, .col-md-6, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-xl-3 { flex:1 1 100%; } /* มือถือเริ่มต้น = เต็ม */
.g-3 > * { padding-left:12px; padding-right:12px; margin-bottom:12px; }
.mb-3 { margin-bottom:16px; } .mb-4 { margin-bottom:24px; } .mt-3 { margin-top:16px; } .mt-4 { margin-top:24px; } .ms-auto { margin-left:auto; }
.d-flex { display:flex; } .justify-content-between { justify-content:space-between; } .align-items-center { align-items:center; } .align-items-end { align-items:flex-end; } .gap-2 { gap:8px; }
.text-end { text-align:right; } .text-center { text-align:center; } .text-muted { color:var(--text-muted); } .small { font-size:13px; } .fw-bold { font-weight:700; } .w-100 { width:100%; }
.btn-sm { padding:6px 12px; font-size:13px; } .py-2 { padding-top:8px; padding-bottom:8px; }
.table-responsive { overflow-x:auto; -webkit-overflow-scrolling:touch; }
.modal-body, .biz-dropdown { -webkit-overflow-scrolling: touch; }
.w-auto { width:auto; }
a { color:var(--gold-dark); text-decoration:none; }

/* ====== Responsive: แท็บเล็ต (≥768px) ====== */
@media (min-width:768px) {
    .col-md-4 { flex:0 0 33.333%; max-width:33.333%; }
    .col-md-6 { flex:0 0 50%; max-width:50%; }
}

/* ====== Responsive: จอใหญ่ (≥992px) ====== */
@media (min-width:992px) {
    .col-lg-4 { flex:0 0 33.333%; max-width:33.333%; }
    .col-lg-5 { flex:0 0 41.666%; max-width:41.666%; }
    .col-lg-6 { flex:0 0 50%; max-width:50%; }
    .col-lg-7 { flex:0 0 58.333%; max-width:58.333%; }
}

/* ====== Responsive: XL (≥1200px) ====== */
@media (min-width:1200px) {
    .col-xl-3 { flex:0 0 25%; max-width:25%; }
}

/* ====== Responsive: มือถือ + แท็บเล็ตเล็ก (<992px) ====== */
@media (max-width:991.98px) {
    /* Sidebar เป็น overlay แบบ drawer */
    .sidebar { transform:translateX(-100%); width:280px; box-shadow:2px 0 30px rgba(0,0,0,.3); }
    .sidebar.show { transform:translateX(0); }
    .main-content { margin-left:0; }
    .btn-toggle { display:flex; }

    /* Topbar: ปรับให้ wrap และ compact */
    .topbar { padding:0 14px; height:auto; min-height:56px; flex-wrap:wrap; gap:8px; padding-top:8px; padding-bottom:8px; }
    .page-title { font-size:17px; width:100%; order:-1; padding:0 4px; }
    .topbar-right { width:100%; justify-content:space-between; }
    .biz-selector { width:100%; order:2; margin-top:4px; }
    .biz-btn { flex:1; justify-content:center; }

    /* Content padding เล็กลง */
    .content-area { padding:16px 14px; }

    /* Cards compact */
    .card { margin-bottom:16px; }
    .card-body { padding:16px; }
    .stat-value { font-size:22px; }
    .stat-card .stat-icon { font-size:34px; }

    /* Charts สั้นลง */
    .chart-container { height:260px; }
    .chart-container.small { height:200px; }

    /* Table scroll + font เล็ก */
    .table thead th { padding:10px 10px; font-size:11px; white-space:nowrap; }
    .table tbody td { padding:10px 10px; font-size:13px; }

    /* Forms compact */
    .form-control, .form-select { padding:10px 12px; font-size:16px; /* 16px กัน iOS auto-zoom */ }
    .btn { padding:11px 16px; font-size:15px; width:100%; }
    .btn-sm { width:auto; }
    .d-flex { gap:8px; flex-wrap:wrap; }

    /* Modal full-screen บนมือถือ */
    .modal-overlay { padding:0; align-items:flex-end; }
    .modal-box { max-width:100%; width:100%; border-radius:16px 16px 0 0; max-height:92vh; }
    .modal-head, .modal-body { padding:16px; }
    .modal-foot { padding:14px 16px; }
    .modal-foot .btn { flex:1; }

    /* Login compact */
    .login-card { padding:32px 24px; }

    /* Biz dropdown เต็มจอ */
    .biz-dropdown { min-width:100%; left:0; right:0; }
}

/* ====== Responsive: มือถือเล็ก (<576px) ====== */
@media (max-width:575.98px) {
    .sidebar-brand { padding:18px 18px; font-size:18px; }
    .sidebar-nav a { padding:14px 20px; font-size:15px; }
    .content-area { padding:12px 10px; }
    .card-body { padding:14px; }
    .stat-value { font-size:20px; }
    .stat-card .stat-icon { font-size:30px; opacity:.08; }
    .page-title { font-size:16px; }
    .chart-container { height:220px; }
    .chart-container.small { height:180px; }
    .table tbody td { padding:9px 8px; font-size:12px; }
    .badge-type { padding:4px 8px; font-size:11px; }
    .biz-btn { padding:7px 10px; font-size:13px; }
    .user-btn span { display:none; } /* ซ่อนชื่อ เหลือแค่ไอคอน */
    .user-btn { padding:8px; }
    .lang-switch a { font-size:12px; }
}

/* ====== Overlay สำหรับ sidebar มือถือ ====== */
.sidebar-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,.5); z-index:1035; }
.sidebar-overlay.show { display:block; }

/* ====== Bottom Nav Bar (มือถือเท่านั้น) ====== */
.bottom-nav { display:none; }
.more-menu { display:none; }
.more-overlay { display:none; }

@media (max-width:991.98px) {
    /* ซ่อน sidebar บนมือถือ ใช้ bottom nav แทน */
    .sidebar { display:none !important; }
    .sidebar-overlay { display:none !important; }
    .btn-toggle { display:none !important; }

    /* Bottom nav bar */
    .bottom-nav {
        display:flex; position:fixed; bottom:0; left:0; right:0; z-index:1040;
        background:var(--card); border-top:1px solid var(--border);
        padding:6px 4px; padding-bottom:calc(6px + env(safe-area-inset-bottom, 0px));
        box-shadow:0 -2px 16px rgba(0,0,0,.08);
    }
    .bottom-nav > a {
        flex:1; display:flex; flex-direction:column; align-items:center; gap:2px;
        padding:6px 2px; color:var(--text-muted); text-decoration:none; font-size:10px; font-weight:500;
        border-radius:10px; transition:color .15s;
    }
    .bottom-nav > a i { font-size:20px; }
    .bottom-nav > a.active { color:var(--gold); }
    .bottom-nav > a:active { background:var(--bg); }

    /* More menu (popup ขึ้นจาก bottom nav) */
    .more-menu {
        display:none; position:fixed; bottom:calc(70px + env(safe-area-inset-bottom, 0px)); right:8px; left:8px;
        background:var(--card); border:1px solid var(--border); border-radius:16px;
        padding:8px; z-index:1045; box-shadow:0 -4px 30px rgba(0,0,0,.2);
    }
    .more-menu.show { display:block; animation:slideUp .2s ease; }
    .more-menu a {
        display:flex; align-items:center; gap:12px; padding:13px 14px; border-radius:10px;
        color:var(--text); text-decoration:none; font-size:15px; font-weight:500;
    }
    .more-menu a:active { background:var(--bg); }
    .more-menu a i { font-size:18px; width:22px; text-align:center; color:var(--gold); }
    .more-divider { height:1px; background:var(--border); margin:6px 0; }
    .more-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,.4); z-index:1044; bottom:70px; }
    .more-overlay.show { display:block; }
    @keyframes slideUp { from { transform:translateY(20px); opacity:0; } to { transform:translateY(0); opacity:1; } }

    /* เพิ่ม padding ล่างให้ content ไม่ถูกบังด้วย bottom nav */
    .content-area { padding-bottom:90px !important; }

    /* Topbar มือถือ: เรียบง่ายขึ้น */
    .topbar { height:auto; min-height:54px; padding:8px 14px !important; gap:10px !important; }
    .page-title { font-size:16px; flex:1; }
    .topbar-right { gap:8px; }
    .lang-switch { font-size:12px; }
    .user-btn span { display:none; }
    .user-btn { padding:8px; }
    .biz-btn { font-size:12px; padding:6px 10px; }
    .biz-btn span { max-width:100px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

    /* Sidebar ซ่อน แต่เก็บ toggle สำหรับ biz dropdown */
}

/* ====== ป้องกัน iOS 100vh bug ====== */
.app-wrapper { min-height:100vh; min-height:100dvh; }

