/* ==========================================================
   KM Library — สไตล์กลางของทุกหน้า
   ใช้ร่วมกับ Bootstrap 5.3 / Font Awesome 6 / Kanit
   ========================================================== */

:root {
  --brand:        #1b57ce;
  --brand-dark:   #0b3b91;
  --brand-light:  #e8efff;
  --accent:       #17a2b8;
  --ink:          #1f2937;
  --muted:        #6b7280;
  --bg:           #f4f6fb;
  --card:         #ffffff;
  --line:         #e6e9f2;
  --radius:       14px;
  --shadow-sm:    0 2px 8px rgba(17, 24, 39, .05);
  --shadow:       0 8px 24px rgba(17, 24, 39, .08);

  --bs-primary:       #1b57ce;
  --bs-primary-rgb:   27, 87, 206;
  --bs-link-color:    #1b57ce;
  --bs-body-font-family: 'Kanit', system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Thai', sans-serif;
}

html { scroll-behavior: smooth; }
body {
  font-family: var(--bs-body-font-family);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6, .fw-bold, .fw-semibold, strong, b, th, .btn { font-weight: 500; }
.fw-bold { font-weight: 600 !important; }
.app-main { flex: 1 0 auto; }

.skip-link { position: absolute; left: 8px; top: 8px; z-index: 2000; background: #fff; padding: 6px 10px; border-radius: 8px; }

/* ---------- ปุ่มหลักตามแบรนด์ ---------- */
.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-dark); --bs-btn-active-border-color: var(--brand-dark); }
.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); --bs-btn-active-border-color: var(--brand); }
.text-primary { color: var(--brand) !important; }
.bg-primary { background-color: var(--brand) !important; }
.btn { border-radius: 10px; }
.btn-sm { border-radius: 8px; }
.form-control, .form-select { border-radius: 10px; border-color: #d9deea; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(27, 87, 206, .15); }
.form-label { font-weight: 500; }
.form-text, .hint { color: var(--muted); font-size: .875rem; }

/* ---------- Navbar ---------- */
.app-navbar {
  background: linear-gradient(100deg, var(--brand-dark) 0%, var(--brand) 60%, #2f6fe4 100%);
  box-shadow: 0 4px 16px rgba(11, 59, 145, .25);
}
.app-navbar .navbar-brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; letter-spacing: .2px; }
.app-navbar .brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: rgba(255,255,255,.18); box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.app-navbar .nav-link { color: rgba(255,255,255,.88); font-weight: 400; border-radius: 8px; padding: .5rem .8rem; }
.app-navbar .nav-link:hover, .app-navbar .nav-link.active { color: #fff; background: rgba(255,255,255,.14); }
.app-navbar .dropdown-menu { border: 0; box-shadow: var(--shadow); border-radius: 12px; }
.btn-nav-user {
  display: inline-flex; align-items: center; gap: .5rem; color: #fff; border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px; padding: .25rem .8rem .25rem .3rem; background: rgba(255,255,255,.1);
}
.btn-nav-user:hover { background: rgba(255,255,255,.2); color: #fff; }
.avatar-circle {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: #fff; color: var(--brand); font-weight: 600; font-size: .9rem;
}
@media (max-width: 991.98px) {
  .app-navbar .navbar-collapse { padding: .5rem 0 1rem; }
  .nav-user { padding-top: .5rem; border-top: 1px solid rgba(255,255,255,.15); margin-top: .25rem; }
}

/* ---------- Role badges ---------- */
.role-writer    { background: #fff4d6; color: #92400e; }
.role-reviewer  { background: #dbeafe; color: #1e3a8a; }
.role-publisher { background: #dcfce7; color: #166534; }
.role-admin     { background: #fee2e2; color: #991b1b; }

/* ---------- Page header / hero ---------- */
.page-header { padding: 1.75rem 0 1rem; }
.page-header h1 { font-size: clamp(1.4rem, 2.5vw, 1.9rem); margin: 0; font-weight: 600; }
.page-header .lead { color: var(--muted); font-size: 1rem; margin: .25rem 0 0; }

.hero-card {
  background: linear-gradient(120deg, var(--brand-dark), var(--brand) 70%, #2f6fe4);
  color: #fff; border-radius: 18px; padding: clamp(1.25rem, 3vw, 2rem);
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.hero-card::after {
  content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px;
  border-radius: 50%; background: rgba(255,255,255,.08);
}
.hero-card h1, .hero-card h2 { font-weight: 600; }
.hero-card .opacity-75 { opacity: .8; }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-header { background: #fff; border-bottom: 1px solid var(--line); font-weight: 500; border-radius: var(--radius) var(--radius) 0 0 !important; }
.card-header i { color: var(--brand); }
.section-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--line); padding: 1.25rem; }

/* ---------- Stat cards ---------- */
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm);
  border: 1px solid var(--line); border-left: 5px solid var(--stat-color, var(--brand));
  position: relative; overflow: hidden; height: 100%; transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat-card .stat-label { color: var(--muted); font-size: .85rem; }
.stat-card .stat-value { font-size: 1.9rem; font-weight: 600; line-height: 1.1; color: var(--stat-color, var(--brand)); }
.stat-card .stat-icon { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 2.2rem; opacity: .12; color: var(--stat-color, var(--brand)); }

/* ---------- Article cards (คลังบทความ) ---------- */
.card-article {
  background: var(--card); border-radius: var(--radius); border: 1px solid var(--line);
  overflow: hidden; height: 100%; display: flex; flex-direction: column;
  box-shadow: var(--shadow-sm); transition: transform .25s, box-shadow .25s;
}
.card-article:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.article-thumb { display: block; position: relative; padding-top: 56.25%; background: #e9edf5; overflow: hidden; }
.article-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform .5s; }
.article-thumb .thumb-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #b3bdd1; font-size: 2.5rem; }
.card-article:hover .article-thumb img { transform: scale(1.04); }
.card-article .card-body { padding: 1rem 1.1rem; flex: 1; display: flex; flex-direction: column; }
.article-title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-weight: 500; font-size: 1.05rem; line-height: 1.5; color: var(--ink); text-decoration: none; margin-bottom: .5rem;
}
.article-title:hover { color: var(--brand); }
.meta-info { margin-top: auto; padding-top: .75rem; border-top: 1px solid var(--line); font-size: .82rem; color: var(--muted); display: flex; justify-content: space-between; gap: .5rem; }

/* ---------- Chips / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: .35rem; background: var(--brand-light); color: var(--brand-dark);
  border-radius: 999px; padding: .25rem .7rem; font-size: .8rem; margin: 0 .3rem .3rem 0; text-decoration: none; border: 1px solid transparent;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip-cat { background: #e0f2fe; color: #075985; }
.chip-act { background: #dcfce7; color: #166534; }
.chip-dep { background: #fef3c7; color: #92400e; }
.chip-key { background: #f3f4f6; color: #374151; }
.chip-warn { background: #fff4d6; color: #92400e; }
.badge { font-weight: 500; }

/* ---------- Filter / search bar ---------- */
.search-bar { background: var(--card); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.check-list {
  max-height: 180px; overflow: auto; border: 1px solid #d9deea; border-radius: 10px; padding: .5rem .75rem; background: #fff;
}
.check-list .form-check { margin-bottom: .2rem; }
.check-list .form-check-label { font-size: .92rem; }

/* ---------- Tables ---------- */
.table-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--line); overflow: hidden; }
.table-card .table { margin-bottom: 0; }
.table > :not(caption) > * > * { vertical-align: middle; }
.table thead th { font-weight: 500; color: var(--muted); font-size: .85rem; background: #f8f9fc; white-space: nowrap; }
.table-hover > tbody > tr:hover > * { background: #f5f8ff; }
.action-group { display: flex; flex-wrap: wrap; gap: .35rem; }
.action-group .btn { white-space: nowrap; }

/* ---------- Tabs (แดชบอร์ด) ---------- */
.dash-tabs { display: flex; gap: .25rem; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.dash-tabs .nav-link {
  white-space: nowrap; color: var(--muted); border: 0; border-bottom: 3px solid transparent; border-radius: 10px 10px 0 0; padding: .7rem 1rem; font-weight: 400;
}
.dash-tabs .nav-link:hover { color: var(--brand); background: #fff; }
.dash-tabs .nav-link.active { color: var(--brand); background: #fff; border-bottom-color: var(--brand); font-weight: 500; }
.tab-content-card { background: var(--card); border-radius: 0 var(--radius) var(--radius) var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--line); padding: 1.25rem; }
@media (max-width: 575.98px) { .tab-content-card { padding: .9rem; border-radius: 0 0 var(--radius) var(--radius); } }

/* ---------- Article page ---------- */
.article-wrap { background: var(--card); border-radius: 18px; border: 1px solid var(--line); box-shadow: var(--shadow-sm); overflow: hidden; }
.hero-cover { width: 100%; max-height: 420px; object-fit: cover; display: block; }
.article-body { padding: clamp(1.1rem, 3vw, 2.5rem); }
.article-heading { font-size: clamp(1.4rem, 3vw, 2rem); font-weight: 600; line-height: 1.4; }
.article-content { font-size: 1.05rem; line-height: 1.9; font-weight: 300; word-break: break-word; }
.article-content img { max-width: 100% !important; height: auto !important; border-radius: 10px; }
.article-content table { max-width: 100%; }
.article-content iframe { max-width: 100%; }
.media-section { background: #f8f9fc; border-radius: var(--radius); padding: 1.25rem; }
.file-item {
  display: flex; align-items: center; gap: .75rem; padding: .7rem .9rem; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; color: var(--ink); text-decoration: none; transition: background .15s, transform .15s;
}
.file-item:hover { background: #f5f8ff; transform: translateX(3px); color: var(--brand); }
.file-item i.fa-solid:first-child { font-size: 1.4rem; width: 1.6rem; text-align: center; }
.file-item .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

/* ---------- Comments ---------- */
.comment-item { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 1rem; margin-bottom: .75rem; }
.comment-item.is-reply { margin-left: 1rem; border-left: 3px solid var(--brand-light); }
@media (min-width: 768px) { .comment-item.is-reply { margin-left: 3rem; } }
.comment-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand-light); color: var(--brand-dark); display: grid; place-items: center; font-weight: 600; flex: 0 0 38px; }
.comment-body { white-space: pre-line; overflow-wrap: anywhere; }
.reply-form-wrapper { background: #f8f9fc; border: 1px solid var(--line); border-radius: 10px; padding: .9rem; margin-top: .6rem; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- Team page ---------- */
.team-card { background: var(--card); border-radius: 16px; border: 1px solid var(--line); padding: 1.6rem 1.2rem; text-align: center; height: 100%; box-shadow: var(--shadow-sm); transition: transform .25s, box-shadow .25s; }
.team-card:hover { transform: translateY(-6px); box-shadow: var(--shadow); }
.team-card .avatar { width: 140px; height: 140px; border-radius: 50%; object-fit: cover; object-position: top; border: 4px solid #fff; box-shadow: 0 6px 16px rgba(0,0,0,.12); margin-bottom: 1rem; background: #e9edf5; }
.team-card.is-director { border-top: 5px solid #f59e0b; }
.team-card.is-advisor  { border-top: 5px solid #6b7280; }
.team-card.is-dev      { border-top: 5px solid var(--brand); }
.section-title { text-align: center; font-weight: 600; margin-bottom: 1.5rem; position: relative; }
.section-title::after { content: ""; display: block; width: 56px; height: 4px; background: var(--brand); border-radius: 2px; margin: .6rem auto 0; }

/* ---------- Manual ---------- */
.manual-toc { position: sticky; top: 84px; }
.manual-toc .nav-link { color: var(--ink); border-radius: 8px; padding: .5rem .8rem; font-weight: 300; }
.manual-toc .nav-link.active, .manual-toc .nav-link:hover { background: var(--brand-light); color: var(--brand-dark); font-weight: 500; }
.manual-section { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 1.5rem; margin-bottom: 1.25rem; scroll-margin-top: 90px; }
.manual-section h2 { font-size: 1.3rem; font-weight: 600; margin-bottom: 1rem; }
.step-list { counter-reset: step; list-style: none; padding-left: 0; }
.step-list > li { position: relative; padding-left: 2.6rem; margin-bottom: 1rem; }
.step-list > li::before { counter-increment: step; content: counter(step); position: absolute; left: 0; top: 0; width: 1.9rem; height: 1.9rem; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 500; font-size: .9rem; }
.workflow-step { background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--wf-color, var(--brand)); border-radius: 12px; padding: 1.25rem; text-align: center; height: 100%; }
.workflow-arrow { color: #c5cbd8; font-size: 1.5rem; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: clamp(1rem, 3vw, 2rem);
  background: radial-gradient(900px 500px at 10% -10%, rgba(27,87,206,.18), transparent 60%),
              radial-gradient(800px 480px at 100% 0%, rgba(47,111,228,.12), transparent 60%), var(--bg); }
.login-card { max-width: 900px; width: 100%; background: #fff; border-radius: 22px; overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-hero { background: linear-gradient(135deg, var(--brand-dark), var(--brand)); color: #fff; padding: clamp(1.5rem, 3vw, 2.25rem); }
.login-body { padding: clamp(1.25rem, 3vw, 2rem); }
.feature { display: flex; gap: .8rem; align-items: flex-start; color: var(--muted); font-size: .95rem; }
.feature .icon { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px; background: var(--brand-light); color: var(--brand); display: grid; place-items: center; }

/* ---------- Pagination ---------- */
.pagination { flex-wrap: wrap; gap: .25rem; }
.page-link { border-radius: 8px !important; border: 1px solid var(--line); color: var(--ink); }
.page-item.active .page-link { background: var(--brand); border-color: var(--brand); }

/* ---------- Footer ---------- */
.app-footer { background: #fff; border-top: 1px solid var(--line); padding: 1.25rem 0; margin-top: 3rem; font-size: .92rem; }
.footer-link { color: var(--muted); text-decoration: none; }
.footer-link:hover { color: var(--brand); }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state i { font-size: 3rem; opacity: .25; margin-bottom: .75rem; }

/* ---------- Print ---------- */
@media print {
  .app-navbar, .app-footer, .no-print, .btn, .alert { display: none !important; }
  body { background: #fff; }
  .article-wrap, .card { box-shadow: none; border: 0; }
}

/* ---------- Mobile tweaks ---------- */
@media (max-width: 575.98px) {
  .page-header { padding: 1.25rem 0 .75rem; }
  .stat-card .stat-value { font-size: 1.5rem; }
  .table-responsive { border-radius: var(--radius); }
  .btn-group-mobile-stack { flex-direction: column; }
  .btn-group-mobile-stack .btn { width: 100%; }
}
