/* ==========================================================================
   รพ.สต.บ้านท่าข่อย — admin
   ========================================================================== */
:root {
  --ink: #275F49;
  --paper: #E4F2D4;
  --bg: #F3F2ED;
  --white: #FFFFFF;
  --green: #275F49;
  --lime: #E4F2D4;
  --mint: #E4F2D4;
  --coral: #E5482B;
  --amber: #FFE6A3;
  --muted: #66746C;
  --line: #E4E6DC;
  --f-display: "Noto Serif Thai", "Anuphan", system-ui, sans-serif;
  --f-body: "Anuphan", system-ui, sans-serif;
  --r: 16px;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 var(--f-body); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
h1, h2 { font-family: var(--f-display); margin: 0; line-height: 1.3; }
[data-lucide] { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; }
.muted { color: var(--muted); }
.link { color: var(--green); font-weight: 600; display: inline-flex; align-items: center; gap: .3em; }
.link:hover { text-decoration: underline; }

.mark { width: 40px; height: 40px; border-radius: 50%; background: var(--green); display: grid; place-items: center; flex-shrink: 0; }
.mark svg { width: 22px; fill: var(--lime); }
.mark--xl { width: 84px; height: 84px; }
.mark--xl svg { width: 46px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .45em; justify-content: center;
  padding: .7em 1.2em; border-radius: 999px; border: 1.5px solid transparent;
  font: 600 .95rem/1 var(--f-body); cursor: pointer; transition: background .2s, color .2s, transform .2s;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--ink); color: var(--lime); }
.btn--primary:hover { background: var(--green); color: var(--white); }
.btn--ghost { border-color: var(--line); background: var(--white); }
.btn--ghost:hover { border-color: var(--ink); }
.btn--danger { background: #FDE8E4; color: var(--coral); }
.btn--danger:hover { background: var(--coral); color: var(--white); }
.btn--block { width: 100%; padding: 1em; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--ink);
}
.icon-btn:hover { background: var(--bg); }
.icon-btn--danger:hover { background: #FDE8E4; color: var(--coral); }

/* Layout */
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.side {
  background: var(--ink); color: var(--paper);
  display: flex; flex-direction: column; padding: 1.25rem 1rem;
  position: sticky; top: 0; height: 100vh;
}
.side__brand { display: flex; gap: .7rem; align-items: center; padding: .25rem .5rem 1.25rem; border-bottom: 1px solid rgba(244,241,234,.12); }
.side__brand strong { display: block; font-family: var(--f-display); font-size: 1.05rem; }
.side__brand small { color: rgba(244,241,234,.6); font-size: .8rem; }
.side__nav { display: flex; flex-direction: column; gap: 2px; margin-top: 1rem; flex: 1; overflow-y: auto; }
.side__group { margin: 1.1rem .75rem .35rem; font-size: .75rem; color: rgba(244,241,234,.45); font-weight: 600; letter-spacing: .04em; }
.side__nav a { display: flex; align-items: center; gap: .7rem; padding: .65rem .75rem; border-radius: 12px; color: rgba(244,241,234,.85); transition: background .2s; }
.side__nav a:hover { background: rgba(244,241,234,.08); }
.side__nav a.is-active { background: var(--lime); color: var(--ink); font-weight: 600; }
.badge { margin-left: auto; background: var(--coral); color: var(--white); font-size: .75rem; font-weight: 700; padding: .05em .55em; border-radius: 999px; }
.side__foot { border-top: 1px solid rgba(244,241,234,.12); padding-top: .75rem; display: grid; gap: 2px; }
.side__view, .side__logout {
  display: flex; align-items: center; gap: .7rem; width: 100%; padding: .6rem .75rem; border-radius: 12px;
  background: none; border: 0; color: rgba(244,241,234,.75); font: inherit; cursor: pointer; text-align: left;
}
.side__view:hover, .side__logout:hover { background: rgba(244,241,234,.08); color: var(--white); }

.main { min-width: 0; }
.topnav {
  display: flex; align-items: center; gap: 1rem; padding: 1.25rem 2rem;
  position: sticky; top: 0; z-index: 5; background: rgba(243,242,237,.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topnav h1 { font-size: 1.6rem; font-weight: 400; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topnav__actions { display: flex; gap: .5rem; }
.menu-btn { display: none; }
.content { padding: 1.75rem 2rem 4rem; max-width: 1200px; }

/* Flash */
.flash { display: flex; align-items: center; gap: .6rem; padding: .85rem 1.1rem; border-radius: 12px; margin-bottom: 1rem; font-weight: 500; }
.flash--success { background: var(--mint); color: var(--green); }
.flash--error { background: #FDE8E4; color: var(--coral); }
.flash--warn { background: var(--amber); }
.flash--warn a { text-decoration: underline; font-weight: 700; }

/* Cards */
.card { background: var(--white); border-radius: var(--r); padding: 1.5rem; border: 1px solid var(--line); margin-bottom: 1.25rem; }
.card--flush { padding: 0; overflow: hidden; }
.card__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; }
.card__head h2, .card__title { font-size: 1.15rem; font-weight: 600; }
.card__title { margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--r); padding: 1.2rem; display: flex; flex-direction: column; transition: transform .2s; }
.stat:hover { transform: translateY(-3px); }
.stats--4 { grid-template-columns: repeat(4, 1fr); }
.stat [data-lucide] { width: 22px; height: 22px; margin-bottom: 1rem; color: var(--green); }
.stat__num { font: 400 2.2rem/1.2 var(--f-display); }
.stat__num small { font-size: .5em; color: var(--muted); font-weight: 600; }
.stat__label { color: var(--muted); font-size: .9rem; }
.stat--lime { background: var(--lime); border-color: var(--lime); }
.stat--lime [data-lucide], .stat--lime .stat__label { color: var(--ink); }
.stat--ink { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.stat--ink [data-lucide] { color: var(--lime); }
.stat--ink .stat__label, .stat--ink small { color: rgba(244,241,234,.6); }

/* Row links (messages, recent lists) */
.row-link { display: grid; gap: .1rem; padding: .75rem .5rem; border-top: 1px solid var(--line); border-radius: 8px; position: relative; }
.row-link:first-of-type { border-top: 0; }
.row-link:hover { background: var(--bg); }
.row-link--pad { padding: 1rem 1.5rem; border-radius: 0; }
.row-link__title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-link__meta { font-size: .85rem; color: var(--muted); }
.row-link__preview { font-size: .9rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-link.is-unread .row-link__title::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--coral); margin-right: .5rem; vertical-align: middle; }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .8rem; font-weight: 600; color: var(--muted); padding: .85rem 1rem; background: #FAF9F5; border-bottom: 1px solid var(--line); }
.table td { padding: .75rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #FBFAF6; }
.table .strong { font-weight: 600; }
.table .strong:hover { color: var(--green); text-decoration: underline; }
.col-thumb { width: 72px; }
.col-thumb img, .thumb-empty { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; display: grid; place-items: center; background: var(--bg); color: var(--muted); }
.col-actions { width: 96px; white-space: nowrap; text-align: right; }
.col-actions form { display: inline; }
.pill { display: inline-block; padding: .15em .75em; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--bg); color: var(--muted); }
.pill--on { background: var(--mint); color: var(--green); }

/* Forms */
.form { display: grid; gap: 1.1rem; }
.form > .card { margin-bottom: 0; }
.form--narrow { max-width: 520px; }
.field { display: grid; gap: .35rem; }
.field > span { font-weight: 600; font-size: .9rem; }
.field input, .field textarea, .field select {
  width: 100%; font: inherit; padding: .7rem .9rem; border: 1.5px solid var(--line); border-radius: 10px; background: #FCFBF8;
  transition: border-color .2s, box-shadow .2s;
}
.field textarea { resize: vertical; line-height: 1.7; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(15,107,74,.12); background: var(--white); }
.form__actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: .5rem; }
.form__actions form { display: inline; }
.push-right { margin-left: auto; }
.sticky-save { position: sticky; bottom: 0; padding: 1rem 0; background: linear-gradient(transparent, var(--bg) 35%); }

.upload { display: flex; gap: 1rem; align-items: flex-start; padding: 1rem; border: 1.5px dashed var(--line); border-radius: 12px; }
.upload__preview { width: 160px; aspect-ratio: 4/3; object-fit: cover; border-radius: 10px; }
.upload__controls { display: grid; gap: .4rem; }
/* อัลบั้มรูปกิจกรรม (หลายรูป) */
.album { display: grid; gap: .75rem; padding: 1rem; border: 1.5px dashed var(--line); border-radius: 12px; }
.album__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; }
.album__item { position: relative; display: block; border-radius: 10px; overflow: hidden; cursor: pointer; }
.album__item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; transition: opacity .2s, filter .2s; }
.album__remove {
  position: absolute; left: 6px; bottom: 6px; display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .55rem .15rem .35rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: rgba(255,255,255,.92); color: var(--coral);
}
.album__item:has(input:checked) img { opacity: .35; filter: grayscale(1); }
.album__item:has(input:checked) { outline: 2px solid var(--coral); outline-offset: -2px; }
.album__item--new { cursor: default; outline: 2px solid var(--green); outline-offset: -2px; }
.album__drop {
  position: relative; display: grid; justify-items: center; gap: .25rem; padding: 1.25rem; text-align: center;
  border-radius: 10px; background: var(--paper, #f4f1ea); cursor: pointer; transition: background .2s;
}
.album__drop:hover { background: rgba(15,107,74,.08); }
.album__drop [data-lucide] { width: 28px; height: 28px; color: var(--green); }
.album__drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.check { display: inline-flex; align-items: center; gap: .4rem; color: var(--coral); font-size: .9rem; cursor: pointer; }

.switch { display: inline-flex; align-items: center; gap: .75rem; font-weight: 600; cursor: pointer; width: fit-content; }
.switch input { position: absolute; opacity: 0; }
.switch__track { width: 46px; height: 26px; border-radius: 999px; background: var(--line); position: relative; transition: background .2s; }
.switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--white); transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + .switch__track { background: var(--green); }
.switch input:checked + .switch__track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--green); outline-offset: 2px; }

.icon-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; }
.icon-pick input { position: absolute; opacity: 0; }
.icon-pick span { display: grid; justify-items: center; gap: .3rem; padding: .8rem .4rem; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; text-align: center; transition: all .15s; }
.icon-pick span [data-lucide] { width: 24px; height: 24px; }
.icon-pick small { font-size: .75rem; color: var(--muted); line-height: 1.3; }
.icon-pick input:checked + span { border-color: var(--green); background: var(--mint); color: var(--green); }
.icon-pick input:focus-visible + span { outline: 2px solid var(--green); }

.meta { display: flex; flex-wrap: wrap; gap: 1rem 2.5rem; margin: 0 0 1.25rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.meta dt { font-size: .8rem; color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; }
.message-body { font-size: 1.05rem; line-height: 1.8; margin-bottom: 1rem; }
.message-body p { margin: 0 0 .75em; }

.empty { color: var(--muted); padding: 1rem .5rem; margin: 0; }
.empty--big { text-align: center; padding: 3.5rem 1rem; display: grid; justify-items: center; gap: .5rem; }
.empty--big [data-lucide] { width: 40px; height: 40px; stroke-width: 1.5; }

/* Login */
.login { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.login__art { background: var(--ink); color: var(--paper); padding: 3rem; display: flex; flex-direction: column; justify-content: flex-end; position: relative; overflow: hidden; }
.login__art .mark { position: absolute; top: 3rem; left: 3rem; }
.login__big { font: 300 clamp(2.8rem, 6vw, 5.5rem)/1.15 var(--f-display); color: var(--lime); margin: 0 0 1rem; }
.login__form { display: grid; align-content: center; gap: 1rem; padding: 3rem; max-width: 460px; width: 100%; margin: 0 auto; }
.login__form h1 { font-size: 2.2rem; }
.login__form .muted { margin: -.75rem 0 .5rem; }
.login__back { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); justify-self: center; font-size: .9rem; }

/* Responsive */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stats--4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 20; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .3s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .side.is-open { transform: none; }
  .menu-btn { display: inline-grid; }
  .topnav { padding: 1rem; }
  .topnav h1 { font-size: 1.25rem; }
  .content { padding: 1rem 1rem 3rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .hide-sm { display: none; }
  .login { grid-template-columns: 1fr; }
  .login__art { min-height: 220px; padding: 1.5rem; }
  .login__art .mark { top: 1.5rem; left: 1.5rem; width: 56px; height: 56px; }
  .login__form { padding: 2rem 1rem; }
  .upload { flex-direction: column; }
  .topnav__actions .btn { padding: .6em .9em; }
}
