/* =========================================================================
   FB Auto-Reply — modern UI overrides on top of AdminLTE 4
   Loaded AFTER adminlte.min.css so these win specificity.
   ========================================================================= */

:root {
    --c-bg:           #f6f8fb;
    --c-surface:      #ffffff;
    --c-border:       #eaecef;
    --c-border-soft:  #f1f3f5;
    --c-text:         #0f172a;
    --c-text-dim:     #475569;
    --c-text-muted:   #94a3b8;

    --c-primary:      #4f46e5;     /* indigo-600 */
    --c-primary-50:   #eef2ff;
    --c-primary-100:  #e0e7ff;
    --c-primary-600:  #4f46e5;
    --c-primary-700:  #4338ca;

    --c-success:      #10b981;
    --c-success-soft: #d1fae5;
    --c-warning:      #f59e0b;
    --c-warning-soft: #fef3c7;
    --c-danger:       #ef4444;
    --c-danger-soft:  #fee2e2;
    --c-info:         #0ea5e9;
    --c-info-soft:    #e0f2fe;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow:    0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10);

    --radius:    10px;
    --radius-lg: 14px;

    --bs-primary: var(--c-primary);
    --bs-primary-rgb: 79, 70, 229;
    --bs-link-color: var(--c-primary-700);
    --bs-link-hover-color: var(--c-primary);
}

/* ----- Typography (Thai-first) ----- */
html, body {
    font-family: 'Sarabun', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: var(--c-text);
    font-size: 14.5px;
    letter-spacing: -0.005em;
}
body.bg-body-tertiary,
body.bg-body-secondary { background-color: var(--c-bg) !important; }

h1, h2, h3, h4, h5, h6 { font-weight: 600; letter-spacing: -0.01em; }

code {
    font-family: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace;
    background: var(--c-border-soft);
    color: var(--c-primary-700);
    padding: 0.1em 0.4em;
    border-radius: 4px;
    font-size: 0.88em;
}

/* ----- App shell ----- */
.app-wrapper { background: var(--c-bg); }

.app-header.navbar {
    background: var(--c-surface) !important;
    border-bottom: 1px solid var(--c-border) !important;
    box-shadow: none;
    min-height: 60px;
}
.app-header .nav-link { color: var(--c-text-dim); }
.app-header .nav-link:hover { color: var(--c-text); }

.app-content-header { padding-block: 1.5rem 0.5rem; }
.app-content-header h3 { font-size: 1.5rem; margin: 0; }

.app-content { padding-block: 0.5rem 2rem; }

.app-footer {
    background: transparent;
    color: var(--c-text-muted);
    border: none;
    font-size: 0.85rem;
}

/* ----- Sidebar ----- */
.app-sidebar {
    background: #0f172a !important;       /* slate-900 */
    border-right: none !important;
    box-shadow: none !important;
}
.sidebar-brand {
    background: transparent;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-brand .brand-link { color: #fff; }
.sidebar-brand .brand-text { font-weight: 700; letter-spacing: -0.01em; }
.sidebar-brand .brand-image {
    color: var(--c-primary);
    margin-right: 0.5rem;
}

.app-sidebar .sidebar-menu .nav-link {
    color: #cbd5e1;             /* slate-300 */
    border-radius: 8px;
    margin: 2px 8px;
    padding: 9px 12px;
    transition: all .15s ease;
}
.app-sidebar .sidebar-menu .nav-link:hover {
    color: #fff;
    background: rgba(255,255,255,0.06);
}
.app-sidebar .sidebar-menu .nav-link.active {
    color: #fff;
    background: rgba(79, 70, 229, 0.18);
    box-shadow: inset 3px 0 0 var(--c-primary);
}
.app-sidebar .sidebar-menu .nav-icon { color: inherit; opacity: .85; }

/* ----- Cards ----- */
.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--c-border-soft);
    padding: 0.9rem 1.1rem;
    font-weight: 600;
}
.card-header .card-title { font-size: 0.95rem; font-weight: 600; }
.card-body { padding: 1.1rem; }
.card-footer {
    background: transparent;
    border-top: 1px solid var(--c-border-soft);
    padding: 0.75rem 1.1rem;
}

/* ----- Stat tiles (modern replacement for AdminLTE small-box) ----- */
.stat-tile {
    display: flex;
    flex-direction: column;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.25rem 1.1rem;
    height: 100%;
    transition: transform .15s ease, box-shadow .15s ease;
}
.stat-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-tile .stat-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    margin-bottom: 0.9rem; font-size: 18px;
}
.stat-tile .stat-icon.bg-primary-soft { background: var(--c-primary-50); color: var(--c-primary); }
.stat-tile .stat-icon.bg-success-soft { background: var(--c-success-soft); color: #047857; }
.stat-tile .stat-icon.bg-warning-soft { background: var(--c-warning-soft); color: #b45309; }
.stat-tile .stat-icon.bg-info-soft    { background: var(--c-info-soft);    color: #0369a1; }
.stat-tile .stat-value { font-size: 1.85rem; font-weight: 700; color: var(--c-text); letter-spacing: -0.02em; line-height: 1.1; }
.stat-tile .stat-label { color: var(--c-text-dim); font-size: 0.85rem; margin-top: 0.25rem; }
.stat-tile .stat-sub   { color: var(--c-text-muted); font-size: 0.78rem; margin-top: 0.15rem; }

/* ----- Tables ----- */
.table { color: var(--c-text); --bs-table-bg: transparent; }
.table > :not(caption) > * > * { padding: 0.85rem 1rem; }
.table > thead th {
    background: #f8fafc;
    color: var(--c-text-dim);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--c-border);
}
.table > tbody > tr { border-color: var(--c-border-soft); }
.table-hover > tbody > tr:hover > * {
    background-color: #f8fafc;
}
.table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: transparent;          /* turn off — hover only */
}

/* ----- Badges (pill-shaped, soft) ----- */
.badge { font-weight: 500; padding: 0.35em 0.7em; border-radius: 999px; letter-spacing: 0; }
.badge.text-bg-success   { background: var(--c-success-soft) !important; color: #047857 !important; }
.badge.text-bg-warning   { background: var(--c-warning-soft) !important; color: #b45309 !important; }
.badge.text-bg-danger    { background: var(--c-danger-soft)  !important; color: #b91c1c !important; }
.badge.text-bg-info      { background: var(--c-info-soft)    !important; color: #0369a1 !important; }
.badge.text-bg-primary   { background: var(--c-primary-50)   !important; color: var(--c-primary-700) !important; }
.badge.text-bg-secondary { background: #f1f5f9 !important; color: #475569 !important; }

/* ----- Buttons ----- */
.btn { border-radius: 8px; font-weight: 500; transition: all .15s ease; }
.btn-primary {
    background: var(--c-primary); border-color: var(--c-primary);
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.18);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--c-primary-700); border-color: var(--c-primary-700);
}
.btn-outline-primary { color: var(--c-primary); border-color: var(--c-primary-100); }
.btn-outline-primary:hover { background: var(--c-primary); border-color: var(--c-primary); }
.btn-outline-secondary { color: var(--c-text-dim); border-color: var(--c-border); }
.btn-outline-secondary:hover { background: #f1f5f9; color: var(--c-text); border-color: var(--c-border); }
.btn-outline-info { color: #0369a1; border-color: var(--c-info-soft); }
.btn-outline-warning { color: #b45309; border-color: var(--c-warning-soft); }
.btn-outline-danger { color: #b91c1c; border-color: var(--c-danger-soft); }
.btn-link { color: var(--c-primary); text-decoration: none; font-weight: 500; }
.btn-link:hover { color: var(--c-primary-700); text-decoration: underline; }

/* ----- Forms ----- */
.form-control, .form-select {
    border: 1px solid var(--c-border);
    border-radius: 8px;
    background-clip: padding-box;
    color: var(--c-text);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus, .form-select:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.form-label { font-weight: 500; color: var(--c-text-dim); font-size: 0.88rem; margin-bottom: 0.4rem; }
.form-text { color: var(--c-text-muted); }
.form-check-input:checked { background-color: var(--c-primary); border-color: var(--c-primary); }

/* ----- Alerts ----- */
.alert { border: none; border-radius: var(--radius); padding: 0.85rem 1rem; }
.alert-success { background: var(--c-success-soft); color: #047857; }
.alert-danger  { background: var(--c-danger-soft);  color: #b91c1c; }
.alert-warning { background: var(--c-warning-soft); color: #b45309; }
.alert-info    { background: var(--c-info-soft);    color: #0369a1; }

/* ----- Login page ----- */
body.login-page {
    background: linear-gradient(160deg, #eef2ff 0%, #f6f8fb 55%, #fff 100%) !important;
}
.login-box {
    width: 380px;
}
.login-box .card { border-radius: var(--radius-lg); border: 1px solid var(--c-border); box-shadow: var(--shadow-lg); }
.login-box .card-header { background: transparent; border-bottom: none; padding: 1.5rem 1.5rem 0.5rem; }
.login-box .card-body { padding: 1rem 1.5rem 1.75rem; }
.login-box .card-header h1 { font-size: 1.5rem; }
.login-box .login-box-msg { color: var(--c-text-dim); font-size: 0.95rem; padding: 0; margin-bottom: 1.25rem; }
.login-box .input-group-text { background: var(--c-border-soft); color: var(--c-text-dim); border-color: var(--c-border); }

/* ----- Nav tabs ----- */
.nav-tabs { border-bottom: 1px solid var(--c-border); }
.nav-tabs .nav-link {
    color: var(--c-text-dim);
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.75rem 1.1rem;
    font-weight: 500;
    border-radius: 0;
}
.nav-tabs .nav-link:hover { color: var(--c-primary); border-color: transparent; background: transparent; }
.nav-tabs .nav-link.active { color: var(--c-primary); background: transparent; border-bottom-color: var(--c-primary); }

/* ----- Modals ----- */
.modal-content { border: none; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--c-border-soft); }
.modal-footer { border-top: 1px solid var(--c-border-soft); }

/* ----- Page card (custom grid for /pages) ----- */
.page-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
}
.page-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--c-primary-100);
}
.page-card .page-avatar {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--c-border-soft);
    background-size: cover; background-position: center;
    flex-shrink: 0;
    border: 2px solid var(--c-surface);
    box-shadow: 0 0 0 1px var(--c-border);
}
.page-card .page-avatar.empty {
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--c-text-muted); font-size: 22px;
}
.page-card .page-name { font-weight: 600; color: var(--c-text); font-size: 1.05rem; line-height: 1.25; }
.page-card .page-id   { font-size: 0.78rem; color: var(--c-text-muted); }
.page-card .page-stats { display: flex; gap: 1.5rem; margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid var(--c-border-soft); }
.page-card .page-stats .stat-num { font-weight: 700; color: var(--c-text); font-size: 1.05rem; }
.page-card .page-stats .stat-cap { color: var(--c-text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.page-card .page-actions { margin-top: 1rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ----- Pagination ----- */
.pagination .page-link {
    color: var(--c-text-dim);
    border-color: var(--c-border);
    border-radius: 8px;
    margin: 0 2px;
    padding: 0.4rem 0.75rem;
}
.pagination .page-item.active .page-link {
    background: var(--c-primary);
    border-color: var(--c-primary);
    color: #fff;
}
.pagination .page-link:hover {
    color: var(--c-primary-700);
    background: var(--c-primary-50);
    border-color: var(--c-primary-100);
}
.pagination .page-item.active .page-link:hover {
    color: #fff;
    background: var(--c-primary-700);
    border-color: var(--c-primary-700);
}
.pagination .page-item.disabled .page-link { color: var(--c-text-muted); }

/* ----- Small polish ----- */
.dropdown-menu {
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.4rem;
}
.dropdown-item { border-radius: 6px; padding: 0.45rem 0.7rem; font-size: 0.9rem; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--c-primary-50); color: var(--c-primary-700); }

.fs-7 { font-size: 0.8rem; }
.text-secondary { color: var(--c-text-dim) !important; }
.text-muted { color: var(--c-text-muted) !important; }

/* SweetAlert match */
.swal2-popup { border-radius: var(--radius-lg) !important; font-family: inherit !important; }
.swal2-confirm.btn-primary { background: var(--c-primary) !important; }

/* =========================================================================
   Responsive — Tablet (≤ 992px)
   ========================================================================= */
@media (max-width: 992px) {
    .app-content-header { padding-block: 1rem 0.25rem; }
    .app-content-header h3 { font-size: 1.35rem; }
    .app-content { padding-block: 0.25rem 1.5rem; }

    .card-body { padding: 0.9rem; }
    .stat-tile { padding: 1rem 1rem 0.85rem; }
    .stat-tile .stat-value { font-size: 1.6rem; }
    .stat-tile .stat-icon { width: 36px; height: 36px; margin-bottom: 0.6rem; }
}

/* =========================================================================
   Responsive — Mobile (≤ 768px)
   ========================================================================= */
@media (max-width: 768px) {
    html, body { font-size: 14px; }

    .app-content-header h3 { font-size: 1.2rem; }

    .card-header { padding: 0.75rem 0.85rem; }
    .card-body   { padding: 0.85rem; }
    .card-footer { padding: 0.6rem 0.85rem; }

    /* Tables — tighter spacing so more fits on screen */
    .table > :not(caption) > * > * { padding: 0.6rem 0.55rem; font-size: 0.85rem; }
    .table > thead th { font-size: 0.7rem; }

    /* Tabs — horizontal scroll instead of wrapping awkwardly */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: var(--c-border) transparent;
    }
    .nav-tabs::-webkit-scrollbar { height: 4px; }
    .nav-tabs::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 2px; }
    .nav-tabs .nav-link {
        white-space: nowrap;
        flex-shrink: 0;
        padding: 0.6rem 0.85rem;
        font-size: 0.9rem;
    }

    /* Page cards — slight padding adjust */
    .page-card { padding: 1rem; }
    .page-card .page-avatar { width: 48px; height: 48px; }
    .page-card .page-name   { font-size: 1rem; }
    .page-card .page-stats  { gap: 1rem; margin-top: 0.75rem; padding-top: 0.7rem; }

    /* Modals — use full screen on very small viewports */
    .modal-dialog { margin: 0.5rem; }
    .modal-dialog.modal-lg { max-width: calc(100vw - 1rem); }

    /* Pagination — wrap if needed, tighter spacing */
    .pagination .page-link { padding: 0.3rem 0.55rem; font-size: 0.85rem; margin: 0 1px; }

    /* Header navbar — tighter */
    .app-header.navbar { min-height: 54px; }
    .app-header .nav-link { padding: 0.4rem 0.65rem; }

    /* Login box — full width with safe padding */
    .login-box { width: 100% !important; max-width: 380px; padding: 0 1rem; }

    /* Buttons in tables — easier to tap */
    .table .btn-sm { padding: 0.3rem 0.55rem; }
}

/* =========================================================================
   Responsive — Small Mobile (≤ 480px)
   ========================================================================= */
@media (max-width: 480px) {
    html, body { font-size: 13.5px; }
    .app-content-header { padding-block: 0.75rem 0.25rem; }
    .app-content-header h3 { font-size: 1.1rem; }

    .card-body { padding: 0.75rem; }
    .stat-tile .stat-value { font-size: 1.4rem; }

    /* Detail modal header text tighter */
    .modal-title { font-size: 1rem; }

    /* Footer fits */
    .app-footer { font-size: 0.78rem; padding: 0.5rem 0.85rem; }

    /* Login card header heading smaller */
    .login-box .card-header h1 { font-size: 1.2rem; }
}

/* =========================================================================
   Make tables less cramped via responsive wrap (already used in views)
   ========================================================================= */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

/* =========================================================================
   Filter form rows on /comments — stack better on mobile (already use col-md-*)
   add safe gap when stacking
   ========================================================================= */
@media (max-width: 768px) {
    form .row.g-2 > [class*="col-"] { margin-bottom: 0.5rem; }
}
