/* ============================================================
   ระบบขอคัดสำเนาประวัติ (ก.พ.7) — ธีมหน้าเว็บ (Bootstrap 5)
   ดีไซน์: สว่าง เรียบ ทันสมัย เน้นใช้งานบนมือถือ
   คงโทนสีหลักม่วงคราม (indigo) ไว้ตามเดิม
   ============================================================ */

:root {
    /* --- โทนสีหลัก (indigo) --- */
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-darker: #3730a3;
    --brand-soft: #eef2ff;      /* พื้นอ่อนสำหรับ hover/active-tint */
    --brand-softer: #f5f6ff;

    /* --- พื้นผิว / เส้น / ตัวอักษร --- */
    --surface: #ffffff;
    --body-bg: #f6f7fb;
    --ink: #1f2430;             /* ตัวอักษรหลัก */
    --ink-muted: #6b7280;       /* ตัวอักษรรอง */
    --ink-faint: #9096a8;
    --line: #e8eaf1;            /* เส้นขอบบาง */
    --line-strong: #dfe2ec;

    /* --- ความโค้ง / เงา (นุ่ม เบา) --- */
    --sidebar-width: 264px;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 9px;
    --shadow-xs: 0 1px 2px rgba(30, 41, 59, 0.05);
    --shadow-sm: 0 1px 3px rgba(30, 41, 59, 0.06), 0 1px 2px rgba(30, 41, 59, 0.04);
    --shadow-md: 0 6px 20px rgba(30, 41, 59, 0.08);
    --shadow-lg: 0 16px 40px rgba(30, 41, 59, 0.14);

    /* --- override ตัวแปรของ Bootstrap ให้คอมโพเนนต์มาตรฐานเข้าธีม --- */
    --bs-primary: #4f46e5;
    --bs-primary-rgb: 79, 70, 229;
    --bs-body-bg: var(--body-bg);
    --bs-body-color: var(--ink);
    --bs-border-color: var(--line);
    --bs-border-radius: var(--radius-md);
    --bs-link-color: var(--brand);
    --bs-link-hover-color: var(--brand-dark);
    --bs-link-color-rgb: 79, 70, 229;
    --bs-emphasis-color: var(--ink);
}

body {
    background-color: var(--body-bg);
    font-family: 'Sarabun', 'Segoe UI', sans-serif;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.01em;
}

a {
    text-decoration: none;
}

/* ---------- Layout ---------- */

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--surface);
    color: var(--ink);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    /* ยึดเมนูด้านข้างให้ติดจอเสมอ ไม่เลื่อนตามเนื้อหา (เมนูยาวก็เลื่อนภายในตัวเอง) */
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
}

.app-sidebar .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 1.35rem 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
}

.app-sidebar .sidebar-brand .brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--brand), #7c3aed);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.app-sidebar .nav {
    padding: 0.75rem;
    gap: 0.12rem;
}

.app-sidebar .nav-link {
    display: flex;
    align-items: center;
    color: var(--ink-muted);
    padding: 0.68rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.93rem;
    font-weight: 500;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.app-sidebar .nav-link:hover {
    color: var(--brand-dark);
    background-color: var(--brand-soft);
}

.app-sidebar .nav-link.active {
    color: #fff;
    background: var(--brand);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.28);
}

.app-sidebar .nav-link .bi:first-child {
    width: 1.4rem;
    text-align: center;
    font-size: 1.02rem;
}

/* ลูกศรของเมนูที่ขยายได้ */
.app-sidebar .nav-link .bi-chevron-down {
    transition: transform 0.2s ease;
    font-size: 0.75rem;
}
.app-sidebar .nav-link[aria-expanded="true"] .bi-chevron-down {
    transform: rotate(180deg);
}

.app-sidebar .nav .nav {
    background-color: var(--brand-softer);
    border-radius: var(--radius-sm);
    margin-top: 0.15rem;
    padding: 0.3rem;
}

.app-sidebar .nav .nav .nav-link {
    padding-left: 2.4rem;
    font-size: 0.86rem;
}

/* บัญชีผู้ใช้ท้ายเมนู (เข้าสู่ระบบ / ชื่อผู้ใช้ + ออกจากระบบ) */
.app-sidebar .sidebar-account {
    margin-top: auto;
    padding: 0.75rem;
    border-top: 1px solid var(--line);
}

.app-sidebar .sidebar-account .nav-link {
    display: flex;
    align-items: center;
    color: var(--ink-muted);
    padding: 0.68rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.93rem;
    font-weight: 500;
}

.app-sidebar .sidebar-account .nav-link:hover {
    color: var(--brand-dark);
    background-color: var(--brand-soft);
}

.app-sidebar .sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 0.85rem;
    color: var(--ink);
    font-weight: 600;
    font-size: 0.9rem;
    word-break: break-word;
}

.app-sidebar .sidebar-user .bi {
    color: var(--brand);
    font-size: 1.1rem;
    flex-shrink: 0;
}

.app-main {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--line);
    padding: 0.8rem 1.75rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.app-content {
    padding: 1.85rem;
    flex: 1 0 auto;
}

@media (max-width: 575.98px) {
    .app-content {
        padding: 1.15rem;
    }
    .app-topbar {
        padding: 0.7rem 1.15rem;
    }
}

/* ---------- Sidebar บนมือถือ (off-canvas + ฉากหลัง) ---------- */

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(17, 20, 31, 0.45);
    backdrop-filter: blur(2px);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.sidebar-backdrop.show {
    opacity: 1;
    visibility: visible;
}

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        z-index: 1045;
        transition: left 0.25s ease-in-out;
        box-shadow: var(--shadow-lg);
    }

    .app-sidebar.show {
        left: 0;
    }
}

@media (min-width: 992px) {
    .sidebar-backdrop {
        display: none;
    }
}

/* ---------- ส่วนท้ายเว็บ (footer) ---------- */

.site-footer {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
    gap: 0.75rem 1.5rem;
    padding: 1.4rem 1.85rem;
    border-top: 1px solid var(--line);
    background-color: transparent;
    color: var(--ink-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.site-footer__meta {
    text-align: right;
}

@media (max-width: 575.98px) {
    .site-footer {
        flex-direction: column;
        align-items: flex-start;
        padding: 1.25rem 1.15rem;
    }
    .site-footer__meta {
        text-align: left;
    }
}

/* footer บนหน้า login: ยึดไว้ด้านล่างสุดของจอ โดยไม่กระทบการจัดการ์ดให้อยู่กึ่งกลาง */
.auth-shell {
    position: relative;
}

.auth-shell .site-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: transparent;
    border-top-color: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.75);
}

.auth-shell .site-footer .fw-semibold {
    color: rgba(255, 255, 255, 0.92);
}

.auth-shell .site-footer .text-muted {
    color: rgba(255, 255, 255, 0.6) !important;
}

/* ---------- Cards ---------- */

.card {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    background: var(--surface);
}

.card-body {
    padding: 1.4rem;
}

@media (max-width: 575.98px) {
    .card-body {
        padding: 1.15rem;
    }
}

/* การ์ดที่คลิกได้ / การ์ดทางลัดหน้าแรก */
a.card,
.card.h-100 {
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

a.card:hover,
.card.h-100:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--line-strong);
}

.card-title {
    font-weight: 600;
}

.shadow-sm {
    box-shadow: var(--shadow-sm) !important;
}

/* ---------- Stat cards (แดชบอร์ด) — พื้นขาว เน้นตัวเลขด้วยสี ---------- */

.stat-card {
    --accent: var(--brand);
    --accent-soft: var(--brand-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    color: var(--ink);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.stat-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.stat-card .card-body {
    padding: 1.35rem 1.5rem;
}

.stat-icon-wrap {
    width: 3rem;
    height: 3rem;
    border-radius: 13px;
    background-color: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card .small.text-uppercase {
    letter-spacing: 0.04em;
    color: var(--ink-muted);
    font-size: 0.74rem;
    font-weight: 600;
}

.stat-card .fs-2 {
    color: var(--accent);
    line-height: 1.1;
    margin-top: 0.15rem;
}

.stat-card.stat-total {
    --accent: #4f46e5;
    --accent-soft: #eef2ff;
}

.stat-card.stat-progress {
    --accent: #ea580c;
    --accent-soft: #fff2e8;
}

.stat-card.stat-done {
    --accent: #16a34a;
    --accent-soft: #e7f7ee;
}

/* ---------- Buttons — แบน สีทึบ ---------- */

.btn {
    --bs-btn-border-radius: var(--radius-sm);
    border-radius: var(--radius-sm);
    font-weight: 500;
    padding: 0.5rem 1.1rem;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.btn-lg {
    padding: 0.7rem 1.4rem;
    font-size: 1.02rem;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
}

.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-darker);
    --bs-btn-active-border-color: var(--brand-darker);
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
}

.btn-primary:hover,
.btn-primary:focus-visible {
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-bg: var(--brand-dark);
    --bs-btn-active-border-color: var(--brand-dark);
}

.btn:focus-visible {
    box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.25);
}

/* ---------- Forms ---------- */

.form-label {
    font-weight: 500;
    font-size: 0.88rem;
    color: #444a5c;
    margin-bottom: 0.35rem;
}

.form-control,
.form-select {
    border-radius: var(--radius-sm);
    border-color: var(--line-strong);
    padding: 0.55rem 0.85rem;
    color: var(--ink);
    background-color: var(--surface);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control::placeholder {
    color: var(--ink-faint);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.15);
}

.form-control.bg-light {
    background-color: #f5f6fa !important;
    color: var(--ink-muted);
}

.form-text {
    color: var(--ink-muted);
    font-size: 0.82rem;
}

.form-check-input:checked {
    background-color: var(--brand);
    border-color: var(--brand);
}

.form-check-input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.15);
}

/* หัวข้อย่อยของฟอร์ม (เส้นสีนำหน้า) */
h6.text-muted {
    position: relative;
    padding-left: 0.85rem;
    font-weight: 600;
    color: var(--ink) !important;
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
}

h6.text-muted::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.1rem;
    bottom: 0.1rem;
    width: 3px;
    border-radius: 2px;
    background: var(--brand);
}

/* ---------- Badges & alerts ---------- */

.badge {
    border-radius: 999px;
    padding: 0.4em 0.8em;
    font-weight: 600;
    font-size: 0.75em;
    letter-spacing: 0.01em;
}

.alert {
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
}

.alert-success {
    background-color: #e7f7ee;
    border-color: #c6ecd6;
    color: #14532d;
}

.alert-danger {
    background-color: #fdecec;
    border-color: #f7cfcf;
    color: #7f1d1d;
}

.alert-warning {
    background-color: #fff6e6;
    border-color: #f7e3ba;
    color: #7c4a03;
}

/* ---------- Tables ---------- */

.table {
    --bs-table-hover-bg: var(--brand-softer);
    margin-bottom: 0;
}

.table thead th {
    background-color: #f7f8fc;
    color: var(--ink-muted);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.table > :not(caption) > * > * {
    padding: 0.85rem 0.85rem;
    border-bottom-color: var(--line);
}

.table-hover > tbody > tr:hover > * {
    background-color: var(--brand-softer);
}

/* ---------- Pagination ---------- */

.pagination {
    --bs-pagination-color: var(--ink-muted);
    --bs-pagination-hover-color: var(--brand-dark);
    --bs-pagination-hover-bg: var(--brand-soft);
    --bs-pagination-focus-color: var(--brand-dark);
    --bs-pagination-focus-bg: var(--brand-soft);
    --bs-pagination-focus-box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.15);
    --bs-pagination-active-bg: var(--brand);
    --bs-pagination-active-border-color: var(--brand);
    --bs-pagination-border-color: var(--line);
    --bs-pagination-border-radius: var(--radius-sm);
    gap: 0.25rem;
}

.page-link {
    margin: 0;
}

/* ---------- List group ---------- */

.list-group-item {
    border-color: var(--line);
}

/* ---------- Definition list (หน้าติดตาม/รายละเอียด) ---------- */

dl.row dt {
    color: var(--ink-muted);
    font-weight: 600;
}

/* ---------- Login page ---------- */

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 15% 20%, rgba(124, 58, 237, 0.28), transparent 45%),
        radial-gradient(circle at 85% 80%, rgba(79, 70, 229, 0.32), transparent 45%),
        linear-gradient(160deg, #12141f, #1e2333 60%, #2a2f45);
    padding: 1.5rem;
}

.auth-card {
    border: none;
    border-radius: 20px;
    box-shadow: 0 24px 55px rgba(10, 12, 25, 0.4);
    overflow: hidden;
}

.auth-card .auth-icon {
    width: 62px;
    height: 62px;
    margin: 0 auto;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--brand), #7c3aed);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: #fff;
    box-shadow: 0 12px 26px rgba(79, 70, 229, 0.42);
}

/* ---------- Scrollbar ---------- */

::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

::-webkit-scrollbar-thumb {
    background: #cdd0dd;
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background: #b7bacb;
    background-clip: content-box;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* ---------- Status stepper (track.php) ---------- */

.status-stepper {
    display: flex;
    justify-content: space-between;
}

.status-stepper .step {
    flex: 1;
    position: relative;
    text-align: center;
}

.status-stepper .step:not(:last-child)::after {
    content: "";
    position: absolute;
    top: 22px;
    left: 50%;
    width: 100%;
    height: 3px;
    background-color: var(--line-strong);
    z-index: 0;
}

.status-stepper .step.done:not(:last-child)::after {
    background-color: #16a34a;
}

.status-stepper .step-icon {
    position: relative;
    z-index: 1;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background-color: #eceef5;
    color: var(--ink-faint);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.55rem;
    font-size: 1.2rem;
    border: 3px solid var(--surface);
    box-shadow: 0 0 0 1px var(--line);
}

.status-stepper .step.done .step-icon {
    background-color: #16a34a;
    color: #fff;
    box-shadow: none;
}

.status-stepper .step.active .step-icon {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.2);
}

.status-stepper .step.rejected .step-icon {
    background-color: #ef4444;
    color: #fff;
    box-shadow: none;
}

.status-stepper .step-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #444a5c;
}

.status-stepper .step.active .step-label {
    color: var(--brand);
}

.status-stepper .step.rejected .step-label {
    color: #ef4444;
}

.status-stepper .step-date {
    font-size: 0.75rem;
    color: var(--ink-faint);
    margin-top: 0.15rem;
}

.status-stepper .step-sub {
    font-size: 0.72rem;
    color: var(--ink-muted);
    font-style: italic;
    margin-top: 0.15rem;
}

@media (max-width: 575.98px) {
    .status-stepper .step-label {
        font-size: 0.7rem;
    }

    .status-stepper .step-icon {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }

    .status-stepper .step:not(:last-child)::after {
        top: 18px;
    }

    .status-stepper .step-date {
        font-size: 0.65rem;
    }

    .status-stepper .step-sub {
        font-size: 0.62rem;
    }
}

/* ---------- Tracking banner (track.php) ---------- */

.tracking-banner {
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--line);
}

.tracking-banner-head {
    background: var(--brand);
    color: #fff;
    font-weight: 600;
    letter-spacing: 0.01em;
    padding: 1rem 1.5rem;
    text-align: center;
}

.tracking-banner-info {
    background-color: var(--brand-soft);
    display: flex;
    flex-wrap: wrap;
    padding: 1.1rem 1.5rem;
    gap: 1rem;
}

.tracking-banner-info > div {
    flex: 1 1 200px;
    text-align: center;
}

.tracking-banner-info .banner-label {
    font-weight: 600;
    color: var(--ink-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.tracking-banner-info .banner-value {
    color: var(--ink);
    margin-top: 0.2rem;
}

/* ---------- Toasts ---------- */

.toast {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}
