:root {
    color-scheme: light dark;
    --bg: #0f1419;
    --surface: #1a2332;
    --border: #2d3a4d;
    --text: #e7ecf3;
    --muted: #8b9cb3;
    --accent: #3d8bfd;
    --danger: #f87171;
    --success: #4ade80;
}

* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
}

.page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.card {
    width: 100%;
    max-width: 28rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
}

.card.wide {
    max-width: 42rem;
}

.dashboard-card {
    max-width: 48rem;
}

.card-header h1 {
    margin: 0;
    font-size: 1.25rem;
}

.card-header p {
    margin: 0.35rem 0 0;
    color: var(--muted);
}

.card-header.row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

label {
    font-size: 0.9rem;
    color: var(--muted);
}

input {
    width: 100%;
    padding: 0.75rem 0.9rem;
    border-radius: 0.65rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

button {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 0.65rem;
    background: var(--accent);
    color: white;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

button.secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

button.danger {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
}

.message {
    margin: 1rem 0 0;
    padding: 0.75rem 0.9rem;
    border-radius: 0.65rem;
    background: rgba(61, 139, 253, 0.12);
    border: 1px solid rgba(61, 139, 253, 0.35);
}

.message.error {
    background: rgba(248, 113, 113, 0.12);
    border-color: rgba(248, 113, 113, 0.35);
}

.message.success {
    background: rgba(74, 222, 128, 0.12);
    border-color: rgba(74, 222, 128, 0.35);
}

.muted {
    color: var(--muted);
    font-size: 0.9rem;
}

.divider {
    margin: 1.25rem 0;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

.qr-box {
    display: flex;
    justify-content: center;
    padding: 1rem;
    background: white;
    border-radius: 0.75rem;
}

.token-list {
    margin-top: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.token-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--bg);
}

.token-item.revoked {
    opacity: 0.55;
}

.token-meta strong {
    display: block;
}

.token-meta span {
    color: var(--muted);
    font-size: 0.85rem;
}

.token-reveal {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--success);
    background: rgba(74, 222, 128, 0.08);
}

.token-reveal code {
    display: block;
    margin-top: 0.5rem;
    word-break: break-all;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.9rem;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.75rem;
}

.tab {
    padding: 0.5rem 0.85rem;
    border-radius: 0.65rem;
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    font-weight: 600;
}

.tab.active {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text);
}

a.tab-link {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

a.tab-link:hover {
    color: var(--text);
}

.tab-panel[hidden] {
    display: none !important;
}

.section-title {
    margin: 0 0 1rem;
    font-size: 1.05rem;
}

textarea,
select {
    width: 100%;
    padding: 0.75rem 0.9rem;
    border-radius: 0.65rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

textarea {
    resize: vertical;
    min-height: 6rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text);
}

.checkbox-row input {
    width: auto;
}

.memories-section {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.memories-section h3 {
    margin: 0 0 0.35rem;
    font-size: 1rem;
}

.memory-form {
    margin: 1rem 0 1.25rem;
}

.memory-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.memory-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.9rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--bg);
}

.memory-meta {
    flex: 1;
    min-width: 0;
}

.memory-content {
    margin: 0.35rem 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.memory-category {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: rgba(61, 139, 253, 0.15);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 600;
}

.memory-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

.activity-header {
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.activity-header .section-title {
    margin-bottom: 0.35rem;
}

.activity-controls {
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.activity-status {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
}

.activity-status.activity-status-error {
    color: #e05252;
}

.activity-log {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 28rem;
    overflow-y: auto;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--bg);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.82rem;
}

.activity-entry {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 0.5rem 0.65rem;
    align-items: baseline;
    padding: 0.45rem 0.5rem;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.02);
}

.activity-detail {
    grid-column: 2 / -1;
    font-size: 0.78rem;
    word-break: break-word;
}

.activity-time {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.activity-badge {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.activity-connect .activity-badge {
    background: rgba(61, 139, 253, 0.18);
    color: var(--accent);
}

.activity-request .activity-badge {
    background: rgba(148, 163, 184, 0.18);
    color: var(--muted);
}

.activity-chat .activity-badge {
    background: rgba(52, 211, 153, 0.18);
    color: #34d399;
}

.activity-thinking .activity-badge {
    background: rgba(167, 139, 250, 0.18);
    color: #a78bfa;
}

.activity-tool .activity-badge {
    background: rgba(251, 191, 36, 0.18);
    color: #fbbf24;
}

.activity-error .activity-badge {
    background: rgba(239, 68, 68, 0.18);
    color: #ef4444;
}

.activity-agent .activity-badge {
    background: rgba(244, 114, 182, 0.18);
    color: #f472b6;
}

.activity-message {
    word-break: break-word;
}
