/* =========================================================
   alerts.css — การแจ้งเตือน (design 1c, 1r) + กำหนดค่า Alarm & Event (1s, 1t)
   + ตัวเลือกหลายรายการ MultiSelect (msel-*)
   ========================================================= */

.al-page { gap: calc(11px * var(--k)); }

.al-head { gap: calc(9.5px * var(--k)); flex-wrap: wrap; }
.al-title { font-size: calc(20px * var(--k)); }

.al-live {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: auto;
    font-size: calc(11px * var(--k));
    color: var(--c-ink-soft);
}
.al-live i { width: 7px; height: 7px; border-radius: 50%; background: #c9c3b6; }
.al-live.on { color: var(--c-ok-fg); }
.al-live.on i { background: var(--c-ok); animation: alDot 1.6s ease-in-out infinite; }

.al-tab-n.hot { background: var(--c-err) !important; color: #fff !important; }

/* ดันกลุ่มปุ่มไปชิดขวา (เหมือนหน้าอื่น) */
.al-push { margin-left: auto; }
.al-dirty { margin-right: 4px; font-size: calc(11.5px * var(--k)); color: #8a938c; }
.al-dirty.on { color: #a86b00; font-weight: 600; }

/* ---------- Alarm ปัจจุบัน ---------- */
.al-chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: calc(11.5px * var(--k)); }
.al-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 14px;
    background: var(--c-surface-2); color: var(--c-ink-soft);
}
.al-chip.new { background: var(--c-err-bg); color: var(--c-err-fg); font-weight: 600; }
.al-chip.new i { width: 7px; height: 7px; border-radius: 50%; background: var(--c-err); animation: alDot 1s ease-in-out infinite; }
.al-note { margin-left: auto; color: var(--c-ink-soft); }

.al-grid { width: max(100%, calc(1270px * var(--k))); }
.al-grid .grid-row {
    /* step58: ไปที่ (ปุ่ม IOT / มิเตอร์น้ำ / ข้อมูลย้อนหลัง) ต่อจากจุดสถานะ */
    grid-template-columns: 12px calc(84px * var(--k)) calc(140px * var(--k)) minmax(170px, 1.3fr) 64px minmax(240px, 2.4fr) 100px minmax(140px, 1fr) calc(170px * var(--k));
}

@keyframes alRow { 0%, 100% { background: #fdeceb; } 50% { background: #fff8f7; } }
@keyframes alDot { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.al-grid .grid-row.al-new { animation: alRow 1.4s ease-in-out infinite; }
.al-dot { display: block; width: 9px; height: 9px; border-radius: 50%; background: #c9c3b6; }
.al-dot.on { background: var(--c-err); animation: alDot 1s ease-in-out infinite; }

.al-dev, .al-msg, .al-ackby { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.al-dev small, .al-msg small, .al-ackby small {
    display: flex; align-items: center; gap: 4px;
    font-size: calc(10.5px * var(--k)); color: var(--c-ink-soft);
}
.al-dev .ms { font-size: 14px; }
.al-dev b { display: flex; align-items: center; gap: 5px; font-weight: 600; }
.al-msg b { font-weight: 500; }
.al-msg b.hot { font-weight: 600; color: var(--c-err-fg); }

.al-st { display: inline-flex; padding: 2.5px 9px; border-radius: 14px; font-size: calc(11px * var(--k)); font-weight: 600; }
.al-st.new { background: var(--c-err); color: #fff; }
.al-st.ack { background: var(--c-surface-2); color: var(--c-ink-soft); }

.al-ok { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.al-ok .ms { font-size: 28px; color: var(--c-ok-fg); }

/* รหัส Error: สีตามหมวด E / A / H / อุปกรณ์ */
.code {
    display: inline-block;
    padding: 1.5px 6px;
    border-radius: 5px;
    font-family: var(--font-num);
    font-size: calc(11px * var(--k));
    font-weight: 500;
}
.code-E { background: #e8effd; color: #2563eb; }
.code-A { background: #fdeee6; color: #c2410c; }
.code-H { background: #f1eafd; color: #7c3aed; }
.code-D { background: var(--c-ok-bg); color: var(--c-sidebar); }
.code.nobit { opacity: .45; }

/* ---------- history ---------- */
.al-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.al-filters .hs-range { min-width: calc(330px * var(--k)); }
.al-search { margin-left: auto; }

.al-check { position: relative; display: inline-flex; align-items: center; gap: 7px; font-size: calc(11.5px * var(--k)); cursor: pointer; }
.al-check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.al-box {
    display: flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border: 1.5px solid #b8b2a6; border-radius: 4px; background: #fff;
}
.al-box .ms { font-size: 13px; color: #fff; visibility: hidden; }
.al-check input:checked + .al-box { border-color: var(--c-sidebar); background: var(--c-sidebar); }
.al-check input:checked + .al-box .ms { visibility: visible; }
.al-check input:focus-visible + .al-box { outline: 3px solid #2563eb; outline-offset: 2px; }

.al-hgrid { width: max(100%, calc(1090px * var(--k))); }
.al-hgrid .grid-row {
    /* step58: ไปที่ (ปุ่ม IOT / มิเตอร์น้ำ / ข้อมูลย้อนหลัง) หน้าสุด */
    grid-template-columns: calc(84px * var(--k)) calc(140px * var(--k)) 92px minmax(150px, 1.2fr) 64px minmax(260px, 3fr) minmax(90px, .8fr);
    min-height: calc(40px * var(--k));
}

.al-kind {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 12px;
    font-size: calc(10.5px * var(--k)); font-weight: 600;
}
.al-kind .ms { font-size: 12px; }
.al-kind.k-A { background: var(--c-err-bg); color: var(--c-err-fg); }
.al-kind.k-E { background: var(--c-surface-2); color: var(--c-ink-soft); }
.al-kind.k-U { background: #e8effd; color: #2563eb; }

/* ---------- MultiSelect ---------- */
.msel-select { position: relative; }
.msel-btn {
    display: flex; align-items: center; gap: 6px;
    height: calc(34px * var(--k)); min-width: calc(170px * var(--k));
    padding: 0 10px;
    border: 1px solid #d5cfc2; border-radius: 6.5px; background: #fff;
    color: var(--c-ink); font: inherit; font-size: calc(11.5px * var(--k)); cursor: pointer;
}
.msel-select.open .msel-btn { border-color: var(--c-sidebar); box-shadow: 0 0 0 3px rgba(15, 107, 58, .12); }
.msel-label { color: var(--c-ink-soft); }
.msel-value { font-weight: 600; max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msel-btn > .ms { margin-left: auto; font-size: 16px; }
.msel-backdrop { position: fixed; inset: 0; z-index: 19; }
.msel-pop {
    position: absolute; left: 0; top: calc(100% + 6px); z-index: 20;
    width: 280px; max-width: calc(100vw - 32px);
    display: flex; flex-direction: column; gap: 4px;
    padding: 8px; border: 1px solid #d5cfc2; border-radius: 8px; background: #fff;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .14);
}
.msel-search {
    display: flex; align-items: center; gap: 6px;
    height: 30px; padding: 0 8px; border: 1px solid #e7e2d8; border-radius: 6px;
}
.msel-search .ms { font-size: 15px; color: #8a938c; }
.msel-search input { flex: 1; min-width: 0; border: 0; outline: none; font: inherit; font-size: 12px; background: transparent; }
.msel-list { max-height: 260px; overflow: auto; display: flex; flex-direction: column; }
.msel-opt {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px; border: 0; border-radius: 5px; background: transparent;
    color: var(--c-ink); font: inherit; font-size: 12px; text-align: left; cursor: pointer;
}
.msel-opt:hover { background: #f7f5f0; }
.msel-opt b { font-weight: 600; }
.msel-chk {
    display: flex; align-items: center; justify-content: center; flex: none;
    width: 15px; height: 15px; border: 1.5px solid #b8b2a6; border-radius: 4px; background: #fff;
}
.msel-chk .ms { font-size: 12px; color: #fff; visibility: hidden; }
.msel-opt.on .msel-chk { border-color: var(--c-sidebar); background: var(--c-sidebar); }
.msel-opt.on .msel-chk .ms { visibility: visible; }
.msel-sub { margin-left: auto; font-size: 10.5px; color: var(--c-ink-soft); white-space: nowrap; }
.msel-empty { padding: 12px; text-align: center; font-size: 12px; color: var(--c-ink-soft); }
.msel-foot { display: flex; justify-content: space-between; padding: 6px 2px 0; border-top: 1px solid var(--c-line); }
.msel-link { padding: 2px 4px; border: 0; background: transparent; color: var(--c-ink-soft); font: inherit; font-size: 11.5px; cursor: pointer; }
.msel-ok { color: var(--c-sidebar); font-weight: 600; }

/* ---------- กำหนดค่า Alarm & Event ---------- */
.acf-cats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.acf-cat { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border-radius: 7px; }
.acf-cat-id {
    display: flex; align-items: center; justify-content: center; flex: none;
    width: 26px; height: 26px; border-radius: 6px; background: #fff;
    font-family: var(--font-num); font-weight: 700; font-size: 15px;
}
.acf-cat-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.acf-cat-body b { font-size: calc(12px * var(--k)); font-weight: 600; }
.acf-cat-body small { font-size: calc(11px * var(--k)); line-height: 1.45; color: #3d4a42; }
.acf-cat.cat-E { background: #e8effd; } .acf-cat.cat-E b, .acf-cat.cat-E .acf-cat-id { color: #2563eb; }
.acf-cat.cat-A { background: #fdeee6; } .acf-cat.cat-A b, .acf-cat.cat-A .acf-cat-id { color: #c2410c; }
.acf-cat.cat-H { background: #f1eafd; } .acf-cat.cat-H b, .acf-cat.cat-H .acf-cat-id { color: #7c3aed; }

.acf-legend { display: flex; gap: 6px 16px; flex-wrap: wrap; align-items: center; font-size: calc(11px * var(--k)); color: var(--c-ink-soft); }
.acf-legend b { color: var(--c-ink); font-weight: 600; }
.acf-mask { margin-left: auto; }
.acf-mask code { padding: 2px 7px; border-radius: 5px; background: var(--c-surface-2); color: var(--c-ink); font-family: var(--font-num); }

.acf-grid { width: max(100%, calc(1180px * var(--k))); }
.acf-grid .grid-row { grid-template-columns: minmax(220px, 1.4fr) repeat(3, 230px); gap: 8px; }
.acf-grid .acf-h1 { padding-bottom: 0; font-size: calc(12px * var(--k)); font-weight: 600; text-align: center; }
.acf-grid .acf-h2 { top: calc(26px * var(--k)); border-bottom: 1px solid #e7e2d8; }
.acf-h1 .cat-E { color: #2563eb; } .acf-h1 .cat-A { color: #c2410c; } .acf-h1 .cat-H { color: #7c3aed; }
.acf-sub, .acf-cell {
    display: grid;
    grid-template-columns: 44px 36px 100px 40px;
    align-items: center;
    justify-items: center;
}
.acf-sub { border-left: 2px solid #e7e2d8; padding-left: 6px; }
.acf-group { display: flex; flex-direction: column; gap: 5px; border-left: 2px solid #e7e2d8; padding: 4px 0 4px 6px; }
.acf-cell { min-height: 24px; border-radius: 5px; }
.acf-cell.changed, .acf-dgrid .grid-row.changed { background: #fff6d6; }
.acf-name { display: flex; flex-direction: column; gap: 1px; }
.acf-name b { font-weight: 600; }
.acf-name small { font-size: calc(10.5px * var(--k)); color: var(--c-ink-soft); }

.acf-chk {
    display: flex; align-items: center; justify-content: center;
    width: 17px; height: 17px; padding: 0;
    border: 1.5px solid #b8b2a6; border-radius: 4px; background: #fff; cursor: pointer;
}
.acf-chk .ms { font-size: 13px; color: #fff; visibility: hidden; }
.acf-chk.on { border-color: var(--c-sidebar); background: var(--c-sidebar); }
.acf-chk.on .ms { visibility: visible; }
.acf-chk:disabled, .acf-sw:disabled { opacity: .35; cursor: not-allowed; }

/* สวิตช์ Alarm / Event พร้อมป้าย */
.acf-sw { display: inline-flex; align-items: center; gap: 5px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.acf-sw i { position: relative; width: 30px; height: 17px; flex: none; border-radius: 9px; background: #c9c3b6; transition: background .15s; }
.acf-sw i::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform .15s;
}
.acf-sw.on i { background: #dc2626; }
.acf-sw.on i::after { transform: translateX(13px); }
.acf-sw em {
    min-width: 40px; padding: 1px 5px; border-radius: 9px;
    font-style: normal; font-size: 10px; font-weight: 600; text-align: center;
    background: var(--c-surface-2); color: var(--c-ink-soft);
}
.acf-sw.on em { background: var(--c-err-bg); color: var(--c-err-fg); }
.acf-dash { width: 17px; text-align: center; }
.acf-note { font-size: calc(11px * var(--k)); color: var(--c-ink-soft); }

.acf-dgrid { width: max(100%, calc(820px * var(--k))); }
.acf-dgrid .grid-row { grid-template-columns: 64px minmax(170px, 1.5fr) minmax(140px, 1.2fr) 170px 140px 70px; }
.acf-devtype { display: inline-flex; align-items: center; gap: 5px; color: var(--c-ink-soft); }
.acf-devtype .ms { font-size: 15px; }

@media (max-width: 900px) {
    .acf-cats { grid-template-columns: 1fr; }
    .al-note, .acf-mask { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .al-grid .grid-row.al-new, .al-dot.on, .al-chip.new i, .al-live.on i { animation: none; }
    .acf-sw i, .acf-sw i::after { transition: none; }
}

/* step57: กรอง Alarm ปัจจุบันตามอุปกรณ์ที่เปิดมาจากแผนที่ / ภาพรวม (กด ✕ = แสดงทั้งหมด) */
.al-focus {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    height: calc(26px * var(--k));
    padding: 0 8px;
    border: 1px solid #B7D9BE;
    border-radius: 13px;
    background: var(--c-ok-bg);
    color: var(--c-ok-fg);
    font: inherit;
    font-size: calc(11px * var(--k));
    font-weight: 600;
    cursor: pointer;
}

.al-focus .ms { font-size: 15px; }
.al-focus:hover { filter: brightness(.97); }