:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2330;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-dim: #1f6feb;
    --success: #3fb950;
    --danger: #f85149;
    --warning: #d29922;
    --human: #58a6ff;
    --session: #d2a8ff;
    --radius: 6px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    --mono: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    height: 100vh;
}

#app { height: 100%; }

.view[hidden] { display: none !important; }

.view {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Buttons + inputs */
button {
    padding: 0.45rem 0.95rem;
    background: var(--accent-dim);
    color: var(--text);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
}
button:hover { opacity: 0.9; }
button.secondary { background: transparent; border: 1px solid var(--border); }
button.small { padding: 0.25rem 0.7rem; font-size: 0.78rem; }
button.ghost { background: transparent; color: var(--text-muted); }
button.primary { background: var(--accent-dim); }
button.danger { background: var(--danger); }

input[type="text"], input[type="password"], input[type="url"], textarea, select {
    padding: 0.45rem 0.65rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.875rem;
    font-family: var(--font);
    width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; font-family: var(--font); }

/* Login */
.login-card {
    max-width: 360px;
    margin: auto;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.login-card h1 { font-size: 1.5rem; }
.subtitle { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1.5rem; }
form { display: flex; flex-direction: column; gap: 0.75rem; }
.error { color: var(--danger); font-size: 0.8rem; margin-top: 0.5rem; }

/* Header */
header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
header h1, header h2 { font-size: 1.05rem; flex: 1; }
.header-right {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-muted);
    font-size: 0.78rem;
}

/* Workspaces list */
#ws-list {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    flex: 1;
}
.ws-card {
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.ws-card:hover { border-color: var(--accent); }
.ws-card .ws-meta { text-align: right; font-size: 0.75rem; color: var(--text-muted); }
.ws-card h3 { font-size: 0.95rem; }
.ws-card .desc { font-size: 0.8rem; color: var(--text-muted); }
#no-ws { text-align: center; color: var(--text-muted); padding: 3rem; }

/* Workspace body */
#workspace-body {
    flex: 1;
    display: grid;
    grid-template-columns: 220px 1fr;
    overflow: hidden;
}
#workspace-body.with-info {
    grid-template-columns: 220px 1fr 280px;
}
#participants, #info-panel {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 0.75rem 1rem;
    overflow-y: auto;
}
#info-panel {
    border-right: none;
    border-left: 1px solid var(--border);
}
#participants h3, #info-panel h3 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}
#participants .section { margin-bottom: 1rem; }
.section-title {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}
#humans-list, #sessions-list, #members-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
#humans-list li, #sessions-list li, #members-list li {
    font-size: 0.82rem;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    cursor: pointer;
}
#humans-list li:hover, #sessions-list li:hover { background: var(--bg); }
#humans-list li::before { content: '● '; color: var(--human); }
#sessions-list li::before { content: '◆ '; color: var(--session); }
#members-list li::before { content: '• '; color: var(--text-muted); }
.policy-tag {
    display: inline-block;
    font-size: 0.65rem;
    padding: 0.05rem 0.4rem;
    border-radius: 8px;
    margin-left: 0.4rem;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.policy-tag.open { color: var(--success); border-color: var(--success); }
.policy-tag.info-only { color: var(--text-muted); }
.policy-tag.approval { color: var(--warning); border-color: var(--warning); }

#info-panel dl { font-size: 0.82rem; }
#info-panel dt {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-top: 0.6rem;
}
#info-panel dd { word-break: break-all; }
#admin-actions { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* Conversation */
#conversation {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.msg {
    max-width: 75%;
    padding: 0.55rem 0.75rem;
    background: var(--surface);
    border-radius: var(--radius);
    border-left: 3px solid var(--border);
}
.msg.self {
    align-self: flex-end;
    border-left: none;
    border-right: 3px solid var(--accent);
    background: var(--surface-2);
}
.msg.human { border-left-color: var(--human); }
.msg.session { border-left-color: var(--session); }
.msg.system {
    align-self: center;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
}
.msg.rejected {
    border-left-color: var(--danger);
    opacity: 0.6;
}
.msg .meta {
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
    margin-bottom: 0.2rem;
    font-size: 0.72rem;
}
.msg .sender { font-weight: 600; }
.msg.human .sender { color: var(--human); }
.msg.session .sender { color: var(--session); }
.msg .addr {
    color: var(--text-muted);
}
.msg .type-tag {
    font-size: 0.65rem;
    padding: 0.05rem 0.4rem;
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-muted);
}
.msg .body { font-size: 0.9rem; white-space: pre-wrap; word-wrap: break-word; }
.msg .ts { color: var(--text-muted); font-size: 0.7rem; margin-left: auto; }

/* Event (inline tool use) */
.event {
    align-self: center;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-family: var(--mono);
    padding: 0.15rem 0.5rem;
}

/* Compose */
#compose {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 0.55rem 0.9rem 0.75rem;
}
#compose-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}
#compose-to.addr-chip {
    background: var(--accent-dim);
    color: var(--text);
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.72rem;
    font-family: var(--mono);
}
#msg-type {
    width: auto;
    font-size: 0.75rem;
}
#msg-input {
    padding: 0.55rem 0.75rem;
    width: 100%;
}
#mention-popup {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem;
    box-shadow: 0 4px 14px rgba(0,0,0,0.4);
    max-height: 240px;
    overflow-y: auto;
    z-index: 200;
}
#mention-popup .item {
    padding: 0.3rem 0.6rem;
    font-size: 0.82rem;
    cursor: pointer;
    border-radius: 4px;
}
#mention-popup .item:hover, #mention-popup .item.active { background: var(--accent-dim); }
#mention-popup .item .role { color: var(--text-muted); font-size: 0.7rem; margin-left: 0.4rem; }

/* Dialog */
.dialog[hidden] { display: none !important; }
.dialog {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.dialog-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 480px;
    width: 90%;
}
.dialog-content h3 { margin-bottom: 0.75rem; }
.dialog-content label { display: flex; flex-direction: column; font-size: 0.78rem; color: var(--text-muted); gap: 0.2rem; }
.dialog-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.75rem; }

/* Responsive */
@media (max-width: 800px) {
    #workspace-body { grid-template-columns: 1fr; }
    #workspace-body.with-info { grid-template-columns: 1fr; }
    #participants, #info-panel { display: none; }
}
