/* ===== RTS THEME CSS ===== */
/* Colors: #fa7921 (orange) | #0f82aa (blue) | #10b981 (green) */

:root {
    --color-primary:        #fa7921;
    --color-primary-light:  #fff3e8;
    --color-primary-dark:   #e0661a;
    --color-secondary:      #0f82aa;
    --color-secondary-light:#e8f4f8;
    --color-success:        #10b981;
    --color-success-light:  #d1fae5;
    --color-danger:         #ef4444;
    --color-danger-light:   #fee2e2;
    --color-warning:        #f59e0b;
    --color-warning-light:  #fef3c7;

    --bg-body:              #f5f6fa;
    --bg-card:              #ffffff;
    --bg-sidebar:           #1a1f2e;
    --bg-sidebar-hover:     #252c3d;
    --bg-sidebar-active:    #0f82aa;
    --bg-table-head:        #f8f9fb;

    --text-primary:         #1a1f2e;
    --text-secondary:       #4b5563;
    --text-muted:           #9ca3af;
    --text-sidebar:         #c8d0de;
    --text-sidebar-active:  #ffffff;

    --border-color:         #e5e7eb;
    --border-radius:        10px;
    --border-radius-sm:     6px;
    --border-radius-lg:     16px;

    --shadow:               0 1px 4px rgba(0,0,0,0.07), 0 4px 16px rgba(0,0,0,0.05);
    --shadow-lg:            0 4px 24px rgba(0,0,0,0.10);

    --sidebar-width:        250px;
    --topbar-height:        64px;
    --font-family:          'Sarabun', sans-serif;
    --transition:           all 0.2s ease;
}

[data-theme="dark"] {
    --bg-body:              #0f1117;
    --bg-card:              #1a1f2e;
    --bg-sidebar:           #111318;
    --bg-sidebar-hover:     #1a1f2e;
    --bg-table-head:        #1e2436;

    --text-primary:         #e9ecf3;
    --text-secondary:       #a0aec0;
    --text-muted:           #6b7280;

    --border-color:         #2a3147;
    --shadow:               0 1px 4px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.2);
    --shadow-lg:            0 4px 24px rgba(0,0,0,0.4);
    --color-primary-light:  #2a1a0a;
    --color-secondary-light:#0a1e28;
    --color-success-light:  #0a2018;
    --color-danger-light:   #2a0a0a;
    --color-warning-light:  #2a1e00;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
    font-family: var(--font-family);
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
}
a { color: var(--color-secondary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--color-primary); }
img { max-width: 100%; }
ul { list-style: none; }

/* ===== LAYOUT ===== */
.layout {
    display: flex;
    min-height: 100vh;
}
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}
.main-content.expanded { margin-left: 72px; }

/* ===== TOPBAR ===== */
.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 90;
    box-shadow: var(--shadow);
}
.topbar-left  { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-user  { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.topbar-user-info { display: flex; flex-direction: column; line-height: 1.3; }
.topbar-user-name { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.topbar-user-role { font-size: 0.78rem; color: var(--text-muted); }
.page-title   { font-size: 1.1rem; font-weight: 700; margin: 0; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    min-height: var(--topbar-height);
}
.sidebar-logo-icon {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    border-radius: var(--border-radius-sm);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    color: #fff;
}
.sidebar-logo-text { font-size: 0.92rem; font-weight: 700; color: #fff; line-height: 1.2; }
.sidebar-logo-sub  { font-size: 0.75rem; color: var(--text-sidebar); margin-top: 1px; }
.sidebar-nav  { flex: 1; padding: 12px 10px; }
.sidebar-section { margin-bottom: 8px; }
.sidebar-section-title {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(200,208,222,0.45);
    padding: 8px 10px 4px;
}
.sidebar-footer { padding: 10px; border-top: 1px solid rgba(255,255,255,0.07); }
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* ===== NAV ITEM ===== */
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--border-radius-sm);
    color: var(--text-sidebar);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    text-decoration: none;
    font-family: var(--font-family);
}
.nav-item:hover { background: var(--bg-sidebar-hover); color: #fff; }
.nav-item.active { background: var(--bg-sidebar-active); color: var(--text-sidebar-active); }
.nav-item-icon {
    width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    opacity: 0.8;
}
.nav-item.active .nav-item-icon { opacity: 1; }
.nav-item svg { width: 18px; height: 18px; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--border-radius-sm);
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary   { background: var(--color-primary);   color: #fff; border-color: var(--color-primary); }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-dark); }

.btn-secondary { background: var(--color-secondary); color: #fff; border-color: var(--color-secondary); }
.btn-secondary:hover:not(:disabled) { background: #0d6f90; }

.btn-success   { background: var(--color-success);   color: #fff; border-color: var(--color-success); }
.btn-success:hover:not(:disabled) { background: #0d9e6d; }

.btn-danger    { background: var(--color-danger);    color: #fff; border-color: var(--color-danger); }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.btn-outline:hover:not(:disabled) {
    background: var(--bg-body);
    border-color: var(--text-muted);
    color: var(--text-primary);
}
.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
    padding: 7px;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-body); color: var(--text-primary); }

.btn-sm  { padding: 5px 12px; font-size: 0.82rem; }
.btn-lg  { padding: 12px 28px; font-size: 1rem; }
.btn-icon { padding: 8px; border-radius: var(--border-radius-sm); }
.btn-full { width: 100%; }
.w-full   { width: 100%; }

/* ===== CARD ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
}
.card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-title svg { width: 18px; height: 18px; }
.card-body { padding: 20px; }
.mb-3 { margin-bottom: 16px; }

/* ===== PAGE LAYOUT ===== */
.page-content { padding: 24px; flex: 1; }
.page-header  {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header-title  { font-size: 1.3rem; font-weight: 700; color: var(--text-primary); margin-bottom: 2px; }
.page-breadcrumb    { font-size: 0.83rem; color: var(--text-muted); }
.page-breadcrumb a  { color: var(--text-muted); }
.page-breadcrumb a:hover { color: var(--color-secondary); }

/* ===== STATS CARD ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    box-shadow: var(--shadow);
}
.stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--border-radius-sm);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-icon-primary   { background: var(--color-primary-light);   color: var(--color-primary); }
.stat-icon-secondary { background: var(--color-secondary-light); color: var(--color-secondary); }
.stat-icon-success   { background: var(--color-success-light);   color: var(--color-success); }
.stat-icon-warning   { background: var(--color-warning-light);   color: var(--color-warning); }
.stat-icon-danger    { background: var(--color-danger-light);    color: var(--color-danger); }
.stat-number { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-label  { font-size: 0.83rem; color: var(--text-secondary); margin-top: 4px; }

/* ===== TABLE ===== */
.table-wrapper { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.table th {
    background: var(--bg-table-head);
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 10px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    color: var(--text-primary);
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-body); }

/* ===== FORM ===== */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 0.87rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-card);
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-family: var(--font-family);
    font-size: 0.93rem;
    color: var(--text-primary);
    transition: var(--transition);
    outline: none;
}
.form-control:focus { border-color: var(--color-secondary); box-shadow: 0 0 0 3px rgba(15,130,170,0.12); }
.form-control::placeholder { color: var(--text-muted); }
.form-control.error { border-color: var(--color-danger); }
.form-error { font-size: 0.8rem; color: var(--color-danger); margin-top: 4px; }
textarea.form-control { resize: vertical; min-height: 100px; }
.required { color: var(--color-danger); }

/* ===== SEARCH BAR ===== */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-body);
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 0 12px;
    transition: var(--transition);
}
.search-bar:focus-within { border-color: var(--color-secondary); box-shadow: 0 0 0 3px rgba(15,130,170,0.1); }
.search-bar .form-control { background: transparent; border: none; box-shadow: none; padding-left: 0; }
.search-icon { color: var(--text-muted); display: flex; align-items: center; }
.search-icon svg { width: 16px; height: 16px; }

/* ===== BADGE ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-draft    { background: var(--bg-table-head);    color: var(--text-muted); }
.badge-pending  { background: var(--color-warning-light); color: #b45309; }
.badge-approved { background: var(--color-success-light); color: #065f46; }
.badge-rejected { background: var(--color-danger-light);  color: #991b1b; }
.badge-master   { background: var(--color-secondary-light); color: var(--color-secondary); }
.badge-doctoral { background: var(--color-primary-light);   color: var(--color-primary); }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }
.modal-box {
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-body  { padding: 24px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

/* ===== AVATAR ===== */
.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary-dark), var(--color-primary));
    display: flex; align-items: center; justify-content: center;
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    overflow: hidden;
}

/* ===== THEME TOGGLE ===== */
.theme-toggle {
    width: 34px; height: 34px;
    border-radius: var(--border-radius-sm);
    background: var(--bg-body);
    border: 1.5px solid var(--border-color);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}
.theme-toggle:hover { border-color: var(--color-secondary); color: var(--color-secondary); }
.theme-toggle svg { width: 16px; height: 16px; }

/* ===== SPINNER ===== */
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-secondary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}
.spinner-sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state-icon { margin-bottom: 12px; color: var(--border-color); }
.empty-state-icon svg { width: 48px; height: 48px; }
.empty-state-title { font-size: 1rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state-text  { font-size: 0.87rem; }

/* ===== PAGINATION ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 20px 0;
    flex-wrap: wrap;
}
.page-btn {
    min-width: 36px; height: 36px;
    padding: 0 10px;
    border-radius: var(--border-radius-sm);
    border: 1.5px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 0.87rem;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex; align-items: center; justify-content: center;
}
.page-btn:hover:not(:disabled) { border-color: var(--color-secondary); color: var(--color-secondary); }
.page-btn.active { background: var(--color-secondary); border-color: var(--color-secondary); color: #fff; font-weight: 700; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== TOAST ===== */
#toastContainer {
    position: fixed;
    top: 20px; right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--color-secondary);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 14px 18px;
    max-width: 340px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: toastIn 0.3s ease;
    pointer-events: auto;
}
.toast.success { border-left-color: var(--color-success); }
.toast.error   { border-left-color: var(--color-danger); }
.toast.warning { border-left-color: var(--color-warning); }
.toast-icon svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.toast.success .toast-icon { color: var(--color-success); }
.toast.error   .toast-icon { color: var(--color-danger); }
.toast.warning .toast-icon { color: var(--color-warning); }
.toast-info .toast-icon    { color: var(--color-secondary); }
.toast-body { flex: 1; }
.toast-title { font-size: 0.87rem; font-weight: 700; margin-bottom: 2px; }
.toast-msg   { font-size: 0.82rem; color: var(--text-secondary); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ===== CHARTS GRID ===== */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }

/* ===== CONFIRM DIALOG ===== */
.confirm-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.confirm-box {
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    padding: 28px;
    max-width: 380px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.confirm-icon { margin-bottom: 14px; }
.confirm-icon svg { width: 44px; height: 44px; color: var(--color-warning); }
.confirm-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 8px; }
.confirm-msg   { font-size: 0.88rem; color: var(--text-secondary); margin-bottom: 20px; line-height: 1.6; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }

/* ===== RESEARCH CARD (Public) ===== */
.research-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.research-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: var(--transition);
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
}
.research-card:hover {
    border-color: var(--color-secondary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    color: inherit;
}
.research-card-title { font-size: 0.95rem; font-weight: 700; color: var(--text-primary); line-height: 1.5; }
.research-card-en    { font-size: 0.82rem; color: var(--text-muted); }
.research-card-meta  { display: flex; gap: 12px; font-size: 0.82rem; color: var(--text-muted); flex-wrap: wrap; }
.research-card-meta svg { width: 13px; height: 13px; }
.research-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
    flex-wrap: wrap;
    gap: 6px;
}

/* ===== RESPONSIVE ===== */
.d-none-mobile { display: flex; }

@media (max-width: 768px) {
    .main-content { margin-left: 0 !important; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.mobile-open { transform: translateX(0); }
    .charts-grid { grid-template-columns: 1fr !important; }
    .stats-grid  { grid-template-columns: repeat(2, 1fr); }
    .d-none-mobile { display: none !important; }
    .page-content  { padding: 16px; }
    .topbar { padding: 0 16px; }
    .research-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}
