/* Modern Mobile-First UI Styles */
:root {
    --primary-color: #6366f1;
    --primary-light: #e0e7ff;
    --primary-dark: #4338ca;
    --secondary-color: #10b981;
    --secondary-light: #d1fae5;
    --accent-color: #f59e0b;
    --accent-light: #fef3c7;
    --light-color: #f8fafc;
    --dark-color: #1e293b;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --danger-light: #fee2e2;
    --success-color: #10b981;
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-success: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --border-radius: 16px;
    --border-radius-lg: 24px;
}

* {
    font-family: "Itim", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
    color: var(--dark-color);
    overflow-x: hidden;
    position: relative;
}

/* Background Pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle at 20% 50%, rgba(99, 102, 241, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(16, 185, 129, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* Navbar */
.navbar-custom {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    border-bottom: 1px solid rgba(99, 102, 241, 0.1);
    padding: 1rem 0;
}

/* Navbar Toggler (ปุ่ม Menu มือถือ) */
.navbar-toggler {
    border: 2px solid var(--primary-color);
    border-radius: 10px;
    padding: 0.5rem 0.75rem;
    transition: all 0.3s ease;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

.navbar-toggler:hover {
    background: var(--primary-light);
}

.navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%236366f1' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2.5' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
    width: 1.5rem;
    height: 1.5rem;
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.25rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.navbar-brand img {
    filter: drop-shadow(0 2px 4px rgba(99, 102, 241, 0.3));
}

.nav-link {
    color: var(--dark-color) !important;
    font-weight: 500;
    font-size: 0.95rem;
    padding: 0.5rem 1rem !important;
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.nav-link::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 2px;
    background: var(--gradient-primary);
    transform: translateX(-50%);
    transition: width 0.3s ease;
}

.nav-link:hover::before,
.nav-link.active::before {
    width: 60%;
}

.nav-link:hover,
.nav-link.active {
    background: var(--primary-light);
    color: var(--primary-color) !important;
    transform: translateY(-2px);
}

/* Cards */
.card {
    border-radius: var(--border-radius-lg);
    border: none;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 1.5rem;
    overflow: hidden;
    position: relative;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--gradient-primary);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.card:hover {
    transform: translateY(-8px);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12);
}

.card:hover::before {
    opacity: 1;
}

.card-header {
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0 !important;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(16, 185, 129, 0.1) 100%);
    border: none;
    padding: 1.25rem 1.5rem;
    font-weight: 600;
    font-size: 1.1rem;
}

.card-body {
    padding: 1.5rem;
}

/* Buttons */
.btn {
    border-radius: 12px;
    padding: 0.625rem 1.5rem;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
    z-index: -1;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: var(--gradient-primary);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4);
}

.btn-warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-warning:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(245, 158, 11, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.4);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    border-radius: 10px;
}

.btn-lg {
    padding: 0.875rem 2rem;
    font-size: 1.05rem;
    border-radius: 14px;
}

/* Login Container */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
}

.login-card {
    max-width: 450px;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    padding: 2rem;
    position: relative;
    overflow: hidden;
    text-align: center;
}

.login-logo {
    margin-bottom: 1.5rem;
    align-items: center;
    text-align: center;

}

.login-title {
    font-weight: 700;
    font-size: 1.75rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    text-align: center;
}

.login-subtitle {
    color: #64748b;
    margin-bottom: 2rem;
    font-size: 0.95rem;
    text-align: center;
}

.btn-google {
    background: white;
    color: #1f2937;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    padding: 0.3rem 1.5rem;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.btn-google:hover {
    background: #f9fafb;
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.feature-list {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, rgba(16, 185, 129, 0.05) 100%);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-top: 2rem;
}

.feature-list h6 {
    font-weight: 700;
    color: var(--dark-color);
    margin-bottom: 1rem;
}

.feature-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.feature-list li {
    padding: 0.5rem 0;
    display: flex;
    align-items: center;
    color: #475569;
    transition: all 0.3s ease;
}

.feature-list li:hover {
    transform: translateX(8px);
    color: var(--primary-color);
}

.feature-list i {
    color: var(--success-color);
    margin-right: 0.75rem;
    font-size: 1rem;
}

/* Stats Cards */
.stats-card {
    background: var(--gradient-primary);
    border-radius: var(--border-radius-lg);
    padding: 2rem;
    color: white;
    box-shadow: 0 12px 32px rgba(99, 102, 241, 0.3);
    position: relative;
    overflow: hidden;
}

.stats-card::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    border-radius: 50%;
}

.stats-number {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stats-label {
    font-size: 1rem;
    opacity: 0.95;
    margin-top: 0.5rem;
}

/* Table */
.table-responsive {
    border-radius: var(--border-radius);
    overflow-x: auto;
    overflow-y: visible;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    -webkit-overflow-scrolling: touch;
}

.table {
    margin-bottom: 0;
    min-width: 800px;
    white-space: nowrap;
}

.table thead th {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(16, 185, 129, 0.1) 100%);
    color: var(--dark-color);
    font-weight: 700;
    font-size: 0.9rem;
    padding: 1rem;
    border: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.table tbody tr {
    transition: all 0.3s ease;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.table tbody tr:hover {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.03) 0%, rgba(16, 185, 129, 0.03) 100%);
}

.table td {
    padding: 1rem;
    vertical-align: middle;
}

/* Mobile Table Adjustments */
@media (max-width: 768px) {
    .table {
        min-width: 100%;
        font-size: 0.85rem;
    }

    .table thead th {
        padding: 0.75rem 0.5rem;
        font-size: 0.8rem;
        white-space: normal;
    }

    .table td {
        padding: 0.75rem 0.5rem;
    }

    /* ทำให้คอลัมน์บางคอลัมน์แคบลงในมือถือ */
    .table td:first-child,
    .table th:first-child {
        min-width: 40px;
        width: 40px;
    }

    .table td:nth-child(3),
    .table th:nth-child(3) {
        min-width: 80px;
    }

    .table td:nth-child(4),
    .table th:nth-child(4) {
        min-width: 80px;
    }

    .table td:nth-child(5),
    .table th:nth-child(5) {
        min-width: 100px;
    }

    .table td:last-child,
    .table th:last-child {
        min-width: 100px;
        position: sticky;
        right: 0;
        background: white;
        box-shadow: -2px 0 4px rgba(0, 0, 0, 0.05);
    }

    /* Hover effect สำหรับ sticky column */
    .table tbody tr:hover td:last-child {
        background: linear-gradient(135deg, rgba(99, 102, 241, 0.03) 0%, rgba(16, 185, 129, 0.03) 100%);
    }
}

@media (max-width: 576px) {
    .table {
        font-size: 0.8rem;
    }

    .table thead th {
        padding: 0.5rem 0.25rem;
        font-size: 0.75rem;
    }

    .table td {
        padding: 0.5rem 0.25rem;
    }

    /* ปรับ button ให้เล็กลง */
    .table .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    .table .btn-sm i {
        font-size: 0.75rem;
    }
}

/* Status Badges */
.status-active {
    color: var(--success-color);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    padding: 0.375rem 0.875rem;
    background: var(--secondary-light);
    border-radius: 20px;
    font-size: 0.875rem;
}

.status-inactive {
    color: var(--danger-color);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    padding: 0.375rem 0.875rem;
    background: var(--danger-light);
    border-radius: 20px;
    font-size: 0.875rem;
}

.status-active i,
.status-inactive i {
    font-size: 0.5rem;
    margin-right: 0.5rem;
}

.unit-badge {
    background: var(--primary-light);
    color: var(--primary-color);
    padding: 0.25rem 0.75rem;
    border-radius: 16px;
    font-size: 0.85rem;
    font-weight: 600;
}

/* Forms */
.form-control,
.form-select {
    border-radius: 12px;
    border: 2px solid #e5e7eb;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    background: white;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
    background: white;
}

.form-label {
    font-weight: 600;
    color: var(--dark-color);
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

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

/* Input Group */
.input-group-text {
    background: var(--primary-light);
    border: 2px solid #e5e7eb;
    border-right: none;
    border-radius: 12px 0 0 12px;
    color: var(--primary-color);
    font-weight: 600;
}

.input-group .form-control {
    border-left: none;
    border-radius: 0 12px 12px 0;
}

/* User Profile */
.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-profile img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--dark-color);
}

.user-email {
    font-size: 0.8rem;
    color: #64748b;
}

/* Logs */
.log-entry {
    background: white;
    border-left: 4px solid var(--primary-color);
    border-radius: 0 12px 12px 0;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
}

.log-entry:hover {
    transform: translateX(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.log-action {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 0.95rem;
}

.log-time {
    font-size: 0.85rem;
    color: #64748b;
}

/* Pagination */
.pagination {
    gap: 0.5rem;
}

.page-item {
    margin: 0;
}

.page-link {
    border-radius: 10px;
    border: 2px solid transparent;
    color: var(--dark-color);
    font-weight: 600;
    padding: 0.5rem 0.875rem;
    transition: all 0.3s ease;
}

.page-link:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.page-item.active .page-link {
    background: var(--gradient-primary);
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.page-item.disabled .page-link {
    opacity: 0.5;
}

/* Footer */
.footer {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: white;
    padding: 2rem 0;
    margin-top: 3rem;
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.1);
}

/* Modal */
.modal-content {
    border-radius: var(--border-radius-lg);
    border: none;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
}

.modal-header {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(16, 185, 129, 0.1) 100%);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    border-bottom: none;
    padding: 1.5rem;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    border-top: none;
    padding: 1.5rem;
}

/* PDF Container Styles */
.pdf-table-container {
    display: none;
    font-family: "Sarabun", "Itim", sans-serif !important;
    background: white;
    padding: 20px;
    max-width: 100%;
    box-sizing: border-box;
}

.pdf-header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--primary-color);
}

.pdf-header h2 {
    color: var(--primary-color);
    font-size: 28px;
    margin-bottom: 10px;
    font-family: "Sarabun", sans-serif !important;
    font-weight: 700;
}

.pdf-header h3 {
    color: #666;
    font-size: 20px;
    margin-bottom: 20px;
    font-family: "Sarabun", sans-serif !important;
}

.pdf-header .date-info {
    color: #333;
    font-size: 16px;
    margin-bottom: 8px;
    font-weight: 500;
}

.pdf-table {
    width: 100%;
    border-collapse: collapse;
    font-family: "Sarabun", sans-serif !important;
    font-size: 14px;
}

.pdf-table th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    padding: 12px 10px;
    border: 1px solid #ddd;
    text-align: center;
    font-size: 16px;
}

.pdf-table td {
    padding: 10px 8px;
    border: 1px solid #ddd;
    text-align: left;
    font-size: 14px;
}

.pdf-table tr:nth-child(even) {
    background-color: #f9f9f9;
}

.pdf-footer {
    margin-top: 30px;
    padding-top: 15px;
    border-top: 1px solid #ddd;
    font-size: 13px;
    color: #666;
    text-align: right;
    font-family: "Sarabun", sans-serif !important;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .stats-number {
        font-size: 2rem;
    }

    .stats-card {
        padding: 1.5rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 1rem;
        font-size: 1rem;
    }

    .table thead th,
    .table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    .btn-lg {
        padding: 0.75rem 1.5rem;
        font-size: 0.95rem;
    }

    .login-card {
        padding: 1.5rem;
    }

    .login-title {
        font-size: 1.5rem;
    }

    .navbar-brand {
        font-size: 1.1rem;
    }

    .nav-link {
        padding: 0.5rem !important;
        font-size: 0.9rem;
    }

    .user-profile {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .form-control,
    .form-select {
        font-size: 16px;
        /* Prevents zoom on iOS */
    }
}

@media (max-width: 576px) {
    .stats-card h2 {
        font-size: 1.25rem;
    }

    .stats-number {
        font-size: 1.75rem;
    }

    .card {
        border-radius: 16px;
    }

    .table {
        font-size: 0.8rem;
    }

    .btn-group .btn {
        font-size: 0.75rem;
        padding: 0.375rem 0.75rem;
    }

    .modal-body {
        padding: 1rem;
    }
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Loading States */
.spinner-border {
    color: var(--primary-color);
}

/* Alerts */
.alert {
    border-radius: var(--border-radius);
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.alert-info {
    background: linear-gradient(135deg, rgba(66, 133, 244, 0.1) 0%, rgba(66, 153, 244, 0.1) 100%);
    color: #0369a1;
}

.alert-success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(5, 150, 105, 0.1) 100%);
    color: #065f46;
}

.alert-warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1) 0%, rgba(217, 119, 6, 0.1) 100%);
    color: #92400e;
}

.alert-danger {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(220, 38, 38, 0.1) 100%);
    color: #991b1b;
}

/* Print Styles */
@media print {
    body * {
        visibility: hidden;
    }

    #pdf-container,
    #pdf-container * {
        visibility: visible !important;
    }

    #pdf-container {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        padding: 20px !important;
        background-color: white !important;
    }

    .no-print {
        display: none !important;
    }
}

/* Accessibility */
.btn:focus,
.form-control:focus,
.form-select:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, #059669 100%);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card,
.stats-card,
.log-entry {
    animation: fadeIn 0.6s ease-in-out;
}

/* Touch Feedback */
@media (hover: none) {

    .btn:active,
    .card:active,
    .nav-link:active {
        transform: scale(0.98);
    }
}