.app { display: flex; height: 100vh; }

.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px;
}
.brand {
  font-weight: 600; font-size: 15px;
  padding: 8px 10px 16px; letter-spacing: .3px;
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-dim);
  text-decoration: none; font-size: 13px;
}
.nav-item:hover { background: var(--bg-elev); color: var(--text); }
.nav-item.active { background: var(--bg-elev); color: var(--text); }
.nav-item .ic { font-size: 14px; width: 18px; text-align: center; }
.nav-item.locked { opacity: .45; cursor: not-allowed; }
.admin-only, .platinum-only { display: none; }
.admin-only.show, .platinum-only.show { display: flex; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 12px; margin-top: 8px;
  display: flex; flex-direction: column; gap: 8px;
}
.user-card { padding: 0 4px; }
.user-name { font-size: 13px; font-weight: 500; }
.user-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.tier-pill {
  display: inline-block; padding: 1px 6px; border-radius: 999px;
  font-size: 10px; margin-right: 4px;
}
.tier-pill.silver { background: rgba(148,163,184,.2); color: #cbd5e1; }
.tier-pill.gold { background: rgba(234,179,8,.2); color: #facc15; }
.tier-pill.platinum { background: rgba(167,139,250,.2); color: #c4b5fd; }
.tier-pill.admin { background: rgba(239,68,68,.2); color: #fca5a5; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.view { flex: 1; display: none; flex-direction: column; min-height: 0; }
.view.active { display: flex; }

.topbar {
  height: 48px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
}
.topbar-title { font-weight: 500; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.quota-text { font-size: 12px; color: var(--text-dim); margin-right: 8px; }
.quota-text.danger { color: var(--danger); }

.empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 40px;
}

.chat-layout { flex: 1; display: flex; min-height: 0; }
.chat-history-panel {
  width: 220px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 12px;
}
.ch-title { font-size: 12px; color: var(--text-dim); padding: 4px 8px 10px; }
.ch-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.ch-item {
  padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-dim);
}
.ch-item:hover { background: var(--bg-elev); color: var(--text); }
.ch-item.active { background: var(--bg-elev); color: var(--text); }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.messages {
  flex: 1; overflow-y: auto;
  padding: 24px 24px 8px;
  display: flex; flex-direction: column; gap: 16px;
}
.msg { display: flex; gap: 12px; max-width: 880px; width: 100%; margin: 0 auto; }
.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg-elev); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.msg.user .msg-avatar { background: var(--accent); border-color: var(--accent); }
.msg-bubble {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  max-width: calc(100% - 50px);
  word-wrap: break-word; white-space: pre-wrap;
}
.msg.user .msg-bubble { background: rgba(107,138,253,.12); border-color: rgba(107,138,253,.4); }
.msg-bubble img {
  max-width: 100%; max-height: 360px;
  border-radius: var(--radius-sm); margin-top: 8px; display: block;
  cursor: pointer;
}
.msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.msg-images img { max-height: 200px; }
.msg-meta { font-size: 11px; color: var(--text-dim); margin-top: 6px; }
.msg .typing { display: inline-block; }
.msg .typing::after {
  content: '▋'; animation: blink 1s steps(2) infinite;
  margin-left: 2px; color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }

.composer {
  border-top: 1px solid var(--border);
  padding: 12px 24px 16px;
  background: var(--bg);
}
.attachments {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px;
}
.attachments:empty { display: none; }
.attachment {
  position: relative; width: 64px; height: 64px;
  border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--border);
}
.attachment img { width: 100%; height: 100%; object-fit: cover; }
.attachment .x {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.7); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 14px; line-height: 1;
}
.composer-row {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px;
  max-width: 880px; margin: 0 auto;
}
.composer-row textarea {
  flex: 1; border: none; background: transparent;
  resize: none; max-height: 200px; padding: 6px 4px;
  outline: none;
}
.icon-btn { padding: 6px 10px; }
.icon-btn.active {
  background: rgba(107,138,253,.18);
  border-color: var(--accent); color: var(--accent);
}
.composer-tools {
  display: flex; gap: 6px; align-items: center;
}
.composer-hint {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 6px; max-width: 880px; margin-left: auto; margin-right: auto;
  font-size: 12px;
}

.config-panel {
  width: 300px; flex-shrink: 0;
  border-left: 1px solid var(--border);
  padding: 16px; overflow-y: auto;
  display: flex; flex-direction: column;
}
.cp-title {
  font-size: 12px; color: var(--text-dim);
  padding-bottom: 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.cp-pane { display: none; flex-direction: column; gap: 0; }
.cp-pane.active { display: flex; }

.agent-list { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.agent-item {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
  cursor: pointer; transition: border-color .15s;
}
.agent-item:hover { border-color: #2f3547; }
.agent-item.active { border-color: var(--accent); background: rgba(107,138,253,.08); }
.agent-item-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.agent-name { font-weight: 500; font-size: 13px; }
.agent-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.agent-item:hover .agent-actions { opacity: 1; }
.agent-actions button { padding: 2px 6px; font-size: 11px; }
.agent-desc { font-size: 11px; color: var(--text-dim); line-height: 1.4; }

.agent-editor {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.agent-editor-card {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  width: 480px; max-width: 90vw;
  box-shadow: var(--shadow);
}
.agent-editor-card h3 { margin: 0 0 16px; font-size: 16px; }

@media (max-width: 1100px) {
  .config-panel { display: none; }
  .chat-history-panel { width: 180px; }
}
@media (max-width: 800px) {
  .sidebar { width: 64px; }
  .sidebar .brand, .nav-item span:not(.ic), .user-card, .sidebar-foot button { display: none; }
  .chat-history-panel { display: none; }
}
