/* training.miworkspace.org shared styles — pages load /css/training.css?v=N; bump N in every html file
   when this changes (1-day browser cache). Standalone, no framework.
   2026-10-21: roster columns (nowrap toggles, name min-width, email break, compact dates); v=8.
   2026-10-21: calendar lock (quick add off by default, amber card while unlocked); v=7.
   2026-10-21: date tile weekday/month in solid white (stale muted rule removed); v=6.
   2026-10-21: admin month calendar with quick-add (click a day → session from the template bar); v=4.
   2026-10-20 (night): UX pass (ui-ux-pro-max checklist) — skeleton loading, spinner-in-button, shared confirm
     dialog, 44px touch targets on mobile, focus rings on segmented controls, reduced-motion, skip link,
     sr-only h1, icon sprite via TR.icon, empty states with a next action; v=3.
   2026-10-20 (evening): MI brand — charcoal #41413d from the owner's logo (img/mi_logo.png, white on charcoal)
     is the primary colour, dark top bar carries the logo; v=2.
   2026-10-20: initial version. Tokens first, components below. Thai-first typography: Prompt + Sarabun. */

:root {
    --accent: #41413d;            /* MI charcoal (logo background), 9.6:1 on white */
    --accent-dark: #2a2a27;
    --accent-tint: #ecece9;
    --ink: #41413d;
    --bg: #f5f4f0;
    --surface: #ffffff;
    --text: #262220;
    --muted-fg: #655e56;
    --success: #157a5a;
    --success-tint: #e0f3ec;
    --warn: #8a5a00;
    --warn-tint: #fff4d6;
    --danger: #b3261e;
    --danger-tint: #fbe6e4;
    --border: #e1ddd5;
    --ring: #41413d;
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
    --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-full: 999px;
    --shadow-1: 0 1px 3px rgba(40, 30, 20, .07);
    --shadow-2: 0 6px 20px rgba(40, 30, 20, .12);
    --font-head: 'Prompt', -apple-system, 'Noto Sans Thai', 'Sukhumvit Set', sans-serif;
    --font-body: 'Sarabun', -apple-system, 'Noto Sans Thai', 'Sukhumvit Set', Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
button, a, input, select, textarea, label { touch-action: manipulation; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -48px; z-index: 100; background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: var(--r-sm); border: 2px solid var(--ring); font-weight: 600; transition: top .15s; }
.skip-link:focus { top: 8px; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
body { background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 16px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--font-head); line-height: 1.35; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; margin-bottom: var(--sp-2); }
a { color: var(--accent); }
.wrap { max-width: 640px; margin: 0 auto; padding: var(--sp-4); }
.wrap-wide { max-width: 1180px; }
.muted { color: var(--muted-fg); font-size: .9rem; }
.small { font-size: .85rem; }
.center { text-align: center; }
.mt { margin-top: var(--sp-4); }
.mb { margin-bottom: var(--sp-4); }
.hidden { display: none !important; }
.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.right { margin-left: auto; }

/* ---------------- top bar (charcoal, carries the white-on-charcoal MI logo) ---------------- */
.topbar { background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar .inner { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); max-width: 1180px; margin: 0 auto; }
.brand { font-family: var(--font-head); font-weight: 600; color: #fff; text-decoration: none; font-size: 1.05rem; display: flex; align-items: center; gap: 10px; }
.brand .logo-wide { height: 40px; width: auto; display: block; }
.brand .badge { background: rgba(255,255,255,.18); color: #fff; }
.topbar .user { color: rgba(255,255,255,.75); font-size: .85rem; margin-left: auto; text-align: right; line-height: 1.3; }
.topbar .user b { color: #fff; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.35); background: transparent; }
.topbar .btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,.12); }
@media (max-width: 640px) {
    .topbar .inner { gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); }
    .topbar .brand span:not(.badge) { display: none; }
    .brand .logo-wide { height: 32px; }
    .topbar .user { font-size: .8rem; min-width: 0; }
    .topbar .user b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
    .topbar .user br { display: none; }
    .topbar .btn-sm { padding: 0 10px; }
    .topbar .btn-sm span { display: none; }          /* icon-only on phones; aria-label keeps the name */
}
.hero { text-align: center; padding: var(--sp-6) 0 var(--sp-4); }
.hero h1 { color: var(--accent); font-size: 1.6rem; font-weight: 600; margin-top: var(--sp-4); }
.hero .tagline { color: var(--muted-fg); }
.hero .logo-wide { width: 220px; max-width: 70%; height: auto; border-radius: var(--r-md); box-shadow: var(--shadow-2); }

/* ---------------- surfaces ---------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-5); margin-bottom: var(--sp-4); box-shadow: var(--shadow-1); }
.card.accent { border-color: var(--accent); border-width: 2px; background: linear-gradient(180deg, #fff, var(--accent-tint)); animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card .eyebrow { display: flex; align-items: center; gap: 6px; color: var(--success); font-weight: 700; font-size: .85rem; margin-bottom: var(--sp-2); }
.card.compact { padding: var(--sp-4); }
.section-title { display: flex; align-items: baseline; gap: var(--sp-2); margin: var(--sp-5) 0 var(--sp-3); }
.section-title h2 { margin: 0; }

/* slot card (student list) */
.slot { display: grid; grid-template-columns: 76px 1fr auto; gap: var(--sp-4); align-items: center; }
/* charcoal date tile: everything solid white (a stale muted weekday rule used to win — owner reported it faint) */
.slot .date { text-align: center; background: var(--ink); color: #fff; border-radius: var(--r-md); padding: var(--sp-2) 0; line-height: 1.2; }
.slot .date .w { color: #fff; font-weight: 600; font-size: .82rem; }
.slot .date .d { font-family: var(--font-head); font-size: 1.6rem; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.slot .date .m { font-size: .8rem; color: #fff; }
.slot .title { font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; }
.slot .meta { color: var(--muted-fg); font-size: .9rem; }
.slot .act { display: flex; flex-direction: column; gap: var(--sp-2); align-items: flex-end; }
.slot .act .why { color: var(--muted-fg); font-size: .8rem; text-align: right; max-width: 160px; }
@media (max-width: 520px) { .slot .act { flex-wrap: wrap; } .slot .act .why { flex-basis: 100%; text-align: left; max-width: none; } }
@media (max-width: 520px) {
    .slot { grid-template-columns: 64px 1fr; }
    .slot .act { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
}

/* ---------------- badges ---------------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: var(--r-full); font-size: .8rem; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge .icon { width: 14px; height: 14px; }
.badge-ok { background: var(--success-tint); color: var(--success); }
.badge-warn { background: var(--warn-tint); color: var(--warn); }
.badge-danger { background: var(--danger-tint); color: var(--danger); }
.badge-muted { background: #eeebe5; color: var(--muted-fg); }
.badge-accent { background: var(--accent-tint); color: var(--accent-dark); }

/* ---------------- forms ---------------- */
label { display: block; font-weight: 600; margin-bottom: var(--sp-1); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=datetime-local], select, textarea {
    width: 100%; min-height: 44px; padding: var(--sp-2) var(--sp-3); border: 1.5px solid #c9c3b8; border-radius: var(--r-sm);
    font: inherit; background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px rgba(65, 65, 61, .18); }
.field { margin-bottom: var(--sp-3); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
@media (max-width: 520px) { .grid-2 { grid-template-columns: 1fr; } }
.input-affix { position: relative; }
.input-affix input { padding-right: 52px; }
.input-affix .affix-btn { position: absolute; top: 0; right: 0; height: 100%; width: 48px; display: flex; align-items: center; justify-content: center; background: none; border: none; cursor: pointer; color: var(--muted-fg); }
.check { display: flex; align-items: center; gap: var(--sp-2); font-weight: 400; }
.check input { width: 18px; height: 18px; }

/* ---------------- buttons ---------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 var(--sp-4); border-radius: var(--r-sm); border: 1.5px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s; white-space: nowrap; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-outline { background: var(--surface); color: var(--accent-dark); border-color: var(--accent); }
.btn-outline:hover:not(:disabled) { background: var(--accent-tint); }
.btn-ghost { background: transparent; color: var(--muted-fg); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: #f0ede7; }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-tint); }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 var(--sp-3); font-size: .85rem; }
@media (max-width: 768px) { .btn, .btn-sm { min-height: 44px; } }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ''; position: absolute; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-outline.is-loading::after, .btn-ghost.is-loading::after, .btn-danger.is-loading::after { border-color: rgba(0,0,0,.15); border-top-color: var(--accent); }
.btn-lg { min-height: 48px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; vertical-align: -3px; }
.btn-sm .icon { width: 16px; height: 16px; }
.meta .icon { width: 15px; height: 15px; color: var(--muted-fg); }
.lang-fixed { position: fixed; top: 12px; right: 12px; z-index: 30; background: var(--surface); }
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.spinner-dark { border-color: rgba(0,0,0,.15); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- skeleton loading ---------------- */
.skel { background: linear-gradient(90deg, #ece9e3 25%, #f5f3ef 50%, #ece9e3 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: var(--r-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-line { height: 14px; margin: 8px 0; }
.skel-tile { width: 76px; height: 72px; border-radius: var(--r-md); }
.skel-btn { width: 110px; height: 36px; }
.skel-row td { padding: 14px 10px; }

/* ---------------- feedback ---------------- */
.error { color: var(--danger); font-weight: 600; }
.success { color: var(--success); font-weight: 600; }
.notice { padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); margin-bottom: var(--sp-3); font-size: .95rem; }
.notice-info { background: var(--accent-tint); color: var(--accent-dark); }
.notice-warn { background: var(--warn-tint); color: var(--warn); }
.notice-ok { background: var(--success-tint); color: var(--success); }
.empty { text-align: center; color: var(--muted-fg); padding: var(--sp-5); }
.empty .icon { width: 36px; height: 36px; stroke-width: 1.5; color: #b8b2a8; display: block; margin: 0 auto var(--sp-2); }
.empty .btn { margin-top: var(--sp-3); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--r-full); font-size: .95rem; box-shadow: var(--shadow-2); z-index: 200; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); }
#toast.ok { background: var(--success); }

/* ---------------- dialog ---------------- */
dialog { border: none; border-radius: var(--r-lg); padding: 0; max-width: min(560px, 94vw); width: 100%; box-shadow: var(--shadow-2); }
dialog::backdrop { background: rgba(20, 15, 10, .45); }
dialog .dlg { padding: var(--sp-5); }
dialog h2 { margin-bottom: var(--sp-3); }
dialog .actions { display: flex; gap: var(--sp-2); justify-content: flex-end; margin-top: var(--sp-4); flex-wrap: wrap; }
dialog .dlg-err { color: var(--danger); font-weight: 600; margin-top: var(--sp-3); min-height: 1.4em; }
dialog .dlg-body b { color: var(--text); }
.hint { color: var(--muted-fg); font-size: .85rem; margin-top: var(--sp-1); }
.req { color: var(--danger); font-weight: 700; }

/* ---------------- tables (admin) ---------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 768px) { .tbl { min-width: 760px; } }
@media (max-width: 480px) { .stats { grid-template-columns: repeat(2, 1fr); } .toolbar .right { margin-left: 0; } }
table.tbl { width: 100%; border-collapse: collapse; font-size: .93rem; }
.tbl th, .tbl td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl th { font-family: var(--font-head); font-weight: 600; color: var(--muted-fg); font-size: .85rem; white-space: nowrap; }
.tbl tbody tr:hover td { background: #faf9f6; }
.tbl tr.muted-row td { color: var(--muted-fg); }
.tbl tr.muted-row td .name { text-decoration: line-through; }
.tbl td .name { font-weight: 600; }
.tbl td .sub { color: var(--muted-fg); font-size: .85rem; }
.tbl .nowrap { white-space: nowrap; }
.tbl .name-col { min-width: 150px; }
.tbl .email-col { font-size: .85rem; word-break: break-all; max-width: 230px; }
.tbl .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1.5px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: none; background: var(--surface); min-height: 36px; min-width: 44px; padding: 4px 10px; white-space: nowrap; font: inherit; font-size: .85rem; cursor: pointer; color: var(--muted-fg); touch-action: manipulation; }
.seg button:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; position: relative; z-index: 1; }
@media (max-width: 768px) { .seg button { min-height: 44px; } }
.seg button + button { border-left: 1.5px solid var(--border); }
.seg button.on-yes { background: var(--success-tint); color: var(--success); font-weight: 700; }
.seg button.on-no { background: var(--danger-tint); color: var(--danger); font-weight: 700; }
.seg button.on-none { background: #eeebe5; color: var(--text); font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-4); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); }
.stat .n { font-family: var(--font-head); font-size: 1.6rem; font-weight: 700; color: var(--accent); line-height: 1.2; }
.stat .l { color: var(--muted-fg); font-size: .85rem; }
.toolbar { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; margin-bottom: var(--sp-3); }
.toolbar select { width: auto; min-height: 40px; }
.footer { text-align: center; color: var(--muted-fg); font-size: .8rem; padding: var(--sp-6) 0 var(--sp-4); }

/* ---------------- admin calendar (quick add) ---------------- */
.cal-head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); flex-wrap: wrap; }
.cal-head h2 { margin: 0; min-width: 180px; font-variant-numeric: tabular-nums; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow { text-align: center; font-size: .8rem; color: var(--muted-fg); font-family: var(--font-head); padding: 4px 0; }
.cal-day { position: relative; min-width: 0; min-height: 84px; border: 1px solid var(--border); border-radius: var(--r-sm); padding: 4px; background: var(--surface); text-align: left; font: inherit; cursor: pointer; display: flex; flex-direction: column; gap: 3px; transition: background .15s, border-color .15s; }
.cal-day:hover:not(.disabled), .cal-day:focus-visible { border-color: var(--ring); background: #faf9f6; outline: none; }
.cal-day:focus-visible { box-shadow: 0 0 0 3px rgba(65,65,61,.18); }
.cal-day.disabled { cursor: default; background: #f3f1ec; color: var(--muted-fg); }
.cal-day.is-loading { opacity: .6; pointer-events: none; }
.cal-day.other { opacity: .45; }
.cal-day .n { font-family: var(--font-head); font-weight: 600; font-size: .9rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.cal-day.today .n { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: #fff; }
.cal-day .plus { position: absolute; right: 6px; top: 4px; color: var(--muted-fg); opacity: 0; transition: opacity .15s; }
.quick-on .cal-day:hover:not(.disabled) .plus, .quick-on .cal-day:focus-visible .plus { opacity: 1; }
#cal_card.quick-on { border-color: var(--warn); box-shadow: 0 0 0 3px var(--warn-tint); }
#cal_mode { margin: var(--sp-2) 0 var(--sp-3); }
.chip { display: block; width: 100%; text-align: left; border: none; border-radius: 6px; padding: 2px 6px; font: inherit; font-size: .75rem; line-height: 1.35; cursor: pointer; background: var(--accent-tint); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.chip:hover, .chip:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.chip.full { background: var(--danger-tint); color: var(--danger); }
.chip.closed { background: #eeebe5; color: var(--muted-fg); text-decoration: line-through; }
.chip.hidden-slot { background: var(--warn-tint); color: var(--warn); }
.chip.past { opacity: .6; }
.chip.sel { box-shadow: inset 0 0 0 2px var(--ink); }
.tpl { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: var(--sp-2) var(--sp-3); align-items: end; margin-bottom: var(--sp-3); }
.tpl .field { margin: 0; }
.tpl input { min-height: 40px; }
.tpl label { font-size: .85rem; margin-bottom: 2px; }
.tpl-hint { display: flex; align-items: center; gap: 6px; color: var(--muted-fg); font-size: .85rem; margin-bottom: var(--sp-3); }
.tpl-hint .icon { width: 16px; height: 16px; }
@media (max-width: 640px) {
    .cal-day { min-height: 60px; padding: 3px; }
    .chip { font-size: .68rem; padding: 1px 4px; }
    .chip .chip-cap { display: none; }   /* phones: time only, the seat count is in the table below */
    .cal-head h2 { min-width: 0; }
}
