:root {
    --primary: #132099;
    --secondary: #764ba2;
    --dark: #2d3748;
    --light: #f7fafc;
    --white: #ffffff;
    --success: #48bb78;
    --warning: #ed8936;
    --danger: #f56565;
    --gray: #718096;

    /* Semantic Variables - Light Mode */
    --bg-body: radial-gradient(circle at top right, #f8fafc 0%, #f1f5f9 100%);
    --bg-card: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --text-main: #2d3748;
    --text-muted: #718096;
    --border-main: rgba(226, 232, 240, 0.8);
    --header-gradient: linear-gradient(135deg, #14259b 0%, #3a6ad6 100%);
    --sidebar-gradient: linear-gradient(135deg, #132099 0%, #3a6ad6 100%);
}

[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-glass: rgba(30, 41, 59, 0.85);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-main: rgba(51, 65, 85, 0.8);
    --header-gradient: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    --sidebar-gradient: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    --white: #ffffff;
    --light: #f7fafc;
    --dark: #2d3748;

    /* Color adjustments for dark mode */
    --text-main: #e2e8f0 !important;
    --text-muted: #94a3b8;
}

/* Dark Mode Overrides for Tailwind/Bootstrap classes */
[data-theme="dark"] .text-slate-600,
[data-theme="dark"] .text-slate-700,
[data-theme="dark"] .text-slate-800,
[data-theme="dark"] .text-slate-900,
[data-theme="dark"] .text-gray-600,
[data-theme="dark"] .text-gray-700,
[data-theme="dark"] .text-gray-800 {
    color: #e2e8f0 !important;
}

[data-theme="dark"] .text-slate-400,
[data-theme="dark"] .text-slate-500,
[data-theme="dark"] .text-gray-400,
[data-theme="dark"] .text-gray-500 {
    color: #94a3b8 !important;
}

[data-theme="dark"] .bg-white {
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
}

[data-theme="dark"] .form-select,
[data-theme="dark"] .form-control {
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
    border-color: #334155 !important;
}

/* Sidebar Specific Theme override */
[data-theme="dark"] .sidebar {
    background: #1e293b;
    border-right: 1px solid var(--border-main);
}
[data-theme="dark"] .main-content {
    background: #0f172a;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

* :not(.fa):not(.fas):not(.far):not(.fab):not(.fat):not(.fal):not(.fad) {
    font-family: 'Prompt', sans-serif !important;
}

body {
    font-family: 'Prompt', sans-serif;
    background: var(--bg-body);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%2394a3b8' fill-opacity='0.1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    z-index: -1;
    pointer-events: none;
}

/* Sidebar & Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--sidebar-gradient);
    color: white;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    margin-bottom: 40px;
    text-align: center;
}

.logo-small {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
}

.logo-small i {
    font-size: 24px;
}

.logo-small h2 {
    font-size: 18px;
    font-weight: 600;
}

.nav-menu {
    list-style: none;
    flex-grow: 1;
}

.nav-item {
    margin-bottom: 5px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.3s ease;
}

.nav-link i {
    width: 20px;
    text-align: center;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    transform: translateX(5px);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px border rgba(255, 255, 255, 0.1);
}

.logout-btn {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
    border-radius: 12px;
    transition: all 0.3s ease;
}

.logout-btn:hover {
    background: rgba(245, 101, 101, 0.2);
    color: #feb2b2;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    margin-left: 280px;
    padding: 40px;
    width: calc(100% - 280px);
    min-width: 0;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    background: var(--header-gradient);
    padding: 24px 35px;
    border-radius: 24px;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.3);
    color: white;
    position: relative;
    z-index: 1000;
}

.welcome-text h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 2px;
    color: white;
}

.welcome-text p {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
}

.user-profile {
    position: relative;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
    padding: 0;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.user-profile-trigger {
    padding: 10px 22px;
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
    cursor: pointer;
}

.user-profile:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: translateY(-2px);
}

.user-info span {
    display: block;
    color: white;
    font-weight: 600;
    font-size: 14px;
}

.user-info small {
    color: rgba(255, 255, 255, 0.8);
    font-size: 11px;
}

.user-img {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
}

/* Header User Profile Dropdown */
.user-profile-trigger[aria-expanded="true"] .fa-chevron-down {
    transform: rotate(180deg);
}

.user-profile .dropdown-menu {
    border: 1px solid rgba(226, 232, 240, 0.8) !important;
    position: absolute !important;
    top: calc(100% - 2px) !important;
    /* Move up -2px to overlap/touch trigger border */
    right: 0 !important;
    left: auto !important;
    margin: 0 !important;
    display: block !important;
    opacity: 0;
    visibility: hidden;
    transform: translateY(5px) !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.user-profile .dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) !important;
}

.dropdown-item {
    transition: all 0.2s ease;
    border-radius: 10px !important;
    margin: 2px 8px;
    width: calc(100% - 16px);
}

.dropdown-item:hover {
    background: #f1f5f9 !important;
    color: var(--primary) !important;
    transform: translateX(4px);
}

.dropdown-divider {
    border-top: 1px solid #f1f5f9;
    margin: 4px 0;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

.card {
    background: var(--bg-card);
    padding: 30px;
    border-radius: 20px;
    text-decoration: none;
    color: inherit;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    border: 1px solid var(--border-main) !important;
}

.card:hover {
    transform: translateY(-10px);
    box-shadow: 0 15px 35px rgba(102, 126, 234, 0.15);
    border-color: var(--primary);
}

.card-icon {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    color: var(--primary);
    font-size: 28px;
    transition: all 0.3s ease;
}

.card:hover .card-icon {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    transform: rotate(5deg);
}

.card h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
}

.card p {
    font-size: 14px;
    color: var(--gray);
    line-height: 1.5;
}

/* Admin Section & Forms */
.admin-section,
.admin-form-container {
    margin-top: 30px;
    background: var(--bg-card) !important;
    padding: 40px !important;
    border-radius: 24px !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05) !important;
    border: 1px solid var(--border-main) !important;
}

/* Unified Form Controls */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 25px;
    margin-bottom: 25px;
}

/* Fallback for fixed 2 columns if grid row is explicitly requested */
.form-row-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    margin-bottom: 25px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 14px;
    color: #64748b;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    height: 52px;
    /* Fixed height for consistency */
    padding: 12px 20px;
    font-size: 15px;
    font-family: 'Sarabun', sans-serif !important;
    border: 1px solid var(--border-main);
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-main);
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.form-group textarea {
    height: auto;
    min-height: 120px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
    outline: none;
    background: #fff;
}

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
    background-size: 18px;
    padding-right: 45px;
}

.btn-submit {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    padding: 16px 30px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    font-weight: 700;
    font-size: 16px;
    width: 100%;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.btn-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.3);
}

.btn-submit:active {
    transform: translateY(0);
}

.glass-card {
    background: var(--bg-glass) !important;
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-main) !important;
    box-shadow: 0 4px 15px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05) !important;
    border-radius: 24px !important;
}

.glass-card:hover {
    border-color: rgba(59, 130, 246, 0.4) !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.05) !important;
    transform: translateY(-2px);
    transition: all 0.3s ease;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid #f0f2f5;
}

.btn-add {
    background: linear-gradient(135deg, var(--success) 0%, #38a169 100%);
    color: white;
    padding: 10px 20px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.btn-add:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.3);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th {
    text-align: left;
    padding: 15px;
    font-size: 14px;
    color: var(--gray);
    border-bottom: 1px solid #f0f2f5;
}

.admin-table td {
    padding: 15px;
    font-size: 14px;
    border-bottom: 1px solid #f0f2f5;
}

.btn-action {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    margin-right: 5px;
    transition: all 0.2s;
}

.btn-edit {
    background: #ebf4ff;
    color: #3182ce;
}

.btn-delete {
    background: #fff5f5;
    color: #e53e3e;
}

.btn-action:hover {
    transform: scale(1.1);
}

/* Compact Table Specifics (Requested for Juristic) */
#juristicTable th,
#juristicTable td {
    padding: 10px 8px !important;
    font-size: 12.5px !important;
    line-height: 1.2 !important;
}

#juristicTable .badge {
    font-size: 10.5px !important;
    padding: 3px 10px !important;
}

#juristicTable .btn-action {
    width: 28px;
    height: 28px;
    font-size: 12px;
}

#juristicTable .text-xs {
    font-size: 11px !important;
}

#juristicTableSection {
    padding: 25px 30px !important;
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: 80px;
        padding: 20px 10px;
    }

    .logo-small h2,
    .nav-link span,
    .sidebar-footer span {
        display: none;
    }

    .sidebar-header {
        margin-bottom: 30px;
    }

    .nav-link {
        justify-content: center;
        padding: 15px;
    }

    .main-content {
        margin-left: 80px;
    }
}

@media (max-width: 768px) {
    .logo-small h2,
    .nav-link span,
    .sidebar-footer span {
        display: inline;
    }

    .nav-link {
        justify-content: flex-start;
        padding: 12px 14px;
    }

    .sidebar {
        width: min(300px, 82vw);
        transform: translateX(-100%);
        transition: transform 0.28s ease;
        padding: 20px 14px;
        z-index: 1200;
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .mobile-sidebar-close {
        display: inline-flex;
        width: 34px;
        height: 34px;
        border: 0;
        border-radius: 10px;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.16);
        color: #fff;
        margin-left: auto;
        margin-bottom: 14px;
        cursor: pointer;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.45);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.22s ease, visibility 0.22s ease;
        z-index: 1100;
    }

    .sidebar-overlay.is-visible {
        opacity: 1;
        visibility: visible;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 20px;
    }

    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding: 18px 16px;
        border-radius: 18px;
    }

    .header-controls {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 10px !important;
    }

    .welcome-text h1 {
        font-size: 20px;
    }

    .user-profile {
        margin-left: auto;
    }

    .mobile-menu-btn {
        display: inline-flex;
        width: 38px;
        height: 38px;
        border-radius: 12px;
        border: 0;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.14);
        color: #fff;
        cursor: pointer;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .card {
        padding: 22px 18px;
        border-radius: 16px;
    }

    .admin-section,
    .admin-form-container {
        padding: 20px !important;
        border-radius: 18px !important;
    }

    .form-row,
    .form-row-2col {
        grid-template-columns: 1fr;
        gap: 14px;
    }
}

@media (min-width: 769px) {
    .mobile-menu-btn,
    .sidebar-overlay,
    .mobile-sidebar-close {
        display: none !important;
    }
}

/* Dashboard Specific Components */
.chart-container {
    position: relative;
    height: 320px;
    width: 100%;
    padding: 10px;
}

.premium-gradient {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.stat-card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.stat-card.active {
    border-bottom-width: 4px;
}

.filter-select {
    display: none !important;
}

/* Premium Select2 Styling - Borderless & Clean */
.select2-container--default .select2-selection--single {
    background-color: transparent !important;
    border: none !important;
    height: 40px !important;
    padding: 0 !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
}

.select2-container--default .select2-selection--single:focus {
    outline: none !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #334155 !important;
    font-weight: 700 !important;
    font-size: 15px !important;
    line-height: normal !important;
    padding-left: 0 !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 40px !important;
    right: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: #94a3b8 transparent transparent transparent !important;
    border-width: 5px 4px 0 4px !important;
}

/* Dropdown Window */
.premium-select-dropdown {
    border: 1px solid rgba(226, 232, 240, 0.8) !important;
    border-radius: 16px !important;
    box-shadow: 0 15px 30px -5px rgba(0, 0, 0, 0.1) !important;
    margin-top: 8px !important;
    overflow: hidden !important;
    background: #ffffff !important;
    z-index: 10000 !important;
}

.select2-results__option {
    padding: 12px 20px !important;
    font-size: 14px !important;
    font-family: 'Prompt', sans-serif !important;
    color: #64748b !important;
    font-weight: 500 !important;
}

.select2-results__option--highlighted[aria-selected] {
    background-color: #f1f5f9 !important;
    color: #3b82f6 !important;
}

.select2-container--default .select2-results__option--selected {
    background-color: #eff6ff !important;
    color: #2563eb !important;
    font-weight: 700 !important;
}