@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
    /* Color Palette - Modern Government/Enterprise Theme */
    --primary-color: #1e3a8a;
    /* Deep Royal Blue */
    --primary-light: #3b82f6;
    /* Bright Blue */
    --primary-dark: #172554;
    /* Darker Navy */
    --secondary-color: #64748b;
    /* Slate Gray */
    --accent-color: #0ea5e9;
    /* Sky Blue */

    --success: #10b981;
    /* Emerald */
    --warning: #f59e0b;
    /* Amber */
    --danger: #ef4444;
    /* Red */
    --info: #3b82f6;
    /* Blue */

    --bg-body: #f1f5f9;
    /* Slate 100 */
    --bg-card: #ffffff;
    --bg-sidebar: #0f172a;
    /* Slate 900 */

    --text-main: #334155;
    /* Slate 700 */
    --text-muted: #64748b;
    /* Slate 500 */
    --text-light: #f8fafc;
    /* Slate 50 */

    --border-color: #e2e8f0;
    /* Slate 200 */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Sarabun', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    line-height: 1.6;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    padding: 24px;
    flex-shrink: 0;
    transition: width 0.3s ease;
}

.sidebar h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 40px;
    color: var(--accent-color);
    text-align: center;
    letter-spacing: 0.5px;
}

.nav-links {
    list-style: none;
    flex-grow: 1;
}

.nav-links li {
    margin-bottom: 8px;
}

.nav-links a {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.nav-links a:hover,
.nav-links a.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--accent-color);
}

.nav-links a.active {
    background-color: var(--primary-color);
    color: var(--bg-card);
    box-shadow: var(--shadow-sm);
}

/* Main Content */
.main-content {
    flex-grow: 1;
    padding: 32px;
    overflow-y: auto;
    height: 100vh;
}

header {
    margin-bottom: 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-dark);
}

/* Dashboard Cards */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

.stat-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

/* Color accents for cards - applied via style attribute or specific classes in HTML */
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: currentColor;
    /* Inherits color from card style */
    opacity: 0.8;
}

.stat-content h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-content .number {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.1;
}

.stat-content .unit {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 4px;
}

.stat-icon {
    font-size: 3rem;
    opacity: 0.15;
    transform: scale(1.2) rotate(-10deg);
    position: absolute;
    right: 20px;
    bottom: 10px;
    transition: all 0.3s ease;
}

.stat-card:hover .stat-icon {
    transform: scale(1.4) rotate(0deg);
    opacity: 0.25;
}

/* Tables */
.table-container {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
    padding: 0;
}

.table-header {
    padding: 20px 24px;
    background: white;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-header h2 {
    margin: 0;
    border: none;
    padding: 0;
    font-size: 1.25rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    /* Changed to collapse for cleaner lines */
    border-spacing: 0;
    background: white;
    margin-top: 0;
    /* Remove top margin as it's inside container */
    border: none;
    box-shadow: none;
}

thead th {
    background-color: #f8fafc;
    color: #475569;
    font-weight: 600;
    padding: 16px 24px;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid #e2e8f0;
}

tbody tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: #f1f5f9;
}

td {
    padding: 16px 24px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    font-size: 0.95rem;
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

/* Badge Styles */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    display: inline-block;
}

.badge-blue {
    background: #e0f2fe;
    color: #0284c7;
}

.badge-green {
    background: #dcfce7;
    color: #16a34a;
}

.badge-yellow {
    background: #fef3c7;
    color: #d97706;
}

.badge-red {
    background: #fee2e2;
    color: #dc2626;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 24px;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    gap: 8px;
}

.btn:active {
    transform: translateY(1px);
    box-shadow: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-success:hover {
    background-color: #059669;
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-warning {
    background-color: var(--warning);
    color: white;
}

.btn-warning:hover {
    background-color: #d97706;
}

.btn-info {
    background-color: var(--info);
    color: white;
}

.btn-info:hover {
    background-color: #2563eb;
}

.btn-outline {
    background-color: white;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: #f8fafc;
    border-color: var(--text-muted);
}

/* Forms */
.form-container {
    background: var(--bg-card);
    padding: 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 1200px;
    margin: 0 auto;
}

.form-section {
    margin-bottom: 40px;
}

.form-section-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.95rem;
}

input[type="text"],
input[type="date"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-main);
    background-color: #f8fafc;
    transition: all 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    background-color: white;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 48px 0;
}

h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--warning);
    display: inline-block;
}

/* Action Bar */
.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.search-box {
    display: flex;
    gap: 12px;
    flex-grow: 1;
    max-width: 500px;
}

/* Utils */
.text-center {
    text-align: center;
}

.mt-4 {
    margin-top: 16px;
}

.mb-4 {
    margin-bottom: 16px;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    background: var(--bg-sidebar);
    border: none;
    cursor: pointer;
    padding: 14px;
    z-index: 1001;
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.mobile-menu-toggle:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transform: translateY(-2px);
}

.mobile-menu-toggle:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.mobile-menu-toggle:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Animated Hamburger Icon */
.hamburger-icon {
    width: 24px;
    height: 20px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.hamburger-icon span {
    display: block;
    height: 3px;
    width: 100%;
    background: var(--text-light);
    border-radius: 2px;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    transform-origin: center;
}

/* Hamburger to X transformation */
.mobile-menu-toggle.active .hamburger-icon span:nth-child(1) {
    transform: translateY(8.5px) rotate(45deg);
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(3) {
    transform: translateY(-8.5px) rotate(-45deg);
}

/* Accessibility - Reduce motion */
@media (prefers-reduced-motion: reduce) {

    .mobile-menu-toggle,
    .hamburger-icon span {
        transition: none;
    }
}


/* Responsive Breakpoints */

/* Large Tablets and Small Desktops (1024px and below) */
@media (max-width: 1024px) {
    .main-content {
        padding: 24px;
    }

    h1 {
        font-size: 1.75rem;
    }

    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
        gap: 16px;
    }

    .stat-content .number {
        font-size: 2.2rem;
    }

    .form-container {
        padding: 32px;
    }
}

/* Tablets (768px and below) */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    /* Mobile Sidebar */
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        z-index: 999;
        transition: left 0.3s ease;
        padding: 24px;
        flex-direction: column;
        overflow-y: auto;
    }

    .sidebar.active {
        left: 0;
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.3);
    }

    .sidebar h2 {
        font-size: 1.5rem;
        margin-bottom: 32px;
        text-align: left;
    }

    .sidebar .nav-links {
        flex-direction: column;
    }

    .sidebar .nav-links li {
        margin-bottom: 8px;
    }

    .sidebar .nav-links a {
        justify-content: flex-start;
        padding: 12px 16px;
    }

    /* Mobile Header */
    .mobile-menu-toggle {
        display: block;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 1001;
    }


    /* Overlay for mobile menu */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .main-content {
        padding: 20px 16px;
        height: auto;
        margin-top: 60px;
        /* Space for mobile menu button */
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
        margin-bottom: 24px;
    }

    h1 {
        font-size: 1.5rem;
    }

    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-content h3 {
        font-size: 0.75rem;
    }

    .stat-content .number {
        font-size: 1.8rem;
    }

    .stat-icon {
        font-size: 2rem;
        right: 10px;
        bottom: 10px;
    }

    .table-container {
        overflow-x: auto;
    }

    .table-header {
        padding: 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .table-header h2 {
        font-size: 1.1rem;
    }

    table {
        min-width: 600px;
        /* Ensure table scrolls on small screens */
    }

    td,
    th {
        padding: 12px 16px;
        font-size: 0.9rem;
    }

    .form-container {
        padding: 24px 16px;
    }

    .form-section-content {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .action-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .search-box {
        max-width: 100%;
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Mobile Phones (600px and below) */
@media (max-width: 600px) {
    .main-content {
        padding: 16px 12px;
        margin-top: 56px;
    }

    h1 {
        font-size: 1.3rem;
    }

    h2 {
        font-size: 1.1rem;
        margin-bottom: 16px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-content h3 {
        font-size: 0.7rem;
        margin-bottom: 4px;
    }

    .stat-content .number {
        font-size: 1.6rem;
    }

    .stat-content .unit {
        font-size: 0.75rem;
    }

    .stat-icon {
        font-size: 1.8rem;
        right: 8px;
        bottom: 8px;
    }

    .table-header {
        padding: 12px;
    }

    .table-header h2 {
        font-size: 1rem;
    }

    td,
    th {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    thead th {
        font-size: 0.75rem;
        padding: 12px;
    }

    .badge {
        font-size: 0.7rem;
        padding: 3px 8px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .btn-sm {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .form-container {
        padding: 20px 12px;
    }

    .form-group {
        margin-bottom: 16px;
    }

    label {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }

    input[type="text"],
    input[type="date"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    /* Make touch targets larger for mobile */
    .nav-links a {
        padding: 14px 16px;
        font-size: 0.95rem;
    }

    /* Improve readability on small screens */
    body {
        font-size: 14px;
        line-height: 1.5;
    }
}

/* Extra Small Phones (400px and below) */
@media (max-width: 400px) {
    .main-content {
        padding: 12px 8px;
    }

    h1 {
        font-size: 1.2rem;
    }

    .stat-content .number {
        font-size: 1.4rem;
    }

    .dashboard-grid {
        gap: 10px;
    }

    .stat-card {
        padding: 12px;
    }

    td,
    th {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    .btn {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
}

/* Utility Classes for Responsive Design */
.hide-mobile {
    display: block;
}

.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none;
    }

    .show-mobile {
        display: block;
    }
}

/* Responsive Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 1rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

@media (max-width: 768px) {
    .table-responsive {
        margin-top: 0.5rem;
    }

    /* Card-style table for very small screens */
    .table-mobile-cards {
        display: none;
    }

    @media (max-width: 600px) {
        .table-mobile-cards {
            display: block;
        }

        .table-mobile-cards table {
            display: none;
        }

        .mobile-card {
            background: white;
            border: 1px solid var(--border-color);
            border-radius: var(--radius-md);
            padding: 16px;
            margin-bottom: 12px;
            box-shadow: var(--shadow-sm);
        }

        .mobile-card-row {
            display: flex;
            justify-content: space-between;
            padding: 8px 0;
            border-bottom: 1px solid #f1f5f9;
        }

        .mobile-card-row:last-child {
            border-bottom: none;
        }

        .mobile-card-label {
            font-weight: 600;
            color: var(--text-muted);
            font-size: 0.85rem;
        }

        .mobile-card-value {
            color: var(--text-main);
            font-size: 0.9rem;
            text-align: right;
        }
    }
}

/* Print Styles */
@media print {

    .sidebar,
    .mobile-menu-toggle,
    .btn,
    .action-bar {
        display: none;
    }

    .main-content {
        padding: 0;
        margin: 0;
    }

    .stat-card,
    .table-container {
        box-shadow: none;
        border: 1px solid #ddd;
    }

    body {
        background: white;
    }
}

.btn-view-details {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 6px rgba(14, 165, 233, 0.3);
    transition: all 0.3s ease;
}

.btn-view-details:hover {
    background: linear-gradient(135deg, #38bdf8 0%, #0369a1 100%);
    box-shadow: 0 6px 12px rgba(14, 165, 233, 0.4);
    transform: translateY(-2px);
}