/* ===================================================================
   CallStudent SaaS — Design System หลัก
   Theme: ขาว/ฟ้า Professional
   Font: Sarabun (Thai)
   =================================================================== */

/* ===================================================================
   @font-face — Sarabun (ดาวน์โหลดมาเก็บใน vendor)
   =================================================================== */
@font-face {
    font-family: 'Sarabun';
    src: url('../vendor/fonts/sarabun/sarabun-300.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Sarabun';
    src: url('../vendor/fonts/sarabun/sarabun-400.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Sarabun';
    src: url('../vendor/fonts/sarabun/sarabun-400italic.ttf') format('truetype');
    font-weight: 400;
    font-style: italic;
    font-display: swap;
}
@font-face {
    font-family: 'Sarabun';
    src: url('../vendor/fonts/sarabun/sarabun-500.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Sarabun';
    src: url('../vendor/fonts/sarabun/sarabun-600.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Sarabun';
    src: url('../vendor/fonts/sarabun/sarabun-700.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* ===================================================================
   CSS Custom Properties — Design Tokens
   =================================================================== */
:root {
    /* สีหลัก */
    --primary: #1565C0;
    --primary-light: #42A5F5;
    --primary-lighter: #90CAF9;
    --primary-dark: #0D47A1;
    --primary-gradient: linear-gradient(135deg, #1565C0, #42A5F5);
    --primary-gradient-hover: linear-gradient(135deg, #0D47A1, #1565C0);

    /* สีเสริม */
    --accent: #039BE5;
    --success: #2E7D32;
    --success-light: #E8F5E9;
    --warning: #F57F17;
    --warning-light: #FFF8E1;
    --danger: #C62828;
    --danger-light: #FFEBEE;
    --info: #0277BD;
    --info-light: #E1F5FE;

    /* สีพื้นหลัง */
    --bg-primary: #F0F4F8;
    --bg-surface: #FFFFFF;
    --bg-sidebar: rgba(13, 71, 161, 0.95);
    --bg-hover: #F5F8FC;
    --bg-selected: #E3F2FD;

    /* สีตัวอักษร */
    --text-primary: #1A2332;
    --text-secondary: #5A6B7F;
    --text-muted: #8A9AB5;
    --text-white: #FFFFFF;
    --text-link: #1565C0;

    /* สีขอบ */
    --border: #E2E8F0;
    --border-light: #F1F5F9;
    --border-focus: #42A5F5;

    /* ขนาดตัวอักษร */
    --font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-xs: 0.75rem;    /* 12px */
    --font-sm: 0.8125rem;  /* 13px */
    --font-base: 0.9375rem; /* 15px */
    --font-md: 1rem;        /* 16px */
    --font-lg: 1.25rem;     /* 20px */
    --font-xl: 1.5rem;      /* 24px */
    --font-2xl: 1.75rem;    /* 28px */
    --font-3xl: 2rem;       /* 32px */
    --font-4xl: 2.5rem;     /* 40px */

    /* มุมโค้ง */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 20px;
    --radius-full: 50%;

    /* เงา */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(21, 101, 192, 0.08);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.04), 0 10px 24px rgba(21, 101, 192, 0.12);
    --shadow-xl: 0 8px 16px rgba(0, 0, 0, 0.06), 0 20px 40px rgba(21, 101, 192, 0.15);
    --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.08);
    --shadow-card-hover: 0 8px 24px rgba(21, 101, 192, 0.18);

    /* Transition */
    --transition: all 0.2s cubic-bezier(.4, 0, .2, 1);
    --transition-slow: all 0.3s cubic-bezier(.4, 0, .2, 1);
    --transition-fast: all 0.15s ease;

    /* Sidebar */
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --topbar-height: 64px;
}

/* ===================================================================
   Reset & Base
   =================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-base);
    font-weight: 400;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
}

a {
    color: var(--text-link);
    text-decoration: none;
    transition: var(--transition);
}

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

img {
    max-width: 100%;
    height: auto;
}

/* ===================================================================
   Typography
   =================================================================== */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

h1 { font-size: var(--font-2xl); font-weight: 700; }
h2 { font-size: var(--font-xl); }
h3 { font-size: var(--font-lg); }
h4 { font-size: var(--font-md); }

.text-muted { color: var(--text-secondary); }
.text-small { font-size: var(--font-sm); }
.text-center { text-align: center; }

/* ===================================================================
   Buttons
   =================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-family: var(--font-family);
    font-size: var(--font-base);
    font-weight: 500;
    line-height: 1;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary-gradient);
    color: var(--text-white);
    box-shadow: 0 2px 8px rgba(21, 101, 192, 0.3);
}

.btn-primary:hover {
    background: var(--primary-gradient-hover);
    box-shadow: 0 4px 16px rgba(21, 101, 192, 0.4);
    transform: translateY(-1px);
    color: var(--text-white);
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--primary-light);
    color: var(--primary);
}

.btn-success { background: var(--success); color: var(--text-white); }
.btn-success:hover { background: #1B5E20; color: var(--text-white); }

.btn-danger { background: var(--danger); color: var(--text-white); }
.btn-danger:hover { background: #B71C1C; color: var(--text-white); }

.btn-warning { background: var(--warning); color: var(--text-white); }

.btn-sm {
    padding: 6px 14px;
    font-size: var(--font-sm);
    border-radius: var(--radius-md);
}

.btn-lg {
    padding: 14px 28px;
    font-size: var(--font-md);
    border-radius: var(--radius-lg);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
}

.btn-block {
    width: 100%;
}

.btn:disabled,
.btn.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* ปุ่ม loading spinner */
.btn .spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.btn.loading .spinner {
    display: inline-block;
}

.btn.loading .btn-text {
    display: none;
}

/* ===================================================================
   Form Inputs
   =================================================================== */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: var(--font-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    font-family: var(--font-family);
    font-size: var(--font-base);
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    transition: var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(66, 165, 245, 0.15);
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-control.is-invalid {
    border-color: var(--danger);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235A6B7F' d='M6 8.825L1.175 4 2.238 2.938 6 6.7 9.763 2.937 10.825 4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

/* ===================================================================
   Cards
   =================================================================== */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    transition: var(--transition);
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-2px);
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: var(--font-md);
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

.card-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-hover);
}

/* Stat Card — Dashboard */
.stat-card {
    padding: 24px;
    border-radius: var(--radius-xl);
    background: var(--bg-surface);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--primary-gradient);
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-card-hover);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--text-white);
    margin-bottom: 16px;
}

.stat-card .stat-icon.blue { background: var(--primary-gradient); }
.stat-card .stat-icon.green { background: linear-gradient(135deg, #2E7D32, #66BB6A); }
.stat-card .stat-icon.orange { background: linear-gradient(135deg, #F57F17, #FFB300); }
.stat-card .stat-icon.red { background: linear-gradient(135deg, #C62828, #EF5350); }
.stat-card .stat-icon.cyan { background: linear-gradient(135deg, #0277BD, #29B6F6); }

.stat-card .stat-value {
    font-size: var(--font-3xl);
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-card .stat-label {
    font-size: var(--font-sm);
    color: var(--text-secondary);
}

/* ===================================================================
   Tables
   =================================================================== */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-light);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-sm);
}

.table thead th {
    padding: 14px 16px;
    font-weight: 600;
    font-size: var(--font-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border-bottom: 2px solid var(--border);
    text-align: left;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.table tbody tr {
    transition: var(--transition-fast);
}

.table tbody tr:hover {
    background: var(--bg-hover);
}

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

/* ===================================================================
   Badges
   =================================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: var(--font-xs);
    font-weight: 600;
    border-radius: var(--radius-2xl);
    line-height: 1;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger  { background: var(--danger-light); color: var(--danger); }
.badge-info    { background: var(--info-light); color: var(--info); }
.badge-primary { background: var(--bg-selected); color: var(--primary); }
.badge-muted   { background: #F1F5F9; color: var(--text-muted); }

/* ===================================================================
   Avatars
   =================================================================== */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    object-fit: cover;
    border: 2px solid var(--bg-surface);
    box-shadow: var(--shadow-sm);
}

.avatar-sm { width: 32px; height: 32px; }
.avatar-lg { width: 56px; height: 56px; }
.avatar-xl { width: 80px; height: 80px; }

/* ===================================================================
   Pagination
   =================================================================== */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none;
    margin: 20px 0 0;
    justify-content: center;
}

.pagination .page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    font-size: var(--font-sm);
    font-weight: 500;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.pagination .page-link:hover,
.pagination .page-link.active {
    background: var(--primary);
    color: var(--text-white);
    border-color: var(--primary);
}

/* ===================================================================
   Search & Filter Bar
   =================================================================== */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.search-input {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-input i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
}

.search-input .form-control {
    padding-left: 40px;
}

/* ===================================================================
   Empty State
   =================================================================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state h4 {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* ===================================================================
   Loading / Skeleton
   =================================================================== */
.skeleton {
    background: linear-gradient(90deg, var(--border-light) 25%, #E8EDF2 50%, var(--border-light) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease infinite;
    border-radius: var(--radius-md);
}

.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-title { height: 20px; width: 60%; margin-bottom: 12px; }
.skeleton-avatar { width: 40px; height: 40px; border-radius: 50%; }

/* ===================================================================
   Toast (SweetAlert2 ใช้ตรงนี้เป็น config)
   =================================================================== */
.swal2-popup.swal2-toast {
    font-family: var(--font-family) !important;
}

/* ===================================================================
   License Warning Banner
   =================================================================== */
.license-warning {
    background: linear-gradient(135deg, #F57F17, #FFB300);
    color: #fff;
    padding: 12px 24px;
    text-align: center;
    font-weight: 500;
    font-size: var(--font-sm);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.license-warning a {
    color: #fff;
    text-decoration: underline;
    font-weight: 700;
}

/* ===================================================================
   Keyframe Animations
   =================================================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes countUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===================================================================
   Utility Classes
   =================================================================== */
.d-flex { display: flex; }
.d-grid { display: grid; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.p-16 { padding: 16px; }
.p-24 { padding: 24px; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===================================================================
   Responsive
   =================================================================== */
@media (max-width: 768px) {
    :root {
        --font-base: 0.875rem;
        --font-2xl: 1.5rem;
    }

    .filter-bar {
        flex-direction: column;
    }

    .search-input {
        width: 100%;
    }
}
