/* App Portal — layout เมนูซ้าย */

.ap-portal {
	--ap-accent: #0F6E8C;
	--ap-accent-soft: #E4EFF3;
	--ap-accent-ink: #0B5D78;
	--ap-ground: #F3F5F8;
	--ap-surface: #FFFFFF;
	--ap-line: #E2E7EE;
	--ap-ink: #1A2230;
	--ap-ink-2: #4A5568;
	--ap-ink-3: #5B6678;
	--ap-side: #18212F;
	--ap-side-line: #2A3547;
	--ap-side-ink: #D5DCE6;
	--ap-side-ink-2: #8794A8;
	--ap-radius: 14px;
	--ap-sidebar-w: 264px;

	display: flex;
	min-height: 100vh;
	font-family: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Sarabun', sans-serif;
	color: var(--ap-ink);
	background: var(--ap-ground);
	font-size: 15px;
	line-height: 1.5;
	box-sizing: border-box;
}
.ap-portal *, .ap-portal *::before, .ap-portal *::after { box-sizing: border-box; }
.ap-portal a { color: var(--ap-accent-ink); }
.ap-portal h1, .ap-portal h2 { font-family: inherit; color: var(--ap-ink); }
.ap-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

body.ap-fullwidth { margin: 0; background: #F3F5F8; }

/* ---------- Sidebar ---------- */
.ap-sidebar {
	flex: 0 0 var(--ap-sidebar-w);
	width: var(--ap-sidebar-w);
	background: var(--ap-side);
	color: var(--ap-side-ink);
	padding: 20px 14px;
	display: flex;
	flex-direction: column;
	gap: 20px;
	position: sticky;
	top: 0;
	height: 100vh;
	overflow-y: auto;
}
body.admin-bar .ap-sidebar { top: 32px; height: calc(100vh - 32px); }

.ap-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 14px; border-bottom: 1px solid var(--ap-side-line); }
.ap-brand__logo {
	width: 38px; height: 38px; flex: 0 0 38px; border-radius: 10px;
	background: var(--ap-accent); color: #fff;
	display: flex; align-items: center; justify-content: center;
	font-weight: 700; font-size: 17px;
}
.ap-brand__text { display: flex; flex-direction: column; min-width: 0; }
.ap-brand__name { font-weight: 600; font-size: 16px; color: #fff; }
.ap-brand__tag { font-size: 12px; color: #9AA6B8; }

.ap-menu-group__label {
	font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
	color: var(--ap-side-ink-2); padding: 0 10px 6px;
}
.ap-menu { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.ap-portal .ap-menu__link {
	display: flex; align-items: center; gap: 12px;
	min-height: 44px; padding: 10px 12px; border-radius: 10px;
	color: var(--ap-side-ink); text-decoration: none; font-size: 14px;
}
.ap-portal .ap-menu__link:hover { background: #222D3E; color: #fff; }
.ap-portal .ap-menu__link:focus-visible { outline: 2px solid #9CC9DA; outline-offset: 1px; }
.ap-portal .ap-menu__link.is-current { background: var(--ap-accent); color: #fff; font-weight: 600; }
.ap-menu__label { flex: 1; min-width: 0; }
.ap-badge { font-size: 11px; font-weight: 600; background: #E8833A; color: #1A1206; border-radius: 999px; padding: 1px 8px; }

.ap-portal .ap-add-module {
	margin-top: auto; min-height: 44px; display: flex; align-items: center; gap: 10px;
	padding: 10px 12px; border-radius: 10px; border: 1px dashed #3C4A60;
	color: #B7C2D2; font-size: 14px; text-decoration: none;
}
.ap-portal .ap-add-module:hover { color: #fff; border-color: #5A6A82; }

/* ---------- Main ---------- */
.ap-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.ap-topbar {
	display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px;
	padding: 14px 32px; background: var(--ap-surface); border-bottom: 1px solid var(--ap-line);
}
.ap-search { flex: 1 1 260px; max-width: 480px; position: relative; }
.ap-search svg { position: absolute; left: 14px; top: 13px; color: var(--ap-ink-3); }
.ap-search input {
	width: 100%; height: 44px; border: 1px solid #D3DAE4; border-radius: 10px;
	padding: 0 14px 0 42px; font: inherit; font-size: 14px; background: #F7F9FB; color: var(--ap-ink);
}
.ap-search input:focus { outline: 2px solid var(--ap-accent); outline-offset: 0; background: #fff; }
.ap-topbar__right { display: flex; align-items: center; gap: 12px; margin-left: auto; flex-wrap: wrap; }

.ap-portal .ap-icon-btn {
	width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--ap-line);
	background: var(--ap-surface); color: #3A4557;
	display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.ap-portal .ap-icon-btn:hover { background: #F3F5F8; }
.ap-menu-toggle { display: none !important; }

.ap-user { display: flex; align-items: center; gap: 10px; }
.ap-user__avatar {
	width: 40px; height: 40px; border-radius: 999px; background: #DDE8EE; color: var(--ap-accent-ink);
	display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.ap-user__text { display: flex; flex-direction: column; line-height: 1.3; }
.ap-user__name { font-size: 14px; font-weight: 600; }
.ap-user__role { font-size: 12px; color: var(--ap-ink-3); }
.ap-portal .ap-logout { font-size: 13px; color: var(--ap-ink-2); }

.ap-content {
	padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 28px;
	width: 100%; max-width: 1280px;
}
.ap-page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.ap-crumb { font-size: 13px; color: var(--ap-ink-3); }
.ap-portal .ap-title { margin: 4px 0 0; font-size: 28px; font-weight: 700; line-height: 1.3; }
.ap-date { font-size: 13px; color: var(--ap-ink-3); }

/* ---------- Home ---------- */
.ap-home { display: flex; flex-direction: column; gap: 28px; }

.ap-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.ap-portal .ap-stat {
	background: var(--ap-surface); border: 1px solid var(--ap-line); border-radius: var(--ap-radius);
	padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ap-ink);
}
.ap-portal .ap-stat:hover { border-color: #C5CFDB; }
.ap-stat__label { font-size: 13px; color: var(--ap-ink-2); }
.ap-stat__value { font-size: 30px; font-weight: 700; line-height: 1.2; }
.ap-stat__note { font-size: 12px; color: var(--ap-ink-3); }

.ap-section { display: flex; flex-direction: column; gap: 14px; }
.ap-section__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.ap-portal .ap-section__head h2, .ap-portal .ap-panel h2 { margin: 0; font-size: 18px; font-weight: 600; }
.ap-section__head a { font-size: 14px; }

.ap-modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.ap-portal .ap-card {
	background: var(--ap-surface); border: 1px solid var(--ap-line); border-radius: var(--ap-radius);
	padding: 18px; display: flex; flex-direction: column; gap: 10px; min-height: 150px;
	color: var(--ap-ink); text-decoration: none; transition: border-color .15s, box-shadow .15s;
}
.ap-portal .ap-card:hover { border-color: #C5CFDB; box-shadow: 0 4px 14px rgba(24, 33, 47, .06); }
.ap-portal .ap-card:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 2px; }
.ap-card__top { display: flex; align-items: center; justify-content: space-between; }
.ap-card__icon {
	width: 42px; height: 42px; border-radius: 10px; background: var(--ap-accent-soft); color: var(--ap-accent-ink);
	display: flex; align-items: center; justify-content: center;
}
.ap-pill { font-size: 11px; font-weight: 600; color: var(--ap-ink-2); background: #EEF1F5; border-radius: 999px; padding: 3px 10px; }
.ap-card__title { font-size: 16px; font-weight: 600; }
.ap-card__desc { font-size: 13px; color: var(--ap-ink-2); line-height: 1.5; }
.ap-portal .ap-card--add {
	background: transparent; border: 1.5px dashed #B9C3D0; align-items: center; justify-content: center;
	color: var(--ap-ink-2); font-size: 14px; text-align: center;
}

.ap-split { display: flex; flex-wrap: wrap; gap: 16px; }
.ap-split__main { flex: 2 1 420px; min-width: 0; }
.ap-split__side { flex: 1 1 280px; min-width: 0; }

.ap-panel {
	background: var(--ap-surface); border: 1px solid var(--ap-line); border-radius: var(--ap-radius);
	padding: 20px; display: flex; flex-direction: column; gap: 12px;
}
.ap-list { list-style: none; margin: 0; padding: 0; }
.ap-list__row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid #EEF1F5; }
.ap-list__row:first-child { border-top: 0; }
.ap-list__text { flex: 1; min-width: 0; font-size: 14px; }
.ap-list__time { font-size: 12px; color: var(--ap-ink-3); white-space: nowrap; }
.ap-tag { font-size: 11px; font-weight: 600; color: var(--ap-accent-ink); background: var(--ap-accent-soft); border-radius: 6px; padding: 3px 8px; white-space: nowrap; }
.ap-muted { margin: 0; color: var(--ap-ink-3); font-size: 14px; }

.ap-notice { background: #F3F5F8; border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ap-ink-2); }
.ap-notice strong { font-size: 14px; color: var(--ap-ink); }
.ap-notice--highlight { background: #FBF3EA; color: #4A3826; }
.ap-notice--highlight strong { color: #5A3410; }

.ap-empty { align-items: center; justify-content: center; text-align: center; color: var(--ap-ink-2); }
.ap-empty--module { min-height: 360px; border-style: dashed; border-width: 1.5px; border-color: #B9C3D0; }
.ap-empty--module strong { font-size: 18px; color: var(--ap-ink); }
.ap-empty code { font-size: 12px; background: #F3F5F8; padding: 6px 10px; border-radius: 6px; max-width: 100%; overflow-x: auto; }

.ap-table-wrap { overflow-x: auto; }
.ap-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.ap-table th, .ap-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--ap-line); }
.ap-table th { font-size: 12px; color: var(--ap-ink-3); font-weight: 600; }
.ap-portal .ap-btn {
	display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px; border-radius: 10px;
	background: var(--ap-accent); color: #fff; text-decoration: none; font-weight: 600; font-size: 14px;
}

.ap-portal .ap-btn--ghost { background: transparent; color: var(--ap-accent-ink); border: 1px solid var(--ap-line); }

/* เนื้อหา HTML ของโมดูลที่สร้างจากหน้าตั้งค่า */
.ap-richtext { display: block; font-size: 15px; line-height: 1.7; }
.ap-richtext > :first-child { margin-top: 0; }
.ap-richtext > :last-child { margin-bottom: 0; }
.ap-richtext img { max-width: 100%; height: auto; }
.ap-richtext table { border-collapse: collapse; width: 100%; }
.ap-richtext th, .ap-richtext td { border: 1px solid var(--ap-line); padding: 8px 10px; text-align: left; }

/* ซ่อนรายการที่ไม่ตรงคำค้น */
.ap-portal [data-ap-search].is-hidden { display: none; }
.ap-portal li.is-hidden { display: none; }

/* ---------- Login ---------- */
.ap-portal--login { align-items: center; justify-content: center; padding: 24px; }
.ap-login { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--ap-line); border-radius: var(--ap-radius); padding: 28px; }
.ap-brand--light { border-bottom-color: var(--ap-line); margin-bottom: 16px; }
.ap-brand--light .ap-brand__name { color: var(--ap-ink); }
.ap-brand--light .ap-brand__tag { color: var(--ap-ink-3); }
.ap-login p { margin: 0 0 14px; }
.ap-login label { display: block; font-size: 14px; margin-bottom: 4px; }
.ap-login input[type="text"], .ap-login input[type="password"] { width: 100%; height: 44px; border: 1px solid #D3DAE4; border-radius: 10px; padding: 0 12px; font: inherit; }
.ap-login input[type="submit"] { width: 100%; height: 44px; border: 0; border-radius: 10px; background: var(--ap-accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }

/* ---------- Mobile ---------- */
.ap-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); z-index: 99; }

@media (max-width: 900px) {
	.ap-menu-toggle { display: inline-flex !important; }
	.ap-sidebar {
		position: fixed; left: 0; top: 0; bottom: 0; height: 100vh; z-index: 100;
		transform: translateX(-100%); transition: transform .2s ease;
	}
	body.admin-bar .ap-sidebar { top: 0; height: 100vh; }
	.ap-portal.is-menu-open .ap-sidebar { transform: none; }
	.ap-topbar { padding: 12px 16px; }
	.ap-content { padding: 20px 16px 40px; }
	.ap-user__text, .ap-logout { display: none; }
	.ap-portal .ap-title { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
	.ap-sidebar, .ap-card { transition: none; }
}
