/* ระบบประเมินผลปฏิบัติงาน FEBC - โทนสีให้ไปในแนวเดียวกับระบบ HR Portal เดิม */

:root {
    --navy-dark: #182236;
    --navy-darker: #10182a;
    --nav-active: #2d5478;
    --accent: #4c6ef5;
    --accent-2: #7c5cf0;
    --accent-hover: #3a5adb;
    --success-bg: #e3f5e8;
    --success-text: #1f8a4c;
    --avatar-bg: #3b5bdb;
    --ink: #101828;
    --muted: #667085;
    --page-bg: #eef1f8;
    --card-border: rgba(16, 24, 40, 0.05);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Anuphan', 'Segoe UI', Tahoma, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--page-bg);
}

.app-shell {
    display: flex;
    align-items: stretch;
    min-height: 100vh;
}

.sidebar {
    width: 200px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--navy-dark) 0%, var(--navy-darker) 100%);
    color: #fff;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: transform 0.25s ease;
    z-index: 200;
}

.main-area {
    flex: 1;
    min-width: 0;
}

.mobile-topbar { display: none; }

.sidebar-overlay { display: none; }

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    padding: 0 4px;
}

.brand-logo {
    width: 20px;
    height: 20px;
    display: block;
    flex-shrink: 0;
}

.brand-text { min-width: 0; }

.brand-title {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-subtitle {
    font-size: 10.5px;
    font-weight: 400;
    line-height: 1.25;
    color: rgba(255, 255, 255, 0.55);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.main-nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
}

.main-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    padding: 7px 10px;
    border-radius: 7px;
    background: transparent;
    font-size: 13px;
    transition: background 0.15s ease;
}

.nav-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.main-nav a:hover {
    background: rgba(255, 255, 255, 0.1);
}

.main-nav a.active {
    background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
    color: #fff;
    font-weight: 600;
}

.user-badge {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    gap: 8px;
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(120deg, var(--avatar-bg) 0%, var(--accent-2) 100%);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.user-badge .user-name {
    font-weight: 600;
    font-size: 13px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-badge .logout-link {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    transition: background 0.15s ease, color 0.15s ease;
}

.user-badge .logout-link svg {
    width: 16px;
    height: 16px;
}

.user-badge .logout-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 16px 36px;
}

.card {
    background: #fff;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 12px;
    border: 1px solid var(--card-border);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 32px rgba(16, 24, 40, 0.09);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 48, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal-box {
    background: #fff;
    border-radius: 12px;
    padding: 16px 18px;
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(15, 23, 48, 0.35);
    position: relative;
}

.modal-box h2 { margin-top: 0; }

.modal-close {
    position: absolute;
    top: 14px;
    right: 18px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 26px;
    line-height: 1;
    color: #999;
}

.modal-close:hover { color: #444; }

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    padding: 4px 6px;
}
.btn-link:hover { text-decoration: underline; }

.goal-progress-card { padding: 10px 14px; }

.goal-progress-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    font-weight: 600;
    color: var(--navy-dark);
}

.goal-progress-actions { display: flex; gap: 4px; }

.goal-progress-bar {
    margin-top: 10px;
    height: 8px;
    border-radius: 4px;
    background: #eef1f5;
    overflow: hidden;
}

.goal-progress-fill {
    height: 100%;
    background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
    transition: width 0.2s ease;
}

.goal-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
}

.goal-item {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(24, 34, 54, 0.07);
    overflow: hidden;
}

.goal-item-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
    text-align: left;
    padding: 10px 14px;
    color: inherit;
}

.goal-item-header:hover { background: #f7f9fc; }

.goal-item-desc {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.goal-item.open .goal-item-desc {
    white-space: normal;
}

.goal-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.weight-badge { background: #eef2f5; color: var(--navy-dark); }

.goal-item-chevron {
    color: #999;
    transition: transform 0.2s ease;
    font-size: 13px;
}

.goal-item.open .goal-item-chevron { transform: rotate(180deg); }

.goal-item-body {
    display: none;
    padding: 0 14px 14px;
    border-top: 1px solid #f0f0f0;
}

.goal-item.open .goal-item-body { display: block; padding-top: 10px; }

.goal-self-note {
    background: #f7f9fc;
    border-radius: 8px;
    padding: 10px 12px;
    margin: 8px 0;
    font-size: 13.5px;
}
.goal-self-note p { margin: 6px 0 0; }

.rating-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 6px 0 4px;
}

.rating-radio {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.rating-radio-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid #ddd;
    background: #fff;
    font-weight: 700;
    font-size: 13px;
    color: var(--navy-dark);
    cursor: pointer;
    transition: all 0.15s ease;
}

.rating-radio-label:hover { border-color: var(--accent); }

.rating-radio:checked + .rating-radio-label {
    background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 4px 12px rgba(76, 110, 245, 0.3);
}

.rating-radio:focus-visible + .rating-radio-label {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

h1 { font-size: 17px; margin-top: 0; color: var(--ink); font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 14.5px; color: var(--ink); font-weight: 600; }

label {
    display: block;
    font-weight: 600;
    font-size: 12.5px;
    margin-bottom: 3px;
    margin-top: 8px;
}

input[type=text], input[type=number], input[type=date], input[type=password],
select, textarea {
    width: 100%;
    padding: 6px 9px;
    font-size: 13px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(76, 110, 245, 0.15);
}

textarea { min-height: 70px; resize: vertical; }

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 12px;
}

@media (max-width: 600px) {
    .form-grid-2 { grid-template-columns: 1fr; }
}

.btn {
    display: inline-block;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    margin-top: 10px;
    transition: filter 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
    box-shadow: 0 4px 12px rgba(76, 110, 245, 0.22);
}

.btn:active { transform: translateY(1px); }

.btn:hover { filter: brightness(1.08); box-shadow: 0 6px 16px rgba(76, 110, 245, 0.32); }

.btn-secondary {
    background: linear-gradient(120deg, #6b7280 0%, #565e6c 100%);
    box-shadow: 0 4px 12px rgba(107, 114, 128, 0.2);
}
.btn-secondary:hover { filter: brightness(1.08); box-shadow: 0 6px 16px rgba(107, 114, 128, 0.28); }

.btn-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
}
.btn-group .btn { margin-top: 0; }

.inline-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}
.inline-form .btn { margin-top: 0; min-width: 72px; text-align: center; }
.inline-form select { width: auto; }
td:last-child .inline-form { justify-content: flex-end; }

/* กลุ่มปุ่ม action ต่อแถว (จัดการ/แก้ไข/ลบ ฯลฯ) ที่ป้ายยาวสั้นไม่เท่ากัน — บังคับให้กว้างเท่ากันทุกปุ่ม
   แทนที่จะปล่อยตาม min-width ซึ่งทำให้ปุ่มป้ายยาว (เช่น "จัดการระดับ") กว้างกว่าปุ่มป้ายสั้น (เช่น "ลบ") อย่างเห็นได้ชัด */
.inline-form.actions-equal .btn { width: 118px; }

/* ช่องว่างก่อนขึ้น "กลุ่มฟิลด์ใหม่" ในฟอร์มเดียวกัน (เช่น checkbox toggle ใหม่ หรือหัวข้อย่อยถัดไป)
   ใช้ค่าเดียวนี้แทนการเซ็ต margin-top เป็นตัวเลขต่างกันกระจัดกระจายทีละจุด ซึ่งทำให้จังหวะห่างของฟอร์มไม่สม่ำเสมอ */
.field-gap { margin-top: 10px; }

td .btn { margin-top: 0; }

.flash {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 13.5px;
    font-weight: 600;
}

.flash-success { background: var(--success-bg); color: var(--success-text); }
.flash-error { background: #fbe1e1; color: #a3312e; }

.locked-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.locked-banner .btn {
    margin-top: 0;
    flex-shrink: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 10px;
    font-size: 13px;
    overflow: hidden;
}

th, td {
    text-align: left;
    padding: 7px 10px;
    border-bottom: 1px solid #f0f1f5;
}

th {
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    border-bottom: 2px solid #eef0f5;
}

tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: #f8f9fc; }
tbody tr:last-child td { border-bottom: none; }

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.status-pending { background: #eee; color: #666; }
.status-progress { background: #fff3cd; color: #8a6400; }
.status-done { background: var(--success-bg); color: var(--success-text); }
.status-warn { background: #fdecea; color: #b3261e; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}
.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--card-border);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.stat-card .stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; color: var(--ink); }
.stat-card .stat-compare { font-size: 12px; margin-top: 4px; }
.stat-compare.up { color: var(--success-text); }
.stat-compare.down { color: #b3261e; }
.stat-compare.flat { color: var(--muted); }

.dept-health-bar {
    display: inline-block;
    width: 60px;
    height: 6px;
    border-radius: 4px;
    background: #eee;
    overflow: hidden;
    vertical-align: middle;
    margin-right: 6px;
}
.dept-health-fill { height: 100%; border-radius: 4px; }

.auth-bg {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #0f1730 0%, #2a3577 45%, #4c3fc7 75%, #5a4fe0 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 20px;
    padding: 36px 32px 28px;
    box-shadow: 0 20px 60px rgba(15, 23, 48, 0.35);
    text-align: center;
}

.auth-logo {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    display: block;
}

.auth-card h1 {
    margin: 0 0 4px;
    font-size: 24px;
}

.auth-subtitle {
    color: #666;
    font-size: 15px;
    margin: 0 0 24px;
}

.auth-card label {
    text-align: left;
    font-size: 15px;
    margin-top: 16px;
}

.auth-card input[type=text], .auth-card input[type=password] {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.password-field {
    position: relative;
}

.password-field input {
    padding-right: 46px;
}

.password-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #888;
    display: flex;
    align-items: center;
}

.password-toggle:hover { color: #444; }

.auth-card .btn {
    width: 100%;
    margin-top: 22px;
    background: linear-gradient(135deg, var(--accent) 0%, #7c5cf0 100%);
    padding: 15px;
    font-weight: 600;
}

.auth-card .btn:hover {
    background: linear-gradient(135deg, var(--accent-hover) 0%, #6a4bdb 100%);
}

.auth-footer {
    margin-top: 22px;
    color: #999;
    font-size: 13px;
}

.help-text {
    color: #666;
    font-size: 12px;
    margin-top: 3px;
}

@media (max-width: 1024px) {
    h1 { font-size: 20px; }
    h2 { font-size: 17px; }
    .btn { padding: 10px 16px; font-size: 14px; }
    label { font-size: 13px; }
    input[type=text], input[type=number], input[type=date], input[type=password],
    select, textarea {
        font-size: 14px;
        padding: 9px 11px;
    }
    .card { padding: 18px; }
    .container { padding: 18px 16px 60px; }

    table, thead, tbody, th { display: block; }
    thead { display: none; }
    tr {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        margin-bottom: 14px;
        border: 1px solid #eee;
        border-radius: 8px;
        overflow: hidden;
    }
    td {
        display: block;
        border-bottom: none;
        padding: 8px 10px;
    }
    /* ฟิลด์ข้อความยาวให้กินเต็มแถว ส่วนฟิลด์ปุ่ม (เดี่ยวหรือกลุ่ม) ให้ไหลต่อกันเป็นกลุ่มเดียวกัน
       ไม่บังคับขึ้นแถวใหม่ เพื่อไม่ให้ปุ่ม "บันทึก" แยกอยู่คนละบรรทัดกับปุ่มอื่นๆ ของแถวเดียวกัน */
    td:has(.help-text) { grid-column: 1 / -1; }
    td[data-label=""] { align-self: end; }
    td:last-child .inline-form { justify-content: flex-start; }
    td::before {
        content: attr(data-label);
        display: block;
        font-weight: 700;
        color: var(--navy-dark);
        margin-bottom: 4px;
    }
    td[data-label=""]::before { content: none; margin-bottom: 0; }
}

@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100vh;
        transform: translateX(-100%);
        box-shadow: none;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.25);
    }
    .sidebar-overlay.open {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 48, 0.5);
        z-index: 190;
    }
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 14px;
        background: linear-gradient(120deg, var(--navy-dark) 0%, var(--navy-darker) 100%);
        color: #fff;
        padding: 14px 18px;
        position: sticky;
        top: 0;
        z-index: 150;
    }
    .sidebar-toggle {
        background: none;
        border: none;
        color: #fff;
        cursor: pointer;
        padding: 4px;
        display: flex;
        align-items: center;
    }
    .mobile-topbar-title {
        font-weight: 700;
        font-size: 17px;
    }
}

@media (max-width: 600px) {
    body { font-size: 15px; }
    .btn {
        padding: 9px 14px;
        font-size: 13px;
        border-radius: 10px;
    }
    .btn-group { gap: 8px; }

    .goal-item-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .goal-item-desc {
        white-space: normal;
        max-width: 100%;
    }
    .goal-item-meta {
        width: 100%;
        justify-content: space-between;
    }
}
