:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

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

a:hover {
  text-decoration: underline;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(59, 130, 246, 0.12), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(34, 197, 94, 0.08), transparent 50%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 6px;
}

.login-card .sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 12px;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

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

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

.error-msg {
  color: var(--danger);
  font-size: 0.88rem;
  margin-top: 12px;
  min-height: 1.2em;
}

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

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
}

.brand {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 8px 12px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand small {
  display: block;
  font-weight: 400;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 4px;
}

.nav a {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--muted);
  margin-bottom: 4px;
}

.nav a:hover,
.nav a.active {
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.main {
  padding: 24px 28px;
  overflow: auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h2 {
  font-size: 1.4rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.stat-card .label {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-card .value {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 4px;
}

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

.card h3 {
  font-size: 1rem;
  margin-bottom: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

.badge-online {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.badge-offline {
  background: rgba(139, 156, 179, 0.15);
  color: var(--muted);
}

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

/* Control page */
.control-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .control-layout {
    grid-template-columns: 1fr;
  }
}

.phone-frame {
  background: #000;
  border-radius: 20px;
  border: 3px solid var(--border);
  overflow: hidden;
  aspect-ratio: 9 / 16;
  max-height: 72vh;
  margin: 0 auto;
  position: relative;
  cursor: crosshair;
  user-select: none;
}

.phone-frame video,
.phone-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.phone-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 20px;
}

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

.control-panel .row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.control-panel .section-title {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 14px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.log-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  max-height: 180px;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 14px;
}

.log-box .line {
  margin-bottom: 4px;
}

.log-box .line.err {
  color: var(--danger);
}

.log-box .line.ok {
  color: var(--success);
}

.token-box {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  word-break: break-all;
  margin: 10px 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow);
}

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

.hidden {
  display: none !important;
}

.badge-role-admin {
  background: rgba(245, 158, 11, 0.18);
  color: var(--warning);
}

.badge-role-distributor {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
}

.badge-role-member {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.badge-disabled {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.form-row input,
.form-row select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

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

.modal.wide {
  max-width: 720px;
}

.user-meta {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 2px;
}
