/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * Copyright © 2026 Marcel Rymenhout and IniqDash contributors */
/* ==========================================================================
   Alarm / Security Widget V1. A shield that carries the state colour, the state in words, and
   one button per SUPPORTED mode (+ Disarm). Triggered: red, pulsing (not with reduced motion).
   MaisonFit: compact (too narrow for labels) shows mode icons only; text, buttons and padding scale.
   strip (a long, shallow box): state on the left, the mode buttons on the same line.
   tall (≥ 340 px): the shield grows in the free middle, name + state centred under it.
   ========================================================================== */
.al {
  position: relative;
  container: al / size;
  --fit-ref-w: 340; --fit-ref-h: 220; --fit-min: .72px; --fit-max: 1.3px;
  --al-tone: var(--text-secondary);
  min-width: 0;
  min-height: 120px;
  overflow: hidden;
  border-radius: var(--radius-device);
  color: var(--text-primary);
  font-family: var(--font);
  background: radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--al-tone) 10%, transparent), transparent 60%), linear-gradient(165deg, var(--surface-primary-top) 0%, var(--surface-primary) 58%, var(--surface-secondary) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .055), inset 0 0 0 1px rgba(255, 255, 255, .03), 0 12px 26px -16px rgba(0, 0, 0, .75);
}
.al[data-tone="off"] { --al-tone: var(--success); }
.al[data-tone="armed"] { --al-tone: var(--accent); }
.al[data-tone="busy"] { --al-tone: var(--warning); }
.al[data-tone="alarm"] { --al-tone: var(--danger); animation: al-pulse 1.2s ease-in-out infinite; }
.al[data-tone="na"] { --al-tone: var(--text-muted); }
@keyframes al-pulse { 50% { box-shadow: inset 0 0 0 2px var(--danger), 0 0 30px -4px var(--danger); } }
@media (prefers-reduced-motion: reduce) { .al[data-tone="alarm"] { animation: none; box-shadow: inset 0 0 0 2px var(--danger); } }

.al__in { height: 100%; padding: clamp(10px, calc(16 * var(--fit)), 24px); display: flex; flex-direction: column; gap: calc(10 * var(--fit)); }
.al__head { display: flex; align-items: center; gap: calc(12 * var(--fit)); min-width: 0; }
.al__shield { flex: none; width: calc(44 * var(--fit)); height: calc(44 * var(--fit)); border-radius: 50%; display: grid; place-items: center; color: var(--al-tone); background: var(--surface-tertiary);
  box-shadow: var(--shadow-icon), 0 0 0 1px color-mix(in srgb, var(--al-tone) 40%, transparent); }
.al__shield svg { width: 54%; height: 54%; }
.al__id { min-width: 0; }
.al__name { margin: 0; font-size: max(11.5px, calc(13.5 * var(--fit))); font-weight: var(--iq-fw-title); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.al__state { margin: 1px 0 0; font-size: max(15px, calc(21 * var(--fit))); font-weight: var(--iq-fw-status); line-height: 1.15; color: var(--al-tone); }
.al__hint { margin: 0; font-size: max(11px, calc(12 * var(--fit))); color: var(--warning); }
.al__hint:empty { display: none; }
.al__modes { margin-top: auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, calc(122 * var(--fit))), 1fr)); gap: calc(8 * var(--fit)); }
.al__btn {
  min-width: 0; height: clamp(34px, calc(42 * var(--fit)), 54px); padding: 0 calc(10 * var(--fit));
  display: inline-flex; align-items: center; justify-content: center; gap: calc(6 * var(--fit));
  border: 0; border-radius: calc(14 * var(--fit)); cursor: pointer;
  font: var(--iq-fw-control) max(11.5px, calc(13 * var(--fit))) var(--font); color: var(--text-primary);
  background: var(--control-raised); box-shadow: 0 2px 5px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .07);
}
.al__btn svg { flex: none; width: max(15px, calc(17 * var(--fit))); height: max(15px, calc(17 * var(--fit))); }
.al__btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.al__btn[aria-pressed="true"] { color: var(--al-tone); background: color-mix(in srgb, var(--al-tone) 16%, var(--surface-secondary)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--al-tone) 45%, transparent); opacity: 1; cursor: default; }
.al__btn.is-armed { color: #2a1a03; background: var(--warning); }
.al__btn:disabled:not([aria-pressed="true"]) { cursor: not-allowed; opacity: var(--disabled-opacity); }
.al__btn:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

/* compact: icons only (the name of each mode stays as its accessible label) */
.al[data-fit-arr="compact"] .al__btn span { display: none; }
.al[data-fit-arr="compact"] .al__modes { grid-template-columns: repeat(auto-fit, minmax(max(34px, calc(40 * var(--fit))), 1fr)); }
.al[data-fit-h="xs"] .al__shield, .al[data-fit-h="s"] .al__shield { display: none; }

/* strip: one line — shield · name/state | mode buttons */
.al[data-fit-arr="strip"] .al__in { flex-direction: row; align-items: center; gap: calc(18 * var(--fit)); }
.al[data-fit-arr="strip"] .al__head { flex: 1 1 auto; }
.al[data-fit-arr="strip"] .al__modes { margin-top: 0; flex: 0 1 auto; display: flex; }
.al[data-fit-arr="strip"] .al__btn { flex: 0 1 auto; min-width: 96px; padding: 0 calc(16 * var(--fit)); }
.al[data-fit-arr="strip"] .al__shield { display: grid; }
@container al (max-height: 109px) { .al[data-fit-arr="strip"] .al__shield { display: none; } }

/* tall: the shield (the state at a glance) takes the free middle and grows with the box */
@container al (min-height: 340px) {
  .al:not([data-fit-arr="strip"]) .al__head { flex: 1 1 auto; flex-direction: column; justify-content: center; text-align: center; gap: calc(12 * var(--fit)); }
  .al:not([data-fit-arr="strip"]) .al__shield { display: grid; width: clamp(44px, min(36cqw, 30cqh), 132px); height: auto; aspect-ratio: 1; }
  .al:not([data-fit-arr="strip"]) .al__id { max-width: 100%; }
  .al:not([data-fit-arr="strip"]) .al__modes { margin-top: 0; }
}

/* fine-tune 1 — the compact arrangement keeps the mode NAMES (icon above a short label) when the box is wide enough for four buttons;
   below that it is icons only. MICRO shows the state alone: the controls give way, the shield + state stay. */
@container al (min-width: 224px) {
  .al[data-fit-arr="compact"] .al__btn { flex-direction: column; gap: 2px; height: clamp(46px, calc(54 * var(--fit)), 60px); padding: 0 4px; }
  .al[data-fit-arr="compact"] .al__btn span { display: block; font-size: 11px; font-weight: var(--iq-fw-control); }
  .al[data-fit-arr="compact"] .al__modes { grid-template-columns: repeat(auto-fit, minmax(54px, 1fr)); }
}
.al[data-fit-tier="micro"] .al__modes { display: none; }
.al[data-fit-tier="micro"] .al__in { justify-content: center; gap: 4px; }
.al[data-fit-tier="micro"] .al__shield { display: grid; width: 30px; height: 30px; }
.al[data-fit-tier="micro"] .al__head { flex-direction: column; align-items: flex-start; gap: 6px; }
.al[data-fit-tier="micro"] .al__state { font-size: 15px; }
.al .al__state { font-weight: var(--iq-fw-display); }
.al .al__name { font-weight: var(--iq-fw-title); }
@container al (min-width: 224px) and (min-height: 150px) {
  .al:not([data-fit-arr="strip"]) .al__head { margin: auto 0; }
  .al:not([data-fit-arr="strip"]) .al__shield { width: 54px; height: 54px; }
  .al:not([data-fit-arr="strip"]) .al__state { font-size: 24px; }
}

/* pass 2: a small, short alarm is state first — the mode keys step aside instead of being cut (the full set returns with room) */
@container al (max-width: 223px) and (max-height: 139px) { .al__modes { display: none; } }

/* ---------------------------------------------------------------- PRESETS (variants). Standard: everything above, unchanged. */
/* FULL SECURITY KEYPAD: state · the masked code · a 3 × 4 keypad · the panel's own modes (each one SUBMITS the code) */
.al[data-variant="keypad"] .al__in { gap: calc(8 * var(--fit)); }
.al__pad { display: grid; gap: calc(8 * var(--fit)); }
.al__code { margin: 0; min-height: 1.6em; padding: 4px 10px; border-radius: 10px; text-align: center; letter-spacing: .3em; font-size: max(14px, calc(18 * var(--fit))); font-weight: 700;
  color: var(--text-primary); background: var(--control-well); box-shadow: var(--control-well-shadow); }
.al__code[data-filled="false"] { letter-spacing: normal; font-size: max(12px, calc(13 * var(--fit))); font-weight: 500; color: var(--text-muted); }
.al__keys { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: calc(6 * var(--fit)); }
.al__key { min-height: clamp(34px, calc(42 * var(--fit)), 56px); border: 0; border-radius: calc(12 * var(--fit)); cursor: pointer; font: 700 max(15px, calc(18 * var(--fit))) var(--font); color: var(--text-primary);
  background: var(--control-raised); box-shadow: 0 2px 5px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .07); font-variant-numeric: tabular-nums; }
.al__key--cancel, .al__key--back { font-size: max(12px, calc(13 * var(--fit))); color: var(--text-secondary); }
.al__key:active { transform: scale(.97); }
.al__key:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.al[data-variant="keypad"] .al__modes { margin-top: 0; grid-template-columns: repeat(auto-fit, minmax(min(100%, 88px), 1fr)); }
.al[data-variant="keypad"][data-state="unavailable"] .al__key { opacity: var(--disabled-opacity); cursor: not-allowed; }
/* COMPACT ALARM: one line — state · icon-only mode buttons */
.al[data-variant="compact"] .al__in { flex-direction: row; align-items: center; gap: 12px; }
.al[data-variant="compact"] .al__head { flex: 1 1 auto; min-width: 0; }
.al[data-variant="compact"] .al__hint { display: none; }
.al[data-variant="compact"] .al__modes { margin-top: 0; display: flex; gap: 6px; flex: none; }
.al[data-variant="compact"] .al__btn { width: clamp(34px, calc(40 * var(--fit)), 46px); padding: 0; }
.al[data-variant="compact"] .al__btn span { display: none; }
/* SECURITY STATUS: the state at a glance — no control */
.al[data-variant="status"] .al__modes { display: none; }
.al[data-variant="status"] .al__head { flex: 1 1 auto; flex-direction: column; justify-content: center; text-align: center; }
.al[data-variant="status"] .al__shield { display: grid; width: clamp(44px, min(34cqw, 40cqh), 120px); height: auto; aspect-ratio: 1; }
.al[data-variant="status"] .al__state { font-size: clamp(16px, 9cqmin, 30px); }
/* MODERN ALARM PANEL: a coloured state band, large mode tiles (two per row) */
.al[data-variant="modern"] .al__head { padding: calc(12 * var(--fit)); border-radius: calc(16 * var(--fit)); background: color-mix(in srgb, var(--al-tone) 18%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--al-tone) 35%, transparent); }
.al[data-variant="modern"] .al__shield { background: var(--al-tone); color: var(--surface-primary); }
.al[data-variant="modern"] .al__modes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.al[data-variant="modern"] .al__btn { height: clamp(44px, calc(58 * var(--fit)), 72px); flex-direction: column; gap: 4px; border-radius: calc(16 * var(--fit)); }
.al[data-variant="modern"] .al__btn svg { width: max(18px, calc(22 * var(--fit))); height: max(18px, calc(22 * var(--fit))); }

/* ================================================================ CARD (variant 'card') — shield tile · name · state · since, then the arm / disarm buttons */
.al-card { --sc: #3ce06a; position: relative; box-sizing: border-box; height: 100%; min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 16px;
  padding: 16px 18px; color: #fff; font-family: var(--mai-font, var(--font)); border-radius: 18px; border: 1px solid rgba(255, 255, 255, .06);
  background: radial-gradient(70% 140% at 0% 50%, color-mix(in srgb, var(--sc) 13%, transparent), transparent 60%), linear-gradient(180deg, #22252e 0%, #1f222a 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04), 0 6px 16px rgba(0, 0, 0, .25); }
.al-card[data-tone="armed"] { --sc: #c49bff; } .al-card[data-tone="trig"] { --sc: #ff5a5a; } .al-card[data-tone="na"] { --sc: #5c616e; }
.alc__ic { width: 62px; height: 62px; box-sizing: border-box; border-radius: 18px; display: grid; place-items: center; font-size: 29px; color: var(--sc); background: color-mix(in srgb, var(--sc) 12%, #1a1c23);
  border: 1px solid color-mix(in srgb, var(--sc) 35%, transparent); }
.alc__ic .bi { line-height: 1; }
.alc__t { min-width: 0; }
.alc__t small { display: block; font-size: 9.5px; line-height: 13px; color: #8b909c; }
.alc__t b { display: block; font-size: 21px; font-weight: 600; line-height: 1.2; }
.alc__t span { display: block; font-size: 9px; line-height: 12px; color: #8b909c; margin-top: 2px; }
.alc__ro { color: #858a97; font-size: 14px; padding: 0 4px; }
.alc__ctl { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.alc__btn { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; border-radius: 99px; cursor: pointer; font: 600 10.5px var(--mai-font, var(--font));
  color: #ffb347; background: rgba(255, 138, 43, .1); border: 1px solid rgba(255, 138, 43, .5); }
.alc__btn:hover:not(:disabled) { background: rgba(255, 138, 43, .2); color: #fff; }
.alc__btn.is-disarm { border-color: rgba(47, 192, 255, .5); background: rgba(47, 192, 255, .1); color: #6fd3ff; }
.alc__btn:disabled { opacity: .45; cursor: not-allowed; }

/* ================================================================ SECURITY LOOKS — hero · modes · ring · tiles · list */
.al-sec { box-sizing: border-box; height: 100%; min-width: 0; color: #fff; font-family: var(--mai-font, var(--font)); }
.al-sec--hero, .al-sec--ring, .al-sec--list { border-radius: 20px; padding: 16px 18px; background: linear-gradient(180deg, #1f2129 0%, #1a1c22 100%); border: 1px solid rgba(255, 255, 255, .06); box-shadow: 0 8px 20px rgba(0, 0, 0, .25); }
/* HERO */
.al-sec--hero { --tone: #3ce06a; display: flex; flex-direction: column; gap: 14px; padding: 16px 18px; background: linear-gradient(135deg, color-mix(in srgb, var(--tone) 12%, #1d2026) 0%, #191b21 60%); border-color: color-mix(in srgb, var(--tone) 40%, transparent); }
.al-sec--hero[data-tone="armed"] { --tone: #ff8a2b; } .al-sec--hero[data-tone="alert"] { --tone: #ff4b4b; } .al-sec--hero[data-tone="pending"] { --tone: #ffc83d; } .al-sec--hero[data-tone="off"] { --tone: #6d7280; }
.al-sec__head { display: flex; align-items: center; gap: 16px; }
.al-sec__shield { width: 64px; height: 64px; flex: none; display: grid; place-items: center; font-size: 36px; color: var(--tone); filter: drop-shadow(0 0 12px color-mix(in srgb, var(--tone) 55%, transparent)); }
.al-sec__shield .bi { font-size: 36px; line-height: 1; }
.al-sec__head small { display: block; font-size: 10px; line-height: 14px; color: #c9ccd4; }
.al-sec__head b { display: block; font-size: 22px; font-weight: 700; line-height: 1.15; }
.al-sec__head span { display: block; font-size: 9px; line-height: 12px; color: #8b909c; }
.al-sec__ctl { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.al-sec__btn { flex: 1 1 auto; display: inline-flex; align-items: center; gap: 6px; min-height: 46px; padding: 0 14px; border-radius: 14px; border: 1px solid rgba(255, 170, 60, .45); background: rgba(30, 26, 20, .6); color: #fff;
  font: inherit; font-size: 10.5px; font-weight: 600; cursor: pointer; transition: background .2s; }
.al-sec__btn .bi { color: #ffb347; font-size: 10.5px; }
.al-sec__btn:hover { background: rgba(255, 138, 43, .2); }
.al-sec__btn.is-disarm { border-color: rgba(47, 192, 255, .5); background: rgba(47, 192, 255, .1); color: #6fd3ff; } .al-sec__btn.is-disarm .bi { color: #6fd3ff; }
.al-sec__ctl.is-small { margin: 6px 0 4px; } .al-sec__ctl.is-small .al-sec__btn { flex: none; min-height: 38px; border-radius: 99px; }
/* MODES */
.al-sec--modes { display: inline-flex; gap: 4px; padding: 4px; height: auto; border-radius: 18px; background: #15171d; border: 1px solid rgba(255, 255, 255, .06); width: max-content; max-width: 100%; margin-left: auto; }
.al-sec__mode { display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 16px; border-radius: 14px; border: 1px solid transparent; background: transparent; color: #c9ccd4; font: inherit; font-size: 10.5px; font-weight: 500; cursor: pointer; }
.al-sec__mode .bi { font-size: 13px; }
.al-sec__mode:hover:not(:disabled) { background: #20232b; color: #fff; }
.al-sec__mode.is-on { color: #fff; background: linear-gradient(180deg, #2a2620 0%, #211e1a 100%); border-color: rgba(255, 170, 60, .55); box-shadow: 0 0 12px rgba(255, 150, 40, .18); }
.al-sec__mode.is-on .bi { color: #ffb347; }
.al-sec__mode:disabled:not(.is-on) { opacity: .55; cursor: default; }
/* RING */
.al-sec__h { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; font-weight: 600; line-height: 16px; }
.al-sec__ringrow { display: flex; align-items: center; gap: 16px; margin-top: 10px; }
.al-sec__ring { position: relative; width: 110px; height: 110px; flex: none; }
.al-sec__ring svg { width: 100%; height: 100%; display: block; }
.al-sec__ring div { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.al-sec__ring b { font-size: 26px; font-weight: 600; line-height: 1; }
.al-sec__ring small { font-size: 8.5px; color: #8b909c; }
.al-sec__legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; flex: 1; min-width: 0; }
.al-sec__legend li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; font-size: 10px; line-height: 14px; color: #c9ccd4; }
.al-sec__legend i { width: 9px; height: 9px; border-radius: 50%; }
.al-sec__legend b { font-weight: 600; color: #fff; }
/* TILES */
.al-sec--tiles { display: grid; grid-template-columns: repeat(var(--n, 3), minmax(0, 1fr)); gap: 10px; }
.al-sec__tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 14px 6px; border-radius: 18px; text-align: center; min-width: 0; box-sizing: border-box;
  background: linear-gradient(180deg, #1d2a22 0%, #182019 100%); border: 1px solid rgba(60, 224, 106, .25); }
.al-sec__tico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 19px; color: #e9ebf0; background: rgba(255, 255, 255, .05); margin-bottom: 4px; }
.al-sec__tile b { font-size: 11px; font-weight: 600; line-height: 15px; }
.al-sec__tst { font-size: 10px; line-height: 14px; color: #3ce06a; font-weight: 500; }
.al-sec__tile small { font-size: 8.5px; line-height: 11px; color: #8b909c; }
.al-sec__tile.is-warn { background: linear-gradient(180deg, #2c1e1c 0%, #221817 100%); border-color: rgba(255, 90, 90, .35); }
.al-sec__tile.is-warn .al-sec__tst { color: #ff7a7a; }
.al-sec__tile.is-active .al-sec__tst { color: #ffb347; }
/* LIST */
.al-sec--list { padding: 16px 18px; }
.al-sec__lh { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 13px; }
.al-sec__lh h3 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13.5px; font-weight: 600; line-height: 18px; }
.al-sec__lh h3 .bi { color: #2fc0ff; font-size: 13.5px; }
.al-sec__rows { display: flex; flex-direction: column; }
.al-sec__row { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 52px; border-bottom: 1px solid rgba(255, 255, 255, .05); }
.al-sec__row:last-child { border-bottom: 0; }
.al-sec__ric { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-size: 13.5px; color: #c9ccd4; background: #262932; }
.al-sec__ric.is-warn { color: #ffb347; background: rgba(255, 138, 43, .16); }
.al-sec__rb { min-width: 0; display: flex; flex-direction: column; }
.al-sec__rb b { font-size: 11px; font-weight: 600; line-height: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.al-sec__rb small { font-size: 8px; line-height: 11px; color: #8b909c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.al-sec__chip { display: inline-flex; font-size: 7.5px; font-weight: 600; letter-spacing: .04em; line-height: 10px; text-transform: uppercase; padding: 2px 7px; border-radius: 99px; background: #282b35; color: #b7bbc5; white-space: nowrap; }
.al-sec__chip.is-ok { background: rgba(60, 224, 106, .12); color: #6fe58f; }
.al-sec__chip.is-warn { background: rgba(255, 138, 43, .16); color: #ffb347; }
.al-sec__chip.is-on { background: rgba(255, 200, 61, .14); color: #ffd36b; }
.al-sec__chip.is-na { background: rgba(241, 60, 60, .12); color: #ff8a8a; }
.al-sec__note { margin: 0; font-size: 8px; line-height: 11px; color: #8b909c; }
