:root {
    --app-font-family: 'Noto Sans Thai', 'Noto Sans', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html,
body {
    font-family: var(--app-font-family);
    font-optical-sizing: auto;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: #f8fafc;
    min-width: 0;
    min-height: 100dvh;
}

/* Shared DRC responsive behavior without replacing MDTQ's design system. */
#app-main { min-width: 0; height: 100dvh; }
#sidebar { height: 100dvh; width: 18rem; flex-shrink: 0; background: oklch(0.99 0.003 165); }
#content-area { min-width: 0; overflow-x: hidden; }
.page-section { width: 100%; min-width: 0; max-width: 100%; }
img, video, canvas { max-width: 100%; }
.overflow-x-auto { max-width: 100%; overscroll-behavior-inline: contain; }
.break-anywhere, .message-bubble { min-width: 0; overflow-wrap: anywhere; }
.nav-item { min-height: 44px; }
.nav-item:focus-visible, #sidebar-toggle:focus-visible, button:focus-visible,
a:focus-visible, select:focus-visible, input:focus-visible {
    outline: 3px solid #047857;
    outline-offset: 2px;
}
.modal-box { max-height: calc(100dvh - 2rem); }
.modal-box:not(.overflow-hidden) { overflow-x: hidden; overflow-y: auto; }
.swal2-popup { max-width: calc(100vw - 1rem) !important; }
#app-main > header > div, #app-main > header > div > div { min-width: 0; }
#topbar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sync-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.refresh-btn, #notif-bell-btn { min-width: 44px; min-height: 44px; }
@media (max-width: 1023.98px) {
    #sidebar { width: min(18rem, calc(100vw - 3rem)); }
}
@media (max-width: 639.98px) {
    #app-main > header { padding-inline: 1rem; gap: 0.5rem; }
    #app-main > header > div { gap: 0.75rem; }
    .modal { padding: 0.5rem; }
    .modal-box { width: calc(100vw - 1rem); max-height: calc(100dvh - 1rem); }
}
@media (max-width: 479.98px) {
    #notif-bell-btn + .dropdown-content {
        position: fixed; top: 4.5rem; inset-inline: 0.5rem;
        width: auto; max-width: none; max-height: calc(100dvh - 5rem);
    }
}
@media (hover: none), (pointer: coarse) { .touch-action { opacity: 1 !important; } }
@media (prefers-reduced-motion: reduce) {
    .animate-bounce-short, .sync-dot.syncing::after { animation: none !important; }
    #sidebar, .refresh-btn { transition: none !important; }
}

body,
button,
input,
select,
textarea,
.btn,
.input,
.select,
.textarea,
.badge,
.table,
.modal,
.dropdown-content {
    font-family: var(--app-font-family);
}

[class*="tracking-"] {
    letter-spacing: 0 !important;
}

.font-black {
    font-weight: 800 !important;
}

/* Force 24-hour format: hide AM/PM picker in time inputs */
input[type="time"]::-webkit-calendar-picker-indicator {
    /* Keep the clock icon visible */
}
input[type="time"]::-webkit-datetime-edit-ampm-field {
    display: none;
}

.glass-panel {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

/* Navigation hierarchy: category controls above indented destinations. */
.sidebar-navigation {
    flex: 1; min-height: 0; overflow-y: auto; padding: 1rem 0.75rem;
}
.sidebar-close {
    display: grid; place-items: center; width: 44px; height: 44px;
    flex-shrink: 0; margin-left: auto; border-radius: 0.5rem;
    color: oklch(0.47 0.019 165); font-size: 1.25rem;
}
.sidebar-close:hover { background: oklch(0.96 0.008 165); }
.sidebar-group { margin-bottom: 0.5rem; }
.sidebar-group h2 { margin: 0; }
.sidebar-group-toggle {
    display: flex; align-items: center; gap: 0.625rem;
    width: 100%; min-height: 44px; padding: 0.625rem 0.5rem;
    border: 0; border-radius: 0.5rem; background: transparent;
    text-align: left; color: oklch(0.31 0.025 165);
    font-size: 0.875rem; font-weight: 750; line-height: 1.5;
    cursor: pointer; transition: background-color 160ms ease-out;
}
.sidebar-group-toggle:hover { background: oklch(0.96 0.008 165); }
.sidebar-group-icon { font-size: 1.25rem; flex-shrink: 0; }
.sidebar-chevron { margin-left: auto; font-size: 0.875rem; transition: transform 180ms ease-out; }
.sidebar-group.active .sidebar-chevron { transform: rotate(180deg); }
.sidebar-group.contains-current .sidebar-group-icon { color: oklch(0.46 0.11 165); }
.sidebar-group .group-content {
    list-style: none; margin: 0.25rem 0 0.75rem 1.125rem;
    padding: 0 0 0.75rem 0.75rem;
    border-left: 1px solid oklch(0.87 0.012 165);
}
#sidebar [hidden] { display: none !important; }
.sidebar-group .group-content li + li { margin-top: 0.125rem; }
#sidebar .nav-item {
    display: flex; align-items: center; gap: 0.625rem;
    min-height: 44px; padding: 0.625rem 0.625rem;
    border: 1px solid transparent; border-radius: 0.5rem;
    color: oklch(0.47 0.019 165); font-size: 0.8125rem; font-weight: 500; line-height: 1.5;
    text-decoration: none; transition: color 160ms ease-out, background-color 160ms ease-out;
}
#sidebar .nav-item:hover { background: oklch(0.96 0.008 165); color: oklch(0.3 0.025 165); }
#sidebar .nav-text { min-width: 0; overflow-wrap: anywhere; }
#sidebar .nav-icon { flex-shrink: 0; font-size: 1.125rem; }
#sidebar .sidebar-active {
    background: oklch(0.95 0.035 165); border-color: oklch(0.86 0.065 165);
    color: oklch(0.37 0.085 165); font-weight: 700;
}
#sidebar .sidebar-active .nav-icon { color: inherit; }
@media (prefers-reduced-motion: reduce) {
    .sidebar-chevron, .sidebar-group-toggle, #sidebar .nav-item { transition: none; }
}

/* Force SweetAlert to stays on top of ANY dialog or modal */
.swal2-container {
    z-index: 999999 !important;
}

.swal2-actions {
    margin-top: 1.5rem !important;
    z-index: 1000001 !important;
}

.swal2-confirm,
.swal2-cancel {
    align-items: center;
    justify-content: center;
    font-weight: 700 !important;
    font-family: var(--app-font-family) !important;
    min-height: 48px !important;
    padding: 0 32px !important;
    border-radius: 12px !important;
}

.swal2-popup,
.swal2-title,
.swal2-html-container {
    font-family: var(--app-font-family) !important;
}

.swal2-confirm {
    background-color: #f97316 !important;
    color: #fff !important;
}

.swal2-cancel {
    background-color: #94a3b8 !important;
    color: #fff !important;
}

/* Extra fix for dialog stack context */
dialog .swal2-container {
    position: fixed;
}

/* Tom Select over Modals Fix */
.ts-wrapper .ts-dropdown {
    z-index: 2000 !important;
}

.modal-box {
    overflow: visible !important;
}

.platform-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    font-size: 10px;
    color: white;
}

.bg-facebook { background-color: #1877F2; }
.bg-instagram { background: linear-gradient(135deg, #405DE6, #E1306C, #F77737); }
.bg-line { background-color: #06C755; }
.bg-unknown { background-color: #9CA3AF; }

@keyframes bounce-short {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.animate-bounce-short {
    animation: bounce-short 1s ease-in-out infinite;
}

@media (min-width: 1024px) {
    #sidebar .sidebar-close { display: none; }
    #sidebar.sidebar-mini { width: 88px; }
    #sidebar.sidebar-mini .nav-text,
    #sidebar.sidebar-mini .badge,
    #sidebar.sidebar-mini .sidebar-brand-copy { display: none; }
    #sidebar.sidebar-mini .sidebar-brand { justify-content: center; padding-inline: 0; }
    #sidebar.sidebar-mini .sidebar-navigation { padding-inline: 0.75rem; }
    #sidebar.sidebar-mini .sidebar-group { padding-block: 0.5rem; margin: 0; }
    #sidebar.sidebar-mini .sidebar-group + .sidebar-group { border-top: 1px solid oklch(0.9 0.008 165); }
    #sidebar.sidebar-mini .group-content { border: 0; margin: 0; padding: 0; }
    #sidebar.sidebar-mini .nav-item { padding-inline: 0; justify-content: center; }
    #sidebar.sidebar-mini .nav-icon { font-size: 1.375rem; }
    #sidebar.sidebar-mini .sidebar-footer { padding-inline: 0.75rem; }
    #sidebar.sidebar-mini .sidebar-footer button { justify-content: center; padding-inline: 0; }

    .sync-indicator {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 4px 12px;
        background: #f8fafc;
        border: 1px solid #f1f5f9;
        border-radius: 9999px;
        font-size: 10px;
        font-weight: 700;
        color: #64748b;
        transition: all 0.3s ease;
    }

    .sync-dot {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: #10b981;
        position: relative;
    }

    .sync-dot.syncing {
        background: #f59e0b;
    }

    .sync-dot.syncing::after {
        content: '';
        position: absolute;
        inset: -4px;
        border-radius: 50%;
        border: 2px solid #f59e0b;
        animation: sync-pulse 1.5s cubic-bezier(0.24, 0, 0.38, 1) infinite;
    }

    @keyframes sync-pulse {
        0% { transform: scale(1); opacity: 1; }
        100% { transform: scale(2.5); opacity: 0; }
    }

    .refresh-btn {
        cursor: pointer;
        transition: transform 0.2s ease, color 0.2s ease;
    }

    .refresh-btn:hover {
        color: #10b981;
        transform: scale(1.1);
    }

    .refresh-btn:active {
        transform: scale(0.9);
    }
}


/* DRC tag layout, preserving MDTQ typography and other modules. */
.tag-chip-list {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.375rem;
    min-width: 0;
}

.tag-chip {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    max-width: 100%;
    height: auto;
    padding: 0.1875rem 0.5rem;
    border: 0;
    border-radius: 0.5rem;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.35;
    white-space: normal;
    text-align: left;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Ad chips link out to the Facebook post they came from */
.tag-chip-link {
    cursor: pointer;
    text-decoration: none;
    transition: box-shadow .15s ease, filter .15s ease;
}

.tag-chip-link:hover {
    filter: brightness(0.96);
    box-shadow: 0 0 0 1px currentColor inset;
}

.tag-chip-link:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 1px;
}

.tag-chip-icon {
    margin-right: 3px;
    font-size: 12px;
    vertical-align: -1px;
}
