/* Dashboard tile layout (tile-layout.js), shared by Portal Home and the IT
   dashboard's Portal tiles; the Portal loads it as /portal/shared/tile-layout.css.
   Each page sets the grid's --columns and the Portal tokens these rules use
   (--ink, --muted, --line, --line-strong, --surface, --subtle, --danger,
   --portal-accent, --portal-accent-soft, --focus-ring and the shadows). */

/* Each tile is also a container, so its controls (and the drag preview cloned from it) adapt to the tile's own width. */
.tile { container: tile / inline-size; }
.tiles > .tile { grid-column: span min(var(--columns), var(--tile-width, 1)); min-width: 0; position: relative; isolation: isolate; }

/* The control bar: grip, Move earlier/later, Width, then the page's actions. */
.tile-controls {
  flex-wrap: wrap;
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 2px;
  padding: 7px 10px;
  background: color-mix(in srgb, var(--subtle) 55%, var(--surface))
}
.tiles > .tile > .tile-controls { margin-top: auto; position: relative; z-index: 1; }

/* The controls centre their own labels: a page's global button rules (the IT
   dashboard's are left-aligned flex boxes) must not shift them. */
.tile-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  background: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  min-width: 28px;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer
}

.tile-controls button:disabled {
  opacity: .45;
  cursor: default
}

.tile-controls button:hover:not(:disabled) { color: var(--ink); background: var(--subtle); }

.tile-controls button:last-child {
  margin-left: auto
}

.tile-controls > button:last-child:hover:not(:disabled) {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 9%, transparent)
}

/* A full-size destination moves through the grid as neighboring cards make room. */
.tiles:not(.is-saving) > .tile { cursor: grab; }
.tile-grip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  min-height: 28px;
  color: color-mix(in srgb, var(--muted) 70%, transparent);
  font-size: 18px;
  line-height: 1;
  touch-action: none;
}
.tile-grip svg { width: 14px; height: 14px; }
body.is-reordering, body.is-reordering * { cursor: grabbing !important; user-select: none; }
.tiles.is-reordering .tile { position: relative; transform: none; transition: none; }
.tiles.is-reordering .tile:hover { border-color: var(--line); box-shadow: none; }
.tiles .tile.is-dragging {
  background: var(--subtle);
  border: 1px dashed var(--muted);
  box-shadow: none;
}
.tile.is-dragging > * { visibility: hidden; }
.tile.is-dragging::before {
  content: attr(data-drag-label);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
/* The destination occupies the exact slot the card will take on release. */
.tiles.is-reordering .tile.is-drop-target {
  background: var(--portal-accent-soft);
  border: 1px dashed var(--portal-accent);
  box-shadow: inset 0 0 0 5px var(--surface);
}
.tile.is-drop-target::before {
  align-items: start;
  padding-top: 28px;
  color: var(--portal-accent);
  font-weight: 600;
  font-size: 14px;
}
.tile.tile-drag-preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1200;
  margin: 0;
  opacity: 1;
  pointer-events: none;
  background: var(--surface);
  border-color: var(--portal-accent);
  box-shadow: var(--shadow-lg);
  transition: none;
  will-change: transform;
}

/* Width reads as one segmented control. */
.tile-widths { display: flex; align-items: center; gap: 0; margin-left: 6px; font-size: 11px; color: var(--muted); }
.tile-widths > span { margin-right: 6px; }
.tile-controls .tile-widths button { min-width: 26px; min-height: 24px; padding: 2px 0; margin: 0; border: 1px solid var(--line); border-radius: 0; background: var(--surface); font-variant-numeric: tabular-nums; }
.tile-controls .tile-widths button + button { margin-left: -1px; }
.tile-controls .tile-widths span + button { border-radius: 6px 0 0 6px; }
.tile-controls .tile-widths button:last-child { margin-left: -1px; border-radius: 0 6px 6px 0; }
.tile-controls .tile-widths button[data-width="full"] { padding-inline: 6px; }
.tile-controls .tile-widths button[aria-pressed="true"] { position: relative; color: var(--portal-accent); background: var(--portal-accent-soft); border-color: color-mix(in srgb, var(--portal-accent) 45%, var(--line)); font-weight: 650; }
/* On narrow tiles, drop the "Width" caption so the control row stays on one
   line; the group keeps its accessible name. */
@container tile (max-width: 345px) { .tile-widths > span { display: none; } }

/* The right edge also resizes: a bar appears on hover and snaps to whole columns.
   Pages hide .tile-resize when their grid has a single column. */
.tile-resize { position: absolute; top: 0; right: 0; bottom: 0; width: 14px; cursor: col-resize; touch-action: none; }
.tile-resize::after { content: ""; position: absolute; top: 50%; right: 4px; width: 4px; height: 40px; border-radius: 2px; background: var(--line-strong); opacity: 0; transform: translateY(-50%); }
.tile:hover > .tile-resize::after, .tile.is-resizing > .tile-resize::after { opacity: 1; }
.tile-resize:hover::after, .tile.is-resizing > .tile-resize::after { background: var(--portal-accent); }
.tiles:is(.is-saving, .is-reordering) .tile-resize { display: none; }
@media (hover: none) { .tile-resize::after { opacity: 1; } }
@media (pointer: coarse) { .tile-resize { width: 24px; } }
body.is-resizing, body.is-resizing * { cursor: col-resize !important; user-select: none; }
.tiles.is-resizing .tile { transform: none; transition: none; }
.tiles .tile.is-resizing { border-color: var(--portal-accent); box-shadow: 0 0 0 3px var(--focus-ring), var(--shadow-md); }
.tile.is-resizing::after {
  content: attr(data-resize-label);
  position: absolute;
  top: 12px;
  right: 22px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--portal-accent);
  color: var(--surface);
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
  .tile-resize::after { transition: opacity 140ms ease, background-color 140ms ease; }
}
