:root {
  --bg: #0b1220;
  --bg-elev: #121b2e;
  --bg-panel: #162238;
  --line: #243352;
  --text: #e8eef7;
  --muted: #8fa3bf;
  --accent: #2ec4b6;
  --accent-2: #3d8bfd;
  --warn: #f0a202;
  --danger: #e4572e;
  --ok: #3ddc97;
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Instrument Serif", Georgia, serif;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(46, 196, 182, 0.14), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(61, 139, 253, 0.12), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}

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

a { color: var(--accent); text-decoration: none; }

#root { min-height: 100vh; }

/* —— Login —— */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(22, 34, 56, 0.95), rgba(18, 27, 46, 0.98));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}

.brand-mark {
  font-family: var(--display);
  font-size: 2.35rem;
  letter-spacing: 0.02em;
  line-height: 1;
  margin-bottom: 6px;
}

.brand-mark span { color: var(--accent); }

.auth-card .lede {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 28px;
}

.auth-card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input, .field select, .field textarea {
  width: 100%;
  background: #0d1524;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #249e94);
  color: #04201d;
  width: 100%;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.btn-danger {
  background: rgba(228, 87, 46, 0.15);
  border: 1px solid rgba(228, 87, 46, 0.4);
  color: #ffb4a2;
}

.btn-ok {
  background: rgba(61, 220, 151, 0.12);
  border: 1px solid rgba(61, 220, 151, 0.35);
  color: var(--ok);
}

.btn-sm { padding: 7px 10px; font-size: 0.85rem; }

.alert {
  margin: 12px 0 16px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.alert-error {
  background: rgba(228, 87, 46, 0.12);
  border: 1px solid rgba(228, 87, 46, 0.35);
  color: #ffb4a2;
}

.alert-info {
  background: rgba(61, 139, 253, 0.12);
  border: 1px solid rgba(61, 139, 253, 0.3);
  color: #b7d4ff;
}

.alert-ok {
  background: rgba(61, 220, 151, 0.12);
  border: 1px solid rgba(61, 220, 151, 0.35);
  color: #d8ffe9;
}

.alert-warn {
  background: rgba(240, 162, 2, 0.14);
  border: 1px solid rgba(240, 162, 2, 0.4);
  color: #ffe7b0;
}

.alert-warn ul {
  margin: 8px 0 0 18px;
}

.muted-copy {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 12px;
  line-height: 1.45;
}

.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.import-result {
  margin-top: 14px;
}

.import-result .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.qr-box {
  display: grid;
  place-items: center;
  gap: 10px;
  margin: 16px 0;
  padding: 14px;
  background: #0d1524;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.qr-box img {
  width: 180px;
  height: 180px;
  border-radius: 8px;
  background: #fff;
}

.secret-code {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
  text-align: center;
}

/* —— App shell —— */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: rgba(12, 20, 36, 0.92);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar .brand-mark { font-size: 1.7rem; margin-bottom: 4px; }

.sidebar .role-chip {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 18px;
}

.nav-btn {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  text-decoration: none;
  display: block;
}

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

.nav-btn.active {
  background: rgba(46, 196, 182, 0.1);
  border-color: rgba(46, 196, 182, 0.25);
  color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.sidebar-footer .who {
  font-size: 0.85rem;
  margin-bottom: 10px;
  color: var(--muted);
}

.main {
  padding: 28px 32px 48px;
  overflow-x: auto;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.page-head h1 {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 400;
}

.page-head p {
  color: var(--muted);
  margin-top: 4px;
}

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

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
}

.stat-card .label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .value {
  font-family: var(--display);
  font-size: 2.2rem;
  margin-top: 6px;
}

.stat-card .sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}

.panel h3 {
  font-size: 0.95rem;
  margin-bottom: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  align-items: flex-end;
}

.toolbar .grow {
  flex: 1 1 200px;
  min-width: 160px;
  background: #0d1524;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.toolbar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.toolbar select {
  background: #0d1524;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  min-width: 120px;
}

.toolbar-meta {
  margin: -6px 0 12px;
  font-size: 0.8rem;
  color: var(--muted);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-scroll table.data {
  min-width: 640px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.data th,
table.data td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.data th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-active { background: rgba(61,220,151,.15); color: var(--ok); }
.badge-suspended { background: rgba(240,162,2,.15); color: var(--warn); }
.badge-deleted { background: rgba(228,87,46,.15); color: #ffb4a2; }
.badge-in_stock { background: rgba(61,139,253,.15); color: #9ec1ff; }
.badge-assigned { background: rgba(46,196,182,.12); color: var(--accent); }
.badge-released { background: rgba(143,163,191,.15); color: var(--muted); }
.badge-online { background: rgba(61,220,151,.18); color: var(--ok); }
.badge-offline { background: rgba(143,163,191,.18); color: var(--muted); }
.badge-invited { background: rgba(61,139,253,.15); color: #9ec1ff; }
.badge-paused { background: rgba(240,162,2,.15); color: var(--warn); }
.badge-pending { background: rgba(61,139,253,.15); color: #9ec1ff; }

.family-layout {
  display: grid;
  grid-template-columns: minmax(240px, 340px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.support-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.frame-log-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.mono, .frame-raw {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  word-break: break-all;
}

table.data tr.row-selected td {
  background: rgba(46,196,182,.08);
}

.presence-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
  min-height: 0.9em;
}

.socket-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  font-size: 0.8rem;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.status-dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(61,220,151,.2); }
.status-dot.offline { background: var(--muted); }

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .full { grid-column: 1 / -1; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 16, 0.65);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

/* `display: grid` above would otherwise override the HTML [hidden] attribute. */
.modal-backdrop[hidden] {
  display: none !important;
}

.modal {
  width: min(520px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
  border-color: var(--muted);
}

.modal h3 { margin-bottom: 14px; }

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

.empty {
  color: var(--muted);
  padding: 24px 8px;
  text-align: center;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .sidebar-footer { width: 100%; margin-top: 8px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .family-layout,
  .support-layout { grid-template-columns: 1fr; }
  .nav-btn { flex: 1 1 auto; }
  .row-actions { flex-direction: column; align-items: stretch; }
}

@media (max-width: 560px) {
  .stats-grid { grid-template-columns: 1fr; }
  .main { padding: 18px 14px 36px; }
  .page-head h1 { font-size: 1.55rem; }
  .toolbar .grow { flex-basis: 100%; }
  .auth-card { padding: 28px 20px; }
  .modal { padding: 16px; }
}
