/* ระบบจัดเก็บรายได้ รพ.สต. - Clean CSS */

:root {
    --sidebar-width: 270px;
    --sidebar-collapsed-width: 84px;
    --sidebar-active: #4f46e5;
    --sidebar-active-2: #6366f1;
    --sidebar-text: #d1d5db;
    --topbar-height: 74px;
    --page-bg: #f5f7fb;
    --border-color: #e5e7eb;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    min-width: 320px;
    margin: 0;
    color: #1f2937;
    background: var(--page-bg);
    font-family: "Noto Sans Thai", "Sarabun", sans-serif;
}

/* Sidebar */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1050;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #fff;
    background: linear-gradient(180deg, #111827 0%, #1e293b 55%, #111827 100%);
    box-shadow: 8px 0 30px rgba(15, 23, 42, .12);
    transition: width .3s ease, transform .3s ease;
}

.sidebar-brand {
    min-height: 76px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-brand a {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 800;
    line-height: 1.4;
    text-decoration: none;
}

.sidebar-brand i {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    box-shadow: 0 6px 18px rgba(99, 102, 241, .35);
}

.sidebar-brand span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    margin: 18px 14px;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 16px;
    background: rgba(255, 255, 255, .06);
}

.sidebar-user-icon {
    flex: 0 0 auto;
    color: #a5b4fc;
    font-size: 2rem;
    line-height: 1;
}

.sidebar-user-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sidebar-user-info strong {
    overflow: hidden;
    color: #fff;
    font-size: .9rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-info small {
    color: #a5b4fc;
    font-size: .75rem;
}

.sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 14px 20px;
}

.sidebar-nav::-webkit-scrollbar {
    width: 5px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background: rgba(255, 255, 255, .2);
}

.sidebar-section-title {
    padding: 12px 14px 7px;
    color: #9ca3af;
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.sidebar-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 13px;
    min-height: 48px;
    margin: 4px 0;
    padding: 11px 14px;
    border-radius: 12px;
    color: var(--sidebar-text);
    font-size: .9rem;
    font-weight: 500;
    text-decoration: none;
    transition: color .2s ease, background .2s ease, transform .2s ease;
}

.sidebar-link i {
    width: 21px;
    flex: 0 0 21px;
    color: #9ca3af;
    font-size: 1.08rem;
    text-align: center;
}

.sidebar-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, .08);
    transform: translateX(3px);
}

.sidebar-link:hover i,
.sidebar-link.active i {
    color: #fff;
}

.sidebar-link.active {
    color: #fff;
    background: linear-gradient(135deg, var(--sidebar-active), var(--sidebar-active-2));
    box-shadow: 0 8px 20px rgba(79, 70, 229, .28);
}

.sidebar-link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 12px;
    bottom: 12px;
    width: 3px;
    border-radius: 0 4px 4px 0;
    background: #fff;
}

.sidebar-link.logout-link {
    margin-top: 18px;
    color: #fca5a5;
}

.sidebar-link.logout-link i {
    color: #f87171;
}

.sidebar-link.logout-link:hover {
    color: #fff;
    background: rgba(239, 68, 68, .15);
}

.sidebar-footer {
    padding: 16px 24px 22px;
    border-top: 1px solid rgba(255, 255, 255, .08);
    color: #9ca3af;
    font-size: .72rem;
}

/* Page and Topbar */
.page-wrap {
    min-height: 100vh;
    min-height: 100dvh;
    margin-left: var(--sidebar-width);
    transition: margin-left .3s ease;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    min-height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 28px;
    background: rgba(255, 255, 255, .94);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(15, 23, 42, .04);
    backdrop-filter: blur(12px);
}

.topbar-left,
.topbar-right {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-title {
    display: block;
    color: #1f2937;
    font-size: .95rem;
    font-weight: 800;
}

.topbar-subtitle {
    display: block;
    margin-top: 2px;
    color: #6b7280;
    font-size: .72rem;
}

.mobile-menu-btn {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: #fff;
    color: #374151;
    font-size: 1.2rem;
    cursor: pointer;
}

.sidebar-toggle {
    position: fixed;
    top: 19px;
    left: calc(var(--sidebar-width) - 18px);
    z-index: 1100;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: #fff;
    color: #4f46e5;
    box-shadow: 0 5px 16px rgba(15, 23, 42, .12);
    cursor: pointer;
    transition: left .3s ease, transform .2s ease;
}

.sidebar-toggle:hover {
    transform: scale(1.08);
}

/* Collapsed Desktop */
body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .page-wrap {
    margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .sidebar-toggle {
    left: 66px;
}

body.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    padding: 0;
}

body.sidebar-collapsed .sidebar-brand span,
body.sidebar-collapsed .sidebar-user-info,
body.sidebar-collapsed .sidebar-section-title,
body.sidebar-collapsed .sidebar-link span,
body.sidebar-collapsed .sidebar-footer {
    display: none;
}

body.sidebar-collapsed .sidebar-user {
    justify-content: center;
    margin: 18px 10px;
    padding: 12px 5px;
}

body.sidebar-collapsed .sidebar-link {
    justify-content: center;
    padding: 12px;
}

body.sidebar-collapsed .sidebar-link.active::before {
    display: none;
}

/* Mobile */
.sidebar-overlay {
    display: none;
}

@media (max-width: 991.98px) {
    .sidebar {
        width: min(var(--sidebar-width), 86vw);
        transform: translateX(-100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .page-wrap,
    body.sidebar-collapsed .page-wrap {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: none;
    }

    .mobile-menu-btn {
        display: inline-flex;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 1040;
        background: rgba(15, 23, 42, .55);
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.show {
        display: block;
    }

    body.sidebar-collapsed .sidebar {
        width: min(var(--sidebar-width), 86vw);
    }

    body.sidebar-collapsed .sidebar-brand {
        justify-content: flex-start;
        padding: 0 24px;
    }

    body.sidebar-collapsed .sidebar-brand span,
    body.sidebar-collapsed .sidebar-user-info,
    body.sidebar-collapsed .sidebar-section-title,
    body.sidebar-collapsed .sidebar-link span,
    body.sidebar-collapsed .sidebar-footer {
        display: block;
    }

    body.sidebar-collapsed .sidebar-user {
        justify-content: flex-start;
        margin: 18px 14px;
        padding: 14px;
    }

    body.sidebar-collapsed .sidebar-link {
        justify-content: flex-start;
        padding: 11px 14px;
    }

    .topbar {
        padding: 12px 16px;
    }
}

@media (max-width: 575.98px) {
    .topbar-title {
        font-size: .85rem;
    }

    .topbar-subtitle {
        font-size: .68rem;
    }

    .topbar-right .badge {
        font-size: .7rem;
    }
}

/* General Components */
.card,
.dashboard-card {
    border: 0;
    border-radius: 18px;
    box-shadow: 0 5px 20px rgba(15, 23, 42, .07);
}

.card-header {
    border-bottom: 1px solid #eef2f7;
    background: transparent;
}

.btn {
    border-radius: 10px;
    font-weight: 600;
}

.form-control,
.form-select {
    min-height: 44px;
    border-radius: 10px;
    border-color: #dbe1ea;
}

.form-control:focus,
.form-select:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 .2rem rgba(99, 102, 241, .15);
}

.table {
    vertical-align: middle;
}

.table thead th {
    white-space: nowrap;
    font-weight: 700;
}

.badge {
    font-weight: 600;
}

/* Login */
.login-bg {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #312e81, #7c3aed);
}

.login-card {
    width: min(420px, 100%);
    padding: 35px;
    border-radius: 24px;
    background: #fff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
}

.brand-icon {
    width: 70px;
    height: 70px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 22px;
    color: #4f46e5;
    background: #eef2ff;
    font-size: 34px;
}

/* Accessibility */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(99, 102, 241, .35);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* ===== Official system logo ===== */
.sidebar-brand {
    text-decoration: none;
    color: #fff;
    gap: 10px;
}
.sidebar-brand:hover { color: #fff; }
.system-logo { display: block; object-fit: contain; }
.system-logo-sidebar {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    border-radius: 14px;
    background: #fff;
    padding: 3px;
    box-shadow: 0 5px 18px rgba(0, 174, 190, .28);
}
.topbar-branding { display: flex; align-items: center; gap: 12px; min-width: 0; }
.system-logo-topbar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: #fff;
    padding: 2px;
    border: 1px solid #d8eef0;
}
.footer-logo-wrap { background: #fff !important; border: 1px solid #d7eef0; overflow: hidden; }
.system-logo-footer { width: 48px; height: 48px; border-radius: 13px; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0 12px; }
body.sidebar-collapsed .system-logo-sidebar { width: 46px; height: 46px; }
@media (max-width: 767.98px) {
    .system-logo-topbar { width: 38px; height: 38px; }
    .topbar-branding { gap: 8px; }
}
