:root {
    /* ธีมมหาวิทยาลัยเกษตรศาสตร์ (KU) — เขียว/เหลือง */
    --primary: #006664;        /* เขียว KU */
    --primary-dark: #004f4d;
    --accent: #ffd800;         /* เหลือง KU */
    --accent-2: #b2bb1e;       /* เขียวมะกอก KU */
    --bg: #f0f1f2;
    --card: #ffffff;
    --text: #222221;
    --muted: #5f6b66;
    --border: #e2e6e4;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
    --radius: 12px;
}

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

body {
    font-family: 'Prompt', 'Sarabun', 'Segoe UI', Tahoma, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 15px;
}

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

/* ---------- Header / Nav ---------- */
.navbar {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: var(--shadow);
    border-bottom: 3px solid var(--accent);
}
.navbar-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px 16px;
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand a { color: #fff; font-weight: 700; font-size: 1.15rem; text-decoration: none; }
.brand .brand-icon { font-size: 1.6rem; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-sub { color: #ffe873; font-size: .72rem; font-weight: 500; }
.navbar nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.navbar nav a { display: inline-flex; align-items: center; gap: 6px; color: #d9ecea; padding: 6px 11px; border-radius: 8px; text-decoration: none; font-size: .95rem; }
.nav-ico { width: 17px; height: 17px; flex-shrink: 0; }
.navbar nav a:hover { background: rgba(255, 255, 255, .15); text-decoration: none; }
.navbar nav a.active { background: rgba(255, 255, 255, .18); color: #fff; font-weight: 600; box-shadow: inset 0 -3px 0 var(--accent); }
.user-box { display: flex; align-items: center; gap: 10px; margin-inline-start: auto; }
.user-box .user-name { color: #fff; font-size: .9rem; font-weight: 600; }
.btn-logout {
    background: rgba(255, 255, 255, .15); color: #fff; border: 1px solid rgba(255, 255, 255, .35);
    padding: 6px 12px; border-radius: 8px; font-size: .85rem; cursor: pointer; font-family: inherit;
}
.btn-logout:hover { background: rgba(255, 255, 255, .28); }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 20px; background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}
.login-card { background: #fff; border-radius: 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); padding: 32px; width: 100%; max-width: 400px; }
.login-head { text-align: center; margin-bottom: 22px; }
.login-head .icon { font-size: 2.4rem; }
.login-head h1 { font-size: 1.3rem; margin-top: 8px; }
.login-head p { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.login-hint { margin-top: 18px; padding: 12px; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; font-size: .82rem; color: var(--muted); }
.login-hint code { background: #eef2ff; color: #4338ca; padding: 1px 5px; border-radius: 4px; }

/* ---------- Layout ---------- */
.container { max-width: 1120px; margin: 0 auto; padding: 28px 20px; }
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head h1 { font-size: 1.5rem; font-weight: 700; }
.page-head .subtitle { color: var(--muted); font-size: .9rem; margin-top: 2px; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.card h2 { font-size: 1.05rem; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 16px; border-radius: 9px; border: 1px solid transparent;
    font-size: .92rem; font-weight: 600; cursor: pointer; text-decoration: none;
    transition: filter .15s, background .15s; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-danger { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.btn-success { background: #16a34a; color: #fff; }
.btn-sm { padding: 5px 11px; font-size: .82rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: .92rem; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-error ul { margin: 4px 0 0 18px; }

/* ---------- Stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 16px; box-shadow: var(--shadow); text-decoration: none; color: var(--text);
    display: block; transition: transform .1s, box-shadow .1s;
}
.stat:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.09); }
.stat .num { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.stat.active { outline: 2px solid var(--primary); }
.stat .num.warn { color: #b45309; }

/* ---------- Dashboard ---------- */
.dash-title { font-size: .95rem; color: var(--muted); font-weight: 600; margin: 24px 0 10px; }
.dept-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.dept-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 14px 16px; text-decoration: none; color: var(--text); display: block;
    transition: transform .1s, box-shadow .1s; cursor: pointer;
}
.dept-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.dept-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0, 0, 0, .09); }
.dept-card .dept-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dept-card .dept-name { font-weight: 600; font-size: .95rem; }
.dept-meta { display: flex; gap: 16px; margin-top: 10px; font-size: .85rem; color: var(--muted); }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row .bar-label { font-size: .85rem; width: 100px; color: var(--muted); }
.bar-track { flex: 1; height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-row .bar-val { font-size: .85rem; width: 26px; text-align: right; font-weight: 600; }

.person-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.person-row:last-child { border-bottom: none; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; background: #dcecea; color: #004f4d;
    display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .8rem; flex-shrink: 0;
}
.person-row .p-name { font-size: .9rem; }
.person-row .p-sub { font-size: .78rem; color: var(--muted); }
.due-row { display: flex; justify-content: space-between; gap: 10px; font-size: .85rem; padding: 5px 0; }
.due-date { color: var(--muted); white-space: nowrap; }
.due-date.overdue { color: #b45309; font-weight: 600; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 15px 16px; display: flex; align-items: center; gap: 14px;
}
.kpi-ico { width: 46px; height: 46px; border-radius: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.kpi-ico svg { width: 23px; height: 23px; }
.kpi-num { font-size: 1.7rem; font-weight: 700; line-height: 1.05; }
.kpi-num.warn { color: #b45309; }
.kpi-lbl { color: var(--muted); font-size: .85rem; margin-top: 1px; }
.kpi-ico.k-g { background: #dcecea; color: #006664; }
.kpi-ico.k-b { background: #dbeafe; color: #1d4ed8; }
.kpi-ico.k-p { background: #e6e3fb; color: #4338ca; }
.kpi-ico.k-a { background: #fde9c8; color: #b45309; }
.head-ico { width: 18px; height: 18px; vertical-align: -3px; margin-inline-end: 7px; color: var(--primary); }
.meta-ico { width: 14px; height: 14px; vertical-align: -2px; margin-inline-end: 3px; }

/* ---------- ขอบเขตงาน (scope) ---------- */
.scope-head { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.scope-head .s-name { font-weight: 600; font-size: 1.02rem; }
.scope-head .s-owner { margin-inline-start: auto; font-size: .82rem; color: var(--muted); }
.scope-group { margin-bottom: 14px; }
.scope-group:last-child { margin-bottom: 0; }
.scope-group-label { display: inline-block; font-size: .78rem; font-weight: 600; padding: 3px 11px; border-radius: 999px; margin-bottom: 8px; }
.scope-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.scope-row:last-child { border-bottom: none; }
.scope-title { font-size: .92rem; }
.scope-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 4px; font-size: .8rem; color: var(--muted); }
.scope-ico { width: 13px; height: 13px; vertical-align: -2px; margin-inline-end: 3px; }
.scope-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- Modal / Popup ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, .5);
    align-items: center; justify-content: center; padding: 20px; z-index: 1000;
    display: none;
}
.modal-overlay.is-open { display: flex; }
.modal-box {
    background: var(--card); border-radius: 14px; width: 100%; max-width: 560px; max-height: 85vh;
    display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 18px; background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff; border-bottom: 3px solid var(--accent);
}
.modal-head h3 { font-size: 1.05rem; font-weight: 600; }
.modal-close {
    background: rgba(255, 255, 255, .18); color: #fff; border: none; border-radius: 8px;
    width: 30px; height: 30px; font-size: 1rem; line-height: 1; cursor: pointer; flex-shrink: 0;
}
.modal-close:hover { background: rgba(255, 255, 255, .3); }
.modal-body { padding: 16px 18px; overflow-y: auto; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: .82rem; white-space: nowrap; }
tbody tr:hover { background: #f8fafc; }
td.mono, .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: .85rem; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    font-size: .78rem; font-weight: 600; white-space: nowrap;
}
.badge--blue   { background: #dbeafe; color: #1d4ed8; }
.badge--indigo { background: #e0e7ff; color: #4338ca; }
.badge--amber  { background: #fef3c7; color: #b45309; }
.badge--green  { background: #dcfce7; color: #15803d; }
.badge--gray   { background: #e2e8f0; color: #475569; }
.badge--red    { background: #fee2e2; color: #b91c1c; }
.badge--orange { background: #ffedd5; color: #c2410c; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-group { margin-bottom: 4px; }
.form-group.full { grid-column: 1 / -1; }
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
label .req { color: #dc2626; }
input, select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px;
    font-family: inherit; font-size: .92rem; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 102, 100, .15);
}
textarea { resize: vertical; min-height: 90px; }
.field-error { color: #dc2626; font-size: .82rem; margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.help { color: var(--muted); font-size: .82rem; }

/* ---------- Filter bar ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .form-group { margin: 0; }
.filters .form-group.grow { flex: 1; min-width: 180px; }

/* ---------- Detail (definition list) ---------- */
.detail { display: grid; grid-template-columns: 160px 1fr; gap: 10px 16px; }
.detail dt { color: var(--muted); font-size: .88rem; }
.detail dd { font-weight: 500; }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }

.row-actions { display: inline-flex; gap: 6px; align-items: center; }
.row-actions form { display: inline; }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty .big { font-size: 2.4rem; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 20px; }
.pagination .info { color: var(--muted); font-size: .88rem; }

hr.sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.text-muted { color: var(--muted); }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }

@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .two-col { grid-template-columns: 1fr; }
    .detail { grid-template-columns: 1fr; gap: 2px 0; }
    .detail dd { margin-bottom: 8px; }
    .page-head h1 { font-size: 1.25rem; }
}
