/* Widgets, the dashboard grid and its editor. Positions arrive as --x/--y/--w/--h (cells), colours as --m (module accent). */

.dgrid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: 80px; gap: 12px; position: relative; }
.wcard {
  --m: var(--accent-bg);
  position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  grid-column: calc(var(--x) + 1) / span var(--w); grid-row: calc(var(--y) + 1) / span var(--h);
  background: linear-gradient(170deg, var(--surface-2), var(--surface)); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .2s;
}
.wcard::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: linear-gradient(90deg, var(--m), transparent 85%); opacity: .9; }
.wcard:hover { border-color: color-mix(in srgb, var(--m) 55%, var(--line)); box-shadow: 0 14px 34px -16px color-mix(in srgb, var(--m) 55%, transparent); }
.wcard-head { display: flex; align-items: center; gap: .5rem; padding: .55rem .6rem .15rem .8rem; min-height: 2.5rem; flex: none; }
.wcard-icon { display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 9px; flex: none; background: color-mix(in srgb, var(--m) 24%, transparent); color: var(--text); }
.wcard-icon .icon { width: 1rem; height: 1rem; }
.wcard-title { margin: 0; line-height: 1.3; flex: 1; min-width: 0; font-size: .92rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); text-decoration: none; }
.wcard-title a { color: inherit; text-decoration: none; }
.wcard-title a:hover { text-decoration: underline; }
.wcard-actions { display: flex; gap: .1rem; flex: none; }
.wcard-actions .icon-btn { width: 1.9rem; height: 1.9rem; }
.wcard-actions .icon-btn .icon { width: 1rem; height: 1rem; }
.wbody { flex: 1; min-height: 0; overflow: auto; padding: .15rem .85rem .75rem; container-type: size; display: flex; flex-direction: column; scrollbar-width: thin; }
.wbody > * { min-height: 0; }
.w-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.wbody-loading { display: grid; place-items: center; flex: 1; }
.wbody-loading .orbit { width: 2rem; height: 2rem; }
.wbody-loading .orbit-dot { transform-origin: 50% calc(1rem + 3px); }
.w-empty { margin: auto; text-align: center; }
.w-stale { display: flex; align-items: center; gap: .4rem; margin: .5rem 0 0; font-size: .78rem; color: var(--warn); }
.w-stale .icon { width: .9rem; height: .9rem; }
.w-state { margin: auto; display: grid; justify-items: center; text-align: center; gap: .5rem; max-width: 22rem; }
.w-state-error { color: var(--muted); }
.w-state-error > .icon { color: var(--bad); width: 1.6rem; height: 1.6rem; }
.w-state p { margin: 0; }
.w-notice { margin: auto 0; display: flex; gap: .65rem; align-items: flex-start; }
.w-notice > .icon { margin-top: .15rem; color: var(--info); }
.w-notice.tone-warn > .icon { color: var(--warn); } .w-notice.tone-bad > .icon { color: var(--bad); } .w-notice.tone-ok > .icon { color: var(--ok); }
.w-notice p { margin: 0 0 .5rem; }
.w-notice-act { margin-top: .25rem; }
.w-text { white-space: pre-wrap; margin: 0; overflow-wrap: anywhere; }

@container (max-height: 140px) { .progress-detail { display: none; } }
.dash-meta:not(:empty) { margin-bottom: .75rem; }

/* tones */
.tone-ok { --tone: var(--ok); } .tone-warn { --tone: var(--warn); } .tone-bad { --tone: var(--bad); } .tone-info { --tone: var(--info); } .tone-muted { --tone: var(--muted); }
.tone-bg-ok { background: var(--c6); } .tone-bg-warn { background: var(--c2); } .tone-bg-bad { background: #e5484d; } .tone-bg-info { background: var(--c1); } .tone-bg-muted { background: var(--line-strong); }

/* stat */
.w-stat > *, .w-progress > * { flex: none; }
.w-stat { display: flex; flex-direction: column; justify-content: center; gap: .3rem; flex: 1; min-height: 0; }
.stat-main { display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; }
.stat-value { font-size: clamp(1.6rem, 15cqi, 3.4rem); line-height: 1.05; font-weight: 800; letter-spacing: -.02em; color: var(--tone, var(--text)); font-variant-numeric: tabular-nums; }
.stat-unit { color: var(--muted); font-weight: 600; }
.stat-sub { margin: 0; color: var(--muted); font-size: .92rem; }
.spark { width: 100%; height: 2.25rem; margin-top: .25rem; overflow: visible; }
.spark-line { fill: none; stroke: var(--tone, var(--c1)); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark-area { fill: color-mix(in srgb, var(--tone, var(--c1)) 18%, transparent); stroke: none; }
.spark-dot { fill: var(--tone, var(--c1)); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(5.5rem, 1fr)); gap: .5rem .9rem; margin: .5rem 0 0; }
.stat-grid dt { font-size: .75rem; color: var(--muted); }
.stat-grid dd { margin: 0; font-weight: 750; color: var(--tone, var(--text)); font-variant-numeric: tabular-nums; }
.w-stat > .chip { align-self: flex-start; }

/* list / status / agenda */
.w-list, .w-checks, .w-agenda ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .1rem; }
.w-item, .w-check-row, .agenda-ev { display: flex; align-items: center; gap: .6rem; padding: .35rem .1rem; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); min-width: 0; }
.w-item:last-child, .w-check-row:last-child, .agenda-ev:last-child { border-bottom: 0; }
.w-item-icon { color: var(--muted); display: grid; }
.w-item-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.w-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); text-decoration: none; }
a.w-item-title:hover, a.w-link:hover { text-decoration: underline; }
.w-item-sub { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-item-meta { font-size: .8rem; white-space: nowrap; flex: none; }
.w-item.done .w-item-title { text-decoration: line-through; color: var(--muted); }
.w-check { width: 1.2rem; height: 1.2rem; }
.w-item.tone-bad .w-item-title { color: var(--bad); }
.check-state { display: grid; color: var(--tone); }
.w-link { color: var(--accent); }
.w-agenda { display: grid; gap: .6rem; }
.agenda-date { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .2rem; }
.agenda-ev { border-left: 3px solid var(--ec, var(--accent-bg)); padding-left: .55rem; border-bottom: 0; }
.ev-time { font-size: .8rem; min-width: 4.6rem; font-variant-numeric: tabular-nums; }

/* table */
.w-table-scroll { overflow: auto; flex: 1; min-height: 0; }
.w-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.w-table th, .w-table td { padding: .35rem .5rem; text-align: left; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); white-space: nowrap; }
.w-table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); position: sticky; top: 0; background: var(--surface); }
.w-table tbody th { font-weight: 600; }
.w-table tr.tone-bad td, .w-table tr.tone-bad th { color: var(--bad); } .w-table tr.tone-warn td, .w-table tr.tone-warn th { color: var(--warn); }
.ta-right { text-align: right !important; } .ta-center { text-align: center !important; }

/* progress */
.w-progress { display: flex; flex-direction: column; justify-content: center; gap: .5rem; flex: 1; }
.progress-head { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.progress-pct { font-size: clamp(1.5rem, 12cqi, 2.6rem); font-weight: 800; line-height: 1; color: var(--tone, var(--text)); font-variant-numeric: tabular-nums; }
.progress-label { color: var(--muted); }
.bar { display: flex; height: .8rem; border-radius: 999px; overflow: hidden; background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line); }
.bar-seg { flex: 0 0 calc(var(--p, 0) * 100%); min-width: 0; }
.bar-seg + .bar-seg { margin-left: 2px; }
.bar-fill { background: linear-gradient(90deg, var(--c1), var(--c3)); }
.tone-warn .bar-fill { background: var(--c2); } .tone-bad .bar-fill { background: #e5484d; } .tone-ok .bar-fill { background: var(--c6); }
.progress-detail { margin: 0; font-size: .88rem; }
.legend { list-style: none; margin: .1rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .25rem .9rem; font-size: .82rem; }
.legend li { display: inline-flex; align-items: center; gap: .35rem; }
.dot { width: .65rem; height: .65rem; border-radius: 50%; flex: none; display: inline-block; }
.dot.c0 { background: var(--c1); } .dot.c1 { background: var(--c2); } .dot.c2 { background: var(--c3); } .dot.c3 { background: var(--c4); }
.dot.c4 { background: var(--c5); } .dot.c5 { background: var(--c6); } .dot.c6 { background: var(--c7); } .dot.c7 { background: var(--c8); }

/* charts */
.w-chart { position: relative; display: flex; flex-direction: column; flex: 1; min-height: 0; gap: .35rem; }
.chart-plot { flex: 1; min-height: 5rem; position: relative; }
.chart-svg { display: block; overflow: visible; touch-action: pan-y; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart-svg .tick { fill: var(--muted); font-size: 10.5px; font-family: inherit; }
.chart-svg .line { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .area { stroke: none; opacity: .2; }
.chart-svg .pt { stroke: var(--surface); stroke-width: 1.5; }
.chart-svg .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.c0 { --sc: var(--c1); } .c1 { --sc: var(--c2); } .c2 { --sc: var(--c3); } .c3 { --sc: var(--c4); } .c4 { --sc: var(--c5); } .c5 { --sc: var(--c6); } .c6 { --sc: var(--c7); } .c7 { --sc: var(--c8); }
.chart-svg .line { stroke: var(--sc); } .chart-svg .area, .chart-svg .pt, .chart-svg .bar-rect { fill: var(--sc); }
.chart-tip { position: absolute; z-index: 3; left: var(--tx, 0); top: var(--ty, 0); pointer-events: none; padding: .35rem .55rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow); font-size: .8rem; min-width: 7rem; max-width: 14rem; }
.chart-tip strong { display: block; margin-bottom: .15rem; }
.tip-row { display: flex; align-items: center; gap: .35rem; }

/* ------------------------------------------------------------------ dashboards: switcher, toolbar, editing */
.dash-tabs { display: flex; align-items: center; gap: .35rem; margin: 0 0 1rem; overflow-x: auto; padding: .15rem 0 .35rem; scrollbar-width: thin; }
.dash-tabs a { display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .9rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); text-decoration: none; white-space: nowrap; font-weight: 600; }
.dash-tabs a:hover { border-color: var(--accent); }
.dash-tabs a[aria-current="page"] { background: var(--accent-bg); color: var(--accent-text); border-color: var(--accent-bg); box-shadow: 0 0 16px -2px var(--glow-blue); }
.dash-tabs .icon { width: 1rem; height: 1rem; }
.dash-tabs .btn { flex: none; }
.dash-meta { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .85rem; flex-wrap: wrap; }
.dash-meta .icon { width: .95rem; height: .95rem; }

.edit-bar { position: sticky; top: 3.5rem; z-index: 15; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; padding: .6rem .9rem; margin-bottom: 1rem; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--accent); box-shadow: 0 0 0 1px var(--glow-blue), var(--shadow); }
.edit-bar .edit-hint { color: var(--muted); font-size: .85rem; flex: 1; min-width: 12rem; }
.edit-bar .input { width: min(18rem, 100%); }
.dgrid.editing { background-image: linear-gradient(var(--line) 1px, transparent 1px); background-size: 100% 92px; background-position: 0 -6px; background-repeat: repeat-y; border-radius: 12px; min-height: 12rem; padding-bottom: 5rem; }
.dgrid.editing .wcard { cursor: default; border-style: dashed; border-color: var(--line-strong); transition: border-color .15s, box-shadow .2s, grid-row .15s, grid-column .15s; }
.dgrid.editing .wcard:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 16px; }
.dgrid.editing .wbody { pointer-events: none; opacity: .85; }
.wcard.dragging { z-index: 30; transition: none; opacity: .92; transform: translate(var(--dx, 0px), var(--dy, 0px)); box-shadow: 0 24px 50px -12px rgba(0, 0, 0, .65), 0 0 0 2px var(--accent-bg); cursor: grabbing; }
.wcard-handle { display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 8px; border: 0; background: transparent; color: var(--muted); cursor: grab; touch-action: none; flex: none; }
.wcard-handle:hover { background: var(--surface-3); color: var(--text); }
.rz { position: absolute; right: 0; bottom: 0; width: 1.6rem; height: 1.6rem; border: 0; padding: 0; background: transparent; cursor: nwse-resize; touch-action: none; color: var(--muted); display: grid; place-items: end; }
.rz::after { content: ""; width: .7rem; height: .7rem; margin: 0 .3rem .3rem 0; border-right: 3px solid currentColor; border-bottom: 3px solid currentColor; border-radius: 0 0 4px 0; }
.rz:hover { color: var(--accent); }
.ph { grid-column: calc(var(--x) + 1) / span var(--w); grid-row: calc(var(--y) + 1) / span var(--h); border: 2px dashed var(--accent-bg); background: color-mix(in srgb, var(--accent-bg) 14%, transparent); border-radius: 16px; pointer-events: none; z-index: 1; }
.card-tools { display: none; gap: .3rem; padding: 0 .6rem .4rem .8rem; flex-wrap: wrap; }
.card-tools .btn { padding: .15rem .55rem; font-size: .8rem; }
.dgrid.editing .wcard-head { cursor: grab; touch-action: none; }

@media (max-width: 899px) {
  .dgrid, .dgrid.editing { grid-template-columns: minmax(0, 1fr); background-image: none; }
  .dgrid, .dgrid.editing { grid-auto-rows: auto; }
  .wcard { grid-column: 1; grid-row: auto; min-height: calc(var(--h) * 80px + (var(--h) - 1) * 12px); }
  .ph { grid-column: 1; grid-row: auto; min-height: 3rem; }
  .wbody { container-type: inline-size; overflow: visible; flex: 1 0 auto; }
  .wcard-bare .wbody { overflow: auto; }
  .wcard-handle, .rz { display: none; }
  .dgrid.editing .card-tools { display: flex; }
  .dgrid.editing .wcard-head { cursor: default; touch-action: auto; }
  .edit-bar { top: 3.2rem; padding: .5rem .6rem; }
  .edit-bar .input { width: 100%; }
  .edit-bar .edit-hint:not(.dirty) { display: none; }
  .edit-bar .edit-hint { min-width: 0; flex-basis: 100%; }
  .stat-value { font-size: clamp(1.8rem, 14cqi, 3rem); }
}

/* gallery */
.gal-tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.gal-tools .input { flex: 1; min-width: 12rem; }
.gal-group { margin-bottom: 1.25rem; }
.gal-group > h3 { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; font-size: 1rem; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .75rem; }
.gal-item { display: flex; flex-direction: column; gap: .4rem; padding: .75rem; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.gal-item h4 { margin: 0; font-size: .95rem; }
.gal-item p { margin: 0; font-size: .82rem; }
.gal-preview { position: relative; height: 9.5rem; overflow: hidden; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.gal-inner { position: absolute; inset: 0; pointer-events: none; }
.wcard-bare { position: absolute; inset: 0; border: 0; border-radius: 0; box-shadow: none; background: transparent; }
.wcard-bare::before { display: none; }
.wcard-bare .wbody { padding-top: .6rem; }
.gal-meta { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: auto; }
.cfg-form { display: grid; gap: .9rem; }
.cfg-preview { pointer-events: none; height: 12rem; position: relative; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); overflow: hidden; margin-top: 1rem; }
