
*{
  box-sizing:border-box;
}

:root{
  --bg:#f5f7fb;
  --surface:#ffffff;
  --surface-soft:#f8fafc;
  --border:#e5e7eb;
  --border-strong:#d7dce5;
  --text:#1f2937;
  --text-soft:#64748b;
  --primary:#2563eb;
  --primary-hover:#1d4ed8;
  --vk:#2787f5;
  --vk-hover:#1e78dc;
  --danger:#dc2626;
  --danger-soft:#fee2e2;
  --success:#15803d;
  --success-soft:#dcfce7;
  --shadow:0 8px 30px rgba(15,23,42,.06);
  --radius:16px;
}

html,body{
  margin:0;
  padding:0;
  background:var(--bg);
  color:var(--text);
  font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;
}

body{
  min-height:100vh;
}

a{
  color:inherit;
}

.topbar{
  position:sticky;
  top:0;
  z-index:20;
  background:rgba(255,255,255,.96);
  border-bottom:1px solid var(--border);
  backdrop-filter:blur(10px);
}

.topbar-inner{
  width:min(1180px,calc(100% - 32px));
  height:72px;
  margin:0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:24px;
}

.brand{
  display:inline-flex;
  align-items:center;
  gap:10px;
  font-size:20px;
  font-weight:800;
  text-decoration:none;
  color:var(--text);
  white-space:nowrap;
}

.brand-mark{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:34px;
  height:34px;
  border-radius:10px;
  background:var(--vk);
  color:white;
  font-size:14px;
  font-weight:800;
}

.nav{
  display:flex;
  align-items:center;
  gap:6px;
  padding:4px;
  background:#f1f5f9;
  border-radius:12px;
}

.nav a{
  padding:9px 14px;
  border-radius:9px;
  text-decoration:none;
  color:#475569;
  font-size:14px;
  font-weight:700;
  transition:.15s ease;
}

.nav a:hover{
  background:white;
  color:var(--text);
}

.nav a.active{
  background:white;
  color:var(--primary);
  box-shadow:0 1px 4px rgba(15,23,42,.08);
}

.container{
  width:min(1060px,calc(100% - 32px));
  margin:0 auto;
  padding:36px 0 56px;
}

.container.narrow{
  width:min(760px,calc(100% - 32px));
}

.hero-row,
.page-head{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:24px;
  margin-bottom:22px;
}

.hero-row h1,
.page-head h1{
  margin:0;
  font-size:34px;
  letter-spacing:-.03em;
  line-height:1.15;
}

.page-subtitle,
.muted{
  color:var(--text-soft);
}

.page-subtitle{
  margin:8px 0 0;
  font-size:15px;
  line-height:1.5;
}

.hero-actions,
.page-buttons,
.row-actions,
.group-head-actions,
.form-actions{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  min-height:40px;
  padding:9px 14px;
  border:1px solid transparent;
  border-radius:10px;
  font:inherit;
  font-size:14px;
  font-weight:700;
  line-height:1;
  text-decoration:none;
  cursor:pointer;
  transition:.15s ease;
}

.btn:hover{
  transform:translateY(-1px);
}

.btn-primary,
.btn.primary{
  background:var(--primary);
  color:white;
}

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

.btn-vk,
.btn.vk{
  background:var(--vk);
  color:white;
}

.btn-vk:hover,
.btn.vk:hover{
  background:var(--vk-hover);
}

.btn-secondary,
.btn.secondary{
  background:#f8fafc;
  color:#334155;
  border-color:var(--border);
}

.btn-secondary:hover,
.btn.secondary:hover{
  background:#eef2f7;
}

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

.btn-danger:hover,
.btn.danger:hover{
  background:var(--danger-soft);
}

.btn-sm,
.btn.small{
  min-height:34px;
  padding:7px 10px;
  font-size:13px;
}

.card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:22px;
}

.summary-bar{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:12px;
  margin-bottom:22px;
}

.summary-item{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:14px;
  padding:16px 18px;
  box-shadow:0 4px 16px rgba(15,23,42,.04);
}

.summary-label{
  display:block;
  font-size:12px;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:.04em;
  color:#94a3b8;
  margin-bottom:5px;
}

.summary-value{
  display:block;
  font-size:24px;
  font-weight:800;
  color:var(--text);
}

.groups-grid{
  display:grid;
  gap:18px;
}

.community-group{
  padding:0;
  overflow:hidden;
}

.community-group-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:20px 22px;
  background:linear-gradient(180deg,#fff,#fbfdff);
  border-bottom:1px solid var(--border);
}

.community-group-head h2{
  margin:2px 0 4px;
  font-size:20px;
  letter-spacing:-.01em;
}

.section-kicker{
  font-size:11px;
  font-weight:800;
  color:#94a3b8;
  text-transform:uppercase;
  letter-spacing:.08em;
}

.group-count{
  font-size:13px;
  color:var(--text-soft);
}

.community-list{
  transition:.18s ease;
}

.community-list.collapsed{
  display:none;
}

.community-row{
  display:grid;
  grid-template-columns:minmax(0,1fr) auto;
  gap:20px;
  align-items:center;
  padding:18px 22px;
  border-bottom:1px solid #edf1f5;
}

.community-row:last-child{
  border-bottom:0;
}

.community-main{
  min-width:0;
}

.community-title-line{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
}

.community-name{
  min-width:0;
  font-size:15px;
  font-weight:800;
  color:var(--text);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.community-meta{
  margin-top:4px;
  font-size:13px;
  color:#94a3b8;
}

.status-pill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:26px;
  padding:4px 9px;
  border-radius:999px;
  font-size:11px;
  font-weight:800;
  white-space:nowrap;
}

.status-pill.on{
  color:var(--success);
  background:var(--success-soft);
}

.status-pill.off{
  color:#b91c1c;
  background:#fee2e2;
}

.token-box{
  margin-top:10px;
  display:flex;
  align-items:center;
  gap:10px;
  max-width:100%;
  padding:8px 10px;
  border-radius:10px;
  background:#f8fafc;
  border:1px solid #edf1f5;
}

.token-label{
  flex:0 0 auto;
  font-size:11px;
  font-weight:800;
  color:#94a3b8;
  text-transform:uppercase;
  letter-spacing:.04em;
}

.token{
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-size:12px;
  color:#475569;
}

.community-actions{
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.community-actions form,
.row-actions form{
  margin:0;
}

.standalone-group{
  margin-top:18px;
}

.set-row,
.rule-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:20px;
  padding:16px 0;
  border-bottom:1px solid var(--border);
}

.set-row:first-child,
.rule-row:first-child{
  padding-top:0;
}

.set-row:last-child,
.rule-row:last-child{
  border-bottom:0;
  padding-bottom:0;
}

.set-title,
.rule-key{
  font-size:16px;
  font-weight:800;
}

.rule-details{
  margin-top:6px;
  display:flex;
  align-items:center;
  gap:6px;
  flex-wrap:wrap;
  color:var(--text-soft);
  font-size:13px;
}

.target-chip{
  display:inline-flex;
  padding:4px 8px;
  border-radius:999px;
  background:#eef2ff;
  color:#4f46e5;
  font-size:11px;
  font-weight:800;
}

label{
  display:block;
  margin:16px 0 7px;
  font-size:13px;
  font-weight:800;
  color:#334155;
}

input[type="text"],
input[type="password"],
select,
textarea{
  width:100%;
  border:1px solid var(--border-strong);
  border-radius:10px;
  background:white;
  padding:11px 12px;
  font:inherit;
  color:var(--text);
  outline:none;
}

input:focus,
select:focus,
textarea:focus{
  border-color:#93c5fd;
  box-shadow:0 0 0 3px rgba(37,99,235,.10);
}

textarea{
  resize:vertical;
  min-height:130px;
}

.select-tools{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-top:20px;
}

.community-checklist{
  margin:12px 0 18px;
  border:1px solid var(--border);
  border-radius:12px;
  max-height:430px;
  overflow:auto;
}

.check-row{
  display:grid;
  grid-template-columns:24px 1fr auto;
  gap:10px;
  align-items:center;
  padding:11px 12px;
  margin:0;
  border-bottom:1px solid #eef2f7;
  cursor:pointer;
}

.check-row:last-child{
  border-bottom:0;
}

.alert{
  margin-bottom:18px;
  padding:12px 14px;
  border-radius:10px;
  font-size:14px;
  font-weight:600;
}

.alert.success{
  background:#dcfce7;
  color:#166534;
}

.alert.error{
  background:#fee2e2;
  color:#991b1b;
}

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

.empty-state.big{
  padding:46px 24px;
}

.empty-state h3{
  margin:0 0 6px;
  color:var(--text);
}

.empty-state p{
  margin:0;
}

.connect-code{
  margin:18px 0;
  padding:14px;
  background:#f8fafc;
  border-radius:10px;
  overflow-wrap:anywhere;
}

.full{
  width:100%;
}

.center{
  text-align:center;
}

@media (max-width:860px){
  .topbar-inner{
    height:auto;
    padding:14px 0;
    align-items:flex-start;
    flex-direction:column;
  }

  .nav{
    width:100%;
    overflow:auto;
  }

  .hero-row,
  .page-head{
    align-items:flex-start;
    flex-direction:column;
  }

  .summary-bar{
    grid-template-columns:1fr;
  }

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

  .community-actions{
    justify-content:flex-start;
  }
}

@media (max-width:560px){
  .container,
  .topbar-inner,
  .container.narrow{
    width:min(100% - 20px,1060px);
  }

  .container{
    padding-top:24px;
  }

  .hero-row h1,
  .page-head h1{
    font-size:28px;
  }

  .community-group-head{
    align-items:flex-start;
    flex-direction:column;
  }

  .community-title-line{
    align-items:flex-start;
    flex-direction:column;
  }

  .community-actions{
    display:grid;
    grid-template-columns:1fr 1fr;
    width:100%;
  }

  .community-actions form,
  .community-actions .btn{
    width:100%;
  }

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


/* Hard layout guards */
.community-main,
.community-info,
.rule-main,
.set-row > div:first-child,
.rule-row > div:first-child {
  min-width: 0;
}

.token-box {
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.token {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

.community-row {
  min-width: 0;
  overflow: hidden;
}

@media (min-width:861px){
  .community-actions .btn{
    min-width:92px;
  }
}


/* ===== AUTH PAGE ===== */
.auth-page{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
  background:
    radial-gradient(circle at top left, rgba(39,135,245,.10), transparent 34%),
    radial-gradient(circle at bottom right, rgba(37,99,235,.08), transparent 30%),
    var(--bg);
}

.auth-wrap{
  width:100%;
  max-width:430px;
}

.auth-card{
  width:100%;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:20px;
  box-shadow:0 18px 50px rgba(15,23,42,.10);
  padding:32px;
}

.auth-brand{
  display:inline-flex;
  align-items:center;
  gap:10px;
  margin-bottom:26px;
  font-size:20px;
  font-weight:800;
  color:var(--text);
}

.auth-card h1{
  margin:0;
  font-size:28px;
  letter-spacing:-.03em;
}

.auth-subtitle{
  margin:8px 0 24px;
  color:var(--text-soft);
  font-size:14px;
  line-height:1.5;
}

.auth-form{
  display:block;
}

.auth-field{
  margin-bottom:16px;
}

.auth-field label{
  margin:0 0 7px;
}

.auth-field input{
  width:100%;
  height:44px;
  padding:10px 12px;
  border:1px solid var(--border-strong);
  border-radius:10px;
  background:#fff;
  font-size:15px;
}

.auth-submit{
  width:100%;
  margin-top:4px;
  min-height:44px;
}

@media (max-width:520px){
  .auth-page{
    align-items:flex-start;
    padding-top:52px;
  }

  .auth-card{
    padding:24px 20px;
    border-radius:16px;
  }

  .auth-card h1{
    font-size:24px;
  }
}

.field-hint{
  margin:7px 0 0;
  color:var(--text-soft,#64748b);
  font-size:12px;
  line-height:1.4;
}


/* ===== MULTIPLE ANSWER FIELDS ===== */
.answers-container{
  display:grid;
  gap:14px;
  margin-top:10px;
}

.answer-item{
  padding:14px;
  border:1px solid var(--border,#e5e7eb);
  border-radius:12px;
  background:#f8fafc;
}

.answer-item-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:8px;
}

.answer-number{
  font-size:13px;
  font-weight:800;
  color:#475569;
}

.answer-item textarea{
  margin:0;
  background:#fff;
  min-height:105px;
}

.add-answer-btn{
  margin-top:12px;
}

.remove-answer-btn{
  border:0;
  background:transparent;
  color:#dc2626;
  font:inherit;
  font-size:12px;
  font-weight:800;
  cursor:pointer;
  padding:4px 6px;
  border-radius:6px;
}

.remove-answer-btn:hover{
  background:#fee2e2;
}
