/* =====================================================================
   Integration & API Lab - look and feel on top of Bootstrap 5.3
   Light and dark mode: Bootstrap switches on <html data-bs-theme="dark">
   ===================================================================== */
:root {
    --app-font: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans Thai", Roboto, sans-serif;
    --brand: #0284c7;
    --brand-2: #14b8a6;
    --brand-grad: linear-gradient(135deg, #0284c7 0%, #4f46e5 55%, #14b8a6 100%);
    --page-bg: #f4f6fb;
    --card-bg: #ffffff;
    --card-border: rgba(15, 23, 42, .06);
    --card-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
    --sidebar-w: 264px;
    --sidebar-bg: linear-gradient(180deg, #0b1220 0%, #0c2b3f 100%);
    --muted-bg: #f1f5f9;
    --ring: rgba(2, 132, 199, .25);
}

[data-bs-theme="dark"] {
    --page-bg: #0b1120;
    --card-bg: #111a2e;
    --card-border: rgba(148, 163, 184, .12);
    --card-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --muted-bg: #172036;
    --bs-body-bg: #0b1120;
    --bs-secondary-bg: #111a2e;
    --bs-tertiary-bg: #172036;
}

html, body { height: 100%; }
body {
    font-family: var(--app-font);
    background: var(--page-bg);
    font-size: .9375rem;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
.min-w-0 { min-width: 0; }

/* ---------------------------------------------------------------- shell */
.app-shell { display: flex; min-height: 100vh; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; margin-left: var(--sidebar-w); }
.content { flex: 1; padding: 1.75rem 2rem 2rem; max-width: 1480px; width: 100%; }
.app-footer { padding: 1rem 2rem 1.5rem; font-size: .8rem; color: var(--bs-secondary-color); }

.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 1040;
    background: var(--sidebar-bg); color: #cbd5e1;
    display: flex; flex-direction: column; padding: 1.1rem .9rem;
    transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: .25rem .5rem 1.1rem; color: #fff; text-decoration: none; }
.brand strong { display: block; font-size: 1.02rem; letter-spacing: -.01em; }
.brand small { display: block; color: #7dd3fc; font-size: .72rem; text-transform: uppercase; letter-spacing: .18em; }
.side-nav { flex: 1; overflow-y: auto; margin: 0 -.25rem; padding: 0 .25rem; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .14em; color: #64748b; margin: 1.1rem .75rem .45rem; font-weight: 600; }
.nav-item {
    display: flex; align-items: center; gap: .75rem; padding: .55rem .8rem; margin-bottom: 2px;
    border-radius: .65rem; color: #cbd5e1; text-decoration: none; font-weight: 500; position: relative;
    transition: background .15s, color .15s;
}
.nav-item i { font-size: 1.05rem; width: 1.25rem; text-align: center; opacity: .85; }
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(14, 165, 233, .45), rgba(14, 165, 233, .1)); color: #fff; }
.nav-item.active::before { content: ""; position: absolute; left: -.9rem; top: .45rem; bottom: .45rem; width: 4px; border-radius: 0 4px 4px 0; background: #7dd3fc; }
.side-foot { border-top: 1px solid rgba(255, 255, 255, .08); padding: .9rem .6rem 0; margin-top: .5rem; }
.side-role { background: rgba(165, 180, 252, .16); color: #c7d2fe; font-weight: 500; }

.topbar {
    position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: .75rem;
    padding: .7rem 2rem; background: color-mix(in srgb, var(--page-bg) 82%, transparent);
    backdrop-filter: blur(10px); border-bottom: 1px solid var(--card-border);
}
.topbar-hint { align-items: center; font-size: .875rem; font-weight: 500; }
.btn-icon { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: .7rem; color: var(--bs-body-color); }
.btn-icon:hover { background: var(--muted-bg); }
.user-chip { display: flex; align-items: center; gap: .6rem; border-radius: 999px; padding: .25rem .8rem .25rem .25rem; border: 1px solid var(--card-border); background: var(--card-bg); }
.user-chip::after { margin-left: .2rem; }
[data-bs-theme="dark"] .theme-icon-dark, [data-bs-theme="light"] .theme-icon-light { display: none; }

}

.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
    .main-col { margin-left: 0; }
    .sidebar { transform: translateX(-100%); }
    body.sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .4); }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1030; }
    .content { padding: 1.25rem 1rem 1.5rem; }
    .topbar { padding: .6rem 1rem; }
}

/* ---------------------------------------------------------------- page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-title { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.page-sub { color: var(--bs-secondary-color); margin: .25rem 0 0; }
.crumbs { font-size: .8rem; color: var(--bs-secondary-color); margin-bottom: .35rem; }
.crumbs a { color: inherit; text-decoration: none; }
.crumbs a:hover { color: var(--brand); }

/* ---------------------------------------------------------------- cards */
.card { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 1rem; box-shadow: var(--card-shadow); }
.card-header { background: transparent; border-bottom: 1px solid var(--card-border); padding: 1rem 1.25rem; font-weight: 600; }
.card-header .sub { font-weight: 400; color: var(--bs-secondary-color); font-size: .85rem; }
.card-body { padding: 1.25rem; }
.card-title-sm { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--bs-secondary-color); font-weight: 600; }

.stat-card { padding: 1.15rem 1.25rem; display: flex; align-items: center; gap: 1rem; height: 100%; }
.stat-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 1.35rem; color: #fff; flex: none; }
.stat-value { font-size: 1.65rem; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.stat-label { color: var(--bs-secondary-color); font-size: .85rem; }
.g-indigo { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.g-cyan { background: linear-gradient(135deg, #06b6d4, #3b82f6); }
.g-green { background: linear-gradient(135deg, #10b981, #22c55e); }
.g-amber { background: linear-gradient(135deg, #f59e0b, #f97316); }
.g-rose { background: linear-gradient(135deg, #f43f5e, #ec4899); }
.g-slate { background: linear-gradient(135deg, #475569, #1e293b); }

.hero {
    border-radius: 1.25rem; padding: 1.6rem 1.75rem; color: #fff; background: var(--brand-grad);
    position: relative; overflow: hidden; box-shadow: 0 10px 30px rgba(2, 132, 199, .25);
}
.hero::after { content: ""; position: absolute; right: -60px; top: -60px; width: 240px; height: 240px; border-radius: 50%; background: rgba(255, 255, 255, .12); }
.hero h2 { font-weight: 700; letter-spacing: -.02em; }
.hero .chip { background: rgba(255, 255, 255, .18); border-radius: 999px; padding: .25rem .7rem; font-size: .8rem; display: inline-flex; align-items: center; gap: .35rem; }

/* ---------------------------------------------------------------- avatars */
.avatar { border-radius: 50%; display: inline-grid; place-items: center; object-fit: cover; color: #fff; font-weight: 600; flex: none; letter-spacing: .02em; }
.avatar-sm { width: 32px; height: 32px; font-size: .75rem; }
.avatar-md { width: 40px; height: 40px; font-size: .85rem; }
.avatar-lg { width: 72px; height: 72px; font-size: 1.4rem; }
.avatar-xl { width: 112px; height: 112px; font-size: 2.2rem; box-shadow: 0 0 0 5px var(--card-bg), 0 8px 24px rgba(15, 23, 42, .18); }
.tone-0 { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.tone-1 { background: linear-gradient(135deg, #06b6d4, #3b82f6); }
.tone-2 { background: linear-gradient(135deg, #10b981, #059669); }
.tone-3 { background: linear-gradient(135deg, #f59e0b, #ea580c); }
.tone-4 { background: linear-gradient(135deg, #f43f5e, #db2777); }
.tone-5 { background: linear-gradient(135deg, #14b8a6, #0ea5e9); }
.tone-6 { background: linear-gradient(135deg, #a855f7, #ec4899); }
.tone-7 { background: linear-gradient(135deg, #64748b, #334155); }
.person { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { box-shadow: 0 0 0 2px var(--card-bg); margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* ---------------------------------------------------------------- badges and status */
.role-badge { font-weight: 500; padding: .35em .65em; border-radius: 999px; }
.status-dot { display: inline-flex; align-items: center; gap: .4rem; font-size: .82rem; font-weight: 500; }
.status-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.status-on { color: #059669; }
.status-on::before { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, .18); }
.status-off { color: #dc2626; }
.status-off::before { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, .18); }
.code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .8rem; background: var(--muted-bg); padding: .15rem .45rem; border-radius: .4rem; color: var(--bs-body-color); }

/* ---------------------------------------------------------------- tables */
.table-modern { margin: 0; --bs-table-bg: transparent; }
.table-modern thead th {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--bs-secondary-color);
    font-weight: 600; border-bottom: 1px solid var(--card-border); padding: .75rem 1rem; white-space: nowrap; background: var(--muted-bg);
}
.table-modern tbody td { padding: .8rem 1rem; vertical-align: middle; border-color: var(--card-border); }
.table-modern tbody tr:hover td { background: color-mix(in srgb, var(--brand) 4%, transparent); }
.table-modern tbody tr:last-child td { border-bottom: 0; }
.table-wrap { border-radius: 1rem; overflow: hidden; }
.row-actions { display: flex; gap: .25rem; justify-content: flex-end; }
.row-actions .btn { --bs-btn-padding-y: .25rem; --bs-btn-padding-x: .5rem; }
.sort-link { color: inherit; text-decoration: none; }
.sort-link.active { color: var(--brand); }

/* ---------------------------------------------------------------- forms */
.form-label { font-weight: 500; font-size: .875rem; margin-bottom: .35rem; }
.form-control, .form-select { border-radius: .65rem; padding: .55rem .8rem; border-color: var(--card-border); background-color: var(--card-bg); }
[data-bs-theme="light"] .form-control, [data-bs-theme="light"] .form-select { border-color: #dfe3ea; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .25rem var(--ring); }
.form-section { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--bs-secondary-color); font-weight: 600; margin: 1.5rem 0 .9rem; display: flex; align-items: center; gap: .5rem; }
.form-section::after { content: ""; flex: 1; height: 1px; background: var(--card-border); }
.btn { border-radius: .65rem; font-weight: 500; }
.btn-primary { --bs-btn-bg: #0284c7; --bs-btn-border-color: #0284c7; --bs-btn-hover-bg: #0369a1; --bs-btn-hover-border-color: #0369a1; --bs-btn-active-bg: #075985; --bs-btn-disabled-bg: #0284c7; --bs-btn-disabled-border-color: #0284c7; }
.btn-gradient { background: var(--brand-grad); color: #fff; border: 0; box-shadow: 0 6px 16px rgba(2, 132, 199, .3); }
.btn-gradient:hover { color: #fff; filter: brightness(1.05); }
.check-card {
    display: flex; gap: .6rem; align-items: flex-start; padding: .65rem .8rem; border: 1px solid var(--card-border);
    border-radius: .75rem; cursor: pointer; height: 100%; transition: border-color .15s, background .15s;
}
.check-card:hover { border-color: var(--brand); }
.check-card:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 7%, transparent); }
.check-card .form-check-input { margin-top: .2rem; flex: none; }
.lock-note { font-size: .82rem; color: var(--bs-secondary-color); display: flex; gap: .4rem; align-items: center; }
.filter-bar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.filter-bar .form-control, .filter-bar .form-select { width: auto; min-width: 160px; }
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box i { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--bs-secondary-color); }
.search-box input { padding-left: 2.3rem; width: 100%; }

/* ---------------------------------------------------------------- learn tips */
.learn-tip {
    display: flex; gap: .8rem; padding: .85rem 1rem; border-radius: .85rem; font-size: .875rem;
    background: color-mix(in srgb, var(--brand) 8%, var(--card-bg)); border: 1px dashed color-mix(in srgb, var(--brand) 40%, transparent);
}
.learn-tip > i { color: var(--brand); font-size: 1.2rem; }
.learn-tip code { color: #7c3aed; }

/* ---------------------------------------------------------------- bar chart (dashboard) */
.hbar { display: grid; grid-template-columns: 170px 1fr 36px; gap: .75rem; align-items: center; margin-bottom: .7rem; font-size: .875rem; }
.hbar-track { height: 10px; border-radius: 999px; background: var(--muted-bg); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 999px; background: var(--brand-grad); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: .75rem; padding: .6rem 0; border-bottom: 1px dashed var(--card-border); }
.timeline li:last-child { border-bottom: 0; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: .4rem; flex: none; }

/* ---------------------------------------------------------------- profile */
.profile-cover { height: 120px; border-radius: 1rem 1rem 0 0; background: var(--brand-grad); }
.profile-head { margin-top: -56px; padding: 0 1.5rem 1.25rem; display: flex; align-items: flex-end; gap: 1.25rem; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: .55rem 1rem; font-size: .9rem; }
.kv dt { color: var(--bs-secondary-color); font-weight: 500; }
.kv dd { margin: 0; }
.dropzone { border: 2px dashed var(--card-border); border-radius: 1rem; padding: 1.5rem; text-align: center; transition: border-color .15s, background .15s; }
.dropzone:hover { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 5%, transparent); }
.perm-chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .78rem; padding: .25rem .55rem; border-radius: .5rem; background: var(--muted-bg); margin: 0 .25rem .35rem 0; }
.source-DIRECT { background: rgba(99, 102, 241, .12); color: #4f46e5; }
.source-GROUP { background: rgba(6, 182, 212, .14); color: #0e7490; }
.source-DELEGATED { background: rgba(245, 158, 11, .16); color: #b45309; }
[data-bs-theme="dark"] .source-DIRECT { color: #7dd3fc; }
[data-bs-theme="dark"] .source-GROUP { color: #67e8f9; }
[data-bs-theme="dark"] .source-DELEGATED { color: #fcd34d; }

/* ---------------------------------------------------------------- login */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--page-bg); }
.login-art { background: var(--sidebar-bg); color: #e2e8f0; padding: 3rem; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.login-art::before { content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%; background: radial-gradient(circle, rgba(99, 102, 241, .45), transparent 65%); right: -160px; top: -140px; }
.login-art::after { content: ""; position: absolute; width: 420px; height: 420px; border-radius: 50%; background: radial-gradient(circle, rgba(6, 182, 212, .3), transparent 65%); left: -140px; bottom: -160px; }
.login-art > * { position: relative; z-index: 1; }
.login-art h1 { font-size: 2.4rem; font-weight: 800; letter-spacing: -.03em; color: #fff; }
.feature { display: flex; gap: .8rem; margin-bottom: 1rem; }
.feature i { width: 38px; height: 38px; border-radius: 10px; background: rgba(255, 255, 255, .08); display: grid; place-items: center; color: #7dd3fc; flex: none; }
.login-form-col { display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; }
.login-card { width: 100%; max-width: 440px; }
.demo-account { display: flex; align-items: center; gap: .7rem; width: 100%; padding: .55rem .7rem; border: 1px solid var(--card-border); border-radius: .75rem; background: var(--card-bg); text-align: left; transition: border-color .15s, transform .15s; }
.demo-account:hover { border-color: var(--brand); transform: translateY(-1px); }
@media (max-width: 991.98px) {
    .login-page { grid-template-columns: 1fr; }
    .login-art { display: none; }
}

/* ---------------------------------------------------------------- misc */
.confirm-icon { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center; font-size: 2rem; color: #dc2626; background: rgba(239, 68, 68, .12); }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--bs-secondary-color); }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .5; }
.flash { border: 0; border-radius: .85rem; box-shadow: var(--card-shadow); }
.dept-indent { display: inline-block; }
.tree-line { color: #7dd3fc; margin-right: .35rem; }
.list-tight > * + * { border-top: 1px solid var(--card-border); }
.error-page { min-height: 60vh; display: grid; place-items: center; text-align: center; }
.error-code { font-size: 5rem; font-weight: 800; background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1; }
