/* webapp.css — mobile-first responsive webapp UI */
*{margin:0;padding:0;box-sizing:border-box}

:root{
  --bg:#0f0f11;
  --surface:#1a1a2e;
  --surface-hover:#252540;
  --text:#e4e4e7;
  --text-muted:#a1a1aa;
  --primary:#6366f1;
  --primary-hover:#818cf8;
  --danger:#ef4444;
  --success:#22c55e;
  --border:rgba(255,255,255,.1);
  --radius:12px;
}

@media(prefers-color-scheme:light){
  :root{
    --bg:#f4f4f5;
    --surface:#fff;
    --surface-hover:#f0f0f4;
    --text:#18181b;
    --text-muted:#71717a;
    --border:#e4e4e7;
  }
}

html,body{
  height:100%;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
  background:var(--bg);
  color:var(--text);
  -webkit-text-size-adjust:100%;
}

#app{
  display:flex;
  flex-direction:column;
  min-height:100%;
  min-height:100dvh;
  max-width:480px;
  margin:0 auto;
  padding:0 16px;
}

/* Header */
.header{
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px 0 8px;
  font-size:16px;
  font-weight:600;
  color:var(--text-muted);
}

/* Main content */
.content{
  flex:1;
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap:16px;
  padding:8px 0 16px;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
}

/* Status/loading */
.status{
  text-align:center;
  color:var(--text-muted);
  font-size:14px;
  padding:40px 0;
}

.status .spinner{
  display:inline-block;
  width:24px;height:24px;
  border:3px solid var(--border);
  border-top-color:var(--primary);
  border-radius:50%;
  animation:spin 1s linear infinite;
  margin-bottom:8px;
}

@keyframes spin{to{transform:rotate(360deg)}}

/* Question / message text */
.question-text{
  font-size:17px;
  line-height:1.5;
  padding:8px 0;
  white-space:pre-wrap;
  word-wrap:break-word;
}

.question-text b{font-weight:600}
.question-text i{font-style:italic}

/* Media (images) */
.media-container{
  width:100%;
  border-radius:var(--radius);
  overflow:hidden;
  margin:8px 0;
}

.media-container img{
  width:100%;
  height:auto;
  display:block;
}

/* Buttons (menu, options) */
.buttons{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.buttons.grid-2{
  display:grid;
  grid-template-columns:1fr 1fr;
}

.buttons.grid-3{
  display:grid;
  grid-template-columns:1fr 1fr 1fr;
}

/* Per-level button alignment (buts_align in panel).
 *
 * Works across the three layouts .buttons can be in:
 *   - flex-direction:column (default, no grid-* class)
 *   - grid-2 / grid-3 (grid-template-columns)
 *
 * Container-level justify/align-items are kept as defaults for legacy
 * flex behaviour, but the *real* alignment is done on the .btn itself
 * via align-self + justify-self. That's necessary because:
 *   - grid cells default to justify-self:stretch, which makes .btn
 *     fill the entire column and completely hides justify-items on
 *     the parent.
 *   - flex column items honour align-self to move across the main
 *     (horizontal) axis.
 *
 * Width override is required too: without it the button stays 100% of
 * its cell/flex track, and alignment has nothing to do.
 */
.buttons.buttons-left   { justify-items:start;  align-items:flex-start; text-align:left;   }
.buttons.buttons-center { justify-items:center; align-items:center;     text-align:center; }
.buttons.buttons-right  { justify-items:end;    align-items:flex-end;   text-align:right;  }

/* Also override the inner flex alignment on .btn itself so the *text*
 * inside the button follows the chosen side, not just the button's
 * position in the row. Without these rules the .btn default
 * (justify-content:center; text-align:center) would leave long labels
 * looking centred even when the whole grid has shifted left/right. */
.buttons.buttons-left   .btn { align-self:flex-start; justify-self:start;  justify-content:flex-start; text-align:left;   }
.buttons.buttons-center .btn { align-self:center;     justify-self:center; justify-content:center;     text-align:center; }
.buttons.buttons-right  .btn { align-self:flex-end;   justify-self:end;    justify-content:flex-end;   text-align:right;  }

.buttons.buttons-left .btn,
.buttons.buttons-right .btn{
  width:auto;
  min-width:160px;
  max-width:100%;
}

.btn{
  display:flex;
  align-items:center;
  justify-content:center;
  padding:14px 20px;
  border-radius:var(--radius);
  font-size:15px;
  font-weight:500;
  text-decoration:none;
  cursor:pointer;
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--text);
  transition:background .15s,transform .1s;
  text-align:center;
  min-height:48px;
  word-break:break-word;
}

.btn:hover{background:var(--surface-hover)}
.btn:active{transform:scale(.97)}

.btn-primary{
  background:var(--primary);
  color:#fff;
  border-color:var(--primary);
}
.btn-primary:hover{background:var(--primary-hover)}

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

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

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

/* Text input */
.input-wrap{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.text-input{
  width:100%;
  padding:14px 16px;
  border-radius:var(--radius);
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--text);
  font-size:15px;
  font-family:inherit;
  outline:none;
  transition:border-color .2s;
}

.text-input:focus{border-color:var(--primary)}

.text-input::placeholder{color:var(--text-muted)}

textarea.text-input{
  resize:vertical;
  min-height:80px;
}

/* Hint text */
.hint{
  font-size:13px;
  color:var(--text-muted);
  line-height:1.4;
}

/* Progress bar */
.progress-bar{
  height:4px;
  background:var(--border);
  border-radius:2px;
  overflow:hidden;
  margin:8px 0;
}

.progress-bar .fill{
  height:100%;
  background:var(--primary);
  transition:width .3s ease;
}

/* Confirmation preview */
.confirmation{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:16px;
}

.confirmation .label{
  font-size:13px;
  color:var(--text-muted);
  margin-bottom:4px;
}

.confirmation .value{
  font-size:15px;
}

/* Error */
.error-box{
  background:rgba(239,68,68,.1);
  border:1px solid rgba(239,68,68,.3);
  border-radius:var(--radius);
  padding:16px;
  color:var(--danger);
  text-align:center;
}

/* Poll/quiz specific */
.option-list{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.option-btn{
  display:flex;
  align-items:center;
  gap:12px;
  padding:14px 16px;
  border-radius:var(--radius);
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--text);
  cursor:pointer;
  font-size:15px;
  text-align:left;
  transition:background .15s,border-color .15s;
}

.option-btn:hover{background:var(--surface-hover)}
.option-btn.selected{border-color:var(--primary);background:rgba(99,102,241,.1)}

.option-letter{
  width:28px;height:28px;
  display:flex;align-items:center;justify-content:center;
  border-radius:50%;
  background:var(--border);
  font-size:13px;font-weight:600;
  flex-shrink:0;
}

.option-btn.selected .option-letter{
  background:var(--primary);
  color:#fff;
}

/* Complete screen */
.complete-screen{
  text-align:center;
  padding:40px 0;
}

.complete-screen .icon{
  font-size:48px;
  margin-bottom:16px;
}

.complete-screen .title{
  font-size:20px;
  font-weight:600;
  margin-bottom:8px;
}

.complete-screen .subtitle{
  font-size:14px;
  color:var(--text-muted);
  line-height:1.5;
}

/* Photo upload */
.photo-upload{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:12px;
  padding:24px;
  border:2px dashed var(--border);
  border-radius:var(--radius);
  cursor:pointer;
  transition:border-color .2s;
}

.photo-upload:hover{border-color:var(--primary)}

.photo-upload .preview{
  width:120px;height:120px;
  border-radius:50%;
  object-fit:cover;
}

.photo-upload input[type="file"]{display:none}

/* Footer actions */
.actions{
  padding:16px 0 calc(env(safe-area-inset-bottom,16px) + 16px);
  display:flex;
  gap:8px;
}

.actions .btn{flex:1}

/* QR scanner */
.qr-scanner-wrap{
  position:relative;
  width:100%;
  max-width:300px;
  margin:0 auto;
  border-radius:var(--radius);
  overflow:hidden;
  background:#000;
  aspect-ratio:1;
}

.qr-scanner-wrap video{
  width:100%;
  height:100%;
  object-fit:cover;
}

.qr-overlay{
  position:absolute;
  inset:0;
  border:3px solid var(--primary);
  border-radius:var(--radius);
  pointer-events:none;
  opacity:.6;
}

/* Broadcast push modal */
.broadcast-overlay{
  position:fixed;
  inset:0;
  z-index:200;
  background:rgba(0,0,0,.7);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px;
}

.broadcast-modal{
  background:var(--surface);
  border-radius:var(--radius);
  padding:24px;
  max-width:360px;
  width:100%;
  max-height:90vh;
  overflow-y:auto;
  display:flex;
  flex-direction:column;
  gap:16px;
}

.broadcast-title{
  font-size:18px;
  font-weight:600;
  text-align:center;
}

.broadcast-text{
  font-size:15px;
  line-height:1.5;
  white-space:pre-wrap;
  word-wrap:break-word;
}

.broadcast-ok{
  width:100%;
}

/* Card Preview */
.card-preview-img{
  width:100%;
  text-align:center;
}
.card-preview-img img{
  width:100%;
  max-width:420px;
  height:auto;
  border-radius:var(--radius);
  box-shadow:0 4px 16px rgba(0,0,0,.15);
}
.card-field-list{
  display:flex;
  flex-direction:column;
  gap:4px;
  margin-top:8px;
}
.card-field-item{
  display:flex;
  align-items:center;
  gap:8px;
  padding:10px 12px;
  background:var(--surface);
  border-radius:8px;
  cursor:pointer;
  transition:background .15s;
}
.card-field-item:hover{
  background:var(--surface-hover, rgba(255,255,255,.08));
}
.card-field-item.editing{
  flex-wrap:wrap;
  cursor:default;
}
.card-field-label{
  font-size:12px;
  color:var(--text-muted);
  min-width:80px;
  flex-shrink:0;
}
.card-field-value{
  flex:1;
  font-size:14px;
  color:var(--text);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.card-field-edit-icon{
  font-size:14px;
  color:var(--text-muted);
  opacity:.5;
}
.card-field-input{
  flex:1;
  min-width:0;
  padding:6px 8px;
  border:1px solid var(--primary);
  border-radius:6px;
  background:var(--bg);
  color:var(--text);
  font-size:14px;
  outline:none;
}
.card-field-editor-actions{
  display:flex;
  gap:4px;
  margin-left:auto;
}
.btn-sm{
  min-height:32px;
  padding:4px 12px;
  font-size:14px;
}

/* SMC topic chips — explicit colors for dark/light mode */
.smc-topic-chip{
  padding:8px 16px !important;
  border-radius:20px !important;
  border:2px solid #4A90D9 !important;
  background:transparent !important;
  color:#e4e4e7 !important;
  cursor:pointer;
  font-size:14px !important;
  font-weight:500 !important;
  transition:all .2s;
}
.smc-topic-chip.selected{
  background:#4A90D9 !important;
  color:#fff !important;
}
/* Loading spinner */
.smc-spinner{
  display:inline-block;
  width:32px;
  height:32px;
  border:3px solid rgba(74,144,217,.2);
  border-top-color:#4A90D9;
  border-radius:50%;
  animation:smc-spin .8s linear infinite;
  margin:12px auto;
}
@keyframes smc-spin{to{transform:rotate(360deg)}}
.smc-loading-dots::after{
  content:'';
  animation:smc-dots 1.4s steps(4,end) infinite;
}
@keyframes smc-dots{
  0%{content:''}
  25%{content:'.'}
  50%{content:'..'}
  75%{content:'...'}
  100%{content:''}
}

/* Interest tags */
.smc-interest-tag{
  display:inline-block;
  background:var(--primary);
  color:#fff;
  padding:3px 10px;
  border-radius:12px;
  font-size:12px;
  margin:2px 4px 2px 0;
}

@media(prefers-color-scheme:light){
  .smc-topic-chip{color:#18181b !important}
}

/* SMC — Topic chip container */
.smc-chips{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  justify-content:center;
  margin:16px 0;
}

/* SMC — Custom topic input row */
.smc-custom-topic{
  display:flex;
  gap:8px;
  align-items:center;
  margin:12px 0;
  justify-content:center;
}
.smc-custom-topic .smc-custom-input{
  flex:1;
  max-width:240px;
  padding:10px 14px;
  border-radius:20px;
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--text);
  font-size:14px;
  outline:none;
}
.smc-custom-topic .smc-custom-input:focus{border-color:var(--primary)}
.smc-custom-topic .smc-custom-add{
  padding:10px 16px;
  border-radius:20px;
  font-size:13px;
  min-height:40px;
}

/* SMC — Profile form (left-aligned inside centered parent) */
.smc-profile-form{
  display:flex;
  flex-direction:column;
  gap:12px;
  margin:16px 0;
  width:100%;
  text-align:left;
}
.smc-profile-field{
  display:flex;
  flex-direction:column;
  gap:4px;
}
.smc-profile-field label{
  font-size:13px;
  color:var(--text-muted);
}
.smc-profile-field input{
  padding:12px 14px;
  border-radius:var(--radius);
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--text);
  font-size:15px;
  font-family:inherit;
  outline:none;
  transition:border-color .2s;
}
.smc-profile-field input:focus{border-color:var(--primary)}

/* SMC — Partner/history card (left-aligned) */
.smc-card{
  background:var(--surface);
  color:var(--text);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:16px;
  margin:12px 0;
  text-align:left;
}
.smc-card-avatar-wrap{
  text-align:center;
  margin-bottom:12px;
}
.smc-card-avatar{
  width:80px;height:80px;
  border-radius:50%;
  object-fit:cover;
}
.smc-card-name{
  font-size:18px;
  font-weight:600;
  margin-bottom:8px;
  text-align:center;
}
.smc-card-about{
  color:var(--text-muted);
  margin-bottom:8px;
}
.smc-card-field{
  font-size:13px;
  margin-bottom:4px;
}

/* SMC — History item (compact card with inline avatar) */
.smc-history-item{
  background:var(--surface);
  color:var(--text);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:12px;
  margin:8px 0;
  text-align:left;
}
.smc-history-head{
  display:flex;
  align-items:center;
  gap:12px;
  margin-bottom:6px;
}
.smc-history-avatar{
  width:48px;height:48px;
  border-radius:50%;
  object-fit:cover;
}
.smc-history-name{
  font-size:16px;
  font-weight:600;
}
.smc-history-field{
  font-size:12px;
  margin-bottom:2px;
}

/* SMC — Prominent CTA subtitle for match/completed (override muted .subtitle) */
.smc-cta{
  font-size:16px !important;
  color:var(--text) !important;
  font-weight:500;
}

/* Smaller icons & tighter padding on small screens */
@media(max-width:380px){
  .complete-screen{padding:20px 0}
  .complete-screen .icon{font-size:36px;margin-bottom:12px}
  .smc-card{padding:12px}
  .smc-card-avatar{width:64px;height:64px}
}

/* Reconnecting banner — зелёный, чтобы не пугать пользователя «всё плохо»:
   пересоединение — штатная операция, обычно занимает 1-2с. */
.reconnecting{
  position:fixed;
  top:0;left:0;right:0;
  padding:8px;
  background:rgba(16,185,129,.92);
  color:#fff;
  text-align:center;
  font-size:13px;
  z-index:100;
}
