:root {
    --canvas: #f6f8ef;
    --canvas-deep: #eef2e4;
    --paper: rgba(255, 255, 251, .86);
    --ink: #2d382f;
    --ink-soft: #6f7b70;
    --ink-faint: #9da79d;
    --line: rgba(73, 91, 75, .13);
    --leaf: #71896d;
    --leaf-deep: #516a52;
    --leaf-pale: #dfe8d7;
    --seed: #e2bd63;
    --seed-pale: #f5e8b9;
    --petal: #fffdf4;
    --danger: #a66358;
    --shadow: 0 20px 60px rgba(65, 79, 61, .08);
    --radius: 24px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    min-height: 100vh;
    background:
        radial-gradient(circle at 82% 8%, rgba(238, 222, 158, .24), transparent 28%),
        radial-gradient(circle at 15% 90%, rgba(178, 201, 168, .2), transparent 32%),
        var(--canvas);
    overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.auth-gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 22px; background: rgba(242,246,234,.9); backdrop-filter: blur(18px); }
.auth-gate[hidden] { display: none; }
.access-card { width: min(410px, 100%); display: grid; gap: 18px; padding: 38px; border: 1px solid rgba(73,91,75,.12); border-radius: 30px; background: rgba(255,255,251,.94); box-shadow: 0 28px 90px rgba(55,72,56,.13); }
.access-card h1 { margin: -7px 0 0; font: 500 30px Georgia, "Noto Serif SC", serif; }
.access-card > p:not(.eyebrow):not(.access-error) { margin: -8px 0 5px; color: var(--ink-soft); font-size: 12px; line-height: 1.7; }
.access-mark { display: grid; place-items: center; width: 45px; height: 45px; border-radius: 50%; color: #a78a48; background: linear-gradient(145deg, var(--leaf-pale), var(--seed-pale)); font-size: 20px; }
.access-error { min-height: 16px; margin: -6px 0 0; color: var(--danger); font-size: 11px; }

.app-shell { display: grid; grid-template-columns: 262px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    padding: 26px 18px 20px;
    border-right: 1px solid var(--line);
    background: rgba(248, 250, 242, .72);
    backdrop-filter: blur(18px);
}
.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    border: 0;
    background: transparent;
    padding: 0 8px 26px;
    text-align: left;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,.78);
    box-shadow: 0 9px 25px rgba(75, 95, 72, .1);
}
.brand-mark svg { width: 33px; fill: none; stroke: var(--leaf); stroke-width: 1.6; stroke-linecap: round; }
.brand-mark circle { fill: var(--seed); stroke: none; }
.brand-mark .seed { stroke: #b89c5c; stroke-width: 1.1; }
.brand strong { display: block; font-family: Georgia, "Noto Serif SC", serif; font-size: 21px; letter-spacing: .08em; }
.brand small { display: block; color: var(--ink-faint); font-size: 10px; letter-spacing: .22em; margin-top: 2px; }

.primary-nav { display: grid; gap: 6px; }
.nav-item {
    width: 100%;
    display: grid;
    grid-template-columns: 26px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 11px 13px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: var(--ink-soft);
    text-align: left;
    transition: .2s ease;
}
.nav-item:hover { color: var(--ink); background: rgba(255,255,255,.58); }
.nav-item.active { color: var(--leaf-deep); background: rgba(221, 232, 214, .72); }
.nav-icon { color: var(--leaf); font-size: 20px; line-height: 1; }
.nav-item em { min-width: 21px; padding: 2px 6px; border-radius: 999px; background: rgba(255,255,255,.72); color: var(--ink-faint); font-size: 10px; font-style: normal; text-align: center; }

.conversation-nav { margin-top: 34px; min-height: 0; flex: 1; overflow: hidden; }
.section-label { display: flex; justify-content: space-between; align-items: center; padding: 0 10px 9px; color: var(--ink-faint); font-size: 11px; letter-spacing: .08em; }
.section-label button { border: 0; background: transparent; color: var(--leaf); font-size: 18px; }
.conversation-list { display: grid; gap: 3px; overflow-y: auto; max-height: calc(100vh - 380px); }
.conversation-item { border: 0; background: transparent; padding: 10px 12px; border-radius: 12px; text-align: left; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item:hover, .conversation-item.active { background: rgba(255,255,255,.66); color: var(--ink); }
.conversation-item.active::before { content: ""; display: inline-block; width: 5px; height: 5px; margin: 0 8px 2px 0; border-radius: 50%; background: var(--seed); }
.sidebar-foot { display: flex; align-items: center; gap: 10px; padding: 15px 10px 0; border-top: 1px solid var(--line); }
.sidebar-foot strong, .sidebar-foot small { display: block; }
.sidebar-foot strong { font-size: 12px; font-weight: 600; }
.sidebar-foot small { color: var(--ink-faint); font-size: 10px; margin-top: 2px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #c6a39c; box-shadow: 0 0 0 5px rgba(166,99,88,.08); }
.status-dot.ready { background: #7ea274; box-shadow: 0 0 0 5px rgba(113,137,109,.1); }

.workspace { position: relative; min-width: 0; height: 100vh; overflow: hidden; }
.view { display: none; height: 100%; overflow-y: auto; padding: 38px clamp(28px, 5vw, 76px); }
.view.active { display: flex; flex-direction: column; animation: settle .32s ease; }
@keyframes settle { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; max-width: 1120px; width: 100%; margin: 0 auto 30px; }
.view-head h1 { margin: 5px 0 0; font-family: Georgia, "Noto Serif SC", serif; font-size: clamp(27px, 3vw, 39px); font-weight: 500; letter-spacing: .025em; }
.eyebrow { color: var(--leaf); font-size: 10px; font-weight: 700; letter-spacing: .2em; }
.head-note { max-width: 420px; margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.7; text-align: right; }
.chat-head { margin-bottom: 0; }
.presence-strip { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 11px; }
.presence-dot { width: 6px; height: 6px; border-radius: 50%; background: #8fae81; box-shadow: 0 0 0 4px rgba(143,174,129,.12); }
.divider { width: 1px; height: 12px; margin: 0 4px; background: var(--line); }

.message-stream { width: 100%; max-width: 860px; flex: 1; margin: 0 auto; padding: 36px 4px 170px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(113,137,109,.25) transparent; }
.empty-conversation { min-height: 55vh; display: grid; place-items: center; align-content: center; text-align: center; color: var(--ink-soft); }
.empty-conversation h2 { margin: 4px 0 8px; color: var(--ink); font-family: Georgia, "Noto Serif SC", serif; font-weight: 500; font-size: 25px; }
.empty-conversation p { max-width: 430px; margin: 0; font-size: 13px; line-height: 1.8; }
.empty-conversation .empty-kicker { margin-top: 22px; color: #a88d51; font-size: 11px; letter-spacing: .15em; }
.dandelion-orbit { position: relative; width: 80px; height: 80px; }
.dandelion-orbit .core { position: absolute; left: 35px; top: 35px; width: 10px; height: 10px; border-radius: 50%; background: var(--seed); box-shadow: 0 0 30px rgba(226,189,99,.35); }
.dandelion-orbit i { position: absolute; left: 39px; top: 9px; width: 1px; height: 29px; background: rgba(113,137,109,.5); transform-origin: bottom; }
.dandelion-orbit i::before { content: ""; position: absolute; left: -5px; top: -3px; width: 10px; height: 10px; border: 1px solid rgba(113,137,109,.4); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }
.dandelion-orbit i:nth-child(2) { transform: rotate(60deg); }.dandelion-orbit i:nth-child(3) { transform: rotate(120deg); }.dandelion-orbit i:nth-child(4) { transform: rotate(180deg); }.dandelion-orbit i:nth-child(5) { transform: rotate(240deg); }.dandelion-orbit i:nth-child(6) { transform: rotate(300deg); }
.message { max-width: 78%; margin: 0 0 24px; animation: settle .25s ease; }
.message.user { margin-left: auto; }
.message .who { display: block; margin: 0 8px 6px; color: var(--ink-faint); font-size: 10px; }
.message.user .who { text-align: right; }
.message .bubble { padding: 15px 18px; border-radius: 6px 20px 20px 20px; background: rgba(255,255,252,.72); border: 1px solid rgba(73,91,75,.08); line-height: 1.75; white-space: pre-wrap; box-shadow: 0 8px 32px rgba(74,88,70,.035); }
.message.user .bubble { border-radius: 20px 6px 20px 20px; background: rgba(223,232,215,.62); }
.message.pending .bubble { color: var(--ink-faint); }

.composer { position: absolute; left: 50%; bottom: 24px; z-index: 3; width: min(840px, calc(100% - 64px)); transform: translateX(-50%); padding: 13px 15px 10px 18px; border: 1px solid rgba(73,91,75,.13); border-radius: 23px; background: rgba(255,255,252,.88); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.composer textarea { width: 100%; max-height: 160px; resize: none; border: 0; outline: 0; background: transparent; line-height: 1.6; }
.composer textarea::placeholder { color: var(--ink-faint); }
.composer-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.composer-foot > span { color: var(--ink-faint); font-size: 10px; }
.composer button { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--leaf-deep); color: white; transition: .2s ease; }
.composer button:hover { transform: translateY(-1px); background: #435c46; }
.composer button:disabled { opacity: .4; transform: none; }
.composer button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.memory-summary { width: 100%; max-width: 1120px; margin: 0 auto 26px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.memory-filter { display: flex; align-items: baseline; gap: 9px; padding: 17px 19px; border: 1px solid transparent; border-radius: 18px; background: rgba(255,255,252,.48); text-align: left; }
.memory-filter strong { font-family: Georgia, serif; font-size: 25px; font-weight: 500; }
.memory-filter span { color: var(--ink-soft); font-size: 12px; }
.memory-filter.active { border-color: rgba(113,137,109,.18); background: rgba(255,255,252,.82); box-shadow: 0 10px 34px rgba(72,88,69,.05); }
.memory-garden { width: 100%; max-width: 1120px; margin: 0 auto; columns: 3 260px; column-gap: 18px; padding-bottom: 50px; }
.memory-card { display: inline-block; width: 100%; margin: 0 0 18px; padding: 22px; break-inside: avoid; border: 1px solid rgba(73,91,75,.1); border-radius: 6px 22px 22px 22px; background: var(--paper); box-shadow: 0 10px 40px rgba(73,91,75,.04); cursor: pointer; transition: .22s ease; }
.memory-card:hover { transform: translateY(-3px) rotate(-.2deg); box-shadow: 0 18px 44px rgba(73,91,75,.08); }
.memory-kind { display: inline-flex; padding: 4px 8px; border-radius: 999px; color: var(--leaf-deep); background: var(--leaf-pale); font-size: 10px; letter-spacing: .08em; }
.memory-card.preference .memory-kind { color: #927638; background: var(--seed-pale); }
.memory-card.thread .memory-kind { color: #73778b; background: #e7e8ef; }
.memory-card h3 { margin: 14px 0 9px; font-family: Georgia, "Noto Serif SC", serif; font-size: 18px; font-weight: 500; }
.memory-card p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.75; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.memory-card footer { display: flex; justify-content: space-between; margin-top: 18px; color: var(--ink-faint); font-size: 9px; }
.garden-empty { padding: 80px 20px; color: var(--ink-soft); text-align: center; column-span: all; }

.editor-layout, .settings-grid { width: 100%; max-width: 1120px; margin: 0 auto; }
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 22px; align-items: start; }
.paper-card { padding: 27px; border: 1px solid rgba(73,91,75,.1); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.agent-form, .provider-form { display: grid; gap: 20px; }
label { display: grid; gap: 7px; }
label > span { font-size: 12px; font-weight: 650; }
label > small { margin-top: -4px; color: var(--ink-faint); font-size: 10px; }
input, textarea, select { width: 100%; border: 1px solid rgba(73,91,75,.14); border-radius: 12px; background: rgba(250,251,246,.8); padding: 11px 13px; outline: none; transition: .18s ease; }
textarea { resize: vertical; line-height: 1.65; }
input:focus, textarea:focus, select:focus { border-color: rgba(113,137,109,.55); box-shadow: 0 0 0 3px rgba(113,137,109,.08); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-actions { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding-top: 4px; color: var(--ink-faint); font-size: 10px; }
.button { border: 1px solid transparent; border-radius: 12px; padding: 10px 15px; font-size: 12px; font-weight: 650; }
.button.primary { background: var(--leaf-deep); color: white; }
.button.ghost { border-color: var(--line); background: rgba(255,255,255,.55); color: var(--ink-soft); }
.button.danger { color: var(--danger); }
.version-badge { padding: 8px 12px; border-radius: 999px; background: rgba(255,255,252,.65); color: var(--ink-soft); font-size: 11px; }
.philosophy-card { position: sticky; top: 10px; padding: 26px; border-radius: var(--radius); background: linear-gradient(145deg, rgba(224,233,216,.75), rgba(247,240,207,.56)); }
.philosophy-card h3 { margin: 20px 0 9px; font-family: Georgia, "Noto Serif SC", serif; font-weight: 500; }
.philosophy-card p, .philosophy-card blockquote { color: var(--ink-soft); font-size: 12px; line-height: 1.75; }
.philosophy-card blockquote { margin: 28px 0 0; padding-top: 18px; border-top: 1px solid rgba(73,91,75,.12); font-family: Georgia, "Noto Serif SC", serif; color: var(--leaf-deep); }
.mini-seed { color: #b8984e; font-size: 20px; }

.settings-grid { display: grid; grid-template-columns: 1fr 1.35fr; gap: 20px; align-items: start; }
.vault-card { display: grid; gap: 22px; }
.card-heading { display: flex; gap: 13px; align-items: center; }
.card-heading h2 { margin: 0 0 4px; font-family: Georgia, "Noto Serif SC", serif; font-size: 19px; font-weight: 500; }
.card-heading p { margin: 0; color: var(--ink-faint); font-size: 10px; }
.setting-icon { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 50%; background: var(--leaf-pale); color: var(--leaf-deep); }
#vaultLockedControls { display: grid; gap: 12px; }
.unlocked-panel { padding: 15px; border-radius: 15px; background: rgba(223,232,215,.5); }
.unlocked-panel:not([hidden]) { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.unlocked-panel span { font-size: 11px; }.unlocked-panel i { display: inline-block; width: 6px; height: 6px; margin-right: 7px; border-radius: 50%; background: #7ea274; }
.gateway-card, .timezone-card { display: grid; gap: 18px; }
.gateway-actions, .provider-form-actions { display: flex; align-items: center; gap: 10px; }
.gateway-actions > span { flex: 1; color: var(--ink-faint); font-size: 10px; line-height: 1.5; }
.key-reveal { padding: 14px; border-radius: 14px; background: rgba(245,232,185,.45); }
.key-reveal p { margin: 0 0 9px; color: #846d38; font-size: 10px; }
.key-reveal > div { display: flex; align-items: center; gap: 8px; }
.key-reveal code { min-width: 0; flex: 1; overflow-wrap: anywhere; font-size: 11px; }
.provider-manager { grid-column: 1 / -1; display: grid; gap: 20px; }
.provider-heading > div { flex: 1; }
.provider-form { padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: rgba(250,251,246,.58); }
.provider-form-actions > span { flex: 1; }
.active-choice { display: flex; grid: none; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 11px; }
.active-choice input { width: auto; }
.provider-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.provider-item { display: grid; gap: 13px; padding: 17px; border: 1px solid var(--line); border-radius: 17px; background: rgba(255,255,255,.48); }
.provider-item.active { border-color: rgba(113,137,109,.42); background: linear-gradient(145deg, rgba(223,232,215,.72), rgba(255,253,244,.7)); box-shadow: 0 10px 30px rgba(73,91,75,.06); }
.provider-item-head { display: flex; align-items: center; gap: 8px; }
.provider-item-head strong { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 16px Georgia, "Noto Serif SC", serif; }
.active-mark { padding: 3px 8px; border-radius: 999px; color: var(--leaf-deep); background: rgba(255,255,255,.7); font-size: 9px; }
.provider-item-meta { display: grid; gap: 4px; color: var(--ink-faint); font-size: 10px; }
.provider-item-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.provider-item-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.provider-item-actions .button { padding: 7px 10px; font-size: 10px; }
.provider-models { display: grid; gap: 13px; padding-top: 18px; border-top: 1px solid var(--line); }
.provider-models > div:first-child { display: flex; justify-content: space-between; gap: 10px; }
.provider-models > div:first-child span { color: var(--ink-faint); font-size: 10px; }
.model-list { display: flex; flex-wrap: wrap; gap: 7px; max-height: 280px; overflow-y: auto; }
.model-chip { border: 1px solid var(--line); border-radius: 999px; padding: 6px 9px; background: rgba(255,255,255,.62); color: var(--ink-soft); font-size: 10px; }
.provider-empty { padding: 22px; border: 1px dashed var(--line); border-radius: 16px; color: var(--ink-faint); font-size: 11px; text-align: center; }
.security-note { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 18px 22px; border: 1px dashed rgba(113,137,109,.25); border-radius: 17px; color: var(--ink-soft); font-size: 11px; line-height: 1.7; }
.security-note strong { color: var(--ink); }.security-note p { display: inline; margin-left: 8px; }.security-note code { color: var(--leaf-deep); }
.security-note .button { margin-left: auto; white-space: nowrap; }

.memory-dialog { width: min(640px, calc(100% - 30px)); border: 0; padding: 0; border-radius: 26px; background: transparent; box-shadow: 0 28px 90px rgba(41,53,43,.22); }
.memory-dialog::backdrop { background: rgba(46,57,48,.25); backdrop-filter: blur(6px); }
.dialog-shell { position: relative; display: grid; gap: 13px; padding: 30px; background: #fbfcf7; }
.dialog-close { position: absolute; top: 14px; right: 17px; border: 0; background: transparent; color: var(--ink-faint); font-size: 25px; }
.dialog-shell h2 { margin: 5px 0 0; font-family: Georgia, "Noto Serif SC", serif; font-weight: 500; }
.dialog-meta { margin: 0 0 5px; color: var(--ink-faint); font-size: 10px; }
.reason-field { margin-top: 4px; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 28px; transform: translate(-50%, 20px); padding: 10px 16px; border-radius: 999px; background: #39483c; color: white; font-size: 11px; opacity: 0; pointer-events: none; transition: .25s ease; box-shadow: 0 10px 35px rgba(39,51,41,.2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #88564f; }

.ambient-seeds { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; opacity: .34; }
.ambient-seeds i { position: absolute; width: 5px; height: 5px; border-radius: 50% 50% 50% 0; border: 1px solid #a5ae94; transform: rotate(-45deg); animation: drift 16s ease-in-out infinite alternate; }
.ambient-seeds i:nth-child(1) { left: 72%; top: 12%; }.ambient-seeds i:nth-child(2) { left: 89%; top: 31%; animation-delay: -5s; }.ambient-seeds i:nth-child(3) { left: 67%; top: 72%; animation-delay: -9s; }.ambient-seeds i:nth-child(4) { left: 42%; top: 15%; animation-delay: -3s; }.ambient-seeds i:nth-child(5) { left: 95%; top: 84%; animation-delay: -12s; }
@keyframes drift { to { transform: translate(35px, 22px) rotate(40deg); } }

@media (max-width: 850px) {
    body { overflow: auto; }
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; inset: auto 12px 12px; z-index: 10; flex-direction: row; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
    .brand, .conversation-nav, .sidebar-foot { display: none; }
    .primary-nav { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; gap: 3px; }
    .nav-item { display: flex; justify-content: center; padding: 10px 5px; font-size: 11px; }
    .nav-item em { display: none; }.nav-icon { font-size: 16px; }
    .workspace { height: 100vh; }
    .view { padding: 25px 18px 100px; }
    .view-head { align-items: flex-start; flex-direction: column; gap: 10px; margin-bottom: 22px; }
    .head-note { text-align: left; }
    .chat-head { flex-direction: row; align-items: flex-end; }.presence-strip .divider, #cacheText { display: none; }
    .composer { position: fixed; bottom: 80px; width: calc(100% - 30px); }
    .message-stream { padding-bottom: 190px; }.message { max-width: 90%; }
    .memory-summary { grid-template-columns: 1fr 1fr; }
    .editor-layout, .settings-grid { grid-template-columns: 1fr; }
    .philosophy-card { position: static; }.security-note { grid-column: 1; }
    .field-row { grid-template-columns: 1fr; }
    .form-actions { grid-template-columns: 1fr 1fr; }.form-actions > span { grid-column: 1 / -1; }
    .provider-manager { grid-column: 1; }.provider-form-actions { align-items: flex-start; flex-wrap: wrap; }.provider-form-actions > span { display: none; }
    .provider-list { grid-template-columns: 1fr; }
    .security-note { align-items: flex-start; flex-wrap: wrap; }.security-note p { margin: 0; flex-basis: 100%; }.security-note .button { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
