/* ─── Tokens ─── */
:root {
    /* Tells the rendering engine to draw native UI (form controls, the
     * option-list popup that opens from <select>, scrollbars, etc.) in
     * dark mode. Without this, WebKitGTK falls back to the system theme
     * and pops a white menu over our dark UI. */
    color-scheme: dark;
    /* warm-dark palette — "Her" temperature */
    --bg:            #0E0B12;
    --bg-deep:       #09070C;
    --surface-1:     #16131C;
    --surface-2:     #1E1A26;
    --surface-3:     #272230;
    --surface-4:     #322C3D;
    --border:        rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.10);
    --border-bright: rgba(255, 255, 255, 0.14);
    --text:          #F4EFE9;
    --text-2:        #A8A2B0;
    --text-3:        #6E6878;
    --text-inverse:  #0E0B12;

    /* brand — single deep coral, vertical lift, no rainbow */
    --brand-grad:    linear-gradient(180deg, #C25868 0%, #A24556 100%);
    --brand-grad-soft: linear-gradient(180deg, rgba(194,88,104,0.14) 0%, rgba(162,69,86,0.14) 100%);
    --brand-solid:   #B95163;
    --brand-warm:    #C25868;
    --brand-amber:   #D78471;
    --brand-glow:    rgba(185, 81, 99, 0.14);
    --brand-glow-strong: rgba(185, 81, 99, 0.28);

    /* semantic */
    --success:       #7BC97A;
    --success-soft:  rgba(123, 201, 122, 0.16);
    --warning:       #E0AF68;
    --warning-soft:  rgba(224, 175, 104, 0.16);
    --danger:        #E5484D;
    --danger-soft:   rgba(229, 72, 77, 0.16);
    --info:          #7AA2F7;
    --info-soft:     rgba(122, 162, 247, 0.16);

    /* radii */
    --r-xs:   6px;
    --r-sm:   8px;
    --r-md:  10px;
    --r-lg:  14px;
    --r-xl:  18px;
    --r-pill: 999px;

    /* motion */
    --ease:      cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in:   cubic-bezier(0.4, 0, 1, 1);
    --dur-fast:  120ms;
    --dur:       180ms;
    --dur-slow:  280ms;

    /* shadows — single layer, low spread */
    --shadow-card:   0 1px 2px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--border);
    --shadow-raised: 0 8px 24px -8px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border);
    --shadow-modal:  0 24px 60px -10px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--border-strong);
    --shadow-glow:   0 0 24px var(--brand-glow);
    --ring-focus:    0 0 0 3px var(--brand-glow);

    /* type */
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: "SF Mono", "JetBrains Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;

    /* layout */
    --sidebar-w: 240px;
    --header-h:  52px;
    --content-max: 760px;
}

/* ─── Reset & base ─── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    display: flex;
    flex-direction: column;
}

/* ─── Custom titlebar (macOS-style) ─── */
:root {
    --titlebar-h: 30px;
}

#titlebar {
    height: var(--titlebar-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    z-index: 100;
}

.titlebar-traffic {
    display: flex;
    gap: 8px;
    align-items: center;
    padding-right: 14px;
    -webkit-app-region: no-drag;
}

.traffic-btn {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    border: 0.5px solid rgba(0, 0, 0, 0.25);
    transition: filter var(--dur-fast) var(--ease);
    flex-shrink: 0;
}

.traffic-btn svg { width: 8px; height: 8px; opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
.traffic-btn:hover svg { opacity: 1; }

.traffic-close { background: #FF5F57; color: #4D0000; }
.traffic-min   { background: #FEBC2E; color: #5A3E00; }
.traffic-max   { background: #28C840; color: #003D0E; }

.traffic-btn:hover { filter: brightness(1.05); }
.traffic-btn:active { filter: brightness(0.92); }

body.window-blurred .traffic-btn {
    background: #4A4754;
    border-color: rgba(0, 0, 0, 0.2);
}

.titlebar-title {
    flex: 1;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    letter-spacing: -0.005em;
    pointer-events: none;
}

/* Reserve symmetric space on the right so the title sits visually centered. */
.titlebar-spacer {
    width: 76px;
    flex-shrink: 0;
}

/* ─── Update banner ─── */
.update-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-1);
    flex-shrink: 0;
}

.update-banner[hidden] { display: none; }

.update-banner-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.update-banner-btn {
    background: var(--brand-grad);
    color: #fff;
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: var(--shadow-card);
}

.update-banner-btn:hover { filter: brightness(1.05); }
.update-banner-btn:disabled { opacity: 0.6; cursor: progress; }

.update-banner-dismiss {
    color: var(--text-2);
    font-size: 18px;
    line-height: 1;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.update-banner-dismiss:hover { background: var(--hover); color: var(--text-1); }

button {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    line-height: inherit;
}

input, textarea, select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

a {
    color: var(--brand-solid);
    text-decoration: none;
    transition: color var(--dur) var(--ease);
}
a:hover { color: var(--brand-warm); }

.hidden { display: none !important; }

/* ─── Scrollbars ─── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--r-pill);
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.14);
    background-clip: padding-box;
    border: 2px solid transparent;
}

/* ─── Layout shell ─── */
#app-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    width: 100vw;
    background: var(--bg);
    position: relative;
}

#app {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg);
    position: relative;
}

/* ─── Header ─── */
header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.logo {
    width: 28px;
    height: 28px;
    display: block;
    object-fit: contain;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-drag: none;
    filter: drop-shadow(0 0 6px var(--brand-glow));
}

.header-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    min-width: 0;
}

header h1 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.subtitle {
    font-size: 11px;
    color: var(--text-3);
    letter-spacing: 0.01em;
}

#new-chat-btn {
    height: 30px;
    padding: 0 12px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: 12px;
    font-weight: 500;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
#new-chat-btn:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.profile-picker-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 4px 0 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    transition: border-color var(--dur) var(--ease);
}
.profile-picker-wrap:hover {
    border-color: var(--border-strong);
}
.profile-picker-label {
    font-size: 11px;
    color: var(--text-3);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    user-select: none;
}
.profile-picker {
    height: 26px;
    background: transparent;
    color: var(--text);
    border: 0;
    font-size: 12px;
    font-weight: 500;
    padding: 0 4px;
    cursor: pointer;
    outline: none;
    max-width: 180px;
}
.profile-picker:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.profile-picker option {
    background: var(--surface-2);
    color: var(--text);
}

/* ─── Sidebar ─── */
.sidebar {
    width: var(--sidebar-w);
    height: 100%;
    background: var(--surface-1);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

.sidebar-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.sidebar-header-buttons {
    display: flex;
    gap: 4px;
}

#sidebar-new-chat-btn,
#timeline-toggle-btn {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: var(--r-sm);
    color: var(--text-2);
    background: transparent;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
    font-size: 16px;
}
#sidebar-new-chat-btn:hover,
#timeline-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.session-list-empty {
    color: var(--text-3);
    font-size: 12px;
    text-align: center;
    padding: 24px 12px;
}

.session-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--r-md);
    cursor: pointer;
    color: var(--text-2);
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
    user-select: none;
}
.session-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}
.session-item.active {
    background: var(--surface-3);
    color: var(--text);
}
.session-item.active::before {
    content: "";
    position: absolute;
    left: -4px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: var(--r-pill);
    background: var(--brand-grad);
}

.session-item-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.session-item-name {
    font-size: 13px;
    font-weight: 500;
    color: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-item-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-3);
}

.session-item-date { color: var(--text-3); }

.session-item-count {
    background: rgba(255, 255, 255, 0.06);
    padding: 1px 6px;
    border-radius: var(--r-pill);
    font-size: 10px;
    color: var(--text-2);
}

.arc-notification-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--brand-solid);
    box-shadow: 0 0 8px var(--brand-glow-strong);
    flex-shrink: 0;
}

.arc-source-icon {
    font-size: 12px;
    opacity: 0.7;
}

.arc-branch-badge {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: var(--r-xs);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-2);
}

.session-item-actions {
    display: none;
    gap: 2px;
}
.session-item:hover .session-item-actions { display: flex; }

.session-action-btn {
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    border-radius: var(--r-xs);
    color: var(--text-3);
    background: transparent;
    font-size: 12px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.session-action-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}
.session-action-btn.delete:hover {
    background: var(--danger-soft);
    color: var(--danger);
}
.session-action-btn.busy {
    opacity: 0.55;
    pointer-events: none;
}
.session-action-btn:disabled {
    cursor: default;
}
.session-action-btn.active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}
/* Keep the trigger visible while its menu is open, even when the
   sibling :hover state on .session-item is gone (cursor moved into
   the body-attached menu, which is not a descendant). */
.session-item-actions:has(.arc-menu-trigger.active) { display: flex; }

.arc-menu {
    position: fixed;
    z-index: 200;
    min-width: 168px;
    padding: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
    display: flex;
    flex-direction: column;
    gap: 1px;
    animation: arc-menu-in 110ms var(--ease) both;
}
@keyframes arc-menu-in {
    from { opacity: 0; transform: translateY(-2px); }
    to { opacity: 1; transform: translateY(0); }
}
.arc-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.arc-menu-item:hover { background: rgba(255, 255, 255, 0.06); }
.arc-menu-item.danger { color: var(--danger); }
.arc-menu-item.danger:hover { background: var(--danger-soft); }
.arc-menu-icon {
    width: 16px;
    display: inline-grid;
    place-items: center;
    color: var(--text-3);
    font-size: 12px;
}
.arc-menu-item.danger .arc-menu-icon { color: var(--danger); }
.arc-menu-item:hover .arc-menu-icon { color: var(--text); }
.arc-menu-label { flex: 1; }
.arc-menu-sep {
    height: 1px;
    margin: 4px 2px;
    background: var(--border);
}

.session-rename-input {
    width: 100%;
    background: var(--surface-3);
    border: 1px solid var(--brand-solid);
    border-radius: var(--r-sm);
    padding: 4px 8px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    box-shadow: var(--ring-focus);
}

.sidebar-toggle {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: var(--r-sm);
    color: var(--text-2);
    background: transparent;
    font-size: 16px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.hamburger-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.hamburger-icon svg { display: block; }

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 19;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur) var(--ease);
}
.sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ─── Sidebar footer ─── */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex-shrink: 0;
}

.sidebar-footer-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--r-md);
    color: var(--text-2);
    background: transparent;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sidebar-footer-btn:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.sidebar-icon,
.contacts-icon,
.calendar-icon,
.memory-icon,
.settings-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    opacity: 0.85;
    flex-shrink: 0;
    color: currentColor;
}
.sidebar-icon svg,
.contacts-icon svg,
.calendar-icon svg,
.memory-icon svg,
.settings-icon svg {
    display: block;
}

.notif-badge {
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 6px;
    display: grid;
    place-items: center;
    background: var(--brand-grad);
    color: var(--text);
    font-size: 10px;
    font-weight: 600;
    border-radius: var(--r-pill);
    box-shadow: 0 0 8px var(--brand-glow);
}

/* ─── Chat container ─── */
#chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 32px 24px 16px;
    position: relative;
    background: var(--bg);
}

/* Ambient gradient orb — the "Her" warmth */
.ambient-orb {
    position: absolute;
    top: -120px;
    right: -120px;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: var(--brand-grad);
    filter: blur(120px);
    opacity: 0.07;
    pointer-events: none;
    z-index: 0;
}

#messages {
    max-width: var(--content-max);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    position: relative;
    z-index: 1;
}

/* ─── Welcome ─── */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 64px 24px 32px;
    gap: 12px;
    color: var(--text-2);
}

.welcome-icon {
    width: 96px;
    height: 96px;
    display: block;
    object-fit: contain;
    margin: 0 auto 16px;
    user-select: none;
    -webkit-user-drag: none;
    filter: drop-shadow(0 0 32px var(--brand-glow));
    animation: welcome-icon-in var(--dur-slow) var(--ease) both;
}

@keyframes welcome-icon-in {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

.welcome-message p {
    margin: 0;
    font-size: 15px;
    color: var(--text-2);
    max-width: 480px;
    line-height: 1.55;
}

.welcome-message p strong {
    color: var(--text);
    font-weight: 600;
}

.welcome-hint {
    font-size: 13px !important;
    color: var(--text-3) !important;
    margin-top: 4px !important;
}

/* ─── Messages ─── */
.message-row {
    display: flex;
    flex-direction: column;
    animation: msg-in 280ms var(--ease);
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.message-row.user { align-items: flex-end; }
.message-row.assistant { align-items: stretch; }
.message-row.system { align-items: stretch; }

.message-avatar { display: none; }

.message-content-wrap {
    max-width: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.message-row.user .message-content-wrap {
    width: auto;
    max-width: 80%;
}

.message-bubble {
    background: transparent;
    color: var(--text);
    padding: 0;
    border-radius: 0;
    line-height: 1.65;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-row.assistant .message-bubble {
    position: relative;
    padding-left: 16px;
}

.message-row.assistant .message-bubble::before {
    content: "";
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 2px;
    border-radius: var(--r-pill);
    background: var(--brand-grad);
    opacity: 0.7;
    box-shadow: 2px 0 12px var(--brand-glow);
}

.message-row.user .message-bubble {
    color: var(--text-2);
    text-align: right;
}

.message-row.system .message-bubble {
    color: var(--text-3);
    font-size: 13px;
    font-style: italic;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-3);
    padding-left: 16px;
}
.message-row.user .message-meta {
    padding-left: 0;
    justify-content: flex-end;
}

.message-time { color: var(--text-3); }

/* Markdown bits inside messages */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
    margin: 16px 0 8px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}
.message-bubble h1 { font-size: 19px; }
.message-bubble h2 { font-size: 16px; }
.message-bubble h3 { font-size: 14px; }
.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child { margin-top: 0; }

.message-bubble p { margin: 0 0 8px; }
.message-bubble p:last-child { margin-bottom: 0; }

.message-bubble strong { color: var(--text); font-weight: 600; }
.message-bubble em { color: var(--text); font-style: italic; }

.message-bubble a { color: var(--brand-warm); border-bottom: 1px solid rgba(255,138,92,0.3); }
.message-bubble a:hover { color: var(--brand-amber); border-bottom-color: var(--brand-amber); }

.message-bubble ul,
.message-bubble ol {
    margin: 8px 0;
    padding-left: 22px;
}
.message-bubble li { margin: 2px 0; }

.message-bubble .inline-code,
.inline-code {
    font-family: var(--mono);
    font-size: 12.5px;
    padding: 1px 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-xs);
    color: var(--brand-amber);
}

.message-bubble .code-block,
.code-block {
    margin: 12px 0;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
}
.code-lang {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-3);
    padding: 6px 12px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    text-transform: lowercase;
    letter-spacing: 0.02em;
}
.message-bubble .code-block .code-body,
.code-body {
    padding: 12px;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--text);
    white-space: pre;
}

.message-bubble pre {
    margin: 12px 0;
    padding: 12px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--text);
}

.message-bubble blockquote {
    margin: 8px 0;
    padding-left: 12px;
    border-left: 2px solid var(--border-strong);
    color: var(--text-2);
}

/* ─── Markdown tables ─── */
.message-bubble .md-table-wrap {
    margin: 12px 0;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
    overflow-x: auto;
    background: var(--surface-1);
}
.message-bubble .md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
}
.message-bubble .md-table thead {
    background: linear-gradient(180deg, rgba(255,138,92,0.06) 0%, transparent 100%);
}
.message-bubble .md-table th {
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-2);
    letter-spacing: 0.02em;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
}
.message-bubble .md-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.message-bubble .md-table tbody tr:last-child td {
    border-bottom: none;
}
.message-bubble .md-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}
.message-bubble .md-table .inline-code {
    font-size: 11.5px;
    padding: 1px 5px;
}
.message-bubble .md-table a {
    border-bottom-color: rgba(255, 138, 92, 0.4);
}

.message-bubble.streaming::after {
    content: "▍";
    display: inline-block;
    color: var(--brand-warm);
    animation: blink 1s steps(2) infinite;
    margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ─── Risk badge / domain label ─── */
.risk-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--r-pill);
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.risk-badge.safe    { background: var(--success-soft); color: var(--success); }
.risk-badge.caution { background: var(--warning-soft); color: var(--warning); }
.risk-badge.danger  { background: var(--danger-soft);  color: var(--danger);  }

.domain-label {
    font-size: 10.5px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
}

/* ─── Tool calls / executions ─── */
.tool-calls-container,
.tool-steps-container {
    margin: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tool-call {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: 12.5px;
    color: var(--text-2);
}

.tool-call-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--brand-warm, var(--brand-solid));
    opacity: 0.95;
}
.tool-call-icon svg { display: block; }
.tool-call-name {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
    font-weight: 500;
}
.tool-call.builtin .tool-call-name {
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: -0.005em;
}
.tool-call-summary {
    color: var(--text-3);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.tool-execution-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: 12.5px;
    animation: msg-in 200ms var(--ease);
}
.tool-execution-card .tool-status-icon {
    flex-shrink: 0;
    font-size: 13px;
    margin-top: 1px;
}
.tool-execution-card.in-progress .tool-status-icon { color: var(--info); animation: spin 1.4s linear infinite; }
.tool-execution-card.completed   .tool-status-icon { color: var(--success); }
.tool-execution-card.failed      .tool-status-icon { color: var(--danger);  }

@keyframes spin { to { transform: rotate(360deg); } }

.tool-execution-card .tool-name {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
    font-weight: 500;
}
.tool-execution-card.builtin .tool-name {
    font-family: var(--font);
    font-size: 13px;
    letter-spacing: -0.005em;
}
.tool-execution-card .tool-builtin-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    margin-top: 1px;
    color: var(--brand-warm, var(--brand-solid));
    opacity: 0.95;
}
.tool-execution-card .tool-builtin-icon svg { display: block; }
.tool-execution-card .tool-detail {
    color: var(--text-3);
    font-size: 11.5px;
    margin-top: 2px;
    white-space: pre-wrap;
    word-break: break-word;
}
.tool-execution-card.completed { border-color: rgba(123, 201, 122, 0.18); }
.tool-execution-card.failed    { border-color: rgba(229, 72, 77, 0.22); }

/* ─── Persisted tool group (collapsible dropdown on rehydration) ─── */
.tool-group-history {
    margin: 8px 0;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface-1);
    overflow: hidden;
}
.tool-group-history > summary {
    list-style: none;
    cursor: pointer;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
}
.tool-group-history > summary::-webkit-details-marker { display: none; }
.tool-group-history > summary::after {
    content: '\025BE';
    margin-left: auto;
    color: var(--text-3);
    font-size: 11px;
    transition: transform 120ms var(--ease);
}
.tool-group-history[open] > summary::after { transform: rotate(180deg); }
.tool-group-history:hover > summary { background: rgba(255, 255, 255, 0.02); }
.tool-group-icons {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.tool-group-icon-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    color: var(--brand-warm, var(--brand-solid));
    opacity: 0.95;
}
.tool-group-icon-slot.fallback {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-3);
    background: var(--surface-2);
    border-radius: 3px;
    padding: 0 3px;
    width: auto;
    min-width: 18px;
}
.tool-group-icon-slot.failed { color: var(--danger); opacity: 0.85; }
.tool-group-icon-slot svg { display: block; width: 14px; height: 14px; }
.tool-group-count {
    font-size: 12px;
    color: var(--text-3);
}
.tool-group-body {
    padding: 4px 12px 12px;
    border-top: 1px solid var(--border);
    margin: 0;
}

/* ─── delegate_to_agent inline sub-agent activity ─── */
.tool-card-block.delegate-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.sub-agent-steps {
    margin-left: 22px;
    border-left: 2px solid var(--border);
    padding: 4px 0 4px 10px;
}
.sub-agent-steps-summary {
    cursor: pointer;
    list-style: none;
    font-size: 12px;
    color: var(--text-3);
    padding: 2px 4px;
    user-select: none;
}
.sub-agent-steps-summary::-webkit-details-marker { display: none; }
.sub-agent-steps-summary::after {
    content: '\25be';
    margin-left: 6px;
    transition: transform 120ms ease;
    display: inline-block;
}
.sub-agent-steps[open] > .sub-agent-steps-summary::after { transform: rotate(180deg); }
.sub-agent-steps-summary:hover { color: var(--text-2); }
.sub-agent-steps-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 6px;
}
.sub-agent-step-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sub-agent-step-detail {
    margin-left: 24px;
    font-size: 11.5px;
    color: var(--text-3);
}
.sub-agent-step-detail > summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
    padding: 1px 4px;
}
.sub-agent-step-detail > summary::-webkit-details-marker { display: none; }
.sub-agent-step-detail > summary:hover { color: var(--text-2); }
.sub-agent-step-json {
    margin: 4px 0 0;
    padding: 8px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm, 4px);
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-2);
    overflow-x: auto;
    max-height: 320px;
    overflow-y: auto;
    white-space: pre;
}

/* ─── Thinking blocks ─── */
.thinking-block {
    margin: 8px 0;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed var(--border);
    border-radius: var(--r-md);
    color: var(--text-3);
    font-size: 12.5px;
    font-style: italic;
}
.thinking-content { line-height: 1.5; }

/* ─── Error / approval bubbles ─── */
.message-bubble.error-message {
    border: 1px solid rgba(229, 72, 77, 0.25);
    background: var(--danger-soft);
    border-radius: var(--r-md);
    padding: 12px;
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.message-bubble.error-message::before { display: none; }

.error-icon { font-size: 16px; }
.error-text { color: var(--text); }
.error-retry-btn,
.error-settings-link {
    align-self: flex-start;
    padding: 4px 10px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 12px;
    transition: background var(--dur) var(--ease);
}
.error-retry-btn:hover,
.error-settings-link:hover { background: var(--surface-3); }

.approval-bubble {
    border: 1px solid var(--border-strong);
    background: var(--surface-1);
    border-radius: var(--r-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.approval-bubble::before { display: none; }

.approval-header {
    display: flex;
    align-items: center;
    gap: 10px;
}
.approval-icon { font-size: 18px; }
.approval-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.approval-details {
    display: flex;
    gap: 8px;
    font-size: 11.5px;
    color: var(--text-2);
    align-items: center;
}
.approval-risk {
    padding: 2px 8px;
    border-radius: var(--r-pill);
    background: var(--warning-soft);
    color: var(--warning);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 10.5px;
}
.approval-score { color: var(--text-3); }
.approval-description {
    font-size: 13px;
    color: var(--text-2);
    line-height: 1.55;
}
.approval-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ─── Email cards ─── */
.email-card {
    margin: 8px 0;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
}
.email-card.email-high { border-color: rgba(229, 72, 77, 0.25); }

.email-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.email-card-icon { font-size: 14px; }
.email-card-label { font-size: 12px; font-weight: 600; color: var(--text); }
.email-card-time { margin-left: auto; font-size: 11px; color: var(--text-3); }

.email-card-from {
    padding: 8px 12px 4px;
    font-size: 12px;
    color: var(--text-2);
}
.email-card-subject {
    padding: 0 12px 8px;
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
}
.email-card-body {
    padding: 0 12px 12px;
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.email-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--r-pill);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.email-badge-high   { background: var(--danger-soft); color: var(--danger); }
.email-badge-medium { background: var(--warning-soft); color: var(--warning); }

.email-card-reason {
    padding: 0 12px 8px;
    color: var(--text-3);
    font-size: 11.5px;
    font-style: italic;
}

.email-card-actions {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

.email-action-btn {
    height: 30px;
    padding: 0 12px;
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 12px;
    transition: background var(--dur) var(--ease);
}
.email-action-btn:hover { background: var(--surface-4); }
.email-action-primary {
    background: var(--brand-grad);
    color: var(--text);
    border-color: transparent;
}
.email-action-primary:hover { filter: brightness(1.08); }
.email-action-status {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 12px;
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
}

.email-inline-entry,
.system-inline-entry {
    margin: 6px 0;
    padding: 6px 10px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text-2);
    font-size: 12px;
}

.email-notification {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-bottom: 8px;
}
.email-notification-icon { font-size: 16px; }
.email-notification-content { flex: 1; min-width: 0; }
.email-notification-from { font-size: 12px; color: var(--text-2); }
.email-notification-subject {
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
    margin-top: 2px;
}
.email-notification-close {
    background: transparent;
    color: var(--text-3);
    width: 24px;
    height: 24px;
    border-radius: var(--r-xs);
    display: grid;
    place-items: center;
    font-size: 14px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.email-notification-close:hover {
    background: rgba(255,255,255,0.06);
    color: var(--text);
}

/* ─── Footer / input ─── */
footer {
    flex-shrink: 0;
    padding: 12px 24px 16px;
    background: var(--bg);
    position: relative;
    z-index: 5;
}

#input-form {
    max-width: var(--content-max);
    margin: 0 auto;
}
#input-form.dragover .input-wrapper {
    border-color: rgba(255, 122, 107, 0.6);
    box-shadow: 0 0 0 3px rgba(255, 122, 107, 0.15);
}

.composer-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    padding: 0 4px;
}
.composer-attachments.hidden {
    display: none;
}
.composer-image-chip {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-2);
    border: 1px solid var(--border);
    flex: 0 0 auto;
}
.composer-image-chip img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.composer-image-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}
.composer-image-remove:hover {
    background: rgba(0,0,0,0.85);
}

#composer-attach-btn {
    background: transparent;
    border: none;
    color: var(--text-soft, #888);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
#composer-attach-btn:hover {
    background: var(--surface-3, rgba(255,255,255,0.04));
    color: var(--text);
}
#composer-attach-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
#composer-attach-btn.disabled:hover {
    background: transparent;
    color: var(--text-soft, #888);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 8px 8px 8px 16px;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.input-wrapper:focus-within {
    border-color: rgba(255, 122, 107, 0.5);
    box-shadow: var(--ring-focus);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    padding: 6px 0;
    max-height: 200px;
    min-height: 24px;
    font-family: inherit;
}
#message-input::placeholder { color: var(--text-3); }

#send-btn,
#stop-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease), background var(--dur) var(--ease);
}

#send-btn {
    background: var(--brand-grad);
    color: var(--text);
    box-shadow: 0 4px 14px var(--brand-glow);
}
#send-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.08);
    box-shadow: 0 6px 18px var(--brand-glow-strong);
}
#send-btn:active { transform: translateY(0); }
#send-btn:disabled {
    background: var(--surface-3);
    color: var(--text-3);
    cursor: not-allowed;
    box-shadow: none;
}
#send-btn.hidden { display: none; }

.send-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.send-icon svg { display: block; }

#stop-btn {
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border);
}
#stop-btn:hover { background: var(--surface-4); }
#stop-btn:active { transform: translateY(0); }
#stop-btn.hidden { display: none; }

.stop-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.stop-icon svg { display: block; }

/* ─── Status bar ─── */
#status-bar {
    max-width: var(--content-max);
    margin: 6px auto 0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-3);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-3);
    transition: background var(--dur) var(--ease);
}
.status-dot.idle { background: var(--text-3); }
.status-dot.busy,
.status-dot.working {
    background: var(--brand-solid);
    box-shadow: 0 0 8px var(--brand-glow-strong);
    animation: pulse 1.6s ease-in-out infinite;
}
.status-dot.error { background: var(--danger); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

#status-text { color: var(--text-3); }

/* ─── Buttons ─── */
.btn-primary {
    height: 36px;
    padding: 0 14px;
    background: var(--brand-grad);
    color: var(--text);
    border: none;
    border-radius: var(--r-md);
    font-size: 13px;
    font-weight: 500;
    transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.btn-primary:hover {
    transform: translateY(-1px);
    filter: brightness(1.06);
    box-shadow: 0 6px 18px var(--brand-glow);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
    background: var(--surface-3);
    color: var(--text-3);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    height: 36px;
    padding: 0 14px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: 13px;
    font-weight: 500;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn-secondary:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}
.btn-secondary:disabled {
    color: var(--text-3);
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-danger {
    height: 36px;
    padding: 0 14px;
    background: var(--danger);
    color: var(--text);
    border: none;
    border-radius: var(--r-md);
    font-size: 13px;
    font-weight: 500;
    transition: filter var(--dur) var(--ease);
}
.btn-danger:hover { filter: brightness(1.1); }

.btn-deny {
    height: 36px;
    padding: 0 14px;
    background: transparent;
    color: var(--danger);
    border: 1px solid rgba(229, 72, 77, 0.35);
    border-radius: var(--r-md);
    font-size: 13px;
    font-weight: 500;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn-deny:hover {
    background: var(--danger-soft);
    border-color: var(--danger);
}
.btn-deny:active { transform: translateY(0); }
.btn-deny:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-approve {
    height: 36px;
    padding: 0 14px;
    background: var(--brand-grad);
    color: var(--text);
    border: none;
    border-radius: var(--r-md);
    font-size: 13px;
    font-weight: 500;
    transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn-approve:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* ─── Settings view ─── */
.settings-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
    min-width: 0;
}

.settings-header,
.contacts-header,
.notifications-header,
.calendar-header,
.memory-header,
.timeline-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
}

.settings-header h1,
.timeline-header h1,
.contacts-header h1 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.notifications-header h2,
.memory-header h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.settings-back-btn {
    height: 30px;
    padding: 0 12px;
    background: transparent;
    color: var(--text-2);
    border-radius: var(--r-sm);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.settings-back-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    max-width: 880px;
    width: 100%;
    margin: 0 auto;
}

.settings-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    padding: 4px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-card);
    position: sticky;
    top: 0;
    z-index: 5;
}

.settings-tab {
    flex: 1;
    padding: 9px 14px;
    background: transparent;
    border: none;
    border-radius: var(--r-sm);
    color: var(--text-2);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: -0.005em;
    cursor: pointer;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.settings-tab:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.settings-tab.active {
    background: var(--accent);
    color: #fff;
}

.settings-tab-pane {
    display: none;
    animation: settingsTabFade var(--dur) var(--ease);
}

.settings-tab-pane.active {
    display: block;
}

@keyframes settingsTabFade {
    from { opacity: 0; transform: translateY(2px); }
    to   { opacity: 1; transform: translateY(0); }
}

.settings-section {
    margin-bottom: 24px;
    padding: 24px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-card);
}

.settings-section h2 {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.settings-description {
    margin: 0 0 20px;
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.55;
}

.settings-subhead {
    margin: 24px 0 6px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.setting-row label {
    font-size: 12.5px;
    color: var(--text-2);
    font-weight: 500;
}

.setting-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.setting-hint {
    margin: 4px 0 0;
    color: var(--text-3);
    font-size: 11.5px;
    line-height: 1.5;
}
.setting-hint a { color: var(--brand-warm); }
.setting-hint a:hover { color: var(--brand-amber); }

.settings-field-row {
    display: flex;
    gap: 16px;
}
.settings-field-row .setting-row {
    flex: 1;
}

/* Native dropdown popups: keep them dark across the whole app. The
 * `color-scheme: dark` on :root handles most of this in WebKit, but
 * explicit option styling pins the colors in older renderers and any
 * future contexts (e.g. macOS Aqua) where the system popup might still
 * lean toward the OS theme. */
select,
option {
    background-color: var(--surface-2);
    color: var(--text);
}
option:checked,
option:hover {
    background-color: var(--surface-3);
}

/* ─── Inputs / forms ─── */
.settings-input,
.settings-select,
.cal-field input,
.cal-field select,
.cal-field textarea,
.provider-field input,
.provider-field select,
.onboarding-card input,
.onboarding-card select,
.memory-search input {
    width: 100%;
    height: 36px;
    padding: 0 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
    font-family: inherit;
}

.settings-input::placeholder,
.cal-field input::placeholder,
.cal-field textarea::placeholder,
.provider-field input::placeholder,
.onboarding-card input::placeholder,
.memory-search input::placeholder {
    color: var(--text-3);
}

.settings-input:focus,
.settings-select:focus,
.cal-field input:focus,
.cal-field select:focus,
.cal-field textarea:focus,
.provider-field input:focus,
.provider-field select:focus,
.onboarding-card input:focus,
.onboarding-card select:focus,
.memory-search input:focus {
    border-color: var(--brand-solid);
    box-shadow: var(--ring-focus);
    background: var(--surface-2);
}

.cal-field textarea,
#cal-event-description {
    height: auto;
    min-height: 72px;
    padding: 8px 12px;
    resize: vertical;
}

.settings-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='none' stroke='%23A8A2B0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M3 4.5l3 3 3-3'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    user-select: none;
}
.toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--brand-solid);
    cursor: pointer;
}

.advanced-toggle {
    color: var(--text-2);
    transition: color var(--dur) var(--ease);
}
.advanced-toggle:hover { color: var(--text); }
.advanced-arrow {
    display: inline-block;
    font-size: 9px;
    transition: transform var(--dur) var(--ease);
}

/* ─── API key wrapper ─── */
.api-key-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.api-key-wrapper input {
    padding-right: 40px;
}
.api-key-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    color: var(--text-3);
    background: transparent;
    border-radius: var(--r-xs);
    font-size: 13px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.api-key-toggle:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}
.api-key-hint {
    color: var(--text-3);
    font-size: 11.5px;
    margin-top: 4px;
}

/* ─── Time input ─── */
.time-input {
    display: flex;
    align-items: center;
    gap: 6px;
}
.time-input input {
    width: 60px !important;
    text-align: center;
}
.time-input span {
    color: var(--text-3);
    font-weight: 600;
}

/* ─── Test result ─── */
.test-result {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: var(--r-sm);
    font-size: 12.5px;
    line-height: 1.5;
}
.test-result.success { background: var(--success-soft); color: var(--success); border: 1px solid rgba(123, 201, 122, 0.25); }
.test-result.error   { background: var(--danger-soft);  color: var(--danger);  border: 1px solid rgba(229, 72, 77, 0.25); }
.test-success { color: var(--success); }
.test-error { color: var(--danger); }

/* ─── Provider cards ─── */
.provider-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-bottom: 8px;
    overflow: hidden;
    transition: border-color var(--dur) var(--ease);
}
.provider-card.active {
    border-color: rgba(255, 122, 107, 0.35);
    box-shadow: 0 0 0 1px rgba(255, 122, 107, 0.2);
}

.provider-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: background var(--dur) var(--ease);
}
.provider-card-header:hover { background: rgba(255, 255, 255, 0.02); }

.provider-card-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.provider-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-3);
}
.provider-status-dot.active {
    background: var(--success);
    box-shadow: 0 0 8px rgba(123, 201, 122, 0.5);
}
.provider-status-dot.inactive { background: var(--text-3); }

.provider-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}
.provider-subtitle {
    font-size: 11.5px;
    color: var(--text-3);
}

.provider-active-badge {
    padding: 2px 8px;
    background: var(--brand-grad-soft);
    color: var(--brand-warm);
    border-radius: var(--r-pill);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid rgba(255, 122, 107, 0.25);
}

.btn-set-active {
    height: 28px;
    padding: 0 10px;
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 11.5px;
    font-weight: 500;
    transition: background var(--dur) var(--ease);
}
.btn-set-active:hover { background: var(--surface-4); }
.btn-set-active:active { transform: translateY(0); }

.provider-card-chevron {
    color: var(--text-3);
    font-size: 11px;
    transition: transform var(--dur) var(--ease);
}
.provider-card.expanded .provider-card-chevron { transform: rotate(180deg); }

.provider-card-body {
    display: none;
    padding: 14px;
    border-top: 1px solid var(--border);
    background: var(--surface-1);
}
.provider-card.expanded .provider-card-body { display: block; }

.provider-field {
    margin-bottom: 12px;
}
.provider-field label {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    color: var(--text-2);
    font-weight: 500;
}
.provider-field-checkbox {
    margin-top: 4px;
}
.provider-field-checkbox label.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-weight: 400;
    font-size: 13px;
    color: var(--text);
}
.provider-field-checkbox input[type="checkbox"] {
    width: auto;
    margin: 0;
}
.provider-field .field-hint {
    font-size: 11px;
    color: var(--text-2);
    line-height: 1.45;
}

.provider-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.add-provider-area { margin-top: 12px; }

.add-provider-btn {
    height: 36px;
    padding: 0 14px;
    background: var(--surface-2);
    color: var(--text-2);
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-md);
    font-size: 13px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
    width: 100%;
}
.add-provider-btn:hover {
    background: var(--surface-3);
    color: var(--text);
    border-color: var(--brand-solid);
}

.provider-templates {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.template-btn {
    height: 30px;
    padding: 0 12px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 12px;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.template-btn:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}

/* ─── Permissions ─── */
.permissions-subhead {
    margin: 18px 0 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.permissions-subnote {
    color: var(--text-3);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    margin-left: 6px;
    font-size: 11.5px;
}

.grants-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}
.grants-empty {
    color: var(--text-3);
    font-size: 12.5px;
    padding: 8px 0;
    margin: 0;
}

.grant-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
}
.grant-card-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.grant-card-path {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
    word-break: break-all;
}

.grant-revoke-btn {
    flex-shrink: 0;
    height: 28px;
    padding: 0 10px;
    font-size: 11.5px !important;
}

.add-grant-form {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.add-grant-form .settings-input {
    flex: 1;
}
.grants-access-select {
    width: 110px;
    flex-shrink: 0;
}

/* ─── Grant approval modal ─── */
.grant-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: grid;
    place-items: center;
    z-index: 200;
    animation: fade-in var(--dur) var(--ease);
}
.grant-modal-overlay.hidden { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.grant-modal {
    width: 100%;
    max-width: 480px;
    background: var(--surface-1);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-modal);
    overflow: hidden;
    animation: modal-in var(--dur-slow) var(--ease);
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.grant-modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px 12px;
}
.grant-modal-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.grant-access-badge {
    padding: 2px 8px;
    border-radius: var(--r-pill);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--info-soft);
    color: var(--info);
}
.grant-access-badge.badge-read  { background: var(--info-soft);    color: var(--info); }
.grant-access-badge.badge-write { background: var(--warning-soft); color: var(--warning); }

.grant-modal-body { padding: 0 20px 16px; }

.grant-modal-question {
    color: var(--text-2);
    font-size: 13px;
    margin-bottom: 12px;
    line-height: 1.55;
}

.grant-modal-paths {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 14px;
}
.grant-modal-path {
    padding: 8px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
    word-break: break-all;
}
.grant-modal-path-prefix {
    color: var(--text-3);
    margin-right: 4px;
}
.grant-modal-path code {
    background: transparent;
    color: var(--text);
}

.grant-modal-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
}
.grant-modal-meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}
.grant-modal-meta-label { color: var(--text-3); }
.grant-modal-meta-value { color: var(--text); font-weight: 500; }

.grant-modal-queue {
    margin-top: 10px;
    padding: 8px 10px;
    background: var(--warning-soft);
    border-radius: var(--r-sm);
    color: var(--warning);
    font-size: 12px;
}
.grant-modal-queue.hidden { display: none; }

.grant-modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px 18px;
    gap: 8px;
    border-top: 1px solid var(--border);
}
.grant-modal-actions-right {
    display: flex;
    gap: 8px;
}

/* ─── MCP cards ─── */
.mcp-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-bottom: 8px;
    overflow: hidden;
    transition: border-color var(--dur) var(--ease);
}
.mcp-card.enabled { border-color: rgba(123, 201, 122, 0.25); }

.mcp-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
}
.mcp-card-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.mcp-card-icon {
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-2);
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}
.mcp-card-name-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.mcp-card-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}
.mcp-card-desc {
    font-size: 11.5px;
    color: var(--text-3);
}
.mcp-card-body {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: var(--surface-1);
}
.mcp-config-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* MCP toggle switch */
.mcp-toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}
.mcp-toggle input[type="checkbox"] {
    opacity: 0;
    width: 0;
    height: 0;
}
.mcp-toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--surface-4);
    border-radius: var(--r-pill);
    transition: background var(--dur) var(--ease);
    cursor: pointer;
}
.mcp-toggle-slider::before {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    left: 3px;
    top: 3px;
    background: var(--text);
    border-radius: 50%;
    transition: transform var(--dur) var(--ease);
}
.mcp-toggle input[type="checkbox"]:checked + .mcp-toggle-slider {
    background: var(--brand-grad);
}
.mcp-toggle input[type="checkbox"]:checked + .mcp-toggle-slider::before {
    transform: translateX(16px);
}

/* ─── Calendar ─── */
.calendar-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
    min-width: 0;
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}
.calendar-nav h1 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    min-width: 140px;
    text-align: center;
    letter-spacing: -0.01em;
}

.cal-nav-btn {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--text-2);
    border-radius: var(--r-sm);
    font-size: 13px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.cal-nav-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

.calendar-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cal-today-btn {
    height: 30px;
    padding: 0 12px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 12px;
    font-weight: 500;
    transition: background var(--dur) var(--ease);
}
.cal-today-btn:hover { background: var(--surface-3); }

.cal-view-select {
    height: 30px;
    padding: 0 28px 0 10px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 12px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path fill='none' stroke='%23A8A2B0' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round' d='M2.5 4l2.5 2.5 2.5-2.5'/></svg>");
    background-repeat: no-repeat;
    background-position: right 8px center;
    cursor: pointer;
}
.cal-view-select:focus {
    outline: none;
    border-color: var(--brand-solid);
    box-shadow: var(--ring-focus);
}

.calendar-grid {
    flex: 1;
    overflow: auto;
    padding: 16px 24px 24px;
}

.cal-month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
}

.cal-weekday-header {
    padding: 10px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.cal-day {
    min-height: 100px;
    padding: 6px 8px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--dur) var(--ease);
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--surface-1);
}
.cal-day:hover { background: var(--surface-2); }
.cal-day:nth-child(7n) { border-right: none; }
.cal-day.other-month { background: var(--bg-deep); }
.cal-day.other-month .cal-day-number { color: var(--text-3); }
.cal-day.today { background: rgba(255, 122, 107, 0.06); }
.cal-day.today .cal-day-number {
    color: var(--brand-warm);
    font-weight: 700;
}

.cal-day-number {
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
}
.cal-day-events {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 0;
}
.cal-event-item {
    padding: 2px 6px;
    background: var(--surface-3);
    border-radius: var(--r-xs);
    font-size: 11px;
    color: var(--text);
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: filter var(--dur) var(--ease);
}
.cal-event-item:hover { filter: brightness(1.15); }
.cal-event-more {
    font-size: 10.5px;
    color: var(--text-3);
    padding: 0 6px;
    cursor: pointer;
}
.cal-event-more:hover { color: var(--text); }

/* Calendar week view */
.cal-week-grid {
    display: flex;
    flex-direction: column;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
}
.cal-week-header {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.cal-week-header-cell {
    padding: 10px;
    text-align: center;
    border-right: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.cal-week-header-cell:first-child { background: transparent; }
.cal-week-header-cell:last-child { border-right: none; }
.cal-week-header-cell.today { color: var(--brand-warm); }
.cal-week-header-cell .cal-week-day-num {
    display: block;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-top: 2px;
}
.cal-week-header-cell.today .cal-week-day-num { color: var(--brand-warm); }

.cal-week-allday-row {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    border-bottom: 1px solid var(--border);
    background: var(--surface-1);
}
.cal-week-allday-label {
    padding: 6px 8px;
    font-size: 10.5px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-right: 1px solid var(--border);
    text-align: right;
}
.cal-week-allday-cell {
    padding: 4px;
    border-right: 1px solid var(--border);
    min-height: 26px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cal-week-body {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    flex: 1;
    overflow: auto;
}
.cal-week-time-label {
    padding: 4px 8px;
    font-size: 10.5px;
    color: var(--text-3);
    text-align: right;
    border-right: 1px solid var(--border);
    height: 48px;
}
.cal-week-day-col {
    border-right: 1px solid var(--border);
    position: relative;
    cursor: pointer;
    transition: background var(--dur) var(--ease);
}
.cal-week-day-col:hover { background: var(--surface-2); }

.cal-week-event {
    position: absolute;
    left: 4px;
    right: 4px;
    padding: 4px 6px;
    border-radius: var(--r-xs);
    font-size: 11px;
    color: var(--text);
    overflow: hidden;
    cursor: pointer;
    transition: filter var(--dur) var(--ease);
}
.cal-week-event:hover { filter: brightness(1.15); }

/* Calendar modal */
.cal-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: grid;
    place-items: center;
    z-index: 200;
    animation: fade-in var(--dur) var(--ease);
}
.cal-modal-overlay.hidden { display: none; }

.cal-modal {
    width: 100%;
    max-width: 520px;
    max-height: 88vh;
    overflow-y: auto;
    background: var(--surface-1);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-modal);
    animation: modal-in var(--dur-slow) var(--ease);
}

.cal-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.cal-modal-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.cal-modal-close-btn {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--text-2);
    border-radius: var(--r-sm);
    font-size: 18px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.cal-modal-close-btn:hover {
    background: rgba(255,255,255,0.06);
    color: var(--text);
}

.cal-modal-body {
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cal-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.cal-field label {
    font-size: 12.5px;
    color: var(--text-2);
    font-weight: 500;
}

.cal-time-fields {
    display: flex;
    gap: 12px;
}
.cal-field-half { flex: 1; }
.cal-time-fields.hidden { display: none; }

.cal-color-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.cal-color-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
    box-shadow: 0 0 0 1px var(--border);
}
.cal-color-dot:hover { transform: scale(1.1); }
.cal-color-dot.selected {
    border-color: var(--text);
    transform: scale(1.1);
}

.cal-modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px 18px;
    border-top: 1px solid var(--border);
    gap: 8px;
}
.cal-modal-actions-right {
    display: flex;
    gap: 8px;
}

/* ─── Contacts ─── */
.contacts-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
    min-width: 0;
}

.contacts-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    max-width: 880px;
    width: 100%;
    margin: 0 auto;
}

.contacts-empty {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-2);
}
.contacts-empty-icon {
    font-size: 48px;
    opacity: 0.5;
    margin-bottom: 12px;
}
.contacts-empty-hint {
    color: var(--text-3);
    font-size: 12.5px;
}

.contact-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-bottom: 8px;
    overflow: hidden;
    transition: border-color var(--dur) var(--ease);
}
.contact-card:hover { border-color: var(--border-strong); }
.contact-card.blocked { opacity: 0.6; }

.contact-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
}

.contact-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-badge {
    padding: 2px 8px;
    border-radius: var(--r-pill);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.contact-badge.trust-unknown { background: rgba(255,255,255,0.06); color: var(--text-3); }
.contact-badge.trust-neutral { background: var(--info-soft); color: var(--info); }
.contact-badge.trust-known   { background: var(--warning-soft); color: var(--warning); }
.contact-badge.trust-trusted { background: var(--success-soft); color: var(--success); }
.contact-badge.blocked-badge { background: var(--danger-soft); color: var(--danger); }

.contact-interactions {
    color: var(--text-3);
    font-size: 11.5px;
}

.contact-details {
    display: none;
    padding: 14px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}
.contact-card.expanded .contact-details { display: block; }

.contact-identifiers {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}
.contact-identifier {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--surface-3);
    border-radius: var(--r-sm);
    font-size: 12px;
    color: var(--text);
}
.contact-identifier-kind {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-3);
    font-weight: 600;
}

.contact-meta {
    color: var(--text-3);
    font-size: 11.5px;
    margin-bottom: 12px;
}

.contact-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.contact-trust-select {
    height: 30px;
    padding: 0 28px 0 10px;
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 12px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path fill='none' stroke='%23A8A2B0' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round' d='M2.5 4l2.5 2.5 2.5-2.5'/></svg>");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.contact-action-btn {
    height: 30px;
    padding: 0 10px;
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 11.5px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.contact-action-btn:hover { background: var(--surface-4); }
.contact-action-btn.btn-block { color: var(--warning); }
.contact-action-btn.btn-block:hover { background: var(--warning-soft); border-color: var(--warning); }
.contact-action-btn.btn-unblock { color: var(--success); }
.contact-action-btn.btn-unblock:hover { background: var(--success-soft); border-color: var(--success); }
.contact-action-btn.btn-delete { color: var(--danger); }
.contact-action-btn.btn-delete:hover { background: var(--danger-soft); border-color: var(--danger); }

.contact-override-hint {
    color: var(--text-3);
    font-size: 11px;
    margin-top: 6px;
    font-style: italic;
}

.contact-modal { max-width: 440px; }

#new-contact-btn {
    height: 30px;
    padding: 0 12px;
    font-size: 12px;
}

.contact-edit-btn {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--text-3);
    border-radius: var(--r-xs);
    font-size: 13px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.contact-edit-btn:hover {
    background: rgba(255,255,255,0.06);
    color: var(--text);
}

.identifier-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}
.identifier-row select {
    width: 110px;
    flex-shrink: 0;
}
.identifier-row input { flex: 1; }
.identifier-row .remove-identifier-btn {
    width: 30px;
    height: 36px;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--text-3);
    border-radius: var(--r-sm);
    font-size: 14px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
    flex-shrink: 0;
}
.identifier-row .remove-identifier-btn:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

#contact-identifiers-section { margin-top: 4px; }
#contact-identifiers-section > label {
    display: block;
    font-size: 12.5px;
    color: var(--text-2);
    margin-bottom: 6px;
    font-weight: 500;
}
#contact-identifiers-section .btn-secondary {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
    margin-top: 6px;
}

#contact-trust-modal-select {
    height: 36px;
    padding: 0 32px 0 12px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 13px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='none' stroke='%23A8A2B0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M3 4.5l3 3 3-3'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    width: 100%;
}

/* ─── Notifications ─── */
.notifications-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
    min-width: 0;
}
.notifications-view.hidden { display: none; }
.memory-view.hidden { display: none; }

.mark-all-btn {
    height: 28px;
    padding: 0 10px;
    background: var(--surface-2);
    color: var(--text-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 11.5px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.mark-all-btn:hover { background: var(--surface-3); color: var(--text); }

.notifications-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
}

.notification-item {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 12px 14px;
    transition: border-color var(--dur) var(--ease);
}
.notification-item.unread {
    border-color: rgba(255, 122, 107, 0.25);
    background: linear-gradient(to right, rgba(255, 122, 107, 0.04), transparent);
}
.notification-item.read { opacity: 0.7; }

.notification-item-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}
.notif-icon { font-size: 14px; }
.notif-text { flex: 1; min-width: 0; }
.notif-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}
.notif-body {
    font-size: 12.5px;
    color: var(--text-2);
    margin-top: 4px;
    line-height: 1.5;
}
.notif-time {
    font-size: 11px;
    color: var(--text-3);
    margin-left: auto;
}

.notif-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}
.notif-action-btn {
    height: 26px;
    padding: 0 10px;
    background: var(--surface-2);
    color: var(--text-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 11.5px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.notif-action-btn:hover { background: var(--surface-3); color: var(--text); }
.notif-action-btn.notif-delete-btn:hover {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: var(--danger);
}

.empty-state {
    text-align: center;
    color: var(--text-3);
    padding: 64px 24px;
    font-size: 13px;
}

/* Notification toast */
#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast,
.notification-toast {
    pointer-events: auto;
    min-width: 280px;
    max-width: 360px;
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-raised);
    padding: 12px;
    animation: toast-in var(--dur-slow) var(--ease);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger);  }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(8px); }
    to   { opacity: 1; transform: translateX(0); }
}

.notification-toast.urgency-low      { border-left: 3px solid var(--text-3); }
.notification-toast.urgency-medium   { border-left: 3px solid var(--info); }
.notification-toast.urgency-high     { border-left: 3px solid var(--warning); }
.notification-toast.urgency-critical { border-left: 3px solid var(--danger); }

.toast-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.toast-icon { font-size: 13px; }
.toast-title {
    flex: 1;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
}
.toast-close {
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--text-3);
    border-radius: var(--r-xs);
    font-size: 13px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.toast-close:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.toast-body {
    font-size: 12px;
    color: var(--text-2);
    line-height: 1.5;
}

/* ─── Channel order ─── */
#notif-channel-order {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
}
.channel-order-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
}
.channel-name {
    flex: 1;
    font-size: 12.5px;
    color: var(--text);
}
.channel-order-buttons {
    display: flex;
    gap: 4px;
}
.channel-order-buttons button {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    background: var(--surface-3);
    color: var(--text-2);
    border: 1px solid var(--border);
    border-radius: var(--r-xs);
    font-size: 12px;
    transition: background var(--dur) var(--ease);
}
.channel-order-buttons button:hover:not(:disabled) {
    background: var(--surface-4);
    color: var(--text);
}
.channel-order-buttons button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ─── Memory ─── */
.memory-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
    min-width: 0;
}

.memory-tabs {
    display: flex;
    gap: 4px;
    padding: 12px 24px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.memory-tab {
    height: 36px;
    padding: 0 14px;
    background: transparent;
    color: var(--text-3);
    border: none;
    border-radius: var(--r-sm) var(--r-sm) 0 0;
    font-size: 13px;
    font-weight: 500;
    transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
    position: relative;
}
.memory-tab:hover { color: var(--text-2); }
.memory-tab.active { color: var(--text); }
.memory-tab.active::after {
    content: "";
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: -1px;
    height: 2px;
    background: var(--brand-grad);
    border-radius: var(--r-pill);
}

.memory-panel {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px 24px;
    max-width: 880px;
    width: 100%;
    margin: 0 auto;
}

.memory-search {
    margin-bottom: 16px;
}

.memories-list,
.entities-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.memory-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 12px 14px;
    transition: border-color var(--dur) var(--ease);
}
.memory-card:hover { border-color: var(--border-strong); }

.memory-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.memory-type-badge {
    padding: 2px 8px;
    border-radius: var(--r-pill);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: rgba(255,255,255,0.06);
    color: var(--text-2);
}
.memory-type-badge.keyword      { background: var(--info-soft); color: var(--info); }
.memory-type-badge.semantic     { background: rgba(187, 154, 247, 0.18); color: #BB9AF7; }
.memory-type-badge.conversation { background: var(--warning-soft); color: var(--warning); }
.memory-type-badge.fact         { background: var(--success-soft); color: var(--success); }
.memory-type-badge.preference   { background: var(--brand-grad-soft); color: var(--brand-warm); }

.memory-source {
    flex: 1;
    color: var(--text-3);
    font-size: 11.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.memory-time {
    color: var(--text-3);
    font-size: 11px;
}

.memory-content {
    color: var(--text);
    font-size: 13px;
    line-height: 1.55;
    word-wrap: break-word;
}
.memory-content.editing {
    background: var(--surface-2);
    border: 1px solid var(--brand-solid);
    border-radius: var(--r-sm);
    padding: 8px;
    outline: none;
    box-shadow: var(--ring-focus);
}

.memory-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    justify-content: flex-end;
}
.memory-edit-btn,
.memory-delete-btn {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--text-3);
    border-radius: var(--r-xs);
    font-size: 13px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.memory-edit-btn:hover {
    background: rgba(255,255,255,0.06);
    color: var(--text);
}
.memory-delete-btn:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

/* ─── Entities (knowledge graph) ─── */
.entity-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
    transition: border-color var(--dur) var(--ease);
}
.entity-card:hover { border-color: var(--border-strong); }

.entity-card > summary {
    list-style: none;
    padding: 12px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
}
.entity-card > summary::-webkit-details-marker { display: none; }

.entity-rel-count {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-3);
    background: rgba(255,255,255,0.06);
    padding: 1px 8px;
    border-radius: var(--r-pill);
}

.entity-details {
    padding: 14px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

.entity-section-label {
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

.entity-relation-row,
.entity-id-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 12.5px;
    color: var(--text-2);
}

.relation-arrow { color: var(--text-3); font-family: var(--mono); }
.relation-label {
    padding: 1px 6px;
    background: rgba(255,255,255,0.06);
    border-radius: var(--r-xs);
    font-size: 11px;
    color: var(--text-2);
}
.relation-target { color: var(--text); font-weight: 500; }

.entity-id-value {
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--text);
}

.entity-no-relations {
    color: var(--text-3);
    font-size: 12px;
    font-style: italic;
}

.entity-meta-json {
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--text-2);
    background: var(--bg-deep);
    padding: 8px;
    border-radius: var(--r-sm);
    overflow-x: auto;
    margin-top: 6px;
}

.entity-type-badge {
    padding: 2px 8px;
    border-radius: var(--r-pill);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.entity-type-badge.person       { background: var(--info-soft); color: var(--info); }
.entity-type-badge.organization { background: var(--warning-soft); color: var(--warning); }
.entity-type-badge.project      { background: rgba(115,218,202,0.18); color: #73DACA; }
.entity-type-badge.event        { background: rgba(187,154,247,0.18); color: #BB9AF7; }
.entity-type-badge.document     { background: rgba(255,255,255,0.08); color: var(--text-2); }
.entity-type-badge.concept      { background: var(--danger-soft); color: var(--danger); }
.entity-type-badge.location     { background: var(--brand-grad-soft); color: var(--brand-warm); }
.entity-type-badge.topic        { background: var(--success-soft); color: var(--success); }

.entity-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.entity-summary { color: var(--text-2); font-size: 12.5px; line-height: 1.5; }

.entity-metadata { margin-top: 10px; }

.entity-delete-btn {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--text-3);
    border-radius: var(--r-xs);
    font-size: 13px;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease), opacity var(--dur) var(--ease);
    opacity: 0;
}
.entity-card:hover .entity-delete-btn { opacity: 1; }
.entity-delete-btn:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

/* ─── Timeline ─── */
.timeline-view {
    position: absolute;
    inset: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 25;
}
.timeline-view.hidden { display: none; }

.timeline-new-btn {
    height: 30px;
    padding: 0 12px;
    background: var(--brand-grad);
    color: var(--text);
    border: none;
    border-radius: var(--r-sm);
    font-size: 12px;
    font-weight: 500;
    transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.timeline-new-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }

.timeline-canvas {
    flex: 1;
    overflow: auto;
    padding: 24px;
}

.tl-empty {
    text-align: center;
    color: var(--text-3);
    padding: 64px 24px;
    font-size: 13px;
}

.tl-graph {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
}

.tl-header-row {
    display: flex;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.tl-col-header {
    flex: 1;
    min-width: 140px;
    padding: 12px;
    border-right: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--dur) var(--ease);
    display: flex;
    align-items: center;
    gap: 8px;
}
.tl-col-header:hover { background: var(--surface-3); }
.tl-col-header.tl-merged   { opacity: 0.7; }
.tl-col-header.tl-archived { opacity: 0.5; }

.tl-col-icon { font-size: 14px; }
.tl-col-name {
    flex: 1;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tl-col-count {
    font-size: 10.5px;
    color: var(--text-3);
    background: rgba(255,255,255,0.06);
    padding: 1px 6px;
    border-radius: var(--r-pill);
}

.tl-time-label {
    width: 80px;
    flex-shrink: 0;
    padding: 6px 10px;
    font-size: 10.5px;
    color: var(--text-3);
    border-right: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tl-row {
    display: flex;
    border-bottom: 1px solid var(--border);
    transition: background var(--dur) var(--ease);
}
.tl-row:hover { background: rgba(255,255,255,0.02); }

.tl-cell {
    flex: 1;
    min-width: 140px;
    min-height: 44px;
    border-right: 1px solid var(--border);
    position: relative;
    padding: 6px;
}

.tl-rail {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    background: var(--border);
    transform: translateX(-50%);
}

.tl-node {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--brand-grad);
    box-shadow: 0 0 0 2px var(--surface-1), 0 0 8px var(--brand-glow);
    cursor: pointer;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    transition: transform var(--dur) var(--ease);
}
.tl-node:hover { transform: translateX(-50%) scale(1.3); }

.tl-tooltip {
    position: fixed;
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text);
    box-shadow: var(--shadow-raised);
    z-index: 50;
    pointer-events: none;
    max-width: 280px;
    line-height: 1.5;
}

/* ─── Onboarding ─── */
.onboarding-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-deep);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
    padding: 24px;
}

.onboarding-card {
    width: 100%;
    max-width: 480px;
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-modal);
    padding: 36px 32px 28px;
    animation: modal-in var(--dur-slow) var(--ease);
    max-height: 90vh;
    overflow-y: auto;
    text-align: center;
}
.onboarding-card input,
.onboarding-card select,
.onboarding-card textarea {
    text-align: left;
}

.onboarding-card h1 {
    margin: 0 0 12px;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--brand-grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.onboarding-card p {
    color: var(--text-2);
    line-height: 1.6;
    margin: 0 0 12px;
    font-size: 14px;
}

.onboarding-card ul {
    margin: 0 auto 16px;
    padding: 0;
    list-style: none;
    color: var(--text-2);
    text-align: left;
    max-width: 320px;
}
.onboarding-card li {
    margin: 6px 0;
    line-height: 1.55;
    padding-left: 18px;
    position: relative;
    font-size: 13.5px;
}
.onboarding-card li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 9px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--brand-grad);
    opacity: 0.85;
}

.onboarding-card label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
    font-size: 12.5px;
    color: var(--text-2);
    font-weight: 500;
    text-align: left;
}

.onboarding-pick-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 16px 0 20px;
}

.onboarding-pick-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    text-align: left;
    color: var(--text);
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.onboarding-pick-btn:hover {
    background: var(--surface-3);
    border-color: rgba(255, 122, 107, 0.35);
    transform: translateY(-1px);
}
.onboarding-pick-btn strong {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.onboarding-pick-btn span {
    font-size: 12.5px;
    color: var(--text-3);
    line-height: 1.5;
}

.onboarding-buttons {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.onb-status {
    margin: 12px 0;
    padding: 10px 12px;
    border-radius: var(--r-sm);
    font-size: 12.5px;
    background: var(--surface-2);
    color: var(--text-2);
    min-height: 20px;
    text-align: center;
}
.onb-status:empty { display: none; }
.onb-status.ok    { background: var(--success-soft); color: var(--success); }
.onb-status.err   { background: var(--danger-soft);  color: var(--danger);  }
.onb-status.busy  { background: var(--info-soft);    color: var(--info);    }

.onb-device-tier {
    margin: 0 0 16px;
    padding: 10px 12px;
    border-radius: var(--r-sm);
    background: var(--info-soft);
    color: var(--info);
    font-size: 12.5px;
    line-height: 1.45;
    text-align: center;
}
.onb-device-tier:empty { display: none; }

.onb-runtime-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 4px 0 0;
}
.onb-runtime-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--r-sm);
    background: var(--surface-2);
    border: 1px solid var(--border, transparent);
}
.onb-runtime-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.onb-runtime-meta strong {
    font-size: 13px;
}
.onb-runtime-status {
    font-size: 12px;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.onb-runtime-action button {
    white-space: nowrap;
}

.onb-progress {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: -4px 0 18px;
    font-size: 11px;
    color: var(--text-3, var(--text-2));
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.onb-progress-step {
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-3, var(--text-2));
    transition: background 120ms ease, color 120ms ease;
}
.onb-progress-step.active {
    background: var(--accent-soft, var(--info-soft));
    color: var(--accent, var(--info));
}

.onboarding-hint {
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.5;
    margin: 4px 0 16px;
}

/* ─── Shell toolbox ─── */
.toolbox-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 12px;
}
.toolbox-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.toolbox-group-title {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    margin: 0 0 4px 0;
}
.toolbox-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}
.toolbox-row-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
}
.toolbox-row-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}
.toolbox-row-version {
    font-size: 11.5px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}
.toolbox-row-date {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}
.toolbox-row-reason {
    font-size: 11.5px;
    color: var(--text-3);
    line-height: 1.4;
}

/* ─── Profile manager ─── */
.profile-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}
.profile-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}
.profile-card-main {
    flex: 1;
    min-width: 0;
}
.profile-card-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.profile-card-badge {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: var(--r-sm);
    background: var(--surface-3);
    color: var(--text-3);
}
.profile-card-badge.builtin {
    background: var(--info-soft, rgba(122, 162, 247, 0.15));
    color: var(--info, #7aa2f7);
}
.profile-card-desc {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-2);
    line-height: 1.4;
}
.profile-card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.profile-card-actions button {
    height: 26px;
    padding: 0 10px;
    font-size: 11px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
}
.profile-card-actions button:hover:not(:disabled) {
    background: var(--surface-3);
    border-color: var(--border-strong);
}
.profile-card-actions button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.profile-card-actions .btn-danger {
    color: var(--danger, #f7768e);
    border-color: rgba(247, 118, 142, 0.4);
}

.profile-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: grid;
    place-items: center;
    z-index: 220;
    animation: fade-in var(--dur) var(--ease);
}
.profile-modal-overlay.hidden { display: none; }
.profile-modal {
    width: 100%;
    max-width: 600px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    background: var(--surface-1);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-modal);
    overflow: hidden;
}
.profile-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.profile-modal-header h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}
.profile-modal-body {
    overflow-y: auto;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.profile-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    background: var(--surface-1);
}
.profile-modal-error {
    color: var(--danger, #f7768e);
    font-size: 12px;
    margin: 0;
}
.profile-modal-error.hidden { display: none; }
.profile-chip-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.profile-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 11px;
    color: var(--text-2);
    cursor: pointer;
    user-select: none;
    background: var(--surface-2);
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.profile-chip:hover { border-color: var(--border-strong); }
.profile-chip.selected {
    background: rgba(122, 162, 247, 0.18);
    border-color: rgba(122, 162, 247, 0.5);
    color: var(--text);
}

/* ─── Responsive ─── */
@media (min-width: 769px) {
    .sidebar-toggle { display: none; }
    .sidebar { display: flex; }
}

@media (max-width: 768px) {
    :root { --sidebar-w: 280px; }

    .sidebar-toggle { display: grid; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform var(--dur-slow) var(--ease);
        z-index: 30;
    }
    .sidebar.open { transform: translateX(0); }

    #chat-container { padding: 24px 16px 12px; }
    footer { padding: 10px 16px 14px; }
    .message-content-wrap { max-width: 100%; }
    .input-wrapper { padding: 6px 6px 6px 14px; }

    .calendar-header { flex-wrap: wrap; gap: 8px; }
    .calendar-nav h1 { min-width: auto; }
    .cal-day { min-height: 80px; }
    .cal-day-number { font-size: 11px; }
    .cal-event-item { font-size: 10px; }
    .cal-week-time-label { width: 48px; }
    .cal-modal { max-width: 100%; }

    .ambient-orb {
        width: 400px;
        height: 400px;
        top: -100px;
        right: -100px;
    }
    .welcome-icon { font-size: 72px; }
    .welcome-message { padding: 32px 16px; }
}

/* Compaction summary block — collapsed "Earlier in this arc..." entry. */
.arc-summary-block {
    width: 100%;
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--r-sm);
    padding: 8px 12px;
    color: var(--text-2);
    font-size: 12px;
}
.arc-summary-block summary {
    cursor: pointer;
    list-style: none;
    color: var(--text-2);
    font-weight: 500;
    user-select: none;
}
.arc-summary-block summary::-webkit-details-marker { display: none; }
.arc-summary-block[open] summary {
    margin-bottom: 8px;
    color: var(--text);
}
.arc-summary-body {
    margin: 0;
    padding: 8px 0 0 0;
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 12px;
    color: var(--text-2);
    line-height: 1.5;
}
