/* === reset / base === */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #1f2933;
  background: #f5f7fa;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
button { font: inherit; cursor: pointer; }
input, textarea, select, button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: #6b7785; }
.small { font-size: 0.875rem; }
.row { display: flex; align-items: center; }
.row.gap { gap: 0.5rem; }
.row.right { justify-content: flex-end; }

/* === buttons === */
.btn-primary, .btn-ghost, .btn-danger {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid transparent;
  padding: 0.55rem 1rem; font-weight: 600; line-height: 1.2;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
  min-height: 40px; /* mobile tap target */
}
.btn-primary { background: #1b8755; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #146a43; }
.btn-ghost { background: transparent; color: #1f2933; border-color: #cbd2d9; }
.btn-ghost:hover:not(:disabled) { background: #eef1f5; }
.btn-danger { background: #b3261e; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #8e1c17; }
.btn-primary:disabled, .btn-ghost:disabled, .btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }
.small.btn-primary, .small.btn-ghost, .small.btn-danger,
.btn-primary.small, .btn-ghost.small, .btn-danger.small {
  padding: 0.35rem 0.7rem; font-size: 0.875rem; min-height: 32px;
}
.btn-block { width: 100%; }

/* === auth page === */
.auth-body {
  background: linear-gradient(135deg, #1b8755 0%, #146a43 100%);
  min-height: 100vh; min-height: 100svh;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.auth-shell { width: 100%; max-width: 420px; }
.auth-logo {
  display: inline-flex; align-items: center; gap: 0.5rem;
  color: #fff; font-weight: 700; font-size: 1.25rem; text-decoration: none;
  margin-bottom: 1rem;
}
.auth-card {
  background: #fff; border-radius: 16px; padding: 1.5rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}
.auth-tabs { display: flex; gap: 0.25rem; background: #eef1f5; padding: 0.25rem; border-radius: 10px; margin-bottom: 1.25rem; }
.auth-tab {
  flex: 1; background: transparent; border: 0; padding: 0.6rem;
  border-radius: 8px; font-weight: 600; color: #475260;
}
.auth-tab.active { background: #fff; color: #1f2933; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.auth-form { display: flex; flex-direction: column; gap: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.field input {
  border: 1px solid #cbd2d9; border-radius: 8px; padding: 0.7rem 0.9rem;
  font-size: 1rem; background: #fff;
}
.field input:focus { outline: 2px solid #1b8755; outline-offset: 1px; }
.auth-error { color: #b3261e; min-height: 1.2em; margin: 0; }
.auth-meta { color: #6b7785; font-size: 0.8rem; text-align: center; margin: 0.5rem 0 0; }
.auth-meta a { color: #1b8755; }

/* === app shell / topbar === */
.app-body { min-height: 100vh; min-height: 100svh; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; background: #fff;
  border-bottom: 1px solid #e2e6ec;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.5rem;
  color: #1b8755; font-weight: 700; text-decoration: none; font-size: 1.05rem;
}
.topbar-nav { display: flex; align-items: center; gap: 1rem; }
.nav-link {
  text-decoration: none; color: #475260; font-weight: 600;
  padding: 0.5rem 0.75rem; border-radius: 8px;
}
.nav-link.active { background: #eaf5ee; color: #146a43; }
.nav-signout {
  background: transparent; border: 1px solid #cbd2d9;
  border-radius: 8px; padding: 0.5rem 0.85rem; font-weight: 600;
}
.burger {
  display: none; background: transparent; border: 0; padding: 0.5rem; gap: 4px;
  flex-direction: column; align-items: stretch; width: 38px;
}
.burger span { display: block; height: 3px; background: #1f2933; border-radius: 3px; }

.app-shell {
  max-width: 1100px; margin: 0 auto; padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.view { display: flex; flex-direction: column; gap: 1rem; }

/* === card === */
.card {
  background: #fff; border-radius: 14px; padding: 1rem 1.1rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 0 0 1px rgba(15,23,42,0.04);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap;
}
.card-header h2 { margin: 0; font-size: 1.1rem; }

/* === badges === */
.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.6rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
}
.badge-offline    { background: #eef1f5; color: #475260; }
.badge-connecting { background: #fef3c7; color: #92400e; }
.badge-pairing    { background: #e0f2fe; color: #075985; }
.badge-online     { background: #d1fae5; color: #065f46; }

/* === connection card / QR === */
.connection-card .row { flex-wrap: wrap; }
.qr-area {
  margin-top: 1rem; padding: 1rem; border-radius: 10px;
  background: #f8fafc; border: 1px dashed #cbd2d9; text-align: center;
}
.qr-instruct { margin: 0 0 0.75rem; }
.qr-code { display: flex; justify-content: center; margin: 0.5rem 0; }
.qr-code img { width: 240px; height: 240px; max-width: 70vw; max-height: 70vw; }

/* === groups / members === */
.two-col {
  display: grid; gap: 1rem;
  grid-template-columns: minmax(0, 360px) 1fr;
}
.list { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow-y: auto; }
.group-row {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.7rem 0.5rem; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
}
.group-row:hover { background: #f5f7fa; }
.group-row.selected { background: #eaf5ee; border-color: #b9e1c8; }
.group-row .group-meta { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.group-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-row .star {
  background: transparent; border: 0; font-size: 1.4rem; color: #cbd2d9;
  width: 32px; height: 32px; border-radius: 6px;
}
.group-row .star:hover { background: #eef1f5; }
.group-row .star.on { color: #f59e0b; }

.toolbar { margin: 0 0 0.75rem; }
.member-table-wrap { width: 100%; overflow-x: auto; }
.member-table { width: 100%; border-collapse: collapse; min-width: 540px; }
.member-table th, .member-table td {
  text-align: left; padding: 0.55rem 0.65rem;
  border-bottom: 1px solid #eef1f5; vertical-align: middle;
}
.member-table th.sel, .member-table td.sel { width: 32px; }
.role {
  display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
}
.role-admin { background: #e0f2fe; color: #075985; }
.role-owner { background: #fef3c7; color: #92400e; }

/* === dialogs === */
.dialog {
  border: 0; border-radius: 14px; padding: 0; max-width: 520px; width: 90vw;
  box-shadow: 0 24px 64px rgba(15,23,42,0.25);
}
.dialog::backdrop { background: rgba(15,23,42,0.45); }
.dialog-form { display: flex; flex-direction: column; gap: 0.85rem; padding: 1.25rem; }
.dialog-form h3 { margin: 0; }
.dialog-form textarea {
  width: 100%; resize: vertical; border-radius: 8px; border: 1px solid #cbd2d9;
  padding: 0.6rem 0.75rem;
}
.progress-list { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; font-size: 0.9rem; }
.progress-list li { display: flex; justify-content: space-between; padding: 0.3rem 0; border-bottom: 1px dashed #eef1f5; }
.progress-list .status { color: #6b7785; }
.progress-list .status.ok { color: #065f46; }
.progress-list .status.err { color: #b3261e; }

/* === settings === */
.settings-list { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 1rem; }
.settings-list dt { font-weight: 600; color: #475260; }
.settings-list dd { margin: 0; }

/* === fireworks canvas === */
.fireworks {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  background: transparent;
}

/* === mobile === */
@media (max-width: 720px) {
  .topbar-nav {
    position: absolute; top: 100%; left: 0; right: 0;
    background: #fff; flex-direction: column; align-items: stretch;
    padding: 0.5rem; gap: 0.25rem; border-bottom: 1px solid #e2e6ec;
    transform: translateY(-150%); transition: transform .2s ease;
    box-shadow: 0 12px 20px rgba(15,23,42,.08);
  }
  body.nav-open .topbar-nav { transform: translateY(0); }
  .burger { display: inline-flex; }
  .nav-link, .nav-signout { width: 100%; text-align: left; }
  .two-col { grid-template-columns: 1fr; }
  .app-shell { padding: 0.85rem; }
  .card { padding: 0.9rem; }
  .card-header { gap: 0.5rem; }
  .list { max-height: 420px; }
  .qr-code img { width: 220px; height: 220px; }
}
