/* Licence management for the AMP LAB administration console.
 *
 * Built on the shell's existing tokens (--brand, --surface-*, --danger…) so it
 * reads as one product rather than a bolted-on section. Everything here is
 * namespaced under .lic- to keep it merge-safe alongside app.css.
 *
 * The design leans on one idea: revoking a partner is irreversible, so the
 * interface must make the difference between *pause* and *cut off* impossible
 * to miss. Destructive actions stay visually quiet until hovered, then commit
 * to danger colour, and the confirmation states plainly what will happen.
 */

/* ---------------------------------------------------------------- summary */

.lic-metrics {
  display: grid;
  /* 140px keeps all four on one row inside the console's ~640px workspace at
   * laptop widths (4x140 + 3x14 gap = 602); wider than that and they simply
   * grow. A 3+1 wrap reads as a mistake, so the floor has real headroom. */
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}

.lic-metric {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  background: linear-gradient(180deg, var(--surface-1), var(--surface-soft));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  transition: border-color .18s ease, transform .18s ease;
}

.lic-metric:hover { border-color: var(--border-strong); transform: translateY(-1px); }

.lic-metric-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  flex: 0 0 auto;
}
.lic-metric-icon svg { width: 20px; height: 20px; fill: currentColor; }
.lic-metric-icon.is-active  { background: var(--success-soft); color: var(--success); }
.lic-metric-icon.is-seats   { background: var(--info-soft);    color: var(--info); }
.lic-metric-icon.is-expiring{ background: var(--warning-soft); color: var(--warning); }
.lic-metric-icon.is-revoked { background: var(--danger-soft);  color: var(--danger); }

.lic-metric-body { display: flex; flex-direction: column; line-height: 1.2; }
.lic-metric-body strong { font-size: 1.6rem; font-weight: 650; color: var(--text-primary); }
.lic-metric-body small { color: var(--text-tertiary); font-size: .82rem; margin-top: 2px; }

/* ----------------------------------------------------------------- cards */

.lic-list { display: flex; flex-direction: column; gap: 12px; }

.lic-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color .18s ease, box-shadow .18s ease;
}
.lic-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-raised); }

/* A revoked partner should read as inert at a glance, not just by its badge. */
.lic-card.is-revoked { opacity: .62; }
.lic-card.is-revoked:hover { opacity: .85; }

.lic-card-main {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1.4fr) minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 16px 18px;
}

.lic-identity { min-width: 0; }
.lic-partner {
  display: block;
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lic-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .74rem;
  color: var(--text-tertiary);
}

.lic-badges { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.lic-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}
.lic-badge.tier-trial                  { background: var(--info-soft);    color: var(--info); }
.lic-badge.tier-musician-partner       { background: var(--brand-soft);   color: var(--brand); }
.lic-badge.tier-core-partner-developer { background: var(--success-soft); color: var(--success); }

.lic-badge.state-active    { background: var(--success-soft); color: var(--success); }
.lic-badge.state-suspended { background: var(--warning-soft); color: var(--warning); }
.lic-badge.state-revoked   { background: var(--danger-soft);  color: var(--danger); }
.lic-badge.state-expired   { background: var(--danger-soft);  color: var(--danger); }

.lic-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Seat meter: seats are the thing an owner actually manages, so show them
 * as occupancy rather than a bare number. */
.lic-seats { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.lic-seats-label {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--text-secondary);
}
.lic-seats-label b { color: var(--text-primary); font-weight: 600; }

.lic-meter { display: flex; gap: 3px; }
.lic-meter span {
  height: 5px;
  flex: 1 1 0;
  border-radius: 3px;
  background: var(--surface-raised);
  transition: background .2s ease;
}
.lic-meter span.filled { background: var(--brand); }
.lic-meter.is-full span.filled { background: var(--warning); }
.lic-card.is-revoked .lic-meter span.filled { background: var(--text-tertiary); }

/* Live simultaneous use. Shown only when the concurrency cap is tighter than
 * the seat count, otherwise it just restates the seat meter. */
.lic-usage { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.lic-live { display: flex; align-items: center; gap: 7px; font-size: .78rem; }
.lic-live-text { color: var(--text-secondary); }
.lic-live-text b { color: var(--text-primary); font-weight: 600; }

.lic-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  flex: 0 0 auto;
}
/* A pulse reads as "right now" in a way a static dot does not. */
.lic-live-dot.on {
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(58, 197, 141, .55);
  animation: lic-pulse 2s ease-out infinite;
}
@keyframes lic-pulse {
  70%  { box-shadow: 0 0 0 7px rgba(58, 197, 141, 0); }
  100% { box-shadow: 0 0 0 0 rgba(58, 197, 141, 0); }
}

.lic-device-icon.is-live { color: var(--success); }

.lic-playing {
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .02em;
  vertical-align: middle;
}

.lic-expiry { font-size: .82rem; color: var(--text-secondary); white-space: nowrap; }
.lic-expiry.soon    { color: var(--warning); font-weight: 600; }
.lic-expiry.expired { color: var(--danger);  font-weight: 600; }

.lic-actions { display: flex; gap: 8px; align-items: center; }

.lic-btn {
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: .82rem;
  font-weight: 550;
  cursor: pointer;
  transition: all .16s ease;
  white-space: nowrap;
}
.lic-btn:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--text-primary);
  background: var(--surface-raised);
}
.lic-btn:disabled { opacity: .4; cursor: not-allowed; }
.lic-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.lic-btn.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--canvas);
}
.lic-btn.primary:hover:not(:disabled) { color: var(--canvas); }

/* Quiet until hovered, then unmistakably destructive. */
.lic-btn.danger:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

.lic-disclosure {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
}
.lic-disclosure:hover { color: var(--text-primary); background: var(--surface-2); }
.lic-disclosure svg { width: 18px; height: 18px; fill: currentColor; transition: transform .2s ease; }
.lic-disclosure[aria-expanded="true"] svg { transform: rotate(180deg); }

/* --------------------------------------------------------------- devices */

.lic-devices {
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-soft);
  padding: 6px 18px 14px;
}
.lic-devices[hidden] { display: none; }

.lic-devices-title {
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-tertiary);
  margin: 12px 0 8px;
}

.lic-device {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
}
.lic-device + .lic-device { margin-top: 6px; }
.lic-device.released { opacity: .5; }

.lic-device-icon { color: var(--text-tertiary); display: grid; place-items: center; }
.lic-device-icon svg { width: 18px; height: 18px; fill: currentColor; }

.lic-device-body { flex: 1; min-width: 0; }
.lic-device-name {
  display: block;
  color: var(--text-primary);
  font-size: .9rem;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lic-device-meta { font-size: .76rem; color: var(--text-tertiary); }

/* --------------------------------------------------------- states, misc */

.lic-empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-tertiary);
}
.lic-empty svg { width: 44px; height: 44px; fill: currentColor; opacity: .4; margin-bottom: 12px; }
.lic-empty h3 { color: var(--text-secondary); font-weight: 550; margin: 0 0 6px; }
.lic-empty p { margin: 0; font-size: .88rem; }

.lic-skeleton {
  height: 84px;
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 50%, var(--surface-1) 75%);
  background-size: 200% 100%;
  animation: lic-shimmer 1.4s ease-in-out infinite;
}
.lic-skeleton + .lic-skeleton { margin-top: 12px; }
@keyframes lic-shimmer { to { background-position: -200% 0; } }

/* The consequence text in the revoke dialog; the sentence that stops a
 * mis-click doing something permanent. */
.lic-consequence {
  text-align: left;
  background: var(--danger-soft);
  border: 1px solid rgba(241, 109, 117, .3);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin: 14px 0;
  font-size: .86rem;
  color: var(--text-secondary);
  line-height: 1.5;
}
.lic-consequence strong { color: var(--danger); display: block; margin-bottom: 4px; }

.lic-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.lic-toolbar .lic-spacer { flex: 1; }

.lic-issue-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 16px;
}
.lic-issue-grid .compact-field:last-child { grid-column: 1 / -1; }

.lic-load-error h3 { color: var(--danger); }
.lic-load-error .lic-btn { margin-top: 16px; }

/* Below roughly this width the console's workspace is about 640px, and four
 * columns squeeze partner emails into ellipses and the seat meter into a
 * sliver. Stacking earlier than feels necessary keeps every row legible; a
 * truncated partner address is worse than a taller card. */
@media (max-width: 1080px) {
  .lic-card-main {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 16px;
  }
  .lic-badges { order: 2; }
  .lic-seats { order: 3; max-width: 320px; }
  .lic-actions { order: 4; justify-content: flex-start; flex-wrap: wrap; }
  .lic-partner { white-space: normal; }
}

@media (max-width: 640px) {
  .lic-issue-grid { grid-template-columns: 1fr; }
  .lic-issue-grid .compact-field:last-child { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .lic-metric, .lic-card, .lic-btn, .lic-disclosure svg, .lic-meter span { transition: none; }
  .lic-skeleton { animation: none; }
  /* Keep the dot green, just stop it pulsing. */
  .lic-live-dot.on { animation: none; }
}
