/* ============================================================
   CJ Mart On-boarding System — Main CSS
   ============================================================ */

:root {
    --primary:   #005BAC;
    --primary-dark: #004080;
    --secondary: #FF6B00;
    --success:   #28a745;
    --danger:    #dc3545;
    --warning:   #ffc107;
    --info:      #17a2b8;
    --gray:      #6c757d;
    --light:     #f8f9fa;
    --dark:      #343a40;
    --border:    #dee2e6;
    --shadow:    0 2px 8px rgba(0,0,0,.08);
    --radius:    8px;
    --sidebar-w: 240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Sarabun', 'Segoe UI', sans-serif;
    font-size: 15px;
    color: var(--dark);
    background: #f0f2f5;
    line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   Layout
   ============================================================ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.15);
}
.sidebar-brand h2 { font-size: 18px; font-weight: 700; }
.sidebar-brand small { font-size: 11px; opacity: .7; display: block; }

.sidebar-nav { flex: 1; padding: 8px 0; }

.sidebar-section {
    padding: 12px 16px 4px;
    font-size: 11px;
    text-transform: uppercase;
    opacity: .6;
    letter-spacing: .05em;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: rgba(255,255,255,.85);
    font-size: 14px;
    transition: background .15s;
}
.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255,255,255,.15);
    color: #fff;
    text-decoration: none;
}
.sidebar-nav a .icon { width: 18px; text-align: center; opacity: .8; }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,.15);
    font-size: 13px;
}
.sidebar-footer .user-name { font-weight: 600; }
.sidebar-footer .user-role { font-size: 11px; opacity: .7; }

.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title { font-size: 17px; font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.notification-bell {
    position: relative;
    cursor: pointer;
    font-size: 20px;
    color: var(--gray);
}
.notification-bell .badge-count {
    position: absolute;
    top: -4px; right: -6px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    width: 16px; height: 16px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}

.page-content { padding: 24px; flex: 1; }

/* ============================================================
   Impersonate Banner
   ============================================================ */
.impersonate-banner {
    background: #fff3cd;
    border-bottom: 2px solid #ffc107;
    padding: 8px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 15px;
}
.card-body { padding: 20px; }

/* ============================================================
   Tables
   ============================================================ */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
thead th {
    background: var(--light);
    padding: 10px 12px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-active    { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-failed    { background: #fee2e2; color: #991b1b; }
.badge-resigned  { background: #f3f4f6; color: #374151; }
.badge-cancelled { background: #ffedd5; color: #9a3412; }
.badge-pass      { background: #dcfce7; color: #166534; }
.badge-need_more { background: #fef9c3; color: #713f12; }
.badge-admin     { background: #ede9fe; color: #5b21b6; }
.badge-division_head { background: #dbeafe; color: #1e40af; }
.badge-team_head { background: #cffafe; color: #155e75; }
.badge-employee  { background: #f3f4f6; color: #374151; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
    text-decoration: none;
}
.btn:hover { text-decoration: none; opacity: .9; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-xs { padding: 2px 8px; font-size: 12px; }
.btn-block { width: 100%; }

.btn-primary  { background: var(--primary);   color: #fff; border-color: var(--primary); }
.btn-success  { background: var(--success);   color: #fff; border-color: var(--success); }
.btn-danger   { background: var(--danger);    color: #fff; border-color: var(--danger); }
.btn-warning  { background: var(--warning);   color: var(--dark); border-color: var(--warning); }
.btn-secondary{ background: var(--gray);      color: #fff; border-color: var(--gray); }
.btn-outline  { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-light    { background: var(--light); color: var(--dark); border-color: var(--border); }

.btn-google {
    background: #fff;
    color: #3c4043;
    border: 1px solid var(--border);
    width: 100%;
    padding: 11px;
    font-size: 15px;
    justify-content: center;
    gap: 10px;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.btn-google:hover { background: #f5f5f5; }

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; font-size: 14px; }

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color .15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,91,172,.1);
}

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.form-inline .form-group { margin-bottom: 0; }

/* ============================================================
   Alerts
   ============================================================ */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-success { background: #d1e7dd; color: #0f5132; }
.alert-danger  { background: #f8d7da; color: #842029; }
.alert-warning { background: #fff3cd; color: #664d03; }
.alert-info    { background: #cff4fc; color: #055160; }

/* ============================================================
   Progress Bar
   ============================================================ */
.progress {
    background: #e9ecef;
    border-radius: 20px;
    height: 8px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 20px;
    transition: width .3s;
}
.progress-bar.green { background: var(--success); }
.progress-bar.red   { background: var(--danger); }

/* ============================================================
   Accordion
   ============================================================ */
.accordion-item { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; }
.accordion-header {
    padding: 12px 16px;
    background: var(--light);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    user-select: none;
}
.accordion-header:hover { background: #e9ecef; }
.accordion-body { padding: 16px; display: none; }
.accordion-body.show { display: block; }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.show { display: flex; }

.modal-box {
    background: #fff;
    border-radius: var(--radius);
    width: 90%;
    max-width: 640px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.modal-close {
    background: none; border: none; font-size: 22px;
    cursor: pointer; color: var(--gray); line-height: 1;
}
.modal-close:hover { color: var(--dark); }

/* ============================================================
   Stats Cards
   ============================================================ */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
    border-top: 3px solid var(--primary);
}
.stat-card.blue  { border-top-color: var(--primary); }
.stat-card.green { border-top-color: var(--success); }
.stat-card.red   { border-top-color: var(--danger); }
.stat-card.gray  { border-top-color: var(--gray); }
.stat-card.orange{ border-top-color: var(--secondary); }
.stat-number { font-size: 36px; font-weight: 700; line-height: 1; }
.stat-label  { font-size: 13px; color: var(--gray); margin-top: 4px; }

/* ============================================================
   Sub-topic Status Colors (Progress Page)
   ============================================================ */
.subtopic-row { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.subtopic-row:last-child { border-bottom: none; }
.subtopic-status { width: 140px; flex-shrink: 0; font-size:13px; }
.subtopic-status.pass      { color: var(--success); font-weight: 600; }
.subtopic-status.pending   { color: var(--warning); }
.subtopic-status.nolog     { color: var(--gray); }
.subtopic-status.need_more { color: #d97706; font-weight: 600; }
.subtopic-status.failed    { color: var(--danger); font-weight: 600; }
.subtopic-name { flex: 1; }

/* ============================================================
   Login Page
   ============================================================ */
.login-page { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-container { width: 100%; max-width: 400px; padding: 16px; }
.login-card { background: #fff; border-radius: 12px; padding: 40px 32px; box-shadow: 0 8px 32px rgba(0,0,0,.2); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 28px; color: var(--primary); font-weight: 800; }
.login-logo p { color: var(--gray); font-size: 14px; }
.login-divider { text-align: center; margin: 16px 0; position: relative; }
.login-divider::before { content: ''; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--border); }
.login-divider span { background: #fff; padding: 0 12px; position: relative; color: var(--gray); font-size: 13px; }

/* ============================================================
   Tabs
   ============================================================ */
.tab-nav { display: flex; gap: 4px; border-bottom: 2px solid var(--border); padding-bottom: 0; }
.tab-btn {
    padding: 8px 20px;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray);
    font-family: inherit;
    position: relative;
    bottom: -2px;
    transition: all .15s;
}
.tab-btn:hover { background: var(--light); color: var(--dark); }
.tab-btn.active {
    background: #fff;
    color: var(--primary);
    border-color: var(--border);
    border-bottom-color: #fff;
    font-weight: 600;
}

/* ============================================================
   Pagination
   ============================================================ */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    color: var(--primary);
}
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination a:hover { background: var(--light); text-decoration: none; }

/* ============================================================
   Utility
   ============================================================ */
.d-flex { display: flex; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-muted  { color: var(--gray); }
.text-sm     { font-size: 13px; }
.text-xs     { font-size: 11px; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-success{ color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning{ color: #856404; }
.fw-bold     { font-weight: 700; }
.w-100       { width: 100%; }
.rounded     { border-radius: var(--radius); }

/* ============================================================
   Notification Popup
   ============================================================ */
.notif-panel {
    position: fixed;
    top: 56px;
    right: 16px;
    width: 340px;
    max-height: 460px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    z-index: 200;
    display: none;
    flex-direction: column;
}
.notif-panel.show { display: flex; }
.notif-panel-header { padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px; }
.notif-list { overflow-y: auto; flex: 1; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:hover { background: var(--light); }
.notif-item.unread { background: #eff6ff; }
.notif-item-title { font-weight: 600; font-size: 14px; }
.notif-item-body  { font-size: 13px; color: var(--gray); margin-top: 2px; }
.notif-item-time  { font-size: 11px; color: var(--gray); margin-top: 4px; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    body { font-size: 14px; overflow-x: hidden; }

    .layout { display: block; min-width: 0; }

    .sidebar {
        width: min(82vw, var(--sidebar-w));
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 8px 0 24px rgba(0,0,0,.18);
        z-index: 300;
    }
    .sidebar.open { transform: translateX(0); }
    body.sidebar-open { overflow: hidden; }
    body.sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.35);
        z-index: 250;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        min-width: 0;
    }

    .topbar {
        height: 52px;
        padding: 0 12px;
        gap: 10px;
    }
    #menuToggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border-radius: 6px;
        color: var(--dark);
    }
    #menuToggle:hover { background: var(--light); }
    .topbar-title {
        font-size: 16px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: calc(100vw - 120px);
    }

    .page-content { padding: 12px; }

    .impersonate-banner {
        padding: 10px 12px;
        align-items: flex-start;
        gap: 8px;
        flex-direction: column;
    }

    .card { margin-bottom: 12px; border-radius: 8px; }
    .card-header {
        padding: 12px;
        align-items: flex-start;
        gap: 10px;
        flex-direction: column;
    }
    .card-body { padding: 12px; }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        margin-bottom: 12px;
    }
    .stat-card { padding: 14px 10px; }
    .stat-number { font-size: 28px; }

    .d-flex {
        min-width: 0;
    }
    .form-inline,
    .card-body.d-flex,
    .card-header .d-flex {
        align-items: stretch;
    }
    .form-inline .form-group,
    .form-inline .form-control,
    .form-inline .btn,
    .card-body.d-flex > .form-control,
    .card-body.d-flex > .btn,
    .card-body.d-flex > a.btn {
        width: 100% !important;
        max-width: none !important;
    }
    .card-header input.form-control,
    #tableSearch {
        width: 100% !important;
        max-width: none !important;
    }
    .page-content .form-control {
        max-width: 100%;
    }
    .page-content textarea.form-control,
    .page-content input.form-control,
    .page-content select.form-control {
        min-width: 0;
    }
    .modal-body .d-flex,
    .accordion-body .d-flex {
        flex-wrap: wrap;
    }
    .modal-body .form-group,
    .accordion-body .form-control {
        min-width: 0 !important;
    }

    .btn {
        min-height: 40px;
        padding: 8px 12px;
        white-space: normal;
        text-align: center;
    }
    .btn-sm,
    .btn-xs { min-height: 34px; }

    .table-wrap {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    table { min-width: 680px; }
    thead th,
    tbody td {
        padding: 8px 10px;
        font-size: 13px;
    }

    .accordion-header {
        padding: 10px 12px;
        gap: 8px;
        align-items: flex-start;
    }
    .accordion-body { padding: 12px; }

    .subtopic-row {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 6px 10px;
    }
    .subtopic-status {
        width: auto;
        flex: 0 0 100%;
    }
    .subtopic-name {
        min-width: 0;
        flex-basis: 100%;
    }
    .subtopic-row .btn {
        width: 100%;
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
    .modal-box {
        width: 100%;
        max-width: none !important;
        max-height: 92vh;
        border-radius: 12px 12px 0 0;
    }
    .modal-header,
    .modal-body,
    .modal-footer {
        padding-left: 14px;
        padding-right: 14px;
    }
    .modal-footer {
        flex-wrap: wrap;
    }
    .modal-footer .btn {
        flex: 1 1 140px;
    }

    .notif-panel {
        left: 12px;
        right: 12px;
        top: 58px;
        width: auto;
        max-height: calc(100vh - 74px);
    }

    .login-page {
        align-items: flex-start;
        padding-top: 24px;
    }
    .login-card {
        padding: 28px 20px;
        border-radius: 10px;
    }
}

@media (max-width: 480px) {
    .page-content { padding: 10px; }
    .stats-grid { grid-template-columns: 1fr; }
    .topbar-title { max-width: calc(100vw - 104px); }
    .badge { white-space: normal; }
    table { min-width: 620px; }
}

@media (min-width: 769px) and (max-width: 1180px) {
    :root { --sidebar-w: 220px; }
    .page-content { padding: 18px; }
    .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .card-header { gap: 12px; flex-wrap: wrap; }
}
