/* Standalone styling for the clients backend — intentionally not
   sharing CSS with the rest of the site, so this area has zero visual or
   code dependency on anything outside admin/users/. */

* { box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
  color-scheme: dark;
  --tv-bg: #0f1115;
  --tv-card: #171a21;
  --tv-border: #2a2e37;
  --tv-ink: #e8e9ec;
  --tv-ink-dim: #9aa0ab;
  --tv-accent: #5b9dff;
  --tv-danger: #e2554f;
  --tv-danger-bg: #3a1e1d;
  --tv-ok-bg: #1c3324;
  --tv-ok-text: #7fdb9a;
  --tv-error-bg: #3a1e1d;
  --tv-error-text: #ef8783;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--tv-bg);
  color: var(--tv-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

body.tv-dashboard {
  display: block;
  padding: 0;
}

.tv-topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  background: var(--tv-card);
  border-bottom: 1px solid var(--tv-border);
}

.tv-topnav--user {
  background: #232833;
  border-bottom-color: #363c4a;
}

.tv-pagination-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0;
}

.tv-pagination-size {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--tv-ink-dim);
}

.tv-pagination-size select {
  padding: 6px 10px;
  background: var(--tv-bg);
  border: 1px solid var(--tv-border);
  border-radius: 6px;
  color: var(--tv-ink);
  font-size: 16px;
}

.tv-pagination-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--tv-ink-dim);
  margin-left: auto;
}

.tv-pagination-bar.tv-pagination-sticky {
  position: sticky;
  top: var(--tv-topnav-h, 56px);
  z-index: 90;
  background: var(--tv-card);
  border-bottom: 1px solid var(--tv-border);
  padding: 8px 12px;
  margin: 0;
  flex-wrap: nowrap;
  gap: 8px;
}

.tv-pagination-sticky .tv-pagination-size {
  flex-shrink: 0;
}

.tv-pagination-sticky .tv-pagination-size span:first-child {
  display: none;
}

.tv-pagination-sticky .tv-pagination-size select {
  padding: 6px 8px;
}

.tv-pagination-sticky .tv-pagination-nav {
  gap: 6px;
  white-space: nowrap;
}

.tv-pagination-sticky .tv-pagination-nav .tv-btn {
  padding: 6px 10px;
}

.tv-topnav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.tv-topnav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--tv-ink);
  text-decoration: none;
}

.tv-topnav-links {
  display: flex;
  gap: 16px;
  margin-right: auto;
}

.tv-topnav-menu {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 16px;
}

.tv-topnav-menu-top {
  display: contents;
}

.tv-topnav-menu-header,
.tv-topnav-menu-close {
  display: none;
}

.tv-topnav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  padding: 0;
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
}

.tv-topnav-hamburger span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--tv-ink);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.tv-topnav-hamburger.is-open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.tv-topnav-hamburger.is-open span:nth-child(2) {
  opacity: 0;
}

.tv-topnav-hamburger.is-open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.tv-credits-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--tv-ok-bg);
  color: var(--tv-ok-text);
  font-size: 0.75rem;
  font-weight: 600;
  vertical-align: middle;
  border: none;
  cursor: pointer;
}

.tv-credits-badge:hover {
  filter: brightness(1.1);
}

.tv-credits-pending {
  margin-left: 4px;
  color: var(--tv-danger);
}

.tv-credits-badge--low {
  background: var(--tv-error-bg);
  color: var(--tv-error-text);
}

.tv-credits-wrap {
  position: relative;
  display: inline-block;
}

.tv-table-client-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
}

.tv-table-client-line .tv-list-meta {
  margin-left: 4px;
}

@media (min-width: 641px) {
  .tv-topnav-menu {
    display: contents;
  }

  .tv-topnav-brand {
    order: 1;
  }

  .tv-topnav-links {
    order: 3;
  }

  .tv-credits-wrap {
    order: 4;
  }

  .tv-topnav-right {
    order: 5;
  }

  .tv-credits-wrap .tv-modal-overlay.tv-credits-overlay {
    position: fixed;
    inset: auto;
    top: 0;
    left: 0;
    right: auto;
    background: transparent;
    padding: 0;
    justify-content: flex-start;
    align-items: flex-start;
  }

  #clients-view-cards {
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  }

  #clients-view-cards .tv-client-card {
    display: grid;
    grid-template-columns: auto auto auto;
    justify-content: center;
    align-items: center;
    row-gap: 8px;
    column-gap: 8px;
  }

  #clients-view-cards .tv-client-card-header {
    display: contents;
  }

  #clients-view-cards .tv-client-card-title {
    grid-row: 1;
    grid-column: 1 / -1;
  }

  #clients-view-cards .tv-list-meta {
    grid-row: 2;
    grid-column: 1 / -1;
  }

  #clients-view-cards .tv-client-card-delete-form,
  #clients-view-cards .edit-client-trigger,
  #clients-view-cards .tv-client-card-devices-btn {
    grid-row: 3;
  }

  #clients-view-cards .tv-client-card-devices-row {
    display: none;
  }
}

.tv-credits-modal-balance {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  margin: 2px 0 14px;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--tv-ok-bg);
}

.tv-credits-modal-balance-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--tv-ok-text);
}

.tv-credits-modal-balance-label {
  font-size: 0.75rem;
  color: var(--tv-ok-text);
  opacity: 0.85;
}

.tv-credits-amount-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.tv-credits-amount-row select {
  flex: none;
  width: auto;
  padding: 5px 8px;
  font-size: 0.85rem;
}

.tv-credits-amount-row input[type="number"] {
  width: 9ch !important;
  flex: none;
  padding: 5px 8px !important;
  font-size: 0.85rem;
  text-align: center;
  -moz-appearance: textfield;
}

.tv-credits-amount-row input::-webkit-outer-spin-button,
.tv-credits-amount-row input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.tv-credits-amount-row input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tv-modal.tv-modal--narrow {
  width: max-content;
  max-width: 320px;
  padding: 16px;
  text-align: center;
}

.tv-modal--narrow h3 {
  font-size: 1rem;
  margin-bottom: 8px;
}

.tv-modal--narrow .tv-form {
  gap: 10px;
  align-items: center;
}

.tv-modal--narrow .tv-credits-amount-row {
  justify-content: center;
}

.tv-modal--narrow .tv-modal-actions {
  justify-content: center;
}

.tv-renewal-client {
  margin-bottom: 20px;
}

.tv-renewal-client-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.tv-renewal-client-title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.js-renew-all-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.tv-renewal-client .tv-table-wrap,
.tv-renewal-client .tv-renewal-devices-cards {
  margin-left: 28px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
}

.tv-renewal-toggle.is-active {
  background: var(--tv-accent);
  color: #08111f;
  border-color: var(--tv-accent);
}

.tv-topnav-links a {
  color: var(--tv-ink-dim);
  text-decoration: none;
  font-size: 0.9rem;
}

.tv-topnav-links a:hover,
.tv-topnav-links a.is-active {
  color: var(--tv-accent);
}

.tv-topnav-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.tv-topnav-user {
  color: var(--tv-ink-dim);
  font-size: 0.85rem;
}

.tv-main {
  padding: 32px 16px;
}

.tv-box {
  width: 100%;
  max-width: 360px;
  background: var(--tv-card);
  border: 1px solid var(--tv-border);
  border-radius: 10px;
  padding: 32px;
  text-align: center;
}

.tv-title {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

.tv-subtitle {
  margin: 0 0 20px;
  color: var(--tv-ink-dim);
  font-size: 0.9rem;
}

.tv-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.tv-form label span {
  display: block;
  font-size: 0.85rem;
  color: var(--tv-ink-dim);
  margin-bottom: 4px;
}

.tv-field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

@media (max-width: 640px) {
  .tv-field-row {
    grid-template-columns: 1fr;
  }
}

.tv-form input,
.tv-form textarea,
.tv-form select {
  width: 100%;
  padding: 10px 12px;
  background: var(--tv-bg);
  border: 1px solid var(--tv-border);
  border-radius: 6px;
  color: var(--tv-ink);
  font-size: 16px;
}

.tv-form input:focus,
.tv-form textarea:focus,
.tv-form select:focus {
  outline: none;
  border-color: var(--tv-accent);
}

.tv-form input[type="radio"],
.tv-form input[type="checkbox"] {
  width: auto;
  padding: 0;
}

.tv-checkbox-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
}

.tv-checkbox-row span {
  display: inline !important;
  margin-bottom: 0 !important;
}

.tv-radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.tv-radio-option {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  color: var(--tv-ink);
  cursor: pointer;
}

.tv-radio-option span {
  margin-bottom: 0 !important;
}

.tv-btn {
  display: inline-block;
  padding: 10px 16px;
  background: var(--tv-accent);
  color: #08111f;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

.tv-btn:hover { opacity: 0.9; }

.tv-btn--small { padding: 6px 12px; font-size: 0.85rem; }

.tv-btn--danger { background: var(--tv-danger); color: #fff; }

.tv-btn--ghost {
  background: transparent;
  color: var(--tv-ink-dim);
  border: 1px solid var(--tv-border);
}

.tv-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  line-height: 0;
}

.tv-btn svg {
  width: 14px;
  height: 14px;
  vertical-align: -2px;
  margin-right: 4px;
}

.tv-icon-btn svg {
  width: 14px;
  height: 14px;
  margin-right: 0;
  display: block;
}

.tv-alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  margin: 0 0 16px;
  transition: opacity 0.4s ease;
}

.tv-alert--error { background: var(--tv-error-bg); color: var(--tv-error-text); }
.tv-alert--ok { background: var(--tv-ok-bg); color: var(--tv-ok-text); }

.tv-alert--fading { opacity: 0; }

.tv-row-highlight {
  background: var(--tv-ok-bg) !important;
  transition: background 0.4s ease;
}

.tv-row-highlight--fading {
  background: transparent !important;
}

.tv-wrap {
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
}

.tv-page-title + .tv-alert--ok {
  position: absolute;
  top: 0;
  right: 0;
  left: auto;
  max-width: 60%;
  margin: 0;
  z-index: 5;
}

@media (max-width: 900px) {
  .tv-page-title + .tv-alert--ok {
    position: static !important;
    display: block !important;
    max-width: none;
    margin: 0 0 16px;
  }
}

.tv-grid-2 {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
  align-items: start;
}

.tv-impersonate-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--tv-warn-bg, #4a3a10);
  color: var(--tv-warn-text, #f0c05a);
  font-size: 0.9rem;
  text-align: center;
}

.tv-impersonate-bar .tv-btn {
  color: inherit;
  border-color: currentColor;
}

.tv-nav-badge-wrap {
  position: relative;
}

.tv-nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--tv-error-text, #f85149);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
}

.tv-account-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.tv-account-form {
  margin-top: 12px;
}

@media (max-width: 800px) {
  .tv-grid-2 { grid-template-columns: 1fr; }
}

.tv-card {
  background: var(--tv-card);
  border: 1px solid var(--tv-border);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 20px;
}

.tv-card h1, .tv-card h2 {
  margin-top: 0;
}

.tv-unassigned-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.tv-unassigned-arrow {
  display: none;
}

.tv-card--header {
  padding: 14px 20px;
  margin-bottom: 16px;
}

.tv-card--compact {
  padding: 16px 20px;
}

.tv-card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 10px;
}

.tv-card-header-row h2 {
  margin: 0;
}

.tv-card-header-row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tv-view-toggle {
  display: flex;
  gap: 4px;
  border: 1px solid var(--tv-border);
  border-radius: 6px;
  padding: 2px;
}

.tv-view-toggle .tv-btn {
  border: none;
}

.tv-view-toggle .tv-btn.is-active {
  background: var(--tv-accent);
  color: #08111f;
}

.tv-search {
  width: 100%;
  box-sizing: border-box;
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--tv-border);
  background: var(--tv-bg-alt, #101a2c);
  color: inherit;
  font-size: 16px;
}

.tv-month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tv-client-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.tv-client-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--tv-border);
  border-radius: 8px;
  min-height: 0;
  font-size: 0.9rem;
  text-align: center;
}

.tv-client-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.tv-client-card-header .tv-client-card-delete-form,
.tv-client-card-header .edit-client-trigger {
  flex-shrink: 0;
}

.tv-client-card-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.tv-client-card-title .tv-status {
  margin-left: 0;
}


.tv-client-card-devices {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  width: 100%;
}

.tv-client-card .tv-list-actions {
  margin-top: auto;
  padding-top: 12px;
  flex-wrap: wrap;
}

.tv-client-card .tv-list-actions .tv-btn {
  white-space: nowrap;
}

.tv-list--compact li {
  padding: 8px 10px;
}

.tv-list--compact .tv-list-meta {
  margin-top: 0;
}

.tv-client-row {
  flex-wrap: nowrap;
  overflow-x: auto;
}

.tv-client-row .tv-list-actions {
  flex-shrink: 0;
}

.tv-client-row-info {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  min-width: 0;
}

.tv-device-chip {
  font-size: 0.8rem;
  color: var(--tv-ink-dim);
  white-space: nowrap;
}

.tv-device-grid {
  display: grid;
  grid-template-columns: minmax(100px, auto) 70px minmax(140px, auto) minmax(120px, auto);
  align-items: baseline;
  column-gap: 14px;
  row-gap: 6px;
}

.tv-device-grid-row {
  display: contents;
}

.tv-device-grid-name,
.tv-device-grid-mac {
  font-size: 0.85rem;
}

.tv-device-chip--empty {
  font-style: italic;
}

.tv-untitled {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fdf1a3;
  color: #b91c1c;
  font-weight: 700;
}

.tv-device-chip-divider {
  display: none;
}

.tv-device-manage-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.tv-renewal-devices-cards,
.tv-renewal-log-cards {
  display: none;
}

.tv-message-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tv-message-card-date {
  margin-left: auto;
}

.tv-msg-delete-form {
  margin: 0;
}

.tv-message-card-body {
  margin: 10px 0 0;
  white-space: pre-wrap;
}

.tv-message-reply-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.tv-message-reply-form textarea {
  flex: 1;
  margin: 0;
}

.tv-msg-accordion {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tv-msg-toggle {
  background: var(--tv-card);
  border: 1px solid var(--tv-border);
  border-radius: 8px;
  padding: 0;
}

.tv-msg-toggle > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}

.tv-msg-toggle > summary::-webkit-details-marker {
  display: none;
}

.tv-msg-toggle > summary::before {
  content: '\25B6';
  font-size: 0.75rem;
  color: var(--tv-ink-dim);
  transition: transform 0.15s ease;
}

.tv-msg-toggle[open] > summary::before {
  transform: rotate(90deg);
}

.tv-msg-toggle-name {
  font-weight: 600;
}

.tv-msg-toggle-last {
  margin-left: auto;
}

.tv-msg-panel {
  padding: 0 16px 16px;
  border-top: 1px solid var(--tv-border);
  padding-top: 14px;
}

.tv-msg-toggle-all-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.tv-msg-chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.tv-msg-bubble {
  border-left: 3px solid var(--tv-border);
  padding: 6px 0 6px 12px;
}

.tv-msg-bubble--admin {
  border-left-color: var(--tv-ok-text, #7fdb9a);
}

.tv-msg-accordion .tv-msg-item {
  border-radius: 6px;
  padding: 0;
}

.tv-msg-item > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 10px;
  cursor: pointer;
  list-style: none;
}

.tv-msg-item > summary::-webkit-details-marker {
  display: none;
}

.tv-msg-item > summary::before {
  content: '\25B6';
  font-size: 0.7rem;
  color: var(--tv-ink-dim);
  transition: transform 0.15s ease;
}

.tv-msg-item[open] > summary::before {
  transform: rotate(90deg);
}

.tv-msg-item-body {
  padding: 0 10px 10px 10px;
}

.tv-msg-item-body .tv-message-card-body {
  margin-top: 0;
}

.tv-msg-item--client {
  background: rgba(142, 197, 255, 0.08);
  border-left: 3px solid #8ec5ff;
}

.tv-msg-item--admin {
  background: rgba(127, 219, 154, 0.08);
  border-left: 3px solid var(--tv-ok-text, #7fdb9a);
}

.tv-msg-item--indent {
  margin-left: 24px;
}

@media (max-width: 480px) {
  .tv-msg-item--indent {
    margin-left: 12px;
  }
}

.tv-device-manage-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--tv-border);
  border-radius: 8px;
  text-align: center;
}

.tv-device-manage-card-row {
  width: 100%;
}

.tv-inline-form {
  display: inline-block;
}

.tv-checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--tv-border);
  border-radius: 6px;
}

.tv-checklist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.tv-checklist-item input {
  width: auto;
}

.tv-table-wrap {
  overflow-x: auto;
}

.tv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.tv-table th,
.tv-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--tv-border);
  text-align: left;
  white-space: nowrap;
  vertical-align: top;
}

.tv-table th {
  color: var(--tv-ink-dim);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tv-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.tv-sortable:hover {
  color: var(--tv-ink);
}

.tv-sortable::after {
  content: '';
  display: inline-block;
  width: 10px;
}

.tv-sortable.tv-sort-asc::after {
  content: '\25B2';
}

.tv-sortable.tv-sort-desc::after {
  content: '\25BC';
}

.tv-table-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.tv-devices-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  white-space: normal;
}

.tv-devices-cell-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tv-devices-cell .tv-btn {
  flex-shrink: 0;
}

.tv-client-card-devices-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  width: 100%;
}

.tv-client-card-devices-row .tv-btn {
  flex-shrink: 0;
}

.tv-client-card-devices-row .tv-table-actions {
  justify-content: center;
}

.tv-input-group {
  display: flex;
  align-items: stretch;
}

.tv-input-group-prefix {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 10px 10px;
  background: var(--tv-border);
  border: 1px solid var(--tv-border);
  border-right: none;
  border-radius: 6px 0 0 6px;
  color: var(--tv-ink-dim);
  font-size: 0.95rem;
  white-space: nowrap;
}

.tv-input-group input {
  box-sizing: border-box;
  border-radius: 0 6px 6px 0;
}

.tv-select-small {
  padding: 6px 10px;
  background: var(--tv-bg);
  border: 1px solid var(--tv-border);
  border-radius: 6px;
  color: var(--tv-ink);
  font-size: 0.85rem;
}

@media (max-width: 640px) {
  input.tv-select-small,
  select.tv-select-small {
    font-size: 16px;
  }
}

.tv-page-title {
  font-size: 1.75rem;
  margin-bottom: 10px;
}

.tv-page-title-link {
  color: inherit;
  text-decoration: none;
}

.tv-page-title-link:hover,
.tv-page-title-link:focus,
.tv-page-title-link:active {
  color: inherit;
  text-decoration: none;
}

.tv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tv-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--tv-border);
  border-radius: 6px;
  flex-wrap: wrap;
}

.tv-list-meta {
  display: block;
  color: var(--tv-ink-dim);
  font-size: 0.85rem;
  margin-top: 2px;
}

.tv-list-actions {
  display: flex;
  gap: 8px;
}

.tv-empty {
  color: var(--tv-ink-dim);
  font-size: 0.9rem;
}

.tv-back {
  display: inline-block;
  margin-top: 16px;
  color: var(--tv-ink-dim);
  font-size: 0.85rem;
  text-decoration: none;
}

.tv-back:hover { color: var(--tv-accent); }

.tv-plain-link {
  color: inherit;
  text-decoration: none;
}

button.tv-plain-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

.tv-plain-link:hover {
  text-decoration: underline;
}

.tv-view-as-link {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.tv-view-as-link:hover {
  text-decoration: none;
}

.tv-status {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  vertical-align: middle;
}

.tv-status--active { background: var(--tv-ok-bg); color: var(--tv-ok-text); }
.tv-status--expired { background: var(--tv-error-bg); color: var(--tv-error-text); }
.tv-status--unknown { background: var(--tv-border); color: var(--tv-ink-dim); }
.tv-status--admin { background: #2d2a5c; color: #b8b3ff; }
.tv-status--info { background: #1e3a5c; color: #8ec5ff; }
.tv-status--warn { background: #4a3a10; color: #f0c05a; }
.tv-status--teal { background: #0f3d3a; color: #6fe0d3; }
.tv-status--pink { background: #4a1f3a; color: #f29ad0; }

.tv-msg-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 16px;
}

.tv-login-row--admin {
  background: rgba(184, 179, 255, 0.08);
}

.tv-login-row--admin.tv-device-manage-card {
  border-color: #6a63d1;
}

.tv-client-name--admin {
  color: #b8b3ff;
  font-weight: 700;
}

.tv-device-count {
  color: var(--tv-ink-dim);
  font-size: 0.85em;
  font-weight: normal;
}

.tv-expiry-text--active { color: var(--tv-ok-text); }
.tv-expiry-text--expired { color: var(--tv-error-text); }
.tv-expiry-text--unknown { color: var(--tv-ink-dim); }

/* Modal (replaces native confirm()/alert() dialogs) */
.tv-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.tv-modal-overlay.is-open { display: flex; }

.tv-modal {
  width: 100%;
  max-width: 380px;
  background: var(--tv-card);
  border: 1px solid var(--tv-border);
  border-radius: 10px;
  padding: 24px;
}

.tv-modal--devices {
  position: relative;
  max-height: 80vh;
  overflow-y: auto;
}

.tv-modal--devices #client-devices-modal-body h3 {
  padding-right: 32px;
}

.tv-modal-close {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--tv-ink-dim);
  font-size: 1.6rem;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  z-index: 1;
}

.tv-modal-close:hover {
  color: var(--tv-ink);
}

.tv-device-pagination {
  position: sticky;
  bottom: -24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px -24px -24px;
  padding: 10px 24px;
  background: var(--tv-card);
  border-top: 1px solid var(--tv-border);
}

.tv-device-pagination-label {
  font-size: 0.85rem;
  color: var(--tv-ink-dim);
}

.tv-modal h3 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.tv-modal p {
  margin: 0 0 20px;
  color: var(--tv-ink-dim);
  font-size: 0.9rem;
}

.tv-link-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  margin: 10px 0 16px;
}

.tv-link-list-row {
  margin: 0;
}

.tv-link-list-btn {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
}

.tv-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.tv-modal-actions--split {
  justify-content: space-between;
}

.tv-modal-actions--stacked {
  flex-direction: column;
  align-items: stretch;
}

.tv-modal-actions--stacked .tv-btn {
  text-align: center;
}

.tv-modal-actions-group {
  display: flex;
  gap: 8px;
}

.tv-modal-actions--split button[type="submit"],
.tv-modal-actions-group button[type="submit"] {
  min-width: 64px;
}

/* Mobile */
@media (max-width: 640px) {
  .tv-main {
    padding: 20px 12px;
  }

  .tv-card {
    padding: 16px;
  }

  .tv-modal-close {
    display: block;
  }

  .tv-client-card-title .tv-status {
    display: none;
  }

  .tv-client-card-username {
    display: none;
  }

  .tv-device-chip-divider {
    display: block;
    border: none;
    border-top: 1px solid var(--tv-border);
    margin: 8px 0;
    width: 100%;
  }

  .tv-topnav-inner {
    padding: 12px;
    gap: 12px;
    position: relative;
  }

  .tv-topnav-hamburger {
    display: flex;
  }

  .tv-topnav-menu {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 200;
    width: 100%;
    height: 100dvh;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;
    gap: 24px;
    background: var(--tv-card);
    padding: 16px 20px 24px;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }

  .tv-topnav-menu.is-open {
    transform: translateX(0);
  }

  .tv-topnav-menu-top {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .tv-topnav-menu-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding-bottom: 16px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--tv-border);
  }

  .tv-topnav-menu-user {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--tv-ink);
  }

  .tv-topnav-menu-credits {
    margin-top: 6px;
  }

  .tv-topnav-menu-close {
    display: block;
    background: none;
    border: none;
    color: var(--tv-ink);
    font-size: 1.8rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
  }

  .tv-topnav-links {
    flex-direction: column;
    gap: 0;
    margin-right: 0;
  }

  .tv-topnav-links a {
    padding: 14px 0;
    border-bottom: 1px solid var(--tv-border);
    font-size: 1.05rem;
  }

  .tv-topnav-right {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .tv-card-header-row {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }

  .tv-card-header-row-actions {
    justify-content: flex-end;
  }

  .tv-client-card-title strong {
    font-size: 1.15rem;
  }

  .tv-client-card-devices .tv-device-chip {
    font-size: 1rem;
  }


  .tv-client-cards {
    grid-template-columns: 1fr;
  }

  #clients-view-toggle,
  #devices-view-toggle,
  #device-view-toggle {
    display: none;
  }

  #clients-view-table,
  #devices-view-table,
  #device-view-table,
  #expired-view-table,
  #unassigned-clients-table-wrap,
  #unassigned-devices-table-wrap {
    display: none !important;
  }

  #clients-view-cards,
  #devices-view-cards,
  #device-view-cards,
  #expired-view-cards,
  #unassigned-clients-cards,
  #unassigned-devices-cards {
    display: grid !important;
  }

  .tv-unassigned-body:not(.is-open) {
    display: none;
  }

  .tv-unassigned-arrow {
    display: inline-block;
    margin-left: auto;
    font-size: 0.75rem;
    transition: transform 0.15s ease;
  }

  .tv-unassigned-arrow::after {
    content: '\25B6';
  }

  .tv-unassigned-toggle.is-active .tv-unassigned-arrow {
    transform: rotate(90deg);
  }

  .tv-renewal-devices-table {
    display: none !important;
  }

  .tv-renewal-devices-cards {
    display: grid !important;
  }

  .tv-renewal-log-table {
    display: none !important;
  }

  .tv-renewal-log-cards {
    display: grid !important;
  }

  .tv-renewal-client-title {
    flex-wrap: wrap;
  }

  .js-renew-all-btn-label {
    display: none;
  }

  .js-renew-all-btn::after {
    content: '+';
    font-weight: 700;
  }

  .tv-renewal-client-title .tv-status {
    order: 1;
  }

  .tv-renewal-client-title .tv-plain-link,
  .tv-renewal-client-title .tv-device-count {
    order: 2;
  }

  .tv-renewal-client-title .tv-renewal-client-title-actions {
    order: 3;
    margin-left: auto;
  }

  .tv-renewal-linebreak {
    order: 4;
    flex-basis: 100%;
    width: 0;
    height: 0;
  }

  .tv-renewal-client-title .tv-expiry-text {
    order: 5;
  }

  .tv-renewal-client-title .tv-renewal-toggle {
    order: 6;
    flex-shrink: 0;
    margin-left: 4px;
    padding: 6px 12px;
    background: none;
    border: none;
    color: var(--tv-ink-dim);
  }

  .tv-renewal-client-title .tv-renewal-toggle.is-active {
    background: none;
    color: var(--tv-ink-dim);
    border-color: transparent;
  }

  .tv-renewal-toggle-label {
    display: none;
  }

  .tv-renewal-toggle::after {
    content: '\25B6';
    display: inline-block;
    font-size: 0.85rem;
    transition: transform 0.15s ease;
  }

  .tv-renewal-toggle.is-active::after {
    transform: rotate(90deg);
  }

  .tv-client-card {
    min-height: 0;
  }

  .tv-devices-cell {
    flex-direction: column;
    align-items: flex-start;
  }

  .tv-checklist {
    max-height: 140px;
  }
}
