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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; color: #1a1a2e;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
  background: var(--bg-color, #F8F7F4);
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, textarea, select { font: inherit; border: 1px solid #d1d5db; border-radius: 6px; padding: 6px 10px; background: #fff; color: inherit; }
input:focus, textarea:focus, select:focus { outline: 2px solid #5B50C4; outline-offset: 0; }
fieldset { border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px 16px; }
legend { font-weight: 600; padding: 0 6px; font-size: 12px; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; }

.btn { display: inline-flex; align-items: center; gap: 4px; padding: 7px 16px; border-radius: 7px; font-weight: 500; font-size: 13px; transition: opacity .15s, background .15s; }
.btn--primary { background: #5B50C4; color: #fff; }
.btn--primary:hover { background: #4840a8; }
.btn--danger  { background: #dc2626; color: #fff; }
.btn--danger:hover  { background: #b91c1c; }
.btn--ghost   { background: transparent; border: 1px solid #d1d5db; color: #374151; }
.btn--ghost:hover   { background: #f3f4f6; }
.btn--full    { width: 100%; justify-content: center; }
.btn--sm      { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost    { background: none; border: none; color: #6b7280; font-size: 13px; padding: 6px 10px; border-radius: 6px; }
.btn-ghost:hover { background: #f3f4f6; color: #374151; }
.btn-icon     { background: none; border: none; padding: 2px 4px; opacity: 0; font-size: 14px; border-radius: 4px; transition: opacity .15s, background .15s; }
.btn-icon:hover { background: rgba(0,0,0,.08); opacity: 1 !important; }

.top-nav { height: 52px; background: #fff; border-bottom: 1px solid #e5e7eb; display: flex; align-items: center; padding: 0 20px; gap: 16px; flex-shrink: 0; z-index: 10; }
.nav-brand   { font-weight: 700; font-size: 16px; color: #5B50C4; letter-spacing: -.02em; }
.nav-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.nav-link    { font-size: 13px; color: #374151; padding: 5px 10px; border-radius: 6px; }
.nav-link:hover { background: #f3f4f6; }
.nav-link--admin { color: #7c3aed; font-weight: 500; }

.app-layout  { display: flex; flex: 1; overflow: hidden; }

.sidebar { width: 256px; flex-shrink: 0; background: #2D2B4E; display: flex; flex-direction: column; border-right: 1px solid rgba(255,255,255,.08); }
.sidebar-header { padding: 14px 16px 10px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-space-name { color: #c4b5fd; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.sidebar-actions { padding: 10px 12px; }
.new-thread-form { display: flex; gap: 6px; }
.new-thread-form .input-sm { flex: 1; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15); color: #e5e7eb; border-radius: 6px; padding: 5px 8px; font-size: 13px; }
.new-thread-form .input-sm::placeholder { color: rgba(255,255,255,.4); }
.new-thread-form .input-sm:focus { outline: 2px solid #818cf8; background: rgba(255,255,255,.15); }
.new-thread-form .btn-icon { opacity: 1; color: #a5b4fc; font-size: 18px; padding: 2px 6px; }
.new-thread-form .btn-icon:hover { background: rgba(255,255,255,.1); }
.thread-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.thread-item { display: flex; align-items: center; justify-content: space-between; padding: 9px 10px; border-radius: 7px; margin-bottom: 2px; color: #c4b5fd; transition: background .12s; }
.thread-item:hover { background: rgba(255,255,255,.08); }
.thread-item--active { background: rgba(255,255,255,.15) !important; color: #fff; }
.thread-item__title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.thread-item__meta  { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.thread-item__count { font-size: 11px; color: rgba(255,255,255,.4); }
.unread-dot { color: #a78bfa; font-size: 10px; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.sidebar-empty { color: rgba(255,255,255,.3); font-size: 12px; padding: 12px 10px; }
.sidebar-footer { padding: 10px 14px; border-top: 1px solid rgba(255,255,255,.1); display: flex; gap: 8px; }
.member-dot { width: 28px; height: 28px; border-radius: 50%; background: #5B50C4; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }

.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.thread-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: #9ca3af; font-size: 14px; }

.thread-content { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.thread-header { padding: 12px 20px; background: #fff; border-bottom: 1px solid #e5e7eb; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0; }
.thread-header__title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.thread-header__meta  { font-size: 12px; color: #9ca3af; }
.thread-header .btn-icon { opacity: .6; }
.thread-header .btn-icon:hover { opacity: 1; }
.rename-form { display: flex; align-items: center; gap: 8px; padding: 6px 20px; background: #f9fafb; border-bottom: 1px solid #e5e7eb; flex-shrink: 0; }
.input-inline { flex: 1; }

.message-list { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; }
.empty-state  { color: #9ca3af; text-align: center; margin-top: 32px; }

.message { display: flex; align-items: flex-end; gap: 8px; max-width: 72%; }
.message--own   { align-self: flex-end; flex-direction: row-reverse; }
.message--other { align-self: flex-start; }
.message__bubble { position: relative; padding: 8px 12px 6px; border-radius: 14px; word-break: break-word; line-height: 1.45; }
.message--own   .message__bubble { border-bottom-right-radius: 4px; }
.message--other .message__bubble { border-bottom-left-radius: 4px; }
.message__bubble--editing { background: #f3f4f6 !important; }
.message__author { font-size: 11px; font-weight: 600; color: #374151; margin-bottom: 2px; }
.message--own .message__author { text-align: right; }
.message__content { white-space: pre-wrap; font-size: 14px; }
.message__meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 10px; color: rgba(0,0,0,.45); }
.message--own .message__meta { justify-content: flex-end; }
.message__edited { font-style: italic; }
.message__actions { position: absolute; top: 4px; right: 4px; display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.message__bubble:hover .message__actions { opacity: 1; }
.read-indicator { font-size: 11px; }

.reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; min-height: 4px; position: relative; }
.reaction-btn { background: rgba(0,0,0,.06); border: 1px solid rgba(0,0,0,.1); border-radius: 10px; padding: 2px 7px; font-size: 14px; transition: background .12s; }
.reaction-btn:hover { background: rgba(0,0,0,.12); }
.reaction-btn--mine { background: rgba(91,80,196,.15); border-color: rgba(91,80,196,.3); }
.emoji-picker-wrapper { position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 100; }
.message--own .emoji-picker-wrapper { left: auto; right: 0; }

.message-form-area { flex-shrink: 0; padding: 12px 20px; background: #fff; border-top: 1px solid #e5e7eb; }
.message-form { display: flex; gap: 10px; align-items: flex-end; }
.message-input { flex: 1; resize: none; border-radius: 10px; padding: 8px 12px; font-size: 14px; line-height: 1.4; max-height: 120px; }
.edit-textarea { width: 100%; resize: vertical; border-radius: 8px; padding: 8px; font-size: 14px; }
.edit-actions  { display: flex; gap: 8px; margin-top: 8px; }

.vote-banner { text-align: center; }
.vote-banner__prompt p { margin-bottom: 10px; font-size: 13px; color: #374151; }
.vote-banner__actions  { display: flex; gap: 10px; justify-content: center; }
.vote-banner__waiting, .vote-banner__success, .vote-banner__closed { padding: 10px 16px; border-radius: 8px; font-size: 13px; }
.vote-banner__waiting { background: #fef3c7; color: #92400e; }
.vote-banner__success { background: #d1fae5; color: #065f46; }
.vote-banner__closed  { background: #f3f4f6; color: #6b7280; }

.auth-page    { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card    { background: #fff; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.1); padding: 36px 40px; width: 100%; max-width: 380px; }
.auth-title   { font-size: 24px; font-weight: 700; color: #5B50C4; margin-bottom: 4px; text-align: center; }
.auth-subtitle { font-size: 13px; color: #6b7280; text-align: center; margin-bottom: 20px; }
.auth-form    { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.auth-form label { font-size: 13px; font-weight: 500; color: #374151; }
.auth-form input { padding: 9px 12px; }

.page-content { padding: 24px; overflow-y: auto; flex: 1; }
.card   { background: #fff; border-radius: 10px; border: 1px solid #e5e7eb; padding: 20px 24px; margin-bottom: 20px; }
.card h2 { font-size: 16px; font-weight: 700; margin-bottom: 16px; color: #111827; }
.card h3 { font-size: 14px; font-weight: 600; margin: 16px 0 10px; color: #374151; }
.form-section { display: flex; flex-direction: column; gap: 10px; }
.form-section label { font-size: 13px; font-weight: 500; color: #374151; }
.form-inline  { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field-hint   { font-size: 12px; color: #9ca3af; }

.admin-grid  { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 20px; }
.stats-row   { display: flex; gap: 24px; }
.stat        { display: flex; flex-direction: column; align-items: center; }
.stat__value { font-size: 28px; font-weight: 700; color: #5B50C4; }
.stat__label { font-size: 12px; color: #9ca3af; margin-top: 2px; }
.data-table  { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.data-table th { text-align: left; padding: 6px 8px; border-bottom: 2px solid #e5e7eb; font-weight: 600; color: #6b7280; font-size: 11px; text-transform: uppercase; }
.data-table td { padding: 8px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.data-table--logs .log-date    { white-space: nowrap; color: #6b7280; font-size: 12px; }
.data-table--logs .log-event   { font-family: monospace; font-size: 12px; background: #f3f4f6; padding: 2px 6px; border-radius: 4px; }
.data-table--logs .log-event--login   { background: #dbeafe; }
.data-table--logs .log-event--message { background: #dcfce7; }
.data-table--logs .log-event--thread  { background: #fef9c3; }
.data-table--logs .log-event--vote    { background: #ede9fe; }
.data-table--logs .log-details { font-size: 12px; color: #6b7280; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.alert { padding: 10px 14px; border-radius: 7px; margin-bottom: 16px; font-size: 13px; }
.alert--error   { background: #fee2e2; color: #991b1b; }
.alert--success { background: #d1fae5; color: #065f46; }
.alert--info    { background: #dbeafe; color: #1e40af; }
.badge          { display: inline-flex; align-items: center; justify-content: center; background: #e5e7eb; color: #374151; border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 600; }
.badge--closed  { background: #fef3c7; color: #92400e; font-size: 10px; }
