:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --danger: #e34948;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --card-shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 12px rgba(11, 11, 11, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --danger: #e66767;
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --card-shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
}

#login-view[hidden],
#password-change-view[hidden],
#dashboard-view[hidden] {
  display: none;
}

/* Login */
#login-view,
#password-change-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  box-shadow: var(--card-shadow);
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 6px;
}

.login-card .subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 24px;
}

.login-card label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 6px;
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 0 0 16px;
  font-size: 14px;
  background: var(--page-plane);
  color: var(--text-primary);
}

.login-card button[type="submit"] {
  width: 100%;
  padding: 12px;
  background: var(--series-1);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin: 16px 0 0;
}

/* Dashboard shell — fills the viewport, inner panels scroll instead of the page */
#dashboard-view {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 20px 24px;
  gap: 16px;
  max-width: 1280px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  padding: 10px 4px;
  margin-right: 20px;
  font-size: 13px;
  cursor: pointer;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--series-1);
  font-weight: 600;
}

.tab-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tab-panel[hidden] {
  display: none;
}

#view-overview.tab-panel {
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--series-1);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
}

.last-updated {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.signed-in-as {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
}

.signed-in-as[hidden] {
  display: none;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.ghost-btn:hover {
  background: var(--surface-1);
}

.danger-btn {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.danger-btn:hover {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.danger-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--series-1);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.stat-row {
  flex: 0 0 auto;
  display: grid;
  /* auto-fit + collapsing empty tracks so 3 tiles (e.g. a `cdp`-role account, which never gets the
     WisePCO-owned tile) fill the row evenly instead of leaving a blank 4th column. */
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--card-shadow);
}

.stat-tile[hidden] {
  display: none;
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.status-dot.good {
  background: var(--status-good);
}

.status-dot.warning {
  background: var(--status-warning);
}

.status-dot.danger {
  background: var(--danger);
}

.stat-tile-clickable {
  cursor: pointer;
}

.stat-tile-clickable:hover {
  background: var(--page-plane);
}

.stat-value {
  font-size: 30px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* Lower grid: CDP breakdown (left) + registrations & activity (right), fills remaining height */
.grid-lower {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(340px, 1.5fr);
  gap: 16px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex: 0 0 auto;
}

.card-header h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}

.cdp-card {
  overflow: hidden;
}

.right-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.registrations-card {
  flex: 0 0 auto;
}

.activity-card {
  flex: 1;
  min-height: 0;
}

.scope-note {
  font-size: 13px;
  color: var(--text-secondary);
  margin: -4px 0 12px;
}

.cell-subtext {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.history-summary {
  font-size: 13px;
  color: var(--text-primary);
  margin-top: 6px;
}

.table-scroll {
  overflow-y: auto;
  min-height: 0;
}

.activity-card .table-scroll {
  flex: 1;
}

/* CDP bar list */
.cdp-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

.cdp-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  align-items: center;
}

.cdp-row .cdp-name-btn {
  font: inherit;
  font-size: 12.5px;
  color: var(--text-secondary);
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  width: 100%;
  min-width: 0;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cdp-row .cdp-name-btn:hover,
.cdp-row .cdp-name-btn:focus-visible {
  color: var(--series-1);
  text-decoration: underline;
}

.cdp-row .cdp-count {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.cdp-row .cdp-bar-track {
  grid-column: 1 / -1;
  height: 6px;
  background: var(--gridline);
  border-radius: 3px;
  overflow: hidden;
}

.cdp-row .cdp-bar-fill {
  height: 100%;
  background: var(--series-1);
  border-radius: 3px;
  min-width: 2px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  color: var(--text-primary);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table th[hidden],
.data-table td[hidden] {
  display: none;
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.data-table th.sortable:hover {
  color: var(--text-primary);
}

.data-table th.sort-active {
  color: var(--text-primary);
}

.sort-arrow {
  display: inline-block;
  margin-left: 4px;
  font-size: 9px;
  color: var(--series-1);
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: var(--page-plane);
}

/* Users / CDPs views */
.users-card,
.cdps-card {
  flex: 1;
  min-height: 0;
}

.search-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--page-plane);
  color: var(--text-primary);
  min-width: 240px;
}

.card-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filter-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 30px 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background-color: var(--page-plane);
  color: var(--text-primary);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23898781' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px;
}

.filter-select[hidden] {
  display: none;
}

.pagination {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 12px;
}

.pagination-info {
  font-size: 12px;
  color: var(--text-muted);
}

.pagination .ghost-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.pagination .ghost-btn:disabled:hover {
  background: transparent;
}

.pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.tab-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--status-warning);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.pill-good {
  background: color-mix(in srgb, var(--status-good) 16%, transparent);
  color: var(--status-good);
}

.pill-warning {
  background: color-mix(in srgb, var(--status-warning) 20%, transparent);
  color: var(--status-warning);
}

.pill-danger {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
}

.pill-muted {
  background: var(--gridline);
  color: var(--text-muted);
}

.pill-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font: inherit;
}

.pill-btn:hover .pill {
  opacity: 0.8;
}

.toggle-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--gridline);
  color: var(--text-muted);
}

.toggle-btn.on {
  background: color-mix(in srgb, var(--status-good) 16%, transparent);
  color: var(--status-good);
  border-color: transparent;
}

.toggle-btn.off {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  border-color: transparent;
}

.toggle-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* User detail modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 11, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--card-shadow);
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 18px;
  padding-right: 24px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

.modal-close:hover {
  color: var(--text-primary);
}

.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 16px;
  margin: 0;
}

.detail-list dt {
  font-size: 12px;
  color: var(--text-muted);
}

.detail-list dd {
  margin: 0;
  font-size: 13px;
  color: var(--text-primary);
  word-break: break-word;
}

.modal-action-btn {
  margin-top: 20px;
}

.modal-action-row {
  display: flex;
  gap: 10px;
}

/* Account create modal */
.modal p.subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin: -8px 0 20px;
}

.modal-form label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0 0 6px;
}

.modal-form label[hidden],
.modal-form .checkbox-list[hidden] {
  display: none;
}

.modal-form .checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  margin: 4px 0 20px;
  cursor: pointer;
}

.modal-form .checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

.modal-form .checkbox-list {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  margin: 0 0 16px;
}

.modal-form .checkbox-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  font-size: 14px;
  color: var(--text-primary);
  padding: 6px 0;
  margin: 0;
  cursor: pointer;
}

.modal-form .checkbox-list-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

.modal-form input,
.modal-form select,
.modal-form textarea {
  display: block;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 0 0 16px;
  font-size: 14px;
  font-family: inherit;
  background: var(--page-plane);
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.modal-form textarea {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
}

.modal-form textarea[hidden] {
  display: none;
}

.modal-form select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23898781' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px;
}

.modal-form input:focus,
.modal-form select:focus,
.modal-form textarea:focus {
  outline: none;
  border-color: var(--series-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--series-1) 18%, transparent);
}

.modal-form button[type="submit"] {
  width: 100%;
  padding: 12px;
  background: var(--series-1);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

.modal-form button[type="submit"]:hover {
  opacity: 0.92;
}

.modal-form button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: default;
}

.modal-form button[type="submit"].danger-submit-btn {
  background: var(--danger);
}

.temp-password-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0 20px;
}

.temp-password-box code {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

#account-result p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

#account-result-done-btn {
  width: 100%;
}

/* Bar chart (registrations over time) */
.bar-chart {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 140px;
  border-bottom: 1px solid var(--baseline);
  padding-bottom: 2px;
}

.bar-chart[hidden] {
  display: none;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  min-width: 4px;
}

.bar {
  width: 100%;
  max-width: 14px;
  background: var(--series-1);
  border-radius: 4px 4px 0 0;
  transition: opacity 0.15s ease;
}

.bar:hover {
  opacity: 0.8;
}

.bar-label {
  /* Fixed height so an empty label (bars with no date shown) reserves the same space as one with
     text — otherwise the bar+label stack is shorter for unlabeled bars and, since the column is
     bottom-justified, their bars sit lower than labeled ones instead of sharing a common baseline. */
  height: 12px;
  font-size: 10px;
  line-height: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  white-space: nowrap;
}

.empty-state {
  color: var(--text-secondary);
  font-size: 13px;
}

@media (max-width: 860px) {
  #dashboard-view {
    height: auto;
    min-height: 100vh;
  }

  .stat-row {
    grid-template-columns: 1fr;
  }

  .grid-lower {
    display: flex;
    flex-direction: column;
  }

  .cdp-list,
  .table-scroll {
    max-height: 320px;
  }
}

/* Releases tab */
.modal.modal-wide {
  max-width: 640px;
}

.release-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

#release-add-item-btn {
  margin-bottom: 20px;
}

.release-item-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

/* The shared .modal-form input/select rule adds a bottom margin, which would knock the row out of alignment. */
.release-item-row select,
.release-item-row input {
  margin: 0;
}

.release-item-actions {
  display: flex;
  gap: 2px;
}

.modal-form .release-item-btn {
  width: 28px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.modal-form .release-item-btn:hover:not(:disabled) {
  background: var(--surface-1);
  color: var(--text-primary);
}

.modal-form .release-item-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.modal-form .release-item-remove {
  font-size: 20px;
}

.modal-form .release-item-remove:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
}

.release-items-preview {
  margin: 0;
  padding-left: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.release-item-type {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.04em;
}

@media (max-width: 560px) {
  .release-item-row {
    grid-template-columns: 100px minmax(0, 1fr);
  }

  .release-item-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

.modal-form label .optional {
  font-weight: 400;
  opacity: 0.7;
}
