/* ==========================================================================
   DOAE e-Machine — Unified System Theme (Emerald & Slate)
   ========================================================================== */

:root {
    --em-primary: #059669;
    --em-primary-light: #10b981;
    --em-primary-dark: #047857;
    --em-primary-soft: #ecfdf5;
    --em-primary-border: #a7f3d0;
    --em-bg: #f8fafc;
    --em-surface: #ffffff;
    --em-border: #e2e8f0;
    --em-border-soft: #f1f5f9;
    --em-text: #0f172a;
    --em-text-secondary: #334155;
    --em-text-muted: #64748b;
    --em-radius: 16px;
    --em-radius-md: 12px;
    --em-radius-sm: 10px;
    --em-shadow-sm: 0 4px 18px rgba(15, 23, 42, 0.04);
    --em-shadow-md: 0 12px 32px rgba(15, 23, 42, 0.10);
}

/* Base Canvas & Typography */
html,
body {
    font-family: 'IBM Plex Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
    background-color: var(--em-bg);
    color: var(--em-text);
    -webkit-font-smoothing: antialiased;
}

.c-app,
.c-wrapper {
    background-color: var(--em-bg);
}

.c-main {
    padding-top: 1.25rem;
}

a {
    color: var(--em-primary);
}

a:hover {
    color: var(--em-primary-dark);
}

/* ==========================================================================
   Global Cards
   ========================================================================== */
.card {
    background-color: var(--em-surface);
    border: 1px solid var(--em-border);
    border-radius: var(--em-radius);
    box-shadow: var(--em-shadow-sm);
    margin-bottom: 1.25rem;
}

.card-header {
    background-color: var(--em-surface);
    border-bottom: 1px solid var(--em-border-soft);
    padding: 1rem 1.35rem;
    font-weight: 700;
    color: var(--em-text);
}

.card-header:first-child {
    border-radius: calc(var(--em-radius) - 1px) calc(var(--em-radius) - 1px) 0 0;
}

.card-header h4,
.card-header h5 {
    font-weight: 700;
    color: var(--em-text);
    margin-bottom: 0;
}

.card-footer {
    background-color: var(--em-bg);
    border-top: 1px solid var(--em-border-soft);
}

.card-footer:last-child {
    border-radius: 0 0 calc(var(--em-radius) - 1px) calc(var(--em-radius) - 1px);
}

/* ==========================================================================
   Global Form Controls
   ========================================================================== */
.form-control,
.custom-select {
    border-radius: var(--em-radius-sm);
    border: 1px solid #cbd5e1;
    color: var(--em-text);
    font-size: 0.92rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus,
.custom-select:focus {
    border-color: var(--em-primary-light);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.16);
    outline: none;
}

.form-control:disabled,
.form-control[readonly] {
    background-color: #f8fafc;
}

/* ==========================================================================
   Global Buttons
   ========================================================================== */
.btn {
    border-radius: var(--em-radius-sm);
    font-weight: 600;
    transition: all 0.18s ease;
}

.btn-sm {
    border-radius: 8px;
}

.btn-success,
.btn-green {
    background: linear-gradient(135deg, #10b981, #059669);
    border: none;
    color: #ffffff !important;
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.24);
}

.btn-success:hover,
.btn-success:focus,
.btn-green:hover,
.btn-green:focus {
    background: linear-gradient(135deg, #059669, #047857);
    color: #ffffff !important;
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(16, 185, 129, 0.34);
}

.btn-primary {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    border: none;
    color: #ffffff !important;
    box-shadow: 0 3px 10px rgba(2, 132, 199, 0.22);
}

.btn-primary:hover,
.btn-primary:focus {
    background: linear-gradient(135deg, #0284c7, #0369a1);
    color: #ffffff !important;
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(2, 132, 199, 0.32);
}

.btn-info {
    background: linear-gradient(135deg, #06b6d4, #0891b2);
    border: none;
    color: #ffffff !important;
}

.btn-info:hover,
.btn-info:focus {
    background: linear-gradient(135deg, #0891b2, #0e7490);
    color: #ffffff !important;
    transform: translateY(-1px);
}

.btn-danger,
.btn-red {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border: none;
    color: #ffffff !important;
}

.btn-danger:hover,
.btn-danger:focus,
.btn-red:hover,
.btn-red:focus {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: #ffffff !important;
    transform: translateY(-1px);
}

.btn-warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border: none;
    color: #ffffff !important;
}

.btn-warning:hover,
.btn-warning:focus {
    background: linear-gradient(135deg, #d97706, #b45309);
    color: #ffffff !important;
}

.btn-outline-success {
    color: var(--em-primary);
    border-color: var(--em-primary-light);
}

.btn-outline-success:hover {
    background-color: var(--em-primary);
    border-color: var(--em-primary);
    color: #ffffff !important;
}

/* ==========================================================================
   Global Tables & DataTables
   ========================================================================== */
.table {
    color: var(--em-text-secondary);
}

.table thead th {
    background-color: #f8fafc;
    color: #475569;
    font-weight: 700;
    font-size: 0.84rem;
    border-bottom: 1px solid var(--em-border) !important;
    border-top: none !important;
    padding: 0.85rem 0.9rem;
    vertical-align: middle;
}

.table td {
    border-top: 1px solid var(--em-border-soft);
    vertical-align: middle;
    padding: 0.8rem 0.9rem;
}

.table-bordered {
    border: 1px solid var(--em-border);
    border-radius: var(--em-radius-md);
    overflow: hidden;
}

.table-bordered th,
.table-bordered td {
    border-color: var(--em-border-soft);
}

.table tbody tr:hover {
    background-color: #f8fafc;
}

.dt-container .dt-paging .dt-paging-button {
    border-radius: 8px !important;
    border: 1px solid var(--em-border) !important;
    margin: 0 2px !important;
    padding: 0.35rem 0.75rem !important;
    font-weight: 600 !important;
    color: #475569 !important;
    background: #ffffff !important;
}

.dt-container .dt-paging .dt-paging-button.current,
.dt-container .dt-paging .dt-paging-button.current:hover {
    background: linear-gradient(135deg, #10b981, #059669) !important;
    border-color: #10b981 !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.dt-container .dt-paging .dt-paging-button:hover:not(.disabled):not(.current) {
    background: var(--em-primary-soft) !important;
    border-color: var(--em-primary-light) !important;
    color: var(--em-primary-dark) !important;
}

.dt-container .dt-length select,
.dt-container .dt-search input {
    border-radius: 8px !important;
    border: 1px solid #cbd5e1 !important;
    padding: 0.3rem 0.6rem !important;
}

/* ==========================================================================
   Global Modals, Alerts, Badges, Pagination, Toasts
   ========================================================================== */
.modal-content {
    border: none;
    border-radius: var(--em-radius);
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
    overflow: hidden;
}

.modal-header {
    background-color: #f8fafc;
    border-bottom: 1px solid var(--em-border);
    padding: 1rem 1.35rem;
}

.modal-title {
    font-weight: 700;
    color: var(--em-text);
}

.modal-footer {
    background-color: #f8fafc;
    border-top: 1px solid var(--em-border);
    padding: 0.85rem 1.35rem;
}

.alert {
    border-radius: var(--em-radius-md);
}

.pagination .page-item .page-link {
    border-radius: 8px;
    margin: 0 2px;
    border: 1px solid var(--em-border);
    color: #475569;
    font-weight: 600;
}

.pagination .page-item.active .page-link {
    background: linear-gradient(135deg, #10b981, #059669);
    border-color: #10b981;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.toast {
    border-radius: var(--em-radius-md);
    box-shadow: var(--em-shadow-md);
    border: none;
    overflow: hidden;
}

.toast .modal-header {
    background-color: transparent;
    border-bottom: none;
    padding: 0.85rem 1.15rem;
}

.toast .modal-title {
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.5;
}

.toast .modal-title p:last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   Modern Sidebar (dashboard.base)
   ========================================================================== */
.c-sidebar.c-sidebar-light {
    background: #ffffff;
    border-right: 1px solid var(--em-border);
    box-shadow: 4px 0 20px rgba(15, 23, 42, 0.03);
}

.c-sidebar.c-sidebar-light .c-sidebar-brand {
    background: #ffffff;
    border-bottom: 1px solid var(--em-border-soft);
    min-height: 62px;
    padding: 0 1rem;
    justify-content: flex-start;
}

.em-brand-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    text-decoration: none !important;
    width: 100%;
    overflow: hidden;
}

.em-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.em-brand-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--em-text);
    letter-spacing: -0.01em;
}

.em-brand-sub {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--em-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.c-sidebar-minimized .em-brand-text {
    display: none !important;
}

.c-sidebar-minimized .c-sidebar-brand {
    justify-content: center;
    padding: 0;
}

.c-sidebar-minimized .em-brand-link {
    justify-content: center;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav {
    padding: 0.75rem 0;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-title {
    color: #94a3b8;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.85rem 0.9rem 0.35rem;
    margin-top: 0.25rem;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-item {
    margin: 0.15rem 0.65rem;
}

.c-sidebar-minimized.c-sidebar-light .c-sidebar-nav-item {
    margin: 0.15rem 0;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-link,
.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown-toggle {
    color: #475569;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--em-radius-sm);
    padding: 0.65rem 0.9rem;
    gap: 0;
    transition: all 0.18s ease;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown {
    margin: 0.15rem 0.65rem;
    border-radius: var(--em-radius-sm);
}

.c-sidebar-minimized.c-sidebar-light .c-sidebar-nav-dropdown {
    margin: 0.15rem 0;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-link .c-sidebar-nav-icon,
.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown-toggle .c-sidebar-nav-icon {
    color: var(--em-text-muted);
    font-size: 0.95rem;
    flex: 0 0 1.2rem !important;
    width: 1.2rem !important;
    height: auto;
    margin-left: 0 !important;
    margin-right: 0.5rem !important;
    text-align: center;
    transition: color 0.18s ease;
}

.c-sidebar-minimized.c-sidebar-light .c-sidebar-nav-link .c-sidebar-nav-icon,
.c-sidebar-minimized.c-sidebar-light .c-sidebar-nav-dropdown-toggle .c-sidebar-nav-icon {
    flex: 0 0 56px !important;
    width: 56px !important;
    margin-right: 0 !important;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-link:hover,
.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown-toggle:hover {
    background: #f0fdf4 !important;
    color: var(--em-primary-dark) !important;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-link:hover .c-sidebar-nav-icon,
.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown-toggle:hover .c-sidebar-nav-icon {
    color: var(--em-primary-light) !important;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-link.c-active,
.c-sidebar.c-sidebar-light .c-sidebar-nav-link.em-nav-active {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%) !important;
    color: #065f46 !important;
    font-weight: 700;
    box-shadow: inset 3px 0 0 #10b981;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-link.c-active .c-sidebar-nav-icon,
.c-sidebar.c-sidebar-light .c-sidebar-nav-link.em-nav-active .c-sidebar-nav-icon {
    color: var(--em-primary) !important;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown.c-show {
    background: #f8fafc;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown.c-show > .c-sidebar-nav-dropdown-toggle {
    color: var(--em-text);
    font-weight: 600;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown-items {
    padding: 0.2rem 0 0.35rem;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown-items .c-sidebar-nav-item {
    margin: 0.1rem 0.35rem 0.1rem 0.95rem;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown-items .c-sidebar-nav-link {
    padding: 0.52rem 0.85rem 0.52rem 1.35rem !important;
    font-size: 0.86rem;
}

.c-sidebar.c-sidebar-light .c-sidebar-nav-dropdown-items .c-sidebar-nav-link .c-sidebar-nav-icon {
    flex: 0 0 1rem !important;
    width: 1rem !important;
    margin-right: 0.45rem !important;
}

.c-sidebar-minimized.c-sidebar-light .c-sidebar-nav-dropdown-items .c-sidebar-nav-item {
    margin: 0.1rem 0;
}

.c-sidebar-minimized.c-sidebar-light .c-sidebar-nav-dropdown-items .c-sidebar-nav-link {
    padding-left: 0.9rem !important;
}

.c-sidebar.c-sidebar-light .c-sidebar-minimizer {
    background-color: #f8fafc;
    border-top: 1px solid var(--em-border);
    transition: background-color 0.18s ease;
}

.c-sidebar.c-sidebar-light .c-sidebar-minimizer:hover {
    background-color: var(--em-primary-soft);
}

/* ==========================================================================
   Modern Header Bar (shared across dashboard.base & dashboard.authBase)
   ========================================================================== */
.c-header.em-header {
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--em-border);
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.04);
    min-height: 62px;
    padding: 0 1rem;
}

.em-header .c-header-toggler {
    width: 38px;
    height: 38px;
    border-radius: var(--em-radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #475569;
    transition: all 0.18s ease;
}

.em-header .c-header-toggler:hover {
    background: #f1f5f9;
    color: var(--em-primary);
}

.em-header-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: #f0fdf4;
    border: 1px solid #d1fae5;
    color: #065f46;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.32rem 0.8rem;
    border-radius: 999px;
    margin-left: 0.5rem;
}

.em-header-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--em-primary-light);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.em-header-home-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.84rem;
    font-weight: 600;
    color: #475569 !important;
    background: #f8fafc;
    border: 1px solid var(--em-border);
    border-radius: 999px;
    padding: 0.38rem 0.9rem;
    text-decoration: none !important;
    transition: all 0.18s ease;
}

.em-header-home-btn:hover {
    background: #f0fdf4;
    border-color: var(--em-primary-border);
    color: var(--em-primary-dark) !important;
}

.em-counter-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: #f0fdf4;
    border: 1px solid #d1fae5;
    color: #065f46;
    border-radius: 999px;
    padding: 0.34rem 0.8rem;
    font-size: 0.82rem;
    font-weight: 700;
}

.em-counter-pill i {
    color: var(--em-primary-light);
    font-size: 0.9rem;
}

.em-user-trigger {
    display: inline-flex !important;
    align-items: center;
    gap: 0.6rem;
    padding: 0.28rem 0.75rem 0.28rem 0.32rem !important;
    border-radius: 999px;
    background: #f8fafc;
    border: 1px solid var(--em-border);
    transition: all 0.18s ease;
    text-decoration: none !important;
}

.em-user-trigger:hover {
    background: #f0fdf4;
    border-color: var(--em-primary-border);
}

.em-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid var(--em-primary-light);
    overflow: hidden;
    flex-shrink: 0;
    background: #ffffff;
}

.em-user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.em-user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    text-align: left;
}

.em-user-name {
    font-size: 0.84rem;
    font-weight: 700;
    color: var(--em-text);
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.em-user-role {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--em-primary);
}

.em-user-dropdown {
    min-width: 240px;
    border: 1px solid var(--em-border) !important;
    border-radius: 14px !important;
    box-shadow: 0 14px 36px rgba(15, 23, 42, 0.12) !important;
    padding: 0.45rem !important;
    margin-top: 0.5rem !important;
    overflow: hidden;
}

.em-user-dropdown-head {
    background: linear-gradient(135deg, #f0fdf4 0%, #f8fafc 100%);
    border: 1px solid var(--em-border);
    border-radius: var(--em-radius-sm);
    padding: 0.7rem 0.85rem;
    margin-bottom: 0.4rem;
}

.em-user-dropdown .dropdown-item {
    border-radius: 9px;
    padding: 0.55rem 0.8rem;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--em-text-secondary);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    transition: all 0.15s ease;
}

.em-user-dropdown .dropdown-item:hover {
    background: #f0fdf4;
    color: var(--em-primary-dark);
}

.em-user-dropdown .dropdown-item i {
    width: 18px;
    text-align: center;
    font-size: 0.9rem;
}

.em-user-dropdown .dropdown-item.em-item-danger {
    color: #dc2626;
}

.em-user-dropdown .dropdown-item.em-item-danger:hover {
    background: #fef2f2;
    color: #b91c1c;
}

/* ==========================================================================
   Modern Footer
   ========================================================================== */
.em-footer {
    background: #ffffff !important;
    border-top: 1px solid var(--em-border) !important;
    color: var(--em-text-muted);
    font-size: 0.84rem;
    padding: 0.75rem 1.25rem;
}

.em-footer a {
    color: var(--em-primary);
    font-weight: 600;
    text-decoration: none;
}

.em-footer a:hover {
    color: var(--em-primary-dark);
    text-decoration: underline;
}
