/* ============================================================
   CG Caregiver System - Theme (Light / Dark)
   ============================================================ */

:root {
    --bg-body: #f4f6f9;
    --bg-surface: #ffffff;
    --bg-surface-2: #f8f9fb;
    --bg-sidebar: #ffffff;
    --text-primary: #1f2530;
    --text-secondary: #6b7280;
    --text-muted: #9aa2b1;
    --border-color: #e5e8ee;
    --brand: #2f6fed;
    --brand-hover: #2559c7;
    --brand-soft: rgba(47, 111, 237, 0.1);
    --success: #1fa971;
    --warning: #e0a530;
    --danger: #e5484d;
    --info: #3aa8c1;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
    --sidebar-width: 260px;
    --topbar-height: 64px;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg-body: #0f1420;
    --bg-surface: #171d2c;
    --bg-surface-2: #1d2436;
    --bg-sidebar: #141a29;
    --text-primary: #e7eaf1;
    --text-secondary: #a3aac0;
    --text-muted: #707892;
    --border-color: #2a3145;
    --brand: #5b8cf9;
    --brand-hover: #7ba0fb;
    --brand-soft: rgba(91, 140, 249, 0.15);
    --success: #34c790;
    --warning: #eab850;
    --danger: #f2696d;
    --info: #58c2da;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-body: #0f1420;
        --bg-surface: #171d2c;
        --bg-surface-2: #1d2436;
        --bg-sidebar: #141a29;
        --text-primary: #e7eaf1;
        --text-secondary: #a3aac0;
        --text-muted: #707892;
        --border-color: #2a3145;
        --brand: #5b8cf9;
        --brand-hover: #7ba0fb;
        --brand-soft: rgba(91, 140, 249, 0.15);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: "Sarabun", "Segoe UI", system-ui, -apple-system, sans-serif;
    transition: background-color .15s ease, color .15s ease;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }

/* ---------- Layout ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
    overflow-y: auto;
    transition: transform .2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
    font-size: 1.02rem;
    color: var(--text-primary);
}

.sidebar-brand .icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.sidebar-nav {
    padding: .75rem .6rem 2rem;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .6rem .75rem;
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: .92rem;
    font-weight: 500;
    margin-bottom: .15rem;
}

.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }

.sidebar-nav .nav-link:hover {
    background: var(--bg-surface-2);
    color: var(--text-primary);
}

.sidebar-nav .nav-link.active {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 600;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.page-body {
    padding: 1.5rem;
    flex-grow: 1;
}

.sidebar-toggle-btn {
    display: none;
    background: transparent;
    border: none;
    font-size: 1.3rem;
    color: var(--text-primary);
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); box-shadow: var(--shadow-md); }
    .main-content { margin-left: 0; }
    .sidebar-toggle-btn { display: inline-flex; align-items: center; }
}

/* ---------- Topbar controls ---------- */
.theme-toggle-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface-2);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
}

.theme-toggle-btn:hover { background: var(--brand-soft); color: var(--brand); }

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: .6rem;
    background: transparent;
    border: none;
    padding: .3rem .5rem;
    border-radius: 10px;
    color: var(--text-primary);
}

.user-menu-btn:hover { background: var(--bg-surface-2); }

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .9rem;
    flex-shrink: 0;
    object-fit: cover;
}

/* ---------- Cards / surfaces ---------- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card .stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
    color: #fff;
}

.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-card .stat-label { color: var(--text-secondary); font-size: .85rem; }

.bg-brand { background: var(--brand) !important; }
.bg-success-soft { background: var(--success) !important; }
.bg-warning-soft { background: var(--warning) !important; }
.bg-danger-soft { background: var(--danger) !important; }
.bg-info-soft { background: var(--info) !important; }

.settings-card {
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.settings-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--brand);
}
.settings-card .stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: #fff;
}

/* ---------- Tables ---------- */
.table {
    color: var(--text-primary);
    vertical-align: middle;
}

.table > :not(caption) > * > * {
    background-color: var(--bg-surface);
    border-bottom-color: var(--border-color);
    color: var(--text-primary);
}

.table thead th {
    color: var(--text-secondary);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom-width: 1px;
    font-weight: 600;
}

/* ---------- Forms ---------- */
.form-control, .form-select {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.form-control:focus, .form-select:focus {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--brand);
    box-shadow: 0 0 0 .2rem var(--brand-soft);
}

.form-label { font-weight: 500; font-size: .88rem; color: var(--text-secondary); }

.form-control::placeholder { color: var(--text-muted); }

/* ---------- Buttons ---------- */
.btn-brand {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}
.btn-brand:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }

/* ---------- Badges ---------- */
.badge-adl-social { background: var(--success); color: #fff; }
.badge-adl-home { background: var(--warning); color: #1f2530; }
.badge-adl-bed { background: var(--danger); color: #fff; }
.badge-risk-low { background: var(--success); color: #fff; }
.badge-risk-medium { background: var(--warning); color: #1f2530; }
.badge-risk-high { background: var(--danger); color: #fff; }
.badge-status-active { background: var(--success); color: #fff; }
.badge-status-inactive { background: var(--text-muted); color: #fff; }

/* ---------- Login page ---------- */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--brand-soft), var(--bg-body));
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-surface);
    border-radius: 18px;
    box-shadow: var(--shadow-md);
    padding: 2.25rem 2rem;
}

.login-brand-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    margin: 0 auto 1rem;
}

/* ---------- Misc ---------- */
.text-muted-soft { color: var(--text-muted) !important; }
.section-title { font-weight: 700; font-size: 1.15rem; margin-bottom: 1rem; }

.photo-thumb {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.avatar-lg {
    width: 96px;
    height: 96px;
    border-radius: 16px;
    object-fit: cover;
    border: 1px solid var(--border-color);
    background: var(--bg-surface-2);
}

.dropdown-menu {
    background: var(--bg-surface);
    border-color: var(--border-color);
    box-shadow: var(--shadow-md);
}
.dropdown-item { color: var(--text-primary); }
.dropdown-item:hover, .dropdown-item:focus { background: var(--bg-surface-2); color: var(--text-primary); }

.modal-content {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.modal-header, .modal-footer { border-color: var(--border-color); }

.nav-tabs { border-bottom-color: var(--border-color); }
.nav-tabs .nav-link { color: var(--text-secondary); border: none; border-bottom: 2px solid transparent; }
.nav-tabs .nav-link.active { color: var(--brand); background: transparent; border-bottom-color: var(--brand); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }
