:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --panel: #ffffff;
  --panel-soft: #eef7f4;
  --ink: #18201d;
  --muted: #66736d;
  --line: #dbe4df;
  --normal: #0f766e;
  --adult: #a61955;
  --danger: #b42318;
  --shadow: 0 18px 44px rgba(20, 31, 27, 0.11);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Malgun Gothic", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #eff8f5, #fff7fa);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--normal);
  color: white;
  font-weight: 800;
}
.brand h1, .section-head h2 { margin: 0; }
.brand h1 { font-size: 22px; }

.nav { display: grid; gap: 8px; }
.nav-button, .ghost, button, .primary, .danger {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 12px;
}
.nav-button { text-align: left; font-weight: 700; }
.nav-button.active, .primary {
  border-color: var(--normal);
  background: var(--normal);
  color: white;
}
body.theme-adult .brand-mark { background: var(--adult); }
body.theme-adult .nav-button.active {
  border-color: var(--adult);
  background: var(--adult);
}
body.theme-both .brand-mark,
body.theme-both .nav-button.active {
  border-color: #5a4762;
  background: linear-gradient(110deg, var(--normal) 0%, #5a4762 50%, var(--adult) 100%);
}
.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: white;
}
.badge {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  margin-left: 6px;
  place-items: center;
  border-radius: 999px;
  background: #e11d48;
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.workspace { min-width: 0; }
.setup-notice {
  padding: 12px 28px;
  border-bottom: 1px solid #f3c17b;
  background: #fff8e8;
  color: #7a4812;
  line-height: 1.5;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
}
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.top-actions select, .filters select, .filters input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 0 10px;
}
.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 24px;
  width: min(380px, calc(100vw - 32px));
  max-height: 420px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}

.view { display: none; padding: 24px 28px 36px; }
.view.active { display: block; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.auth-panel {
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.form-grid, .settings-form, .post-form, .meeting-form {
  display: grid;
  gap: 12px;
}
.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: 820px;
}
.form-grid h2, .wide, .actions { grid-column: 1 / -1; }
.auth-status {
  padding: 11px 13px;
  border: 1px solid #9dd8ce;
  border-radius: 8px;
  background: #f2fbf8;
  color: #0b625b;
  font-weight: 700;
}
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, select, textarea {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 10px;
}
textarea { min-height: 96px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 16px; height: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.auth-actions button { flex: 0 1 auto; white-space: nowrap; }
.recovery-form { display: grid; gap: 14px; min-width: 0; }
.recovery-form h2, .recovery-form p { margin: 0; }
.recovery-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.recovery-option {
  display: flex;
  align-items: center;
  min-height: 44px;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
}
.recovery-option:has(input:checked) { border-color: var(--normal); background: var(--panel-soft); }
.recovery-option input { width: 16px; height: 16px; }
.form-help { color: var(--muted); font-size: 13px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  grid-auto-rows: 1fr;
  align-items: stretch;
  gap: 12px;
}
.card, .post, .meeting, .conversation-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
}
.post-button {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}
.post-detail { display: grid; gap: 12px; }
.post-detail p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.post-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.post-title-text { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; min-width: 0; }
.post-title-text strong { overflow-wrap: anywhere; }
.post-title-text small { color: var(--muted); white-space: nowrap; }
.post-title-row .pill { flex: 0 0 auto; }
.card { display: grid; gap: 10px; }
.card.profile-card {
  grid-template-rows: 32px 174px 44px 40px;
  align-content: start;
}
.card.own-profile { border-width: 2px; border-color: var(--normal); }
.card.profile-normal { border-top: 3px solid var(--normal); }
.card.profile-adult { border-top: 3px solid var(--adult); }
.card.own-profile.profile-adult { border-color: var(--adult); }
.card.admin-profile { box-shadow: inset 0 -3px 0 #505a55; }
.card-head, .row-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.profile-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
}
.profile-heading > strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-heading .profile-markers { flex: 0 0 auto; margin-left: 0; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  background: var(--panel-soft);
  color: var(--normal);
  font-size: 12px;
  font-weight: 800;
}
.pill.adult { background: #fde8f1; color: var(--adult); }
.profile-markers { display: inline-flex; gap: 5px; margin-left: 7px; vertical-align: middle; }
.profile-marker {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--normal);
  font-size: 11px;
  font-weight: 800;
}
.profile-marker.admin { background: #ecefed; color: #39423e; }
.traits { display: flex; flex-wrap: wrap; gap: 6px; }
.trait {
  padding: 6px 8px;
  border-radius: 8px;
  background: #f4f4f3;
  font-size: 12px;
  color: #4b5563;
}
.profile-card .traits {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 30px;
  align-content: start;
}
.profile-card .trait {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-bio {
  height: 44px;
  margin: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.4;
}
.profile-bio-full {
  display: block;
  height: auto;
  overflow: visible;
}
.profile-card > .actions {
  min-width: 0;
  min-height: 40px;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 4px;
}
.profile-card > .actions button {
  flex: 1 1 0;
  min-width: 0;
  padding-inline: 3px;
  font-size: 13px;
}
.profile-card.own-profile > .actions button { flex: 0 0 calc((100% - 12px) / 4); }
.profile-card.own-profile.own-admin-actions > .actions button { flex-basis: calc((100% - 16px) / 5); }
.trait button { min-height: 24px; margin-left: 4px; padding: 0 6px; font-size: 11px; }

.messenger {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  height: min(680px, calc(100vh - 160px));
  min-height: 480px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}
.chat-type-tabs { display: flex; gap: 8px; margin: 0 0 10px; }
.chat-type-tab { flex: 0 0 clamp(88px, 16vw, 230px); min-width: 0; min-height: 40px; padding-inline: 6px; border: 1px solid var(--line); background: #fff; color: var(--muted); font-weight: 700; white-space: nowrap; }
.chat-type-tab.active { border-color: var(--normal); background: #e4f5f1; color: var(--normal); }
body.theme-adult .chat-type-tab.active { border-color: var(--adult); background: #ffe7ed; color: var(--adult); }
.conversation-list {
  display: grid;
  align-content: start;
  gap: 0;
  min-height: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
}
.conversation-row {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
}
.conversation-row.active { background: #f0faf7; }
.conversation-section-label { padding: 9px 14px; background: #f6f8f7; color: var(--muted); font-size: 12px; font-weight: 700; }
.group-chat-row { border-left: 3px solid var(--normal); }
.group-chat-row.adult { border-left-color: var(--adult); }
.group-chat-row.adult.active { background: #fff2f7; }
.conversation-row p { margin-bottom: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}
.thread-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.thread-header > strong { min-width: 0; overflow-wrap: anywhere; }
.thread-header .actions { flex: none; }
.message-thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding: 14px;
}
.bubble {
  max-width: min(72%, 640px);
  padding: 10px 12px;
  border-radius: 8px;
  background: #f2f4f3;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.bubble.me {
  align-self: flex-end;
  background: #e4f5f1;
}
.bubble.adult { background: #fff3f5; }
.bubble.me.adult { background: #ffe7ed; }
.bubble-sender { display: block; margin-bottom: 4px; font-size: 12px; }
.thread-member-count { color: var(--muted); font-size: 12px; white-space: nowrap; }
.meta { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.unread-count { color: var(--normal); font-weight: 800; }
.unread-count.adult { color: var(--adult); }
.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.meeting-form {
  grid-template-columns: 112px minmax(150px, .6fr) minmax(260px, 320px) 96px;
  margin-bottom: 14px;
}
.participant-count-input { display: flex; align-items: center; gap: 6px; color: var(--ink); }
.participant-count-input input { width: 100%; }
.participant-count-input span { flex: none; }
.meeting-form textarea, .meeting-form .check { grid-column: 1 / -1; }
.meeting-form-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; }
.meeting-form-actions button { min-width: 180px; }
.meeting {
  display: grid;
  gap: 12px;
}
.meeting p { margin: 0; }
.meeting-participants { min-height: 28px; }
.meeting > .actions { margin-top: 2px; }
.stack { display: grid; gap: 10px; }
.post-form { margin-bottom: 14px; }
.post-options { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.settings-form fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
}
.settings-form legend { font-weight: 800; }
.settings-form .profile-settings {
  border-width: 2px;
  box-shadow: inset 4px 0 0 var(--profile-accent);
}
.settings-form .normal-profile {
  --profile-accent: var(--normal);
  border-color: #9dd8ce;
  background: #f2fbf8;
}
.settings-form .adult-profile {
  --profile-accent: var(--adult);
  border-color: #efb0c9;
  background: #fff5f8;
}
.settings-form .normal-profile legend { color: var(--normal); }
.settings-form .adult-profile legend { color: var(--adult); }
.account-settings { display: grid; gap: 12px; max-width: 820px; margin-top: 18px; }
.account-form fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
}
.account-form legend { font-weight: 800; }
.account-form p, .account-form .auth-status { grid-column: 1 / -1; margin: 0; }
.account-form button { justify-self: start; align-self: end; height: 40px; }
.preference-card { display: grid; gap: 10px; max-width: 820px; margin-top: 18px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.preference-card h3, .preference-card p { margin: 0; }
.preference-card > button { justify-self: start; }
.blocked-user-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.blocked-user-row button { flex: 0 0 auto; }
.admin-sanction-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.admin-report-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.admin-report-row .actions { grid-column: auto; display: flex; flex-wrap: nowrap; align-items: center; justify-content: flex-end; gap: 6px; min-width: max-content; }
.admin-report-row .actions button { min-height: 34px; padding: 0 10px; white-space: nowrap; }
.admin-sanction-info { display: grid; gap: 3px; min-width: 0; }
.admin-sanction-info small { color: var(--muted); }
.admin-sanction-row .actions { flex: 0 0 auto; gap: 6px; }
.admin-sanction-form { display: grid; gap: 14px; }
.admin-sanction-form h2, .admin-sanction-form p { margin: 0; }
.admin-sanction-form > label { display: grid; gap: 6px; }
.admin-sanction-form input[type="number"], .admin-sanction-form input[type="text"] { width: 100%; min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; }
.admin-sanction-form fieldset { display: grid; gap: 8px; margin: 0; border: 1px solid var(--line); border-radius: 8px; }
.notification-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.notification-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 4px 8px; border-bottom: 1px solid var(--line); }
.notification-panel-head button { min-height: 32px; }
.notification-item:last-child { border-bottom: 0; }
.notification-content { min-width: 0; overflow-wrap: anywhere; }
.notification-content p { margin: 6px 0 0; font-size: 13px; }
.notification-delete { flex: 0 0 32px; width: 32px; min-height: 32px; padding: 0; color: var(--muted); font-size: 21px; line-height: 1; }
.notification-delete:hover { border-color: var(--danger); color: var(--danger); }

dialog {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(17, 24, 39, .45); }
.comment-form {
  display: grid;
  gap: 10px;
  margin: 16px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}
.comment-list { display: grid; gap: 8px; margin-bottom: 14px; }
.comment {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
.comment.reply { margin-left: 28px; border-left: 3px solid var(--normal); }
.comment p { margin: 6px 0; white-space: pre-wrap; }
.comment small { color: var(--muted); }
.comment-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.comment-votes { display: flex; gap: 6px; }
.vote-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 9px;
  color: var(--muted);
}
.vote-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.vote-button.up.active {
  border-color: var(--normal);
  background: var(--panel-soft);
  color: var(--normal);
}
.vote-button.down.active {
  border-color: var(--danger);
  background: #fff1f0;
  color: var(--danger);
}
.reply-notice { color: var(--normal); font-size: 13px; font-weight: 700; }
.legal-links { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; font-size: 13px; }
.legal-links a, .auth-panel a { color: var(--normal); }
.legal-page { max-width: 860px; margin: 0 auto; line-height: 1.65; }
.legal-page a { color: var(--normal); }
.legal-page h2 { margin-top: 28px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 24px));
  padding: 10px 14px;
  border-radius: 8px;
  background: #111827;
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
.toast.show { opacity: 1; }
.empty { padding: 18px; color: var(--muted); text-align: center; }

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    align-content: start;
  }
  .rail {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr;
    align-content: start;
    gap: 12px;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav {
    display: flex;
    align-content: start;
    overflow-x: auto;
  }
  .nav-button {
    flex: 1 0 64px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    padding: 0 4px;
    text-align: center;
    font-size: 12px;
    line-height: 1.2;
    white-space: nowrap;
  }
  .topbar { position: static; padding: 12px; align-items: stretch; flex-direction: column; }
  .top-actions { justify-content: flex-start; }
  .auth-panel { padding: 20px 12px; }
  .view { padding: 16px 12px 28px; }
  .setup-notice { padding: 10px 12px; }
  .section-head { align-items: stretch; flex-direction: column; }
  .messenger { grid-template-columns: 1fr; grid-template-rows: minmax(0, 180px) minmax(0, 1fr); height: 72vh; }
  .conversation-list { max-height: 180px; border-right: 0; border-bottom: 1px solid var(--line); }
  .meeting-form, .form-grid, .settings-form fieldset, .account-form fieldset { grid-template-columns: 1fr; }
  .composer { grid-template-columns: 1fr auto; }
  .bubble { max-width: 88%; }
  .comment.reply { margin-left: 14px; }
}

@media (max-width: 320px) {
  .card-grid { grid-template-columns: 1fr; }
}
