/* 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 */
/* ==========================================================================
   Lock Widget V1. A lock glyph in a well, the real state, and the one useful action (Unlock on a
   locked door, Lock otherwise; both when jammed / unknown; Open when the lock can unlatch).
   Unlock / Open: the button turns amber and asks for a second press.
   MaisonFit: stack (≥ 150 px tall) or row (shallow, or a long strip: glyph · name/state · button); --fit scales.
   A tall / large stack (≥ 300 px tall) puts a larger glyph in the free middle, the state under it.
   ========================================================================== */
.lk {
  position: relative;
  container: lk / size;
  --fit-ref-w: 220; --fit-ref-h: 200; --fit-min: .72px; --fit-max: 1.3px;
  min-width: 0;
  min-height: 72px;
  overflow: hidden;
  border-radius: var(--radius-device);
  color: var(--text-primary);
  font-family: var(--font);
  background: radial-gradient(120% 90% at 100% 0%, rgba(255, 255, 255, .03), 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);
  --lk-tone: var(--success);
}
.lk[data-state="unlocked"], .lk[data-state="open"], .lk[data-state="opening"] { --lk-tone: var(--warning); }
.lk[data-state="locking"], .lk[data-state="unlocking"] { --lk-tone: var(--text-secondary); }
.lk[data-state="jammed"] { --lk-tone: var(--danger); }
.lk[data-state="unavailable"], .lk[data-state="unknown"] { --lk-tone: var(--text-muted); }

.lk__in {
  height: 100%;
  padding: clamp(10px, calc(14 * var(--fit)), 22px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "glyph" "id" "state" "ctrls";
  row-gap: calc(6 * var(--fit));
}
.lk__glyph {
  grid-area: glyph;
  width: calc(44 * var(--fit)); height: calc(44 * var(--fit));
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--lk-tone);
  background: var(--surface-tertiary);
  box-shadow: var(--shadow-icon), 0 0 0 1px color-mix(in srgb, var(--lk-tone) 35%, transparent);
  transition: color var(--dur-medium) var(--ease), box-shadow var(--dur-medium) var(--ease);
}
.lk__glyph svg { width: 52%; height: 52%; }
.lk__id { grid-area: id; min-width: 0; }
.lk__name { margin: 0; font-size: max(12px, calc(15 * var(--fit))); font-weight: var(--iq-fw-title); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lk__info { margin: 0; font-size: max(11px, calc(11.5 * var(--fit))); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.lk__info[hidden] { display: none; }
.lk__sub { margin: 1px 0 0; font-size: max(11px, calc(12 * var(--fit))); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lk__state { grid-area: state; align-self: end; margin: 0; display: flex; flex-direction: column; min-width: 0; }
.lk__state b { font-size: max(15px, calc(22 * var(--fit))); font-weight: var(--iq-fw-status); color: var(--lk-tone); line-height: 1.15; }
.lk__hint { font-size: max(11px, calc(11.5 * var(--fit))); color: var(--warning); min-height: 0; }
.lk__hint:empty { display: none; }
.lk__ctrls { grid-area: ctrls; display: flex; gap: calc(8 * var(--fit)); min-width: 0; }
.lk__btn {
  flex: 1 1 0; min-width: 0;
  height: clamp(32px, calc(40 * var(--fit)), 50px);
  padding: 0 calc(12 * var(--fit));
  border: 0; border-radius: var(--radius-pill); cursor: pointer;
  font: var(--iq-fw-control) max(12px, calc(13.5 * 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);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lk__btn[hidden] { display: none; }
.lk__btn.is-armed { color: #2a1a03; background: var(--warning); }
.lk__btn:disabled { cursor: not-allowed; opacity: var(--disabled-opacity); }
.lk__btn:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

/* row: shallow boxes — glyph · name + state · button */
.lk[data-fit-arr="row"] .lk__in { grid-template-columns: auto minmax(0, 1fr) minmax(0, auto); grid-template-rows: auto auto; grid-template-areas: "glyph id ctrls" "glyph state ctrls"; column-gap: calc(12 * var(--fit)); row-gap: 0; align-content: center; }
.lk[data-fit-arr="row"] .lk__glyph { align-self: center; }
.lk[data-fit-arr="row"] .lk__state { align-self: start; }
.lk[data-fit-arr="row"] .lk__state b { font-size: max(12.5px, calc(15 * var(--fit))); }
.lk[data-fit-arr="row"] .lk__ctrls { align-self: center; flex-direction: column; }
.lk[data-fit-arr="row"] .lk__btn { flex: none; }
.lk[data-fit-arr="row"][data-fit-w="xs"] .lk__glyph { display: none; }
.lk[data-fit-arr="row"][data-fit-w="xs"] .lk__in { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "id" "state" "ctrls"; row-gap: 4px; }
.lk[data-fit-arr="row"][data-fit-w="xs"] .lk__state { align-self: start; }
.lk[data-fit-arr="row"][data-fit-w="xs"] .lk__ctrls { align-self: end; flex-direction: row; }
.lk[data-fit-arr="row"][data-fit-w="xs"] .lk__btn { flex: 1 1 0; min-height: 34px; }

/* tall / large stack: the glyph (the state at a glance) takes the free middle and grows with the box */
@container lk (min-height: 230px) and (min-width: 140px) {
  .lk[data-fit-arr="stack"] .lk__in { grid-template-rows: auto minmax(0, 1fr) auto auto; grid-template-areas: "id" "glyph" "state" "ctrls"; row-gap: calc(10 * var(--fit)); }
  .lk[data-fit-arr="stack"] .lk__glyph { width: clamp(56px, min(56cqw, calc(100cqh - 200px)), 168px); height: auto; aspect-ratio: 1; align-self: center; justify-self: center; }
  .lk[data-fit-arr="stack"] .lk__state { align-items: center; text-align: center; }
}
