/* 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 */
/* ==========================================================================
   Action Widget V1 — widget-specific CSS only (surfaces/colours/radii/type from shared tokens).

   Identity: the whole tile is one pressable plate (it gives under the finger); the icon sits in a
   ring that shows the execution status: a turning arc while running, a full ring + check when done,
   a danger ring + "!" when failed, and a draining countdown while a confirmation is armed.
   No LED, no latch, no ON/OFF — that is the Switch.

   Arrangements (container "aw" = the widget's own box):
     short     < 260px wide and < 120px tall: one line — ring | name + status
     compact   < 260px wide      ring on top, name (+ subtitle), status
     standard  260–479           ring | name + subtitle + status | "Run" cue
     wide     >= 480px           ring | name + subtitle | status | "Run" cue — while a strip
                                 (< 240px tall, or ≥ 2 : 1)
     tall     ≥ 240px tall, not a strip: the ring large in the middle (both axes), name + status
                                 centred under it, the "Run" cue at the bottom (≥ 260 wide)
   ========================================================================== */

.aw {
  --aw-confirm: 4000ms;
  --aw-tone: var(--accent);
  position: relative;
  container: aw / size;
  min-width: 0;
  min-height: 92px;
  overflow: hidden;
  border-radius: var(--radius-device);
  font-family: var(--font);
  background: linear-gradient(165deg, var(--surface-primary-top), var(--surface-primary) 55%, var(--surface-secondary));
  box-shadow: var(--shadow-primary), inset 0 0 0 1px var(--border-subtle);
}
.aw[data-status="done"] { --aw-tone: var(--success); }
.aw[data-status="failed"] { --aw-tone: var(--danger); }

/* the plate: the whole tile is the button */
.aw__trigger {
  position: absolute;
  inset: 0;
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: inherit;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "glyph" "." "id" "status";
  row-gap: 3px;
  justify-items: start;
  text-align: left;
  cursor: pointer;
  color: var(--text-primary);
  font: inherit;
  background: transparent;
  transition: transform var(--dur-press) var(--ease), box-shadow var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.aw__trigger:active:not(:disabled) { transform: scale(.985); box-shadow: inset 0 3px 10px rgba(0, 0, 0, .45); }
.aw__trigger:focus-visible { outline: var(--focus-ring); outline-offset: -4px; }
.aw__trigger:disabled { cursor: not-allowed; }

/* ---- icon in its status ring ---- */
.aw__glyph { grid-area: glyph; position: relative; width: 44px; height: 44px; flex: none; }
.aw__icon {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text-primary);
  background: radial-gradient(circle at 40% 30%, var(--surface-tertiary), var(--surface-primary));
  box-shadow: 0 3px 8px rgba(0, 0, 0, .5), inset 0 1px 0 var(--edge-highlight);
}
.aw__icon svg { width: 46%; height: 46%; }
.aw__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--aw-tone) var(--aw-arc, 0deg), var(--border-primary) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
}
.aw__mark { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%; display: none; place-items: center; color: var(--page-bg); background: var(--aw-tone); box-shadow: 0 0 0 2px var(--surface-primary); }
.aw__mark svg { width: 13px; height: 13px; stroke-width: 3; }
.aw[data-status="done"] .aw__mark, .aw[data-status="failed"] .aw__mark { display: grid; }
.aw[data-status="done"] .aw__ring, .aw[data-status="failed"] .aw__ring { --aw-arc: 360deg; }
.aw[data-status="ready"] .aw__icon { color: var(--accent); }

/* running: a turning arc */
.aw[data-status="running"] .aw__ring { --aw-arc: 90deg; animation: aw-turn 1s linear infinite; }
@keyframes aw-turn { to { transform: rotate(360deg); } }
/* confirm: a countdown that drains over the confirmation window */
@property --aw-arc { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
.aw[data-status="confirm"] .aw__ring { animation: aw-drain var(--aw-confirm) linear forwards; }
@keyframes aw-drain { from { --aw-arc: 360deg; } to { --aw-arc: 0deg; } }
@media (prefers-reduced-motion: reduce) {
  .aw[data-status="running"] .aw__ring { animation: none; --aw-arc: 360deg; opacity: .55; }
  .aw[data-status="confirm"] .aw__ring { animation: none; --aw-arc: 360deg; }
}
.aw[data-status="confirm"] { box-shadow: var(--shadow-primary), inset 0 0 0 1px var(--accent-line); }

/* ---- text ---- */
.aw__id { grid-area: id; display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.aw__name { font-size: 14px; font-weight: var(--iq-fw-title); line-height: 1.22; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: break-word; }
.aw[data-has-sub="true"] .aw__name { -webkit-line-clamp: 1; }
.aw__sub { margin-top: 1px; font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aw__sub[hidden] { display: none; }
.aw__status { grid-area: status; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; margin-top: 3px; font-size: 12px; font-weight: var(--iq-fw-status); color: var(--aw-tone); white-space: nowrap; }
.aw__status[hidden] { display: none; }
.aw__status-t { overflow: hidden; text-overflow: ellipsis; }
.aw__dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--aw-tone); }
.aw[data-status="running"] .aw__status { color: var(--text-secondary); }
.aw[data-status="running"] .aw__dot { background: var(--accent); }
.aw[data-status="unavailable"] .aw__status, .aw[data-status="unavailable"] .aw__name { color: var(--text-muted); }
.aw[data-status="unavailable"] .aw__dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-muted); }
.aw[data-status="unavailable"] .aw__glyph { opacity: var(--unavailable-opacity); filter: grayscale(1); }
.aw[data-status="unavailable"] .aw__icon { color: var(--text-muted); }
.aw__go { display: none; }

/* cancel: only while a confirmation is armed */
.aw__cancel {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-secondary);
  background: var(--page-bg);
  box-shadow: var(--shadow-icon), inset 0 0 0 1px var(--border-subtle);
}
.aw__cancel svg { width: 16px; height: 16px; stroke-width: 2.4; }
.aw__cancel[hidden] { display: none; }
.aw__cancel:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

/* ---------------------------------------------------------------- standard: ≥ 260px wide */
@container aw (min-width: 260px) {
  .aw__trigger {
    padding: 14px 18px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr) auto auto minmax(0, 1fr);
    grid-template-areas: "glyph . go" "glyph id go" "glyph status go" "glyph . go";
    column-gap: 14px;
    align-items: center;
  }
  .aw__glyph { width: 56px; height: 56px; }
  .aw__name { font-size: 15px; }
  .aw__go {
    grid-area: go;
    display: inline-flex;
    align-items: center;
    height: 36px;
    padding: 0 14px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--page-bg);
    box-shadow: inset 0 0 0 1px var(--border-subtle);
  }
  .aw__go::after { content: "›"; margin-left: 6px; color: var(--text-muted); }
  .aw[data-status="confirm"] .aw__go { color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-line); }
  .aw[data-status="running"] .aw__go, .aw[data-status="unavailable"] .aw__go { opacity: var(--disabled-opacity); }
  .aw[data-status="confirm"] .aw__trigger { padding-right: 62px; }   /* room for Cancel */
  .aw__cancel { top: 50%; transform: translateY(-50%); right: 12px; }
}

/* ---------------------------------------------------------------- wide: ≥ 480px */
@container aw (min-width: 480px) and ((max-height: 239px) or (min-aspect-ratio: 2 / 1)) {
  .aw__trigger {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "glyph id status go";
    column-gap: 18px;
  }
  .aw__glyph { width: 52px; height: 52px; }
  .aw__name { font-size: 16px; }
  .aw__status { margin: 0; padding: 0 16px; border-inline: 1px solid var(--border-subtle); min-height: 32px; }
}

/* ---------------------------------------------------------------- short: one line (narrow AND < 120px tall) */
@container aw (max-height: 119px) and (max-width: 259px) {
  .aw__trigger {
    padding: 10px 12px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto auto minmax(0, 1fr);
    grid-template-areas: "glyph ." "glyph id" "glyph status" "glyph .";
    column-gap: 10px;
    align-items: center;
  }
  .aw__glyph { width: 38px; height: 38px; }
  .aw__name { font-size: 13.5px; -webkit-line-clamp: 2; }
  .aw[data-has-sub="true"] .aw__name { -webkit-line-clamp: 2; }
  .aw[data-has-sub="true"] .aw__sub { display: none; }
  .aw__status { margin-top: 1px; }
  .aw__go { display: none; }
  .aw[data-status="confirm"] .aw__trigger { padding-right: 56px; }
  .aw__cancel { top: 50%; right: 8px; transform: translateY(-50%); }
}

/* ---------------------------------------------------------------- tall: ≥ 240px tall, not a strip
   The ring is the action's face (and its status): it takes the free middle and grows with the box. */
@container aw (min-height: 240px) and (max-aspect-ratio: 2 / 1) {
  .aw__trigger {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto auto auto minmax(0, .6fr);
    grid-template-areas: "glyph" "id" "status" "go" ".";
    justify-items: center; align-items: center; text-align: center; row-gap: 6px;
  }
  .aw__glyph { width: clamp(56px, min(46cqw, calc(100cqh - 170px)), 150px); height: auto; aspect-ratio: 1; align-self: end; margin-bottom: 8px; }
  .aw__mark { width: max(18px, 22%); height: max(18px, 22%); right: 0; bottom: 0; }
  .aw__mark svg { width: 62%; height: 62%; }
  .aw__id { align-items: center; width: 100%; }
  .aw__sub { max-width: 100%; }
  .aw__name { font-size: clamp(15px, 5cqmin, 20px); }
  .aw__status { margin: 2px 0 0; padding: 0; border: 0; min-height: 0; }
  .aw__go { margin-top: 8px; }
}

/* LOOK: scene card — a large round icon filled with its colour; name and subtitle at the bottom (no Run pill) */
.aw[data-look="scene"] .aw__trigger { flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 18px; height: 100%; box-sizing: border-box; text-align: left; }
.aw[data-look="scene"] .aw__glyph { width: 48px; height: 48px; border-radius: 50%; color: #ffffff; background: radial-gradient(circle at 35% 30%, var(--aw-c1), var(--aw-c2));
  box-shadow: 0 8px 22px color-mix(in srgb, var(--aw-c2) 45%, transparent), inset 0 1px 0 rgba(255, 255, 255, .35); }
.aw[data-look="scene"] .aw__glyph svg { width: 24px; height: 24px; }
.aw[data-look="scene"] .aw__ring { display: none; }
.aw[data-look="scene"] .aw__go { display: none; }
.aw[data-look="scene"] .aw__id { margin-top: auto; }
.aw[data-look="scene"] .aw__name { font-size: 16px; font-weight: 700; }
.aw[data-look="scene"] .aw__sub { font-size: 12px; color: var(--text-muted); white-space: normal; }

/* LOOK: pill — a capsule: a round icon filled with its colour and the name (a row of scene chips) */
.aw[data-look="pill"] .aw__trigger { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 6px 18px 6px 6px; height: 100%; box-sizing: border-box; border-radius: 999px; }
.aw[data-look="pill"] .aw__glyph { width: 36px; height: 36px; border-radius: 50%; color: #ffffff; background: radial-gradient(circle at 35% 30%, var(--aw-c1), var(--aw-c2)); box-shadow: 0 4px 14px color-mix(in srgb, var(--aw-c2) 45%, transparent); }
.aw[data-look="pill"] .aw__glyph svg { width: 18px; height: 18px; }
.aw[data-look="pill"] .aw__ring, .aw[data-look="pill"] .aw__go, .aw[data-look="pill"] .aw__sub { display: none; }
.aw[data-look="pill"] .aw__name { font-size: 14px; font-weight: 600; white-space: nowrap; }
.aw[data-look="scene"] .aw__icon, .aw[data-look="pill"] .aw__icon { background: none; box-shadow: none; color: #ffffff; inset: 0; }
.aw[data-look="scene"] .aw__icon svg { width: 50%; height: 50%; }
.aw[data-look="pill"] .aw__id { min-width: 0; }
.aw[data-look="pill"] .aw__status { display: none; }

/* ================================================================ SCENES (variant 'scenes') — a row of scene cards, two at a time, arrows and dots */
.iq-scn { box-sizing: border-box; height: 100%; min-width: 0; display: flex; flex-direction: column; padding: 16px 12px 12px; border-radius: 20px; color: #fff; font-family: var(--mai-font, var(--font));
  background: linear-gradient(180deg, #1f2028 0%, #1c1d24 100%); }
.iq-scn .iqs-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 8px 0 10px; }
.iq-scn .iqs-title { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .01em; line-height: 14px; }
.iq-scn .iqs-nav { display: flex; gap: 4px; }
.iq-scn .iqs-arrow { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 0; display: grid; place-items: center; font-size: 11px; color: #fff; background: rgba(18, 20, 27, .75); cursor: pointer; transition: background-color .2s; }
.iq-scn .iqs-arrow:hover { background: rgba(255, 255, 255, .14); }
.iq-scn .iqs-track { margin-top: 11px; display: grid; grid-auto-flow: column; grid-auto-columns: calc((100% - 10px) / 2); gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; scroll-behavior: smooth;
  overscroll-behavior-x: contain; padding: 2px 2px 8px; scrollbar-width: none; touch-action: pan-x; }
.iq-scn .iqs-track::-webkit-scrollbar { display: none; }
.iq-scn .iqs-card { --accent: #ff8a2b; scroll-snap-align: start; position: relative; min-height: 132px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 12px 12px 11px;
  border-radius: 18px; text-align: left; color: #fff; font: inherit; cursor: pointer; border: 1px solid rgba(255, 255, 255, .06); background: linear-gradient(180deg, #282a33 0%, #23252d 100%);
  box-shadow: 0 6px 14px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .04); transition: transform .15s, background .3s, box-shadow .3s; box-sizing: border-box; }
.iq-scn .iqs-card:hover { transform: translateY(-2px); }
.iq-scn .iqs-card:active { transform: scale(.98); }
.iq-scn .iqs-orb { width: 37px; height: 37px; border-radius: 50%; display: grid; place-items: center; font-size: 17px; color: #fff; margin-bottom: 5px;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--accent) 50%, #fff) 0%, var(--accent) 55%, color-mix(in srgb, var(--accent) 70%, #000) 100%);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--accent) 18%, transparent), 0 5px 14px color-mix(in srgb, var(--accent) 45%, transparent); }
.iq-scn .iqs-orb .bi { line-height: 1; }
.iq-scn .iqs-name { font-size: 11.2px; font-weight: 600; line-height: 15px; }
.iq-scn .iqs-desc { font-size: 7.8px; color: #8b909c; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.iq-scn .iqs-state { position: absolute; top: 11px; right: 11px; font-size: 7.2px; font-weight: 600; letter-spacing: .04em; color: #6d7280; line-height: 10px; }
.iq-scn .iqs-card.is-active { border-color: transparent; background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 80%, #fff) 0%, var(--accent) 50%, color-mix(in srgb, var(--accent) 85%, #000) 100%);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 35%, transparent); }
.iq-scn .iqs-card.is-active .iqs-orb { background: rgba(255, 255, 255, .22); box-shadow: 0 0 0 4px rgba(255, 255, 255, .1); }
.iq-scn .iqs-card.is-active :is(.iqs-desc, .iqs-state) { color: rgba(255, 255, 255, .85); }
.iq-scn .iqs-card.is-unset .iqs-orb { filter: grayscale(.8); opacity: .6; }
.iq-scn .iqs-card.is-unset .iqs-state { color: #8b909c; }
.iq-scn .iqs-dots { display: flex; justify-content: center; gap: 5px; padding-top: 2px; }
.iq-scn .iqs-dots i { width: 6px; height: 6px; border-radius: 6px; background: #3a3d48; transition: width .25s, background .25s; }
.iq-scn .iqs-dots i.is-on { width: 18px; background: linear-gradient(90deg, #4fd0ff, #2a8ff0); box-shadow: 0 0 8px rgba(47, 192, 255, .6); }

/* ================================================================ RAIL (variant 'rail') — a pill of round icon buttons, the first pressed in */
.iq-rail { display: flex; justify-content: center; font-family: var(--mai-font, var(--font)); }
.iq-rail .iqr-list { width: 43px; margin: 0; padding: 9px 0; list-style: none; display: flex; flex-direction: column; align-items: center; gap: 10px; border-radius: 22px; box-sizing: border-box;
  background: linear-gradient(180deg, #282b36, #22252f); border: 1px solid rgba(255, 255, 255, .09); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), 0 6px 14px rgba(0, 0, 0, .25); }
.iq-rail .iqr-btn { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; font-size: 16.5px; color: #8e93a2; background: transparent; cursor: pointer;
  transition: color .2s, background-color .2s, transform .15s; }
.iq-rail .iqr-btn:hover { color: #d8dbe3; background: rgba(255, 255, 255, .04); }
.iq-rail .iqr-btn:active { transform: scale(.94); }
.iq-rail li:first-child .iqr-btn { background: #191b22; box-shadow: inset 0 2px 5px rgba(0, 0, 0, .55); }
.iq-rail .iqr-btn .bi { line-height: 1; }
.iq-rail .iqr-dots { position: relative; width: 20px; height: 14px; }
.iq-rail .iqr-dots span { position: absolute; top: 0; width: 14px; height: 14px; border-radius: 50%; }
.iq-rail .iqr-dots span:first-child { left: 0; background: radial-gradient(circle at 35% 35%, #ffb06a, #ff6a1a); z-index: 2; box-shadow: 0 0 8px rgba(255, 122, 40, .7); }
.iq-rail .iqr-dots span:last-child { left: 7px; background: radial-gradient(circle at 40% 35%, #f3f3f5, #a9adb8); }

/* ================================================================ PAGE TABS (variant 'tabs') · QUICK ACTIONS (variant 'quick') */
.iq-ptabs { display: flex; align-items: center; gap: 6px; height: 100%; overflow-x: auto; scrollbar-width: none; font-family: var(--mai-font, var(--font)); }
.iq-ptabs::-webkit-scrollbar { display: none; }
.iq-ptab { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 99px; border: 1px solid rgba(255, 255, 255, .1); background: #1b1d24; color: #c9ccd4;
  font: inherit; font-size: 10px; font-weight: 500; line-height: 16px; cursor: pointer; transition: color .15s, background .15s; }
.iq-ptab:hover { color: #fff; }
.iq-ptab.is-active { color: #fff; background: rgba(47, 192, 255, .14); border-color: rgba(47, 192, 255, .5); }
.iq-ptab__n { min-width: 16px; height: 16px; padding: 0 4.5px; box-sizing: border-box; border-radius: 99px; display: inline-flex; align-items: center; justify-content: center; font-size: 8px; font-weight: 700; color: #1a1205; background: #ffb020; }
.iq-ptab__n[hidden] { display: none; }
.iq-quick { box-sizing: border-box; height: 100%; padding: 16px 18px; border-radius: 20px; 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); color: #fff; font-family: var(--mai-font, var(--font)); }
.iq-quick__h { margin: 0; font-size: 13px; font-weight: 600; line-height: 16px; }
.iq-quick__row { display: grid; grid-template-columns: repeat(var(--n, 3), minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.iq-quick__btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 84px; padding: 10px 6px; border-radius: 16px; border: 1px solid rgba(255, 255, 255, .07);
  background: #20232b; color: #e9ebf0; font: inherit; font-size: 9.5px; cursor: pointer; transition: background .15s; }
.iq-quick__btn .bi { font-size: 20px; color: var(--ac); filter: drop-shadow(0 0 8px color-mix(in srgb, var(--ac) 45%, transparent)); }
.iq-quick__btn:hover { background: #262a33; }
.iq-quick__btn.is-done { border-color: color-mix(in srgb, var(--ac) 55%, transparent); }
