/* PTT Admin — matches iOS app dark + green system language */

:root {
  color-scheme: dark;
  --bg: #0b0c0d;
  --bg-elevated: #121416;
  --panel: rgba(255, 255, 255, 0.052);
  --panel-solid: #141618;
  --panel-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.075);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.86);
  --muted: rgba(255, 255, 255, 0.45);
  --muted-2: rgba(255, 255, 255, 0.38);
  --green: #30d158;
  --green-soft: rgba(48, 209, 88, 0.13);
  --green-mid: rgba(48, 209, 88, 0.22);
  --green-border: rgba(48, 209, 88, 0.42);
  --red: #ff453a;
  --red-soft: rgba(255, 69, 58, 0.16);
  --red-text: #ff8a84;
  --orange: #ff9f0a;
  --orange-soft: rgba(255, 159, 10, 0.14);
  --orange-text: #ffd28a;
  --blue: #64d2ff;
  --radius-sm: 12px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-rounded: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  cursor: pointer;
  background: none;
}

.hidden { display: none !important; }

/* ── Shell ─────────────────────────────────────────── */

.app-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 20px 56px;
  min-height: 100vh;
}

/* ── Login (mirrors app Sign In) ───────────────────── */

.login-screen {
  min-height: calc(100vh - 44px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(100%, 400px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  text-align: center;
  margin-bottom: 10px;
}

.brand-icon {
  width: 82px;
  height: 82px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-lg);
  background: var(--green-soft);
  color: var(--green);
}

.brand h1 {
  margin: 0;
  font-family: var(--font-rounded);
  font-size: 31px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted-2);
}

.hint {
  margin: 4px 0 0;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-2);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 0.92em;
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 7px;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.72);
}

/* ── Fields ────────────────────────────────────────── */

.field {
  display: grid;
  gap: 7px;
}

.field > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.field.compact > span {
  font-size: 11px;
}

input {
  width: 100%;
  height: 50px;
  border: 0;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.075);
  color: var(--text);
  padding: 0 14px;
  font-size: 16px;
  font-weight: 500;
  outline: none;
  transition: box-shadow 0.15s ease, background 0.15s ease;
}

input::placeholder {
  color: rgba(255, 255, 255, 0.28);
  font-weight: 500;
}

input:focus {
  background: rgba(255, 255, 255, 0.095);
  box-shadow: 0 0 0 2px rgba(48, 209, 88, 0.35);
}

/* ── Buttons ───────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 48px;
  padding: 0 16px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-rounded);
  transition: transform 0.08s ease, opacity 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--green);
  color: #000;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-block {
  width: 100%;
  height: 50px;
  font-size: 16px;
}

.btn-sm {
  height: 36px;
  padding: 0 12px;
  font-size: 13px;
  border-radius: 12px;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.075);
  color: var(--text-secondary);
  font-weight: 650;
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.11);
}

.btn-warning {
  background: var(--orange-soft);
  color: var(--orange-text);
  font-weight: 650;
}

.btn-warning:hover:not(:disabled) {
  background: rgba(255, 159, 10, 0.22);
}

.btn-danger {
  background: var(--red-soft);
  color: var(--red-text);
  font-weight: 650;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(255, 69, 58, 0.24);
}

.btn-allow {
  background: var(--green-soft);
  color: var(--green);
  font-weight: 650;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.075);
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

/* ── Instance banner ───────────────────────────────── */

.instance-banner {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  border: 1px solid transparent;
}

.instance-banner.local {
  background: rgba(255, 159, 10, 0.12);
  border-color: rgba(255, 159, 10, 0.28);
  color: #ffd28a;
}

.instance-banner.production {
  background: rgba(48, 209, 88, 0.1);
  border-color: rgba(48, 209, 88, 0.28);
  color: #8ce9a8;
}

.instance-banner a {
  color: inherit;
  font-weight: 750;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.instance-banner strong {
  font-weight: 750;
}

/* ── Top bar (mirrors roleScreen header) ───────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mini-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--green-soft);
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.topbar h1 {
  margin: 0;
  font-family: var(--font-rounded);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.topbar .muted {
  margin: 3px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.65);
  user-select: none;
}

.live-badge.is-stale {
  color: var(--orange-text);
}

.live-badge.is-stale .live-dot {
  background: var(--orange);
  box-shadow: 0 0 0 0 rgba(255, 159, 10, 0.4);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(48, 209, 88, 0.45);
  animation: pulse 2s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(48, 209, 88, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(48, 209, 88, 0); }
  100% { box-shadow: 0 0 0 0 rgba(48, 209, 88, 0); }
}

/* ── Stats ─────────────────────────────────────────── */

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: transparent;
  border-radius: 3px 0 0 3px;
}

.stat.accent-green::before { background: var(--green); }
.stat.accent-orange::before { background: var(--orange); }
.stat.accent-red::before { background: var(--red); }
.stat.accent-blue::before { background: var(--blue); }

.stat .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.stat .value {
  margin-top: 6px;
  font-family: var(--font-rounded);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.stat .value.green { color: var(--green); }
.stat .value.orange { color: var(--orange); }
.stat .value.red { color: var(--red-text); }

/* ── Panels / cards ────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header h2 {
  margin: 0;
  font-family: var(--font-rounded);
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.panel-sub {
  margin: 3px 0 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

/* ── Create user form ──────────────────────────────── */

.create-form {
  margin-bottom: 14px;
  padding: 14px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.045);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.form-row:last-child { margin-bottom: 0; }

.form-row-actions {
  display: flex;
  align-items: flex-end;
}

.form-row-actions .btn {
  width: 100%;
  height: 50px;
}

.create-form input {
  height: 44px;
  font-size: 14px;
}

/* ── Tables / rows ─────────────────────────────────── */

.table {
  display: grid;
  gap: 8px;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) auto minmax(0, 1.2fr);
  gap: 12px;
  align-items: center;
  padding: 12px 12px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.row:hover {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.05);
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-family: var(--font-rounded);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.02em;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.avatar.online {
  background: var(--green-soft);
  color: var(--green);
  border-color: var(--green-border);
}

.avatar.restricted {
  background: var(--red-soft);
  color: var(--red-text);
  border-color: rgba(255, 69, 58, 0.35);
}

.user-meta {
  min-width: 0;
}

.user-meta strong {
  display: block;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-meta .sub {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Badges ────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  white-space: nowrap;
}

.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.online {
  background: var(--green-soft);
  color: var(--green);
}

.badge.restricted {
  background: var(--red-soft);
  color: var(--red-text);
}

.badge.offline {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.42);
}

/* ── Actions ───────────────────────────────────────── */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.actions .btn {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 10px;
  font-family: var(--font);
  font-weight: 650;
}

/* ── Devices ───────────────────────────────────────── */

.devices {
  display: grid;
  gap: 10px;
}

.device-card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  padding: 13px;
}

.device-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.device-card h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.device-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
}

.device-meta strong {
  color: rgba(255, 255, 255, 0.72);
  font-weight: 650;
}

.local-account {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.04);
  margin-bottom: 6px;
  font-size: 13px;
}

.local-account:last-child {
  margin-bottom: 0;
}

.local-account strong {
  font-weight: 650;
}

.pin {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  color: var(--blue);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.pin.missing {
  color: var(--muted);
  font-weight: 500;
  font-family: var(--font);
  letter-spacing: 0;
}

/* ── Channels ──────────────────────────────────────── */

.channel-row {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.5fr);
}

.member-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.member-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.member-chip.online {
  color: rgba(255, 255, 255, 0.9);
  border-color: rgba(48, 209, 88, 0.28);
  background: rgba(48, 209, 88, 0.08);
}

.member-chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
}

.member-chip.online .dot {
  background: var(--green);
}

/* ── Empty / errors ────────────────────────────────── */

.empty {
  color: var(--muted);
  padding: 28px 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
}

.error-banner {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--red-soft);
  color: var(--red-text);
  font-size: 13px;
  font-weight: 600;
}

/* ── Modal ─────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  width: min(100%, 400px);
  background: #16181b;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-card h3 {
  margin: 0 0 6px;
  font-family: var(--font-rounded);
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.modal-card > .muted {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.45;
}

.modal-fields {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-fields:empty {
  display: none;
  margin: 0;
}

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

.modal-actions .btn {
  min-width: 96px;
  height: 42px;
  font-size: 14px;
}

.modal-actions .btn.btn-danger {
  background: rgba(255, 69, 58, 0.9);
  color: #fff;
}

/* ── Toast ─────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  padding: 11px 16px;
  border-radius: 999px;
  background: #1c1f23;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 650;
  box-shadow: var(--shadow);
  max-width: min(90vw, 420px);
  text-align: center;
}

.toast.error {
  border-color: rgba(255, 69, 58, 0.4);
  color: var(--red-text);
}

.toast.success {
  border-color: rgba(48, 209, 88, 0.35);
  color: var(--green);
}

/* ── Responsive ────────────────────────────────────── */

@media (max-width: 900px) {
  .grid,
  .stats,
  .form-row {
    grid-template-columns: 1fr;
  }

  .row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .channel-row {
    grid-template-columns: 1fr;
  }

  .actions,
  .member-chips {
    justify-content: flex-start;
  }

  .form-row-actions {
    align-items: stretch;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 22px;
  }
}

@media (max-width: 520px) {
  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .app-shell {
    padding: 16px 14px 40px;
  }

  .live-badge span:last-child {
    display: none;
  }
}
