:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --ink: #17202e;
  --muted: #6b7484;
  --line: #e3e0d9;
  --navy: #1f3a5f;
  --navy-2: #2e5a88;
  --red: #d63a3a;
  --red-soft: #fbe9e7;
  --ok: #2f7d4f;
  --warn: #a8661b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 32, 46, .05), 0 4px 18px rgba(23, 32, 46, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d; --surface: #1b212b; --ink: #e8ebf0; --muted: #98a1b0; --line: #2b3340;
    --navy: #8fb4e3; --navy-2: #a8c6ec; --red: #ef5b5b; --red-soft: #3a2224; --ok: #6cc08e; --warn: #e2a65a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'IBM Plex Sans Thai', 'Leelawadee UI', Tahoma, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.6;
}
a { color: var(--navy-2); }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center-text { text-align: center; }
.empty { color: var(--muted); padding: 1.5rem 0; text-align: center; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; background: var(--navy); position: relative; flex: none;
}
.brand-mark::after {
  content: ''; position: absolute; left: 9px; top: 5px; width: 8px; height: 12px; border-radius: 4px; background: var(--surface);
}
.brand-mark.lg { width: 48px; height: 48px; border-radius: 14px; margin: 0 auto .75rem; display: block; }
.brand-mark.lg::after { left: 17px; top: 9px; width: 14px; height: 22px; border-radius: 7px; }
.topbar nav { display: flex; align-items: center; gap: .75rem; }
.who { font-weight: 500; }

main.wrap { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
main.center { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }

/* buttons & forms */
.btn {
  font: inherit; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .6rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #12161d; } }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.danger:hover:not(:disabled) { background: var(--red-soft); }
.btn.word { border-color: #2b579a; color: #2b579a; font-weight: 600; }
@media (prefers-color-scheme: dark) { .btn.word { color: #8fb0e6; border-color: #8fb0e6; } }
.btn.ghost { background: transparent; }
.btn.sm { padding: .35rem .7rem; font-size: .85rem; }
.btn.block { width: 100%; margin-bottom: .5rem; }
.danger-text { color: var(--red); border-color: transparent; }
.btn.record { background: var(--red); border-color: var(--red); color: #fff; font-size: 1.05rem; padding: .8rem 1.4rem; font-weight: 600; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #fff; }

.form { display: grid; gap: .85rem; }
.form label { display: grid; gap: .3rem; font-size: .92rem; font-weight: 500; }
input {
  font: inherit; padding: .6rem .8rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); width: 100%;
}
input:focus { outline: 2px solid var(--navy-2); outline-offset: 0; border-color: transparent; }

.alert { background: var(--red-soft); color: var(--red); padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.alert.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }

/* auth */
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 2rem 1.6rem; box-shadow: var(--shadow); }
.auth-head { text-align: center; margin-bottom: 1.25rem; }
.auth-head h1 { font-size: 1.5rem; }

/* profile */
.profile-grid { display: grid; grid-template-columns: 320px 1fr; gap: 1rem; }
.profile-grid .card { margin-bottom: 0; }
.profile-grid { margin-bottom: 1rem; }
.profile-card { text-align: center; }
.avatar {
  width: 76px; height: 76px; border-radius: 50%; margin: 0 auto .75rem; display: grid; place-items: center;
  background: var(--navy); color: var(--surface); font-size: 2rem; font-weight: 600;
}
.pname { font-size: 1.35rem; margin-bottom: .1rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 1rem 0; }
.stats div { background: var(--bg); border-radius: 10px; padding: .6rem; display: grid; }
.stats b { font-size: 1.4rem; }
.stats span { font-size: .8rem; color: var(--muted); }
.edit-profile { text-align: left; }
.edit-profile summary { cursor: pointer; color: var(--navy-2); font-size: .9rem; }
.edit-profile form { margin-top: .75rem; }
.start-card { display: flex; flex-direction: column; justify-content: center; }
.start-card h2 { font-size: 1.4rem; }
.start-form { display: flex; gap: .6rem; margin-top: .5rem; flex-wrap: wrap; }
.start-form input { flex: 1 1 260px; }

.meeting-list { list-style: none; margin: 0; padding: 0; }
.meeting-list li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-top: 1px solid var(--line); }
.meeting-list li:first-child { border-top: 0; }
.meeting-list a { flex: 1; display: grid; padding: .8rem 0; text-decoration: none; color: var(--ink); min-width: 0; }
.m-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-meta { font-size: .85rem; color: var(--muted); }
.tag { font-size: .78rem; padding: .15rem .6rem; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.tag.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.tag.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, transparent); }

/* meeting */
.meeting-head { display: flex; align-items: center; gap: .9rem; margin-bottom: 1rem; flex-wrap: wrap; }
.back { text-decoration: none; color: var(--muted); }
.title-input { flex: 1 1 300px; font-size: 1.35rem; font-weight: 600; background: transparent; border-color: transparent; padding: .3rem .5rem; }
.title-input:hover { border-color: var(--line); }

.recorder { padding: 1.25rem 1.5rem; }
.rec-main { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.rec-btn {
  width: 84px; height: 84px; border-radius: 50%; border: 3px solid var(--red); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; flex: none; transition: transform .15s;
}
.rec-btn:hover { transform: scale(1.04); }
.rec-core { width: 52px; height: 52px; border-radius: 50%; background: var(--red); transition: all .2s; }
.rec-btn.on .rec-core { width: 12px; height: 32px; border-radius: 3px; box-shadow: 18px 0 0 var(--red); margin-right: 18px; animation: none; }
.rec-btn.paused .rec-core { width: 52px; height: 52px; border-radius: 50%; box-shadow: none; margin: 0; }
@keyframes pulse { 50% { opacity: .55; } }
.is-recording .rec-btn:not(.paused) { box-shadow: 0 0 0 6px var(--red-soft); }
.rec-info { flex: 1 1 260px; min-width: 0; }
.rec-time { font-size: 2.2rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: .02em; line-height: 1.1; }
.rec-status { color: var(--muted); font-size: .92rem; }
#meter { width: 100%; max-width: 320px; height: 36px; margin-top: .3rem; }
.rec-actions { display: flex; gap: .5rem; }
.live { margin-top: 1rem; background: var(--bg); border-radius: 10px; padding: .7rem 1rem; }
.live-label { font-size: .75rem; font-weight: 600; color: var(--red); text-transform: uppercase; letter-spacing: .06em; }
.live-text { margin: .2rem 0 0; min-height: 1.6em; }
.interim { color: var(--muted); }
.queue:empty { display: none; }
.queue { margin-top: .8rem; display: grid; gap: .35rem; }
.q-item { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.q-item.fail { color: var(--red); }
.spin { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--navy-2); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.meeting-grid { display: grid; grid-template-columns: 1fr 300px; gap: 1rem; align-items: start; }
.side { position: sticky; top: 72px; }
.transcript { max-height: 62vh; overflow-y: auto; padding-right: .3rem; }
.seg { --c: hsl(var(--h) 55% 42%); border-left: 3px solid var(--c); padding: .15rem 0 .15rem .9rem; margin-top: .9rem; }
.seg.cont { margin-top: 0; }
@media (prefers-color-scheme: dark) { .seg { --c: hsl(var(--h) 60% 66%); } }
.seg-head { display: flex; align-items: baseline; gap: .6rem; }
.spk { font: inherit; font-weight: 600; color: var(--c); background: none; border: 0; padding: 0; cursor: pointer; }
.spk:hover { text-decoration: underline; }
.ts { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.seg-text { margin: 0; padding: .1rem .3rem; border-radius: 6px; margin-left: -.3rem; }
.seg-text:hover { background: var(--bg); }
.seg-text:focus { outline: 2px solid var(--navy-2); background: var(--bg); }

.speakers { display: grid; gap: .5rem; }
.spk-row { --c: hsl(var(--h) 55% 42%); display: grid; grid-template-columns: 10px 1fr; gap: .2rem .6rem; align-items: center; }
@media (prefers-color-scheme: dark) { .spk-row { --c: hsl(var(--h) 60% 66%); } }
.spk-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.spk-raw { font-size: .85rem; font-weight: 600; }
.spk-raw em { font-style: normal; font-weight: 400; color: var(--muted); }
.spk-row input { grid-column: 2; padding: .4rem .6rem; }
.actions h2 { margin-bottom: .75rem; }

.summary h3.sum-title { font-size: 1.3rem; }
.summary h4 { margin: 1.1rem 0 .3rem; color: var(--navy); font-size: 1rem; }
.summary ul { margin: 0; padding-left: 1.3rem; }
.topic p { margin: .1rem 0 .6rem; }
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { border: 1px solid var(--line); padding: .45rem .6rem; text-align: left; vertical-align: top; }
th { background: var(--navy); color: var(--surface); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1rem); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: .65rem 1.1rem; border-radius: 10px; transition: all .25s; max-width: 90vw; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red); color: #fff; }

@media (max-width: 860px) {
  .profile-grid, .meeting-grid { grid-template-columns: 1fr; }
  .side { position: static; }
  .transcript { max-height: none; }
  .rec-main { gap: 1rem; }
  .rec-actions { width: 100%; }
  .rec-actions .btn { flex: 1; }
  .topbar .who { display: none; }
}

/* credit */
.credit { text-align: center; font-size: .82rem; color: var(--muted); padding: 1.5rem 1rem 2rem; }
.credit b { color: var(--navy); font-weight: 600; letter-spacing: .02em; }
body.bare main.center { min-height: calc(100vh - 70px); }
