/* ==========================================================================
   ระบบ Ticket ภายในองค์กร — สไตล์หลัก
   เขียนเป็น CSS ล้วน ไม่พึ่งไลบรารีภายนอก (NFR-20)
   ========================================================================== */

:root {
    --paper:        #eef0f4;
    --surface:      #ffffff;
    --surface-2:    #f5f7fa;
    --surface-3:    #e4e8ee;
    --ink:          #16191f;
    --ink-2:        #4a5464;
    --ink-3:        #798395;
    --rule:         #d6dbe3;
    --rule-strong:  #bac2ce;

    --brand:        #2e3d8f;
    --brand-ink:    #ffffff;
    --brand-soft:   #e6e9f7;
    --brand-line:   #b9c0e4;

    --ok:           #1b6b4c;
    --ok-soft:      #e4f2ea;
    --warn:         #8a5b00;
    --warn-soft:    #fbf1dc;
    --danger:       #a32e28;
    --danger-soft:  #f8eae8;

    --radius:       3px;
    --shadow:       0 1px 2px rgba(21, 24, 31, .06), 0 8px 24px -18px rgba(21, 24, 31, .3);

    --font: "IBM Plex Sans Thai", "Noto Sans Thai", "Sarabun", "Segoe UI", system-ui, -apple-system, sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 2px;
}

.skip-link {
    position: absolute;
    left: -9999px;
}
.skip-link:focus {
    left: 12px;
    top: 12px;
    z-index: 100;
    background: var(--surface);
    padding: 8px 14px;
    border: 1px solid var(--brand);
}

.mono { font-family: var(--mono); font-size: .92em; }

/* ---------- แถบบน ---------- */

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
}

.topbar-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
    min-height: 56px;
}

.brand {
    font-weight: 600;
    font-size: 16px;
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
}

.mainnav {
    display: flex;
    gap: 2px;
    flex: 1;
    flex-wrap: wrap;
}

.mainnav a {
    padding: 6px 11px;
    color: var(--ink-2);
    text-decoration: none;
    font-size: 14px;
    border-radius: var(--radius);
    white-space: nowrap;
}
.mainnav a:hover { background: var(--surface-3); color: var(--ink); }
.mainnav a.is-active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.usermenu {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}
.username { color: var(--ink-2); text-decoration: none; }
.username:hover { text-decoration: underline; }

.inline { display: inline; }

.announcement {
    background: var(--warn-soft);
    color: var(--warn);
    border-bottom: 1px solid var(--rule);
    padding: 9px 20px;
    text-align: center;
    font-size: 14px;
}

/* ---------- โครงหน้า ---------- */

.page {
    max-width: 1240px;
    margin: 0 auto;
    padding: 28px 20px 72px;
}

.pagefoot {
    max-width: 1240px;
    margin: 0 auto;
    padding: 16px 20px 32px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    color: var(--ink-3);
    font-size: 12.5px;
    border-top: 1px solid var(--rule);
}

.pagehead {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--rule-strong);
}

.pagehead h1 {
    margin: 0;
    font-size: 23px;
    font-weight: 600;
    line-height: 1.35;
}

.pagehead .subtitle {
    margin: 4px 0 0;
    color: var(--ink-2);
    font-size: 13.5px;
    max-width: 72ch;
}

.pagehead-actions { display: flex; gap: 8px; flex-wrap: wrap; }

h2 { font-size: 17px; font-weight: 600; margin: 28px 0 12px; }
h3 { font-size: 15px; font-weight: 600; margin: 20px 0 8px; }

/* ---------- กล่องเนื้อหา ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 18px;
}

.card > :first-child { margin-top: 0; }
.card > :last-child  { margin-bottom: 0; }

.card-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 4px;
}

.card-hint {
    color: var(--ink-2);
    font-size: 13px;
    margin: 0 0 16px;
    max-width: 78ch;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 18px;
    align-items: start;
}

/* ---------- ข้อความแจ้งเตือน ---------- */

.alert {
    border-left: 3px solid var(--brand);
    background: var(--brand-soft);
    padding: 11px 15px;
    margin-bottom: 16px;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 14px;
}
.alert-success { border-color: var(--ok);     background: var(--ok-soft);     color: var(--ok); }
.alert-error   { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.alert-warning { border-color: var(--warn);   background: var(--warn-soft);   color: var(--warn); }

.alert-list { margin: 6px 0 0; padding-left: 20px; }

.note {
    border-left: 3px solid var(--rule-strong);
    background: var(--surface-2);
    padding: 10px 14px;
    font-size: 13px;
    color: var(--ink-2);
    margin: 12px 0;
}

/* ---------- ฟอร์ม ---------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px 20px;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field-wide { grid-column: 1 / -1; }

.field label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-2);
}

.field .hint {
    font-size: 12.5px;
    color: var(--ink-3);
    line-height: 1.55;
}

.required::after { content: " *"; color: var(--danger); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 8px 11px;
    font-family: inherit;
    font-size: 14px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
}

input:disabled, select:disabled, textarea:disabled {
    background: var(--surface-2);
    color: var(--ink-3);
    cursor: not-allowed;
}

input.is-invalid, select.is-invalid { border-color: var(--danger); }

.checkbox {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    font-size: 14px;
    line-height: 1.55;
}
.checkbox input { margin-top: 4px; flex: none; }

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--rule);
}

/* ---------- ปุ่ม ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 15px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--brand-ink);
}
.btn-primary:hover { filter: brightness(1.12); background: var(--brand); }

.btn-danger {
    background: var(--surface);
    border-color: var(--danger);
    color: var(--danger);
}
.btn-danger:hover { background: var(--danger-soft); }

.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--surface-3); color: var(--ink); }

.btn-sm { padding: 4px 10px; font-size: 13px; }

.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- ตาราง ---------- */

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    min-width: 560px;
}

th, td {
    text-align: left;
    padding: 9px 13px;
    border-bottom: 1px solid var(--rule);
    vertical-align: top;
}

thead th {
    background: var(--surface-2);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ink-3);
    border-bottom: 1px solid var(--rule-strong);
    white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }

.empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--ink-3);
    font-size: 14px;
}

/* ---------- ป้ายสถานะ ---------- */

.pill {
    display: inline-block;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 2px;
    white-space: nowrap;
}
.pill-ok     { color: var(--ok);     box-shadow: inset 0 0 0 1px var(--ok); }
.pill-off    { color: var(--ink-3);  box-shadow: inset 0 0 0 1px var(--rule-strong); }
.pill-warn   { color: var(--warn);   background: var(--warn-soft); }
.pill-danger { color: var(--danger); background: var(--danger-soft); }
.pill-brand  { color: var(--brand-ink); background: var(--brand); }

/* ---------- ตัวกรองและแบ่งหน้า ---------- */

.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
}
.filters .field { min-width: 150px; flex: 1 1 150px; }
.filters .field-grow { flex: 2 1 240px; }
/* .filters เป็น flex ไม่ใช่ grid จึงใช้ grid-column ไม่ได้ ต้องสั่งกินเต็มแถวด้วย flex-basis */
.filters .field-wide { flex: 1 1 100%; }

.pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 14px;
    font-size: 13px;
    color: var(--ink-2);
}
.pager-links { display: flex; gap: 4px; flex-wrap: wrap; }
.pager-links a, .pager-links span {
    padding: 4px 10px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--ink-2);
    background: var(--surface);
}
.pager-links .is-current { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.pager-links .is-disabled { opacity: .45; }

/* ---------- สถิติบนหน้าแรก ---------- */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
}
.stat { background: var(--surface); padding: 14px 16px; }
.stat dt { font-size: 12px; color: var(--ink-3); margin: 0 0 4px; }
.stat dd {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}
.stat.is-alert dd { color: var(--danger); }

/* ---------- หน้าล็อกอิน ---------- */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 32px 16px;
}

.auth-shell { width: 100%; max-width: 420px; }

.auth-card {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 28px 26px;
    box-shadow: var(--shadow);
}

.auth-brand {
    margin: 0 0 4px;
    font-size: 19px;
    font-weight: 600;
    text-align: center;
}

.auth-card h2 {
    margin: 0 0 18px;
    font-size: 14px;
    font-weight: 500;
    color: var(--ink-2);
    text-align: center;
}

.auth-card .field { margin-bottom: 14px; }

.auth-card .btn-primary { width: 100%; }

.auth-links {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--rule);
    text-align: center;
    font-size: 13px;
}

.auth-foot {
    text-align: center;
    color: var(--ink-3);
    font-size: 12.5px;
    margin-top: 18px;
}

/* ---------- ตัวช่วยตั้งรหัสผ่าน (FR-1.4) ---------- */

.pwd-rules {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.pwd-rules li {
    display: flex;
    align-items: baseline;
    gap: 8px;
    color: var(--ink-2);
}

.pwd-rules li::before {
    content: "○";
    color: var(--ink-3);
    font-size: 11px;
    flex: none;
}

.pwd-rules li.is-met { color: var(--ok); }
.pwd-rules li.is-met::before { content: "●"; color: var(--ok); }

.pwd-meter {
    height: 4px;
    background: var(--surface-3);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}
.pwd-meter-bar {
    height: 100%;
    width: 0;
    background: var(--danger);
    transition: width .18s ease, background-color .18s ease;
}
.pwd-meter-bar.is-fair   { background: var(--warn); }
.pwd-meter-bar.is-strong { background: var(--ok); }

.pwd-strength-label {
    font-size: 12.5px;
    color: var(--ink-3);
    margin-top: 4px;
}

/* ---------- กลุ่มสิทธิ์ ---------- */

.perm-group {
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    margin-bottom: 12px;
    background: var(--surface);
}
.perm-group > h3 {
    margin: 0;
    padding: 10px 15px;
    font-size: 13px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--rule);
}
.perm-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 8px 20px;
    padding: 14px 15px;
}

/* ---------- รายการ role ที่กำหนดให้ผู้ใช้ ---------- */

.role-rows { display: flex; flex-direction: column; gap: 8px; }

.role-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr);
    gap: 12px;
    align-items: center;
    padding: 9px 12px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface-2);
}
.role-row select { font-size: 13px; }

/* ---------- audit log ---------- */

.changes { font-size: 12.5px; color: var(--ink-2); }
.changes b { color: var(--ink); font-weight: 600; }
.changes .old { color: var(--danger); }
.changes .new { color: var(--ok); }

/* ---------- หน้า error ---------- */

.errorbox { text-align: center; padding: 40px 20px; }
.errorbox .code { font-size: 44px; font-weight: 600; color: var(--brand); line-height: 1; }
.errorbox p { color: var(--ink-2); margin: 12px 0 22px; }

@media (max-width: 640px) {
    .topbar-inner { padding: 10px 16px; gap: 12px; }
    .mainnav { order: 3; width: 100%; }
    .page { padding: 20px 16px 56px; }
    .role-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ==========================================================================
   เฟส 2 — ticket หมวดหมู่ และไฟล์แนบ
   ========================================================================== */

/* ---------- แท็บมุมมองสำเร็จรูป ---------- */

.viewtabs {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--rule);
}

.viewtab {
    padding: 7px 14px;
    font-size: 13.5px;
    color: var(--ink-2);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}
.viewtab:hover { color: var(--ink); }
.viewtab.is-active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ---------- ตัวกรองสถานะแบบ chip ---------- */

.chipset { display: flex; flex-wrap: wrap; gap: 6px; }

.chip { position: relative; display: inline-flex; }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px;
    font-size: 12.5px;
    border: 1px solid var(--rule-strong);
    border-radius: 20px;
    background: var(--surface);
    cursor: pointer;
    user-select: none;
}
.chip span b { font-variant-numeric: tabular-nums; color: var(--ink-3); font-weight: 600; }
.chip input:checked + span {
    background: var(--brand-soft);
    border-color: var(--brand-line);
    color: var(--brand);
    font-weight: 600;
}
.chip input:checked + span b { color: var(--brand); }
.chip input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- ข้อมูลย่อยในแถวตาราง ---------- */

.rowmeta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin-top: 3px;
    font-size: 12px;
    color: var(--ink-3);
}

/* ---------- โครงหน้ารายละเอียด ticket ---------- */

.ticket-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
    align-items: start;
}

.ticket-main { min-width: 0; }
.ticket-side { display: flex; flex-direction: column; position: sticky; top: 16px; }

@media (max-width: 900px) {
    .ticket-layout { grid-template-columns: minmax(0, 1fr); }
    .ticket-side { position: static; }
}

.ticket-status { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

.deflist { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; }
.deflist dt { color: var(--ink-3); white-space: nowrap; }
.deflist dd { margin: 0; }

.actionform { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.actionform:last-child { margin-bottom: 0; }
.actionform input[type="text"] { font-size: 13px; }

/* ---------- หมายเหตุปฏิบัติงาน (FR-13) ---------- */
/* ใช้สีต่างจากกล่องอื่นชัดเจน เพื่อให้เจ้าหน้าที่รู้ทันทีว่าผู้แจ้งไม่เห็นข้อความนี้ */

.agentnote {
    border: 1px solid var(--warn);
    border-left-width: 4px;
    background: var(--warn-soft);
    border-radius: var(--radius);
    margin-bottom: 18px;
    overflow: hidden;
}

.agentnote-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 9px 16px;
    background: rgba(0, 0, 0, .04);
    font-size: 12.5px;
    color: var(--warn);
}
.agentnote-head strong { font-size: 13px; }

.agentnote-body { padding: 14px 16px; font-size: 14px; }
.agentnote-body > :first-child { margin-top: 0; }
.agentnote-body > :last-child { margin-bottom: 0; }

/* ---------- ข้อความ rich text ---------- */

.richtext { font-size: 14.5px; line-height: 1.75; overflow-wrap: break-word; }
.richtext > :first-child { margin-top: 0; }
.richtext > :last-child { margin-bottom: 0; }
.richtext p { margin: 0 0 10px; max-width: 74ch; }
.richtext ul, .richtext ol { margin: 0 0 10px; padding-left: 22px; }
.richtext li { margin-bottom: 3px; }
.richtext blockquote {
    margin: 0 0 10px;
    padding: 6px 14px;
    border-left: 3px solid var(--rule-strong);
    color: var(--ink-2);
}
.richtext code {
    font-family: var(--mono);
    font-size: .9em;
    background: var(--surface-3);
    padding: 1px 5px;
    border-radius: 2px;
}
.richtext pre {
    background: var(--surface-2);
    border: 1px solid var(--rule);
    padding: 10px 12px;
    overflow-x: auto;
    border-radius: var(--radius);
}

/* ---------- คอมเมนต์ ---------- */

.comment {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 15px 18px;
    margin-bottom: 12px;
}

/* คอมเมนต์ภายในต้องดูต่างจากคอมเมนต์ปกติอย่างชัดเจน (FR-6.2) */
.comment.is-internal {
    background: var(--warn-soft);
    border-color: var(--warn);
    border-left: 4px solid var(--warn);
}

.comment-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 8px;
    font-size: 13px;
}
.comment-head span { color: var(--ink-3); font-size: 12.5px; }

.comment-edit { margin-top: 12px; font-size: 13px; }
.comment-edit summary { cursor: pointer; color: var(--ink-2); }
.comment-edit textarea { margin-top: 10px; font-family: var(--mono); font-size: 12.5px; }

/* ---------- ไฟล์แนบ ---------- */

.filelist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.fileitem {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    font-size: 13.5px;
}

.fileitem-main { min-width: 0; flex: 1 1 240px; }
.fileitem-meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.fileitem-actions { display: flex; gap: 6px; flex: none; }
.fileitem-actions form { display: inline; }

.dropzone {
    border: 1px dashed var(--rule-strong);
    border-radius: var(--radius);
    padding: 18px;
    background: var(--surface-2);
    transition: background-color .15s, border-color .15s;
}
.dropzone.is-over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input[type="file"] { display: block; margin-bottom: 10px; }
.dropzone-label { display: block; font-size: 13.5px; color: var(--ink-2); }
.dropzone .filelist { margin-top: 12px; }

/* ---------- ตัวแก้ไขข้อความ ---------- */

.editor {
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.editor-toolbar {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    padding: 6px 8px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--rule);
}

.editor-btn {
    font-family: inherit;
    font-size: 12.5px;
    padding: 3px 9px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--ink-2);
}
.editor-btn:hover { background: var(--surface-3); color: var(--ink); }

.editor-area {
    min-height: 120px;
    padding: 12px 14px;
    font-size: 14.5px;
    line-height: 1.75;
    outline: none;
    overflow-wrap: break-word;
}
.editor-area:focus { box-shadow: inset 0 0 0 2px var(--brand-soft); }
.editor-area p { margin: 0 0 10px; }
.editor-area ul, .editor-area ol { margin: 0 0 10px; padding-left: 22px; }
.editor-area:empty::before {
    content: "พิมพ์ข้อความที่นี่";
    color: var(--ink-3);
}

/* ---------- timeline ---------- */

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

.timeline-item {
    position: relative;
    padding: 0 0 14px 18px;
    border-left: 1px solid var(--rule);
    font-size: 13px;
}
.timeline-item:last-child { padding-bottom: 0; border-left-color: transparent; }

.timeline-item::before {
    content: "";
    position: absolute;
    left: -4px;
    top: 5px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--rule-strong);
}
.timeline-item.is-internal::before { background: var(--warn); }

.timeline-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.timeline-meta { color: var(--ink-3); font-size: 12px; margin-top: 1px; }
.timeline-change { margin-top: 3px; color: var(--ink-2); font-size: 12.5px; }
.timeline-desc { margin-top: 3px; color: var(--ink-2); font-size: 12.5px; }

/* ==========================================================================
   เฟส 3 — workflow
   ========================================================================== */

/* ---------- แถบขั้นตอนในหน้างาน และผังในหน้าทดลอง ---------- */

.stepflow { list-style: none; margin: 0; padding: 0; }

.stepflow-item {
    position: relative;
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 14px;
    padding-bottom: 16px;
}

.stepflow-item::after {
    content: "";
    position: absolute;
    left: 14px;
    top: 30px;
    bottom: 2px;
    width: 1px;
    background: var(--rule);
}
.stepflow-item:last-child { padding-bottom: 0; }
.stepflow-item:last-child::after { display: none; }

.stepflow-marker {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    background: var(--surface-3);
    color: var(--ink-3);
    position: relative;
    z-index: 1;
}

.stepflow-item.is-active .stepflow-marker   { background: var(--brand);  color: var(--brand-ink); }
.stepflow-item.is-approved .stepflow-marker { background: var(--ok);     color: #fff; }
.stepflow-item.is-rejected .stepflow-marker { background: var(--danger); color: #fff; }
.stepflow-item.is-returned .stepflow-marker { background: var(--warn);   color: #fff; }

.stepflow-item.is-pending .stepflow-body,
.stepflow-item.is-skipped .stepflow-body { opacity: .6; }

.stepflow-body { min-width: 0; padding-top: 3px; }

.stepflow-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 14px;
}

.steptype {
    font-size: 12px;
    color: var(--ink-3);
}

.stepflow-instructions {
    margin-top: 6px;
    padding: 8px 12px;
    background: var(--brand-soft);
    border-left: 3px solid var(--brand);
    font-size: 13px;
    color: var(--ink-2);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.stepflow-people {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 7px;
}

.person {
    font-size: 12px;
    padding: 3px 9px;
    border-radius: 20px;
    background: var(--surface-2);
    border: 1px solid var(--rule);
    color: var(--ink-2);
}
.person.has-acted {
    background: var(--ok-soft);
    border-color: var(--ok);
    color: var(--ok);
}

.stepflow-warning {
    margin-top: 7px;
    font-size: 12.5px;
    color: var(--danger);
    background: var(--danger-soft);
    padding: 6px 10px;
    border-radius: var(--radius);
}

.stepflow-meta { margin-top: 5px; font-size: 12px; color: var(--ink-3); }

/* กล่องที่รอผู้ใช้ทำอะไรบางอย่าง ต้องเด่นกว่ากล่องอื่น */
.card.is-actionable {
    border-color: var(--brand);
    border-left: 4px solid var(--brand);
}

/* ---------- ตัวออกแบบขั้นตอน ---------- */

.steplist { display: flex; flex-direction: column; gap: 14px; }

.stepcard {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    overflow: hidden;
}

.stepcard-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--rule);
}

.stepcard-no {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--brand);
    color: var(--brand-ink);
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    flex: none;
}

.stepcard-title {
    flex: 1;
    font-weight: 600;
    font-size: 14.5px;
    border-color: transparent;
    background: transparent;
}
.stepcard-title:focus { background: var(--surface); border-color: var(--rule-strong); }

.stepcard-body { padding: 16px 18px; }
.stepcard-body h4 {
    margin: 18px 0 4px;
    padding-top: 14px;
    border-top: 1px solid var(--rule);
    font-size: 13px;
    color: var(--ink-2);
}
.stepcard-body h4:first-of-type { margin-top: 16px; }

/* แถวที่ผู้ใช้กดลบ จะถูกซ่อนแทนการลบออกจาก DOM เพื่อให้ลำดับ index ของฟอร์มไม่เพี้ยน */
.stepcard.is-removed { display: none; }

.assignee-row {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(160px, 1.4fr);
    gap: 10px;
    margin-bottom: 8px;
}

@media (max-width: 640px) {
    .assignee-row { grid-template-columns: minmax(0, 1fr); }
}

/* ==========================================================================
   เฟส 4 — แจ้งเตือน SLA และความคิดเห็น
   ========================================================================== */

/* ---------- ความคิดเห็นจากผู้แจ้ง (FR-14) ---------- */

.feedback-result {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.feedback-meta { font-size: 12.5px; color: var(--ink-3); }

.feedback-choice { display: flex; gap: 10px; flex-wrap: wrap; }

.feedback-option { position: relative; display: inline-flex; flex: 1 1 140px; }
.feedback-option input { position: absolute; opacity: 0; width: 0; height: 0; }

.feedback-btn {
    display: block;
    width: 100%;
    text-align: center;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
    border: 2px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    user-select: none;
}

.feedback-option input:checked + .feedback-btn.is-yes {
    border-color: var(--ok);
    background: var(--ok-soft);
    color: var(--ok);
}

.feedback-option input:checked + .feedback-btn.is-no {
    border-color: var(--danger);
    background: var(--danger-soft);
    color: var(--danger);
}

.feedback-option input:focus-visible + .feedback-btn {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* ---------- แถบสัดส่วนความพึงพอใจ ---------- */

.satbar {
    display: flex;
    height: 22px;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-3);
}
.satbar-yes { background: var(--ok); }
.satbar-no  { background: var(--danger); }

.satbar-legend {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin-top: 8px;
    font-size: 12.5px;
    color: var(--ink-2);
}
.satbar-legend b {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 5px;
}

.ratebar {
    height: 6px;
    background: var(--surface-3);
    border-radius: 3px;
    overflow: hidden;
    min-width: 90px;
}
.ratebar-fill { height: 100%; background: var(--ok); }
.ratebar-fill.is-mid { background: var(--warn); }
.ratebar-fill.is-low { background: var(--danger); }

/* ---------- ตัวแปรในเทมเพลตอีเมล ---------- */

.varlist { display: flex; flex-wrap: wrap; gap: 6px; }

.varchip {
    font-family: var(--mono);
    font-size: 11.5px;
    padding: 4px 9px;
    border: 1px solid var(--rule-strong);
    border-radius: 20px;
    background: var(--surface-2);
    color: var(--ink-2);
    cursor: pointer;
}
.varchip:hover { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand); }
.varchip.is-copied { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }

/* ---------- หน้าตรวจสุขภาพระบบ ---------- */

.healthlist { display: flex; flex-direction: column; gap: 8px; }

.healthitem {
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-left-width: 4px;
    border-radius: var(--radius);
}

.healthitem.is-ok    { border-left-color: var(--ok); }
.healthitem.is-warn  { border-left-color: var(--warn); }
.healthitem.is-error { border-left-color: var(--danger); }

.healthitem-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 6px;
}
.healthitem.is-ok    .healthitem-dot { background: var(--ok); }
.healthitem.is-warn  .healthitem-dot { background: var(--warn); }
.healthitem.is-error .healthitem-dot { background: var(--danger); }

.healthitem-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 14.5px;
}

.healthitem-detail { margin-top: 4px; font-size: 13px; color: var(--ink-2); }

.healthitem-hint {
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--ink-2);
    background: var(--surface-2);
    border-left: 2px solid var(--rule-strong);
    padding: 6px 10px;
}
