/**
 * =========================================================================
 * 🎨 Main Stylesheet — Variables, Layout, Controls, Table & Badges
 * =========================================================================
 */

:root {
    --primary: #2563eb;
    --success: #16a34a;
    --bg-body: #f8fafc;
    --status-complete: #16a34a;
    --status-verify: #9333ea;
    --status-schedule: #b45309;
    --status-start: #0284c7;
    --status-report: #1e40af;
    --status-delete: #64748b;
    --status-pending: #db2777;
    --status-urgency: #dc2626;
    --status-import: #ea580c;
}

* {
    box-sizing: border-box;
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

body {
    background-color: var(--bg-body);
    margin: 0;
    padding: 0 8px 8px 8px;
    height: 100%;
    width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 8px;
}

/* =========================================================================
 * 🧭 Header & Control Bar
 * ========================================================================= */
.header-panel {
    background: white;
    margin: 0 -8px 8px -8px;
    border-radius: 0 0 8px 8px;
    padding: 10px 15px;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

/* 📱 ปรับระยะเว้นด้านบนของแถบเมนูใน Telegram Desktop UI Mode เท่านั้น */
/* เปิดผ่าน Local Network = ไม่มี in-telegram-webapp → ไม่เว้นระยะ */
body.in-telegram-webapp:not(.is-mobile-ui) .header-panel,
html.in-telegram-webapp:not(.is-mobile-ui) .header-panel {
    padding-top: 70px;
    padding-left: 15px;
    padding-right: 15px;
}

.mobile-main-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 8px;
    flex-wrap: nowrap;
}

.mobile-bar-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

.mobile-bar-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.mobile-bar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

/* =========================================================================
 * 🚀 Action Menu Bars (Search & Settings Action Bars)
 * ========================================================================= */
.action-bars-wrapper {
    width: calc(100% + 16px);
    margin: -8px -8px 8px -8px;
    position: relative;
    z-index: 10;
}

.action-bar-panel {
    background: #ffffff;
    border-radius: 0 0 10px 10px;
    border: 1px solid #cbd5e1;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    animation: slideDownFade 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDownFade {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

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

.action-bar-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #475569;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.btn-user-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    object-fit: cover;
    display: inline-block;
    vertical-align: middle;
    border: 1px solid #cbd5e1;
    margin: -2px 0;
}

.user-profile-bar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
}

#btnUserProfileMobileIcon {
    font-size: 1.15rem;
    color: #0284c7;
}

.admin-bar-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
}

.admin-bar-btn i {
    color: #ea580c;
    font-size: 1rem;
}

.header-admin-badge {
    position: absolute;
    top: -5px;
    right: -6px;
    background: #ef4444;
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 10px;
    min-width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border: 1.5px solid #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    animation: adminBadgePulse 2s infinite ease-in-out;
}

@keyframes adminBadgePulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

.filter-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #000000;
    white-space: nowrap;
}

input[type="text"],
input[type="number"],
select {
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    outline: none;
    font-size: 0.85rem;
    height: 28px;
    background: white;
    font-weight: 600;
    color: #000;
}

input[type="date"].custom-date-display,
input[type="datetime-local"].custom-datetime-display {
    position: relative;
    color: transparent !important;
    height: 30px;
    padding: 4px 28px 4px 8px !important;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    outline: none;
    font-size: 0.80rem; /* ลดขนาดฟอนต์ลง 1px (~13px) */
    font-weight: 600;
    background: #ffffff;
    box-sizing: border-box;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

input[type="date"].custom-date-display:hover,
input[type="datetime-local"].custom-datetime-display:hover {
    border-color: #94a3b8;
    background: #f8fafc;
}

input[type="date"].custom-date-display:focus,
input[type="datetime-local"].custom-datetime-display:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
    background: #ffffff;
}

input[type="date"].custom-date-display {
    min-width: 120px;
    max-width: 145px;
}

input[type="datetime-local"].custom-datetime-display {
    flex-grow: 1;
    height: 30px;
    font-size: 0.80rem;
    box-sizing: border-box;
}

input[type="date"].custom-date-display::-webkit-datetime-edit,
input[type="datetime-local"].custom-datetime-display::-webkit-datetime-edit {
    color: transparent !important;
}

input[type="date"].custom-date-display::before,
input[type="datetime-local"].custom-datetime-display::before {
    content: attr(data-display);
    position: absolute;
    left: 8px;
    right: 26px;
    color: #1e293b;
    font-weight: 600;
    font-size: 0.80rem; /* ลดขนาดฟอนต์ลง 1px */
    display: flex;
    align-items: center;
    top: 0;
    bottom: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* =========================================================================
 * 🔘 Buttons
 * ========================================================================= */
.btn {
    border: none;
    padding: 0 12px;
    border-radius: 4px;
    height: 28px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.btn-secondary {
    background: #e2e8f0;
    color: #1e293b;
    border: 1px solid #cbd5e1;
}

.btn-secondary:hover:not(:disabled) {
    background: #cbd5e1;
}

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

/* =========================================================================
 * 📅 Date Picker Wrapper
 * ========================================================================= */
.date-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.date-icon {
    position: absolute;
    right: 10px;
    color: #64748b;
    pointer-events: none;
    font-size: 0.92rem;
    z-index: 1;
    transition: color 0.2s ease;
}

.date-wrapper:hover .date-icon {
    color: var(--primary);
}

input[type="date"].custom-date-display::-webkit-calendar-picker-indicator {
    opacity: 0;
    width: 28px;
    height: 100%;
    cursor: pointer;
    position: absolute;
    right: 2px;
    top: 0;
    z-index: 2;
}

/* =========================================================================
 * 📊 Table Styles (Desktop View)
 * ========================================================================= */
.table-container-wrapper {
    flex-grow: 1;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    position: relative;
    height: 100%;
}

.table-container {
    background: white;
    overflow: auto;
    scroll-behavior: smooth;
    transition: all 0.3s ease;
    height: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.85rem;
    transition: font-size 0.2s ease;
}

th {
    padding: 6px 8px;
    color: #000000;
    border-bottom: 2px solid #cbd5e1;
    white-space: nowrap;
    font-weight: bold;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #e2e8f0;
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}

td {
    padding: 4px 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.15);
    color: #000000;
    font-weight: 400;
    vertical-align: middle;
    white-space: nowrap;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
}

td div {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

tbody tr {
    cursor: pointer;
}

/* 🌟 สีไฮไลต์สำหรับแถวที่ถูกกด (คลิกครั้งแรก) */
tr.row-selected td {
    box-shadow: inset 0 0 0 9999px rgba(0, 0, 0, 0.12);
    border-top: 1px solid rgba(255, 255, 255, 0.5) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.5) !important;
}

tr.row-selected td:first-child {
    border-left: 3px solid var(--primary) !important;
}

tr.row-selected td:last-child {
    border-right: 3px solid var(--primary) !important;
}

/* =========================================================================
 * 🏷️ Status Badges & Row Backgrounds
 * ========================================================================= */
tr.row-bg-complete,
.compact-card.row-bg-complete {
    background-color: rgba(22, 163, 74, 0.35);
}

tr.row-bg-verify,
.compact-card.row-bg-verify {
    background-color: rgba(147, 51, 234, 0.35);
}

tr.row-bg-schedule,
.compact-card.row-bg-schedule {
    background-color: rgba(250, 204, 21, 0.35);
}

tr.row-bg-start,
.compact-card.row-bg-start {
    background-color: rgba(2, 132, 199, 0.35);
}

tr.row-bg-report,
.compact-card.row-bg-report {
    background-color: rgba(30, 64, 175, 0.35);
}

tr.row-bg-pending,
.compact-card.row-bg-pending {
    background-color: rgba(219, 39, 119, 0.35);
}

tr.row-bg-urgency,
.compact-card.row-bg-urgency {
    background-color: rgba(220, 38, 38, 0.35);
}

tr.row-bg-import,
.compact-card.row-bg-import {
    background-color: rgba(234, 88, 12, 0.35);
}

tr.row-bg-delete,
.compact-card.row-bg-delete {
    background-color: rgba(100, 116, 139, 0.35);
}

tr.row-bg-default,
.compact-card.row-bg-default {
    background-color: #ffffff;
}

tr:hover,
.compact-card:hover {
    filter: brightness(0.95);
}

.status-badge,
.pacs-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    justify-content: center;
    min-width: 80px;
    width: fit-content;
    color: #000;
    white-space: nowrap;
}

.st-default {
    background: #f8fafc;
    color: #000000;
}

/* =========================================================================
 * 🖱️ Context Menu
 * ========================================================================= */
.context-menu {
    display: none;
    position: absolute;
    z-index: 2000;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    width: 180px;
    padding: 4px 0;
}

.context-menu-item {
    padding: 8px 12px;
    font-size: 0.85rem;
    color: #1e293b;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.context-menu-item:hover:not(.disabled) {
    background: #f1f5f9;
    color: var(--primary);
}

.context-menu-item.disabled {
    color: #94a3b8;
    cursor: not-allowed;
    opacity: 0.6;
    pointer-events: none;
}

.context-menu-divider {
    height: 1px;
    background: #e2e8f0;
    margin: 4px 0;
}

.context-menu-item.has-submenu {
    position: relative;
    overflow: visible;
}

.submenu {
    display: none;
    position: absolute;
    top: -1px;
    left: 100%;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    min-width: 100px;
    padding: 4px 0;
    z-index: 2001;
}

.context-menu-item.has-submenu:hover .submenu {
    display: block;
}

.submenu-left-side .submenu {
    left: auto;
    right: 100%;
}