:root {
  --orange: #f97316;
  --orange-dark: #c2410c;
  --amber: #fbbf24;
  --ink: #172033;
  --navy: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --soft: #fff7ed;
  --white: #ffffff;
  --danger: #b91c1c;
  font-family: "Tahoma", "Noto Sans Thai", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: #fffaf5; line-height: 1.65; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, .primary, .secondary, .tip-button, .login-button {
  border: 0; border-radius: 8px; padding: .75rem 1rem; cursor: pointer; font-weight: 700;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.topbar {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 420px) auto; gap: 1rem; align-items: center;
  padding: 1rem clamp(1rem, 4vw, 3rem); background: var(--white); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; gap: .85rem; align-items: center; }
.brand strong { display: block; font-size: clamp(1rem, 2vw, 1.35rem); }
.brand small { color: var(--muted); }
.brand > span:last-child { min-width: 0; }
.brand .brand-motto { display: block; margin-top: .25rem; color: var(--orange-dark); font-size: .85rem; font-weight: 700; line-height: 1.65; overflow-wrap: anywhere; }
.crest {
  flex-shrink: 0;
  width: 54px; height: 54px; display: grid; place-items: center; border-radius: 50%;
  color: #fff; font-weight: 800; font-size: 1.35rem;
  background: radial-gradient(circle at 35% 25%, var(--amber), var(--orange) 45%, var(--orange-dark));
  box-shadow: 0 10px 25px rgba(249,115,22,.22);
}
.search { display: flex; gap: .5rem; }
.search input, input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: .75rem .85rem; background: #fff;
}
textarea { min-height: 130px; grid-column: 1 / -1; resize: vertical; }
.header-actions { display: flex; gap: .6rem; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.search button, form button, .primary, .tip-button { background: var(--orange); color: #fff; }
.login-button { background: #fff7ed; color: var(--orange-dark); border: 1px solid #fdba74; white-space: nowrap; }
.login-button:hover, .login-button:focus { background: #ffedd5; }
.secondary { background: #fff; color: var(--orange-dark); border: 1px solid #fed7aa; }
.nav { background: var(--navy); color: #fff; padding: 0 clamp(1rem, 4vw, 3rem); }
.nav-toggle { display: none; background: transparent; color: #fff; }
.nav-links { display: flex; gap: .15rem; flex-wrap: wrap; }
.nav a { padding: .85rem 1rem; color: #fff; }
.nav a:hover, .nav a:focus { background: rgba(255,255,255,.12); }
.hero {
  min-height: 520px; display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 2rem; align-items: center;
  padding: clamp(2rem, 5vw, 5rem) clamp(1rem, 4vw, 3rem) clamp(4rem, 8vw, 6.5rem);
  background:
    linear-gradient(120deg, rgba(23,32,51,.93), rgba(124,45,18,.72)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='520' viewBox='0 0 900 520'%3E%3Crect width='900' height='520' fill='%23f97316'/%3E%3Cpath d='M0 420 C180 340 250 500 440 400 C620 305 710 340 900 250 L900 520 L0 520Z' fill='%23fff7ed' fill-opacity='.28'/%3E%3Cpath d='M0 80 C150 140 260 40 410 110 C575 185 705 50 900 120 L900 0 L0 0Z' fill='%231e293b' fill-opacity='.30'/%3E%3C/svg%3E");
  color: #fff; background-size: cover;
}
.eyebrow, .pill { color: var(--orange-dark); background: #ffedd5; border-radius: 999px; padding: .25rem .7rem; display: inline-block; font-weight: 700; }
.hero .eyebrow { color: #fff; background: rgba(255,255,255,.18); }
.hero h1 { font-size: clamp(2.2rem, 5vw, 4.8rem); line-height: 1.08; margin: 1rem 0; letter-spacing: 0; max-width: 900px; }
.hero p { font-size: 1.18rem; max-width: 720px; }
.hero-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.4rem; }
.hero-panel {
  background: rgba(255,255,255,.94); color: var(--ink); border-radius: 8px; padding: 1.4rem; box-shadow: 0 20px 60px rgba(15,23,42,.22);
  display: grid; grid-template-columns: 1fr 132px; gap: 1rem; align-items: center;
}
.hero-panel strong { color: var(--danger); font-size: 4rem; line-height: 1; display: block; }
.tip-qr {
  display: grid; gap: .45rem; justify-items: center; text-align: center; color: var(--orange-dark);
  font-weight: 800; font-size: .9rem;
}
.tip-qr img {
  width: 132px; height: 132px; border-radius: 8px; border: 6px solid #fff; background: #fff;
  box-shadow: 0 10px 24px rgba(15,23,42,.12);
}
.leader-stage {
  display: grid; grid-template-columns: minmax(280px, 370px) 1fr; gap: clamp(1.2rem, 4vw, 3rem); align-items: stretch;
  max-width: 1180px; margin: 0 auto; padding: clamp(1.6rem, 4vw, 3rem) 1rem clamp(1.8rem, 5vw, 4rem); position: relative; z-index: 3;
}
.leader-card {
  background: linear-gradient(180deg, #fff 0%, #fff7ed 100%); border-radius: 8px; padding: 1rem; text-align: center;
  box-shadow: 0 22px 60px rgba(15,23,42,.20); border: 1px solid #fed7aa; display: grid; gap: .9rem;
}
.leader-label {
  color: #8b1d10; font-size: 1.65rem; line-height: 1.25; font-weight: 800;
}
.leader-photo {
  background: #f3f4f6; border: 8px solid #e5e7eb; aspect-ratio: 4 / 5; display: grid; place-items: center; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(15,23,42,.06);
}
.leader-photo img, .person-photo {
  width: 100%; height: 100%; object-fit: cover; object-position: center top; display: block;
}
.leader-placeholder {
  width: 100%; height: 100%; display: grid; place-items: center; align-content: center; gap: .25rem;
  color: var(--muted); background: linear-gradient(135deg, #f8fafc, #e2e8f0); font-weight: 700;
}
.leader-placeholder span { font-size: 1.2rem; }
.leader-placeholder small { color: #94a3b8; }
.leader-nameplate {
  padding: .25rem .5rem .4rem;
}
.leader-nameplate h3 { color: #8b1d10; margin: 0; font-size: 1.25rem; line-height: 1.35; }
.leader-nameplate p { margin: .25rem 0 0; color: #7f1d1d; font-weight: 700; }
.leader-copy {
  color: #fff; background:
    linear-gradient(110deg, rgba(30,41,59,.96), rgba(124,45,18,.88) 62%, rgba(194,65,12,.88)),
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,0));
  border-radius: 8px; padding: clamp(1.5rem, 4vw, 3rem); box-shadow: 0 22px 60px rgba(15,23,42,.16);
  display: flex; flex-direction: column; justify-content: center; position: relative; overflow: hidden;
}
.leader-copy::after {
  content: ""; position: absolute; right: -90px; bottom: -120px; width: 360px; height: 240px;
  background: rgba(251,191,36,.18); transform: rotate(-18deg); border-radius: 40px;
}
.leader-copy > * { position: relative; z-index: 1; }
.leader-copy h2 { font-size: clamp(2rem, 5vw, 4.2rem); line-height: 1.1; margin: .85rem 0; letter-spacing: 0; }
.leader-copy p:not(.eyebrow) { max-width: 760px; font-size: 1.08rem; }
.leader-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; }
.leader-actions a { display: inline-block; }
.section, .page-title { max-width: 1180px; margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) 1rem; }
.page-content-tools { padding-top: .5rem; padding-bottom: .5rem; text-align: right; }
.page-content-tools a { display: inline-block; }
.page-title { text-align: center; }
.page-title h1 { font-size: clamp(2rem, 4vw, 3.25rem); margin-bottom: .4rem; }
.section-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.two-col { display: grid; grid-template-columns: 1.4fr .6fr; gap: 1rem; align-items: start; }
.cards, .content-grid, .people, .stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.content-grid, .people { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card, .feature-card, .notice, .person, .stats-grid article, .panel, .contact-card, .form-card, .result-card, .success-box {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 1.2rem; box-shadow: 0 8px 26px rgba(15,23,42,.06);
}
.card h2, .card h3, .feature-card h3 { margin-top: .7rem; }
.stats-grid { max-width: 1180px; margin: -2rem auto 0; padding: 0 1rem; position: relative; z-index: 2; }
.stats-grid article strong { display: block; color: var(--orange-dark); font-size: 2rem; }
.quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.quick a { background: var(--navy); color: #fff; padding: 1rem; border-radius: 8px; font-weight: 700; }
.services { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.danger { color: var(--danger); font-weight: 700; }
.banner-list { display: grid; gap: 1rem; }
.avatar { width: 86px; height: 86px; border-radius: 50%; background: var(--soft); color: var(--orange-dark); display: grid; place-items: center; font-size: 2rem; font-weight: 800; }
.person { text-align: center; display: grid; gap: .45rem; align-content: start; }
.person-photo { aspect-ratio: 4 / 5; border-radius: 4px; background: #f1f5f9; margin-bottom: .5rem; border: 8px solid #f3f4f6; }
.person h2 { color: #8b1d10; margin: .1rem 0; line-height: 1.35; }
.person small { color: var(--orange-dark); font-weight: 800; }
.person p { margin: 0; color: var(--muted); }
.person .avatar { margin: 0 auto 1rem; }
.empty-state { grid-column: 1 / -1; }
.filter, .form-grid, .identity-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.form-card.wide { max-width: 980px; display: grid; gap: 1rem; }
.form-card.login {
  max-width: 420px;
  display: grid;
  gap: .9rem;
  padding: 1.4rem;
  margin-bottom: clamp(3rem, 8vw, 6rem);
}
.form-card.login input {
  padding: .7rem .85rem;
}
.form-card.login button {
  justify-self: start;
}
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 1rem; }
.identity-fields { display: none; }
body.identified .identity-fields { display: grid; }
.check { display: block; }
.hint { color: var(--muted); margin: .5rem 0 0; }
.success-box strong { display: block; font-size: 1.35rem; color: var(--orange-dark); }
.admin-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 70vh; }
.admin-side { background: #111827; color: #fff; padding: 1.2rem; display: flex; flex-direction: column; gap: .6rem; }
.admin-side a { padding: .75rem; border-radius: 8px; background: rgba(255,255,255,.08); }
.admin-main { padding: clamp(1rem, 3vw, 2rem); min-width: 0; }
.admin-side a[aria-current="page"] { background: var(--orange-dark); }
.chief-editor { display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 620px); gap: 1.2rem; align-items: start; margin-top: 1.5rem; }
.chief-preview { display: grid; gap: .8rem; text-align: center; }
.chief-preview h2 { margin: 0; text-align: left; }
.chief-preview img, .chief-photo-empty { display: grid; place-items: center; width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 8px; background: #f1f5f9; color: var(--muted); }
.chief-preview strong { font-size: 1.15rem; }
.chief-preview span { color: var(--muted); }
.chief-form { display: grid; gap: 1rem; }
.chief-form h2 { margin: 0; }
.chief-name-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.chief-form .cms-actions { margin-top: .25rem; }
.cms-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; padding: 1.5rem 0; margin-bottom: 1.5rem; border-bottom: 1px solid var(--line); }
.cms-form h2, .cms-wide { grid-column: 1 / -1; }
.cms-field { display: grid; gap: .4rem; align-content: start; min-width: 0; }
.cms-field > label { font-weight: 700; }
.cms-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .6rem; }
.user-search { display: flex; gap: .6rem; max-width: 560px; margin: 1.5rem 0; }
.user-duty { min-width: 180px; max-width: 280px; white-space: pre-wrap; overflow-wrap: anywhere; }
.kpi-form { max-width: 900px; }
.kpi-picker { max-width: 100%; }
.kpi-picker-label { font-weight: 700; }
.kpi-dropdown { position: relative; }
.kpi-dropdown summary { display: flex; justify-content: space-between; align-items: center; gap: 1rem; list-style: none; padding: .7rem .85rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.kpi-dropdown summary::-webkit-details-marker { display: none; }
.kpi-dropdown summary::after { content: '⌄'; font-size: 1.25rem; margin-left: auto; line-height: 1; }
.kpi-dropdown[open] summary { border-color: var(--orange-dark); }
.kpi-dropdown[open] summary::after { transform: rotate(180deg); }
.kpi-dropdown-count { color: var(--muted); margin-left: auto; white-space: nowrap; }
.kpi-dropdown-panel { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30; padding: .7rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 16px 36px rgba(15,23,42,.16); }
.kpi-user-search { width: 100%; }
.kpi-search-results:not(:empty) { max-height: 260px; overflow-y: auto; margin-top: .55rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.kpi-search-result { display: flex; align-items: center; gap: .65rem; width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: #fff; color: var(--ink); text-align: left; padding: .65rem .85rem; }
.kpi-search-result:last-child { border-bottom: 0; }
.kpi-search-result:hover, .kpi-search-result:focus-visible { background: var(--soft); }
.kpi-search-result:disabled { color: var(--muted); background: #f8fafc; cursor: default; }
.kpi-result-mark { display: grid; place-items: center; flex: none; width: 1.25rem; height: 1.25rem; border: 1px solid #94a3b8; border-radius: 4px; color: #fff; font-size: .95rem; line-height: 1; }
.kpi-search-result[aria-checked="true"] .kpi-result-mark { background: var(--orange-dark); border-color: var(--orange-dark); }
.kpi-search-result small, .kpi-selected-user small { display: block; color: var(--muted); font-size: .85rem; }
.kpi-search-message { margin: 0; padding: .7rem .85rem; color: var(--muted); }
.kpi-selected-head { margin-top: .6rem; }
.kpi-selected-users { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .5rem; max-height: 270px; overflow-y: auto; }
.kpi-selected-users:empty::before { content: 'ยังไม่ได้เลือกผู้รับมอบหมาย'; color: var(--muted); padding: .55rem 0; }
.kpi-selected-user { display: flex; align-items: center; justify-content: space-between; gap: .7rem; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 0; }
.kpi-selected-user > span { min-width: 0; overflow-wrap: anywhere; }
.kpi-remove-user { padding: .35rem .6rem; color: var(--danger); background: #fff; border: 1px solid #fecaca; flex: none; }
@media (max-width: 620px) { .kpi-dropdown-panel { position: static; margin-top: .35rem; box-shadow: none; } }
.kpi-list { display: grid; gap: 1rem; }
.kpi-task { max-width: 1000px; }
.kpi-task-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: start; gap: .75rem; }
.kpi-task-head h3 { margin: 0; overflow-wrap: anywhere; }
.kpi-task-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.kpi-edit-link { display: inline-block; padding: .35rem .7rem; }
.kpi-meta { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin-top: .75rem; color: var(--muted); }
.kpi-note { margin: 1rem 0 0; white-space: normal; overflow-wrap: anywhere; }
.kpi-assignees { display: grid; gap: .75rem; margin-top: 1rem; }
.kpi-assignee { padding: .85rem 1rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.kpi-assignee > strong { display: inline-block; margin-right: .75rem; }
.kpi-person-status { color: var(--muted); }
.kpi-open { background: #fff7ed; color: #9a3412; }
.kpi-closed { background: #ecfdf5; color: #065f46; }
.kpi-close-form { display: grid; grid-template-columns: minmax(0, 1fr) 210px auto; gap: .75rem; align-items: end; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.kpi-close-form button { white-space: nowrap; }
@media (max-width: 760px) { .kpi-close-form { grid-template-columns: 1fr; } .kpi-close-form button { justify-self: start; } }
.account-profile { max-width: 680px; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.password-form { display: grid; gap: 1rem; max-width: 460px; padding: 1rem 0 3rem; }
.cms-preview { width: 160px; height: 120px; object-fit: contain; background: #fff; }
.content-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.card, .feature-card { min-width: 0; overflow-wrap: anywhere; }
.news-thumbnail { display: block; width: 100%; max-width: 100%; height: 180px; object-fit: contain; background: #fff; margin-bottom: 1rem; }
.news-detail { max-width: 900px; }
.news-cover { display: block; width: 100%; max-width: 640px; height: 360px; object-fit: contain; margin: 0 auto 1.5rem; }
.news-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.news-gallery a { min-width: 0; }
.news-gallery img { display: block; width: 100%; max-width: 100%; height: 220px; object-fit: contain; background: #fff; }
.news-image-manager { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 180px)); gap: 1rem; }
.news-image-item { display: grid; gap: .5rem; }
.news-image-item img { width: 100%; height: 120px; object-fit: contain; background: #fff; }
@media (max-width: 620px) {
  .news-gallery { grid-template-columns: 1fr; }
  .news-cover { height: 240px; }
  .news-gallery img { height: 180px; }
}
.document-list { display: grid; }
.document-list a { display: grid; gap: .3rem; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.document-list span { color: var(--muted); }
@media (max-width: 620px) { .cms-form { grid-template-columns: 1fr; } }
.admin-form { align-items: end; }
.admin-leaders { display: grid; gap: 1rem; }
.admin-leader {
  display: grid; grid-template-columns: 92px 1fr auto; gap: 1rem; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; padding: 1rem; background: #fff;
}
.admin-leader img { width: 92px; height: 116px; object-fit: cover; border-radius: 4px; border: 4px solid #f3f4f6; }
.admin-leader h3, .admin-leader p { margin: .1rem 0; }
.danger-button { background: var(--danger); color: #fff; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--soft); }
.inline-form { display: flex; gap: .5rem; min-width: 280px; }
.bars { display: grid; gap: .8rem; }
.bars div { display: grid; grid-template-columns: 180px 1fr; gap: .8rem; align-items: center; }
.bars b { display: block; min-width: 34px; background: linear-gradient(90deg, var(--orange), var(--amber)); color: #431407; border-radius: 8px; padding: .25rem .6rem; }
.flash { max-width: 1180px; margin: 1rem auto; padding: 1rem; border-radius: 8px; background: #ecfeff; border: 1px solid #a5f3fc; }
.footer { display: flex; justify-content: space-between; gap: 1rem; padding: 2rem clamp(1rem, 4vw, 3rem); background: var(--navy); color: #fff; }
.footer a, .footer button { display: block; color: #fff; background: transparent; border: 0; padding: .25rem 0; text-align: left; }

@media (max-width: 900px) {
  .topbar, .hero, .leader-stage, .two-col, .admin-shell, .chief-editor { grid-template-columns: 1fr; }
  .chief-preview { max-width: 300px; }
  .search { order: 3; }
  .header-actions { justify-content: flex-start; }
  .nav-toggle { display: block; }
  .nav-links { display: none; flex-direction: column; }
  .nav-links.open { display: flex; }
  .cards, .content-grid, .people, .quick, .services, .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .footer { flex-direction: column; }
  .leader-stage { margin-top: 0; }
  .leader-copy { min-height: 320px; }
  .hero-panel { grid-template-columns: 1fr auto; }
}

@media (max-width: 620px) {
  .cards, .content-grid, .people, .quick, .services, .stats-grid, .filter, .form-grid, .identity-fields, .chief-name-fields { grid-template-columns: 1fr; }
  .hero h1 { font-size: 2.25rem; }
  .hero-panel { grid-template-columns: 1fr; }
  .tip-qr { justify-items: start; text-align: left; }
  .topbar { position: static; }
  .leader-stage { padding-top: 1rem; }
  .leader-card { max-width: 360px; margin: 0 auto; }
  .leader-copy h2 { font-size: 2rem; }
  .admin-leader { grid-template-columns: 1fr; }
  .admin-leader img { width: 100%; height: auto; aspect-ratio: 4 / 5; }
}

@media print {
  .topbar, .nav, .footer, .admin-side, .tip-button, .login-button { display: none; }
  body { background: #fff; color: #000; }
  .card, .panel { box-shadow: none; }
}
