/* Basic Setup */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Sarabun', sans-serif;
    margin: 0;
    padding: 0;
    background: #f4f6f8;
    color: #333;
}

a {
    text-decoration: none;
    color: #007bff;
}

h1,
h2,
h3 {
    margin-top: 0;
}

/* Layout */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

.container-xs {
    max-width: 400px;
    margin: 0 auto;
    padding: 20px;
}

.container-sm {
    max-width: 640px;
    margin: 0 auto;
    padding: 20px;
}

.header {
    background: #fff;
    padding: 15px 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

@media (max-width: 600px) {
    .header {
        padding: 10px 15px;
        /* Reduce padding on mobile */
        flex-wrap: nowrap;
        /* Prevent wrapping (Keep single row) */
        gap: 10px;
        /* Space between logo and button */
    }

    .logo {
        font-size: 1rem;
        /* Smaller logo font */
        white-space: nowrap;
        /* Prevent text wrap */
        overflow: hidden;
        text-overflow: ellipsis;
        /* Truncate if too long */
        flex: 1;
        /* Allow logo to shrink if needed but button stays */
        min-width: 0;
        /* Allow flex item to shrink below content size */
    }

    .nav {
        flex-shrink: 0;
        /* Button should not shrink */
    }

    .nav a.btn {
        padding: 5px 10px;
        /* Smaller button padding */
        font-size: 0.9rem;
    }
}

.logo {
    font-size: 1.2rem;
    font-weight: bold;
    color: #2c3e50;
}

.nav {
    display: flex;
    align-items: center;
    gap: 20px;
}

.menu-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* User Label Styling */
.user-label {
    color: #555;
    font-weight: 500;
}

.nav a {
    /* Reset old margins if any */
    margin-left: 0;
    color: #555;
    text-decoration: none;
}

.nav a.btn {
    background: #007bff;
    color: white;
    padding: 8px 15px;
    border-radius: 4px;
    white-space: nowrap;
}

.nav a.btn-danger {
    background: #dc3545;
}

/* Cards & Forms */
.card {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

input[type="text"],
input[type="date"],
input[type="number"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

input:focus {
    border-color: #007bff;
    outline: none;
}

/* Input Groups */
.input-group {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.input-group-text {
    background: #e9ecef;
    border: 1px solid #ddd;
    border-right: none;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    font-weight: bold;
    color: #495057;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

.input-group input {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    flex: 1;
}


/* Generic Button Class */
.btn {
    display: inline-block;
    background: #28a745;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    text-align: center;
}

.btn:hover {
    background: #218838;
}

.btn:disabled,
.btn.disabled {
    background: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    opacity: 0.65;
}


/* Pagination Buttons */
.page-btn {
    background: #fff;
    border: 1px solid #ddd;
    color: #333;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.page-btn:hover {
    background: #f0f0f0;
    border-color: #ccc;
}

.page-btn:disabled {
    background: #e9ecef;
    color: #aaa;
    cursor: not-allowed;
    border-color: #eee;
}

/* Tree List */
.tree-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.tree-item:last-child {
    border-bottom: none;
}

.tree-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    margin-right: 15px;
    background: #eee;
}

.tree-info {
    flex: 1;
}

.tree-id {
    font-weight: bold;
    font-size: 1.1rem;
}

.tree-meta {
    color: #666;
    font-size: 0.9rem;
}

.status-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.85rem;
    background: #e9ecef;
    color: #495057;
    margin-top: 5px;
}

.status-badge.highlight {
    background: #d4edda;
    color: #155724;
}

/* Timeline */
.timeline {
    border-left: 2px solid #ddd;
    padding-left: 20px;
    margin-left: 10px;
}

.timeline-item {
    position: relative;
    margin-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -26px;
    top: 0;
    width: 10px;
    height: 10px;
    background: #007bff;
    border-radius: 50%;
}

.timeline-date {
    font-size: 0.85rem;
    color: #888;
}

/* Login Page */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: #e9ecef;
}

.login-box {
    width: 100%;
    max-width: 400px;
}

/* Print Styles (Label) */
@media print {
    body * {
        visibility: hidden;
    }

    .print-area,
    .print-area * {
        visibility: visible;
    }

    .print-area {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
    }

    .no-print {
        display: none !important;
    }
}

/* Label Specific */
.label-box {
    width: 380px;
    /* Approx 10cm */
    height: 560px;
    /* Approx 15cm */
    border: 2px solid #000;
    padding: 15px;
    text-align: center;
    font-family: 'Sarabun', sans-serif;
    margin: 0 auto;
    background: white;
    position: relative;
    box-sizing: border-box;
    page-break-inside: avoid;
    display: flex;
    flex-direction: column;
}

.qr-frame {
    border: 2px solid #000;
    width: 250px;
    height: 250px;
    margin: 5px auto;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.label-id {
    font-size: 32px;
    font-weight: bold;
    margin: 10px 0;
    flex-shrink: 0;
}

.label-field {
    text-align: left;
    margin: 8px 0;
    font-size: 18px;
    border-bottom: 2px solid #000;
    padding-bottom: 2px;
    display: flex;
    justify-content: space-between;
    flex-shrink: 0;
}

.label-footer {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-weight: bold;
    flex-shrink: 0;
}

/* Actions & Forms */
.action-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: flex-end;
}

.action-buttons .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    font-size: 1rem;
    text-decoration: none;
    border-radius: 4px;
    color: white;
    transition: background 0.2s;
}

.btn-primary {
    background: #007bff;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-info {
    background: #17a2b8;
}

.btn-info:hover {
    background: #138496;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    align-items: end;
    /* Align inputs/buttons to bottom */
}

.filter-group {
    display: flex;
    flex-direction: column;
}

/* Responsive UI */
/* Responsive Utilities */
.flex-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.col-fixed {
    flex: 0 0 200px;
}

.col-fixed-100 {
    flex: 0 0 100px;
}

.col-grow {
    flex: 1;
    min-width: 0;
    /* Fix flex overflow issues */
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.w-100 {
    width: 100%;
}

.text-center {
    text-align: center;
}

.mt-2 {
    margin-top: 10px;
}

.mb-2 {
    margin-bottom: 10px;
}


.items-start {
    align-items: flex-start;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .card {
        padding: 15px;
    }

    .items-start {
        align-items: stretch;
    }

    .col-grow {
        width: 100%;
    }

    /* .header rule removed to prevent conflict with earlier single-row layout */

    .nav {
        /* flex-direction: column; Removed to keep row layout */
        gap: 10px;
        /* width: 100%; Removed */
    }

    .nav a {
        /* display: block; Removed */
        /* width: 100%; Removed */
        /* text-align: center; Removed */
    }

    .menu-group {
        flex-direction: column;
        gap: 5px;
        width: 100%;
    }

    /* Stack flex containers on mobile */
    .flex-row {
        flex-direction: column;
        gap: 15px;
    }

    .col-fixed,
    .col-fixed-100 {
        flex: auto;
        width: 100%;
    }

    .col-fixed img {
        margin: 0 auto;
        display: block;
    }

    .grid-2,
    .filter-grid,
    .form-row {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
    }

    /* Tree List Item Responsive */
    .tree-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .tree-thumb {
        margin-bottom: 10px;
        width: 80px;
        height: 80px;
    }

    .tree-info {
        width: 100%;
        margin-bottom: 10px;
    }
}

/* Hamburger Menu */
.hamburger-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #333;
    padding: 10px;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s;
}

.menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

.menu-drawer {
    position: fixed;
    top: 0;
    right: -280px;
    /* Hidden by default */
    width: 280px;
    height: 100%;
    background: #fff;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
    transition: right 0.3s ease;
    z-index: 1002;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.menu-drawer.active {
    right: 0;
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.menu-title {
    font-weight: bold;
    font-size: 1.1rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #888;
}

.menu-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.menu-link {
    display: flex;
    align-items: center;
    padding: 10px;
    text-decoration: none;
    color: #333;
    border-radius: 4px;
    transition: background 0.2s;
    font-size: 1rem;
}

.menu-link:hover {
    background: #f4f6f8;
}

.menu-link i {
    width: 25px;
    margin-right: 10px;
    text-align: center;
}

.menu-link.danger {
    color: #dc3545;
}

.menu-link.danger:hover {
    background: #fff5f5;
}

.user-info {
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid #eee;
    color: #666;
    font-size: 0.9rem;
}