/* ============================================================
   EduManage - ระบบบริหารการศึกษา
   Design system: sidebar layout + indigo accent (Bootstrap 5 + custom CSS)
   ============================================================ */

:root {
    /* ปรับสี primary ของ Bootstrap ให้เป็นโทน indigo */
    --bs-primary: #6366f1;
    --bs-primary-rgb: 99, 102, 241;

    --em-primary: #6366f1;
    --em-primary-dark: #4f46e5;
    --em-primary-darker: #4338ca;
    --em-primary-soft: #eef2ff;

    --em-bg: #f4f5fb;
    --em-surface: #ffffff;
    --em-border: #edeef3;
    --em-border-strong: #e5e7eb;

    --em-text: #1f2937;
    --em-text-muted: #6b7280;
    --em-text-faint: #9ca3af;

    --em-radius: 16px;
    --em-radius-sm: 10px;
    --em-shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
    --em-shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);

    --em-sidebar-w: 260px;
    --em-topbar-h: 72px;
}

* {
    font-family: 'IBM Plex Sans Thai', 'IBM Plex Sans', sans-serif;
}

body {
    font-family: 'IBM Plex Sans Thai', 'IBM Plex Sans', sans-serif;
    color: var(--em-text);
    background-color: var(--em-bg);
}

/* ============================================================
   Layout
   ============================================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    margin-left: var(--em-sidebar-w);
    display: flex;
    flex-direction: column;
}

.app-content {
    padding: 28px;
    flex: 1 1 auto;
}

/* ============================================================
   Sidebar
   ============================================================ */
.app-sidebar {
    width: var(--em-sidebar-w);
    background: var(--em-surface);
    border-right: 1px solid var(--em-border);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 22px 18px;
}

.sidebar-brand .brand-logo {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.sidebar-brand .brand-name {
    font-weight: 700;
    font-size: 1.15rem;
    line-height: 1.1;
    color: var(--em-text);
}

.sidebar-brand .brand-sub {
    font-size: 0.72rem;
    color: var(--em-text-faint);
}

.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 8px 14px;
    overflow-y: auto;
    flex: 1 1 auto;
}

.sidebar-nav .nav-section {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--em-text-faint);
    padding: 14px 12px 6px;
    font-weight: 600;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 2px;
    border-radius: var(--em-radius-sm);
    color: var(--em-text-muted);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link i {
    font-size: 1.15rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-link:hover {
    background: #f7f7fb;
    color: var(--em-text);
}

.sidebar-link.active {
    background: var(--em-primary-soft);
    color: var(--em-primary-dark);
    font-weight: 600;
}

.sidebar-link.disabled {
    color: var(--em-text-faint);
    pointer-events: none;
    cursor: default;
}

.sidebar-link .soon {
    margin-left: auto;
    font-size: 0.6rem;
    background: #f1f3f5;
    color: #9ca3af;
    padding: 2px 7px;
    border-radius: 999px;
    font-weight: 600;
}

.sidebar-footer {
    border-top: 1px solid var(--em-border);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ============================================================
   Topbar
   ============================================================ */
.app-topbar {
    min-height: var(--em-topbar-h);
    background: var(--em-surface);
    border-bottom: 1px solid var(--em-border);
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 28px;
    gap: 16px;
}

.app-topbar .page-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.app-topbar .page-sub {
    font-size: 0.82rem;
    color: var(--em-text-muted);
    margin: 0;
}

.topbar-icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1px solid var(--em-border);
    background: #fff;
    color: var(--em-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    position: relative;
}

.topbar-icon-btn:hover {
    background: #f7f7fb;
    color: var(--em-text);
}

.topbar-icon-btn .dot {
    position: absolute;
    top: 8px;
    right: 9px;
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 10px 5px 5px;
    border: 1px solid var(--em-border);
    border-radius: 999px;
    background: #fff;
    color: var(--em-text);
    text-decoration: none;
}

.topbar-user:hover {
    background: #f7f7fb;
}

/* ============================================================
   Avatar
   ============================================================ */
.avatar {
    border-radius: 50%;
    background: var(--em-primary-soft);
    color: var(--em-primary-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 600;
}

.avatar-sm { width: 34px; height: 34px; font-size: 1rem; }
.avatar-md { width: 42px; height: 42px; font-size: 1.2rem; }

/* ============================================================
   Cards
   ============================================================ */
.card {
    border: none;
    border-radius: var(--em-radius);
    box-shadow: var(--em-shadow);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid var(--em-border);
    border-radius: var(--em-radius) var(--em-radius) 0 0 !important;
    padding: 16px 20px;
}

/* Stat card */
.stat-card {
    border-radius: var(--em-radius);
}

.stat-icon {
    width: 54px;
    height: 54px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon.blue   { background: #e0f2fe; color: #0284c7; }
.stat-icon.green  { background: #dcfce7; color: #16a34a; }
.stat-icon.orange { background: #ffedd5; color: #ea580c; }
.stat-icon.pink   { background: #fce7f3; color: #db2777; }

.stat-value {
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-label {
    color: var(--em-text-muted);
    font-size: 0.85rem;
}

/* ============================================================
   Content header (title row + actions inside content)
   ============================================================ */
.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.breadcrumb-mini {
    font-size: 0.8rem;
    color: var(--em-text-faint);
    margin: 2px 0 0;
}

.breadcrumb-mini a { color: var(--em-text-muted); text-decoration: none; }
.breadcrumb-mini a:hover { color: var(--em-primary); }

/* ============================================================
   Buttons (indigo theme)
   ============================================================ */
.btn {
    font-weight: 500;
    border-radius: var(--em-radius-sm);
    padding: 0.5rem 1rem;
}

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

.btn-primary {
    --bs-btn-bg: #6366f1;
    --bs-btn-border-color: #6366f1;
    --bs-btn-hover-bg: #4f46e5;
    --bs-btn-hover-border-color: #4f46e5;
    --bs-btn-active-bg: #4338ca;
    --bs-btn-active-border-color: #4338ca;
    --bs-btn-disabled-bg: #a5b4fc;
    --bs-btn-disabled-border-color: #a5b4fc;
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.25);
}

.btn-outline-primary {
    --bs-btn-color: #4f46e5;
    --bs-btn-border-color: #c7d2fe;
    --bs-btn-hover-bg: #6366f1;
    --bs-btn-hover-border-color: #6366f1;
    --bs-btn-active-bg: #4f46e5;
    --bs-btn-active-border-color: #4f46e5;
}

/* ============================================================
   Forms
   ============================================================ */
.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: #374151;
    margin-bottom: 5px;
}

.form-control,
.form-select {
    border-radius: var(--em-radius-sm);
    border-color: var(--em-border-strong);
    padding: 0.55rem 0.85rem;
    font-size: 0.925rem;
}

.form-control:focus,
.form-select:focus {
    border-color: #a5b4fc;
    box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.15);
}

.invalid-feedback { font-size: 0.8rem; }

/* ============================================================
   Tables
   ============================================================ */
.table {
    --bs-table-hover-bg: #f9fafb;
    margin-bottom: 0;
    color: var(--em-text);
}

.table thead th {
    background: #f8f9fc;
    color: var(--em-text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    white-space: nowrap;
    border-bottom: 1px solid var(--em-border);
    padding: 0.85rem 0.75rem;
}

.table tbody td {
    vertical-align: middle;
    font-size: 0.9rem;
    padding: 0.8rem 0.75rem;
    border-bottom: 1px solid #f3f4f6;
}

.table tbody tr:last-child td { border-bottom: none; }

.table-responsive { border-radius: 0 0 var(--em-radius) var(--em-radius); }

/* ============================================================
   Badges (soft, pill)
   ============================================================ */
.badge { font-weight: 600; font-size: 0.78rem; padding: 0.4em 0.65em; }

.badge-soft {
    border-radius: 999px;
    font-weight: 600;
    padding: 0.4em 0.85em;
    font-size: 0.75rem;
    display: inline-block;
}

.badge-soft.green  { background: #dcfce7; color: #15803d; }
.badge-soft.red    { background: #fee2e2; color: #b91c1c; }
.badge-soft.amber  { background: #fef3c7; color: #b45309; }
.badge-soft.blue   { background: #dbeafe; color: #1d4ed8; }
.badge-soft.indigo { background: #e0e7ff; color: #4338ca; }
.badge-soft.gray   { background: #f1f3f5; color: #495057; }

/* ============================================================
   Icon action buttons in tables
   ============================================================ */
.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
}

/* ============================================================
   Alerts / Modal
   ============================================================ */
.alert { font-size: 0.9rem; border-radius: var(--em-radius-sm); border: none; }
.alert-success { background: #dcfce7; color: #15803d; }
.alert-danger { background: #fee2e2; color: #b91c1c; }

.modal-content { border: none; border-radius: var(--em-radius); }
.modal-header { border-bottom: 1px solid var(--em-border); }
.modal-footer { border-top: 1px solid var(--em-border); }

/* ============================================================
   Login page
   ============================================================ */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 45%, #f4f5fb 100%);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 410px;
    background: #fff;
    border-radius: 20px;
    box-shadow: var(--em-shadow-md);
    padding: 36px 34px;
}

.login-logo {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.9rem;
    margin: 0 auto 14px;
}

/* ============================================================
   Sidebar overlay + responsive
   ============================================================ */
.app-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.4);
    z-index: 1039;
}

.topbar-toggle { display: none; }

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.show { transform: translateX(0); box-shadow: var(--em-shadow-md); }
    .app-main { margin-left: 0; }
    .app-overlay.show { display: block; }
    .topbar-toggle { display: inline-flex; }
    .app-content { padding: 18px; }
    .app-topbar { padding: 12px 18px; }
}
