:root {
    --ink: #19211e;
    --muted: #68716c;
    --paper: #fbf9f5;
    --panel: #ffffff;
    --sage: #dfe8df;
    --green: #194f3d;
    --green-dark: #10382c;
    --coral: #c96d52;
    --line: #dedfd9;
    --danger: #8f352d;
    --shadow: 0 22px 60px rgba(34, 48, 41, .12);
    --radius: 24px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; }
button, input, textarea, select { font: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

.companion-body {
    min-height: 100vh;
    color: var(--ink);
    background: var(--paper);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

.companion-body::before {
    position: fixed;
    inset: 0;
    z-index: -1;
    content: "";
    background:
        radial-gradient(circle at 85% 10%, rgba(201,109,82,.13), transparent 30rem),
        radial-gradient(circle at 8% 90%, rgba(25,79,61,.10), transparent 34rem);
}

.companion-topbar {
    width: min(1180px, calc(100% - 40px));
    min-height: 76px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.companion-brand { display: inline-flex; align-items: center; gap: 11px; font-weight: 750; text-decoration: none; letter-spacing: -.02em; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; color: #fff; background: var(--green); border-radius: 12px; font-family: Georgia, serif; }
.locale-switch, .text-link { font-size: .88rem; font-weight: 700; text-decoration: none; }
.locale-switch { padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.7); }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.topbar-logout-form { margin: 0; }
.logout-link { padding: 0; border: 0; color: inherit; background: transparent; cursor: pointer; }

.access-shell {
    width: min(1180px, calc(100% - 40px));
    min-height: calc(100vh - 96px);
    margin: 0 auto;
    padding: 5vh 0 8vh;
    display: grid;
    grid-template-columns: .82fr 1.18fr;
    align-items: center;
    gap: clamp(40px, 7vw, 100px);
}

.companion-eyebrow { margin: 0 0 12px; color: var(--coral); font-size: .78rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.access-intro h1, .companion-heading h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 500; letter-spacing: -.045em; line-height: .98; }
.access-intro h1 { max-width: 650px; font-size: clamp(3.2rem, 6vw, 6.6rem); }
.access-lead { max-width: 600px; margin: 28px 0; color: #46504b; font-size: clamp(1.06rem, 1.7vw, 1.3rem); }
.trust-note { max-width: 520px; padding: 18px 20px; display: grid; gap: 4px; background: var(--sage); border-radius: 18px; }
.trust-note span { color: #46504b; font-size: .93rem; }
.service-boundary { max-width: 680px; margin: 20px 0 0; color: var(--muted); font-size: .82rem; }

.access-card { padding: clamp(24px, 4vw, 46px); background: rgba(255,255,255,.9); border: 1px solid rgba(222,223,217,.9); border-radius: 30px; box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.access-columns { display: grid; grid-template-columns: 1fr 1px 1fr; gap: 30px; }
.access-divider { background: var(--line); }
.access-form { display: flex; flex-direction: column; gap: 14px; }
.access-form h2 { margin: 0 0 6px; font-family: Georgia, serif; font-size: 1.7rem; font-weight: 500; }
.access-form label:not(.check-row), .handoff-form label:not(.check-row) { display: grid; gap: 6px; font-size: .86rem; font-weight: 700; }
.access-form input, .handoff-form input, .handoff-form select, .handoff-form textarea, .chat-composer textarea {
    width: 100%;
    border: 1px solid #cfd3ce;
    border-radius: 13px;
    color: var(--ink);
    background: #fff;
    outline: none;
}
.access-form input { min-height: 48px; padding: 10px 12px; }
.access-form input:focus, .handoff-form input:focus, .handoff-form select:focus, .handoff-form textarea:focus, .chat-composer textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(25,79,61,.13); }
.access-form small { color: var(--muted); }
.password-access-form, .magic-access-form { max-width: 520px; margin: 0 auto; }
.magic-access-form { margin-top: 26px; padding-top: 26px; border-top: 1px solid var(--line); }
.magic-policy-copy, .guest-policy-copy { margin: 2px 0 0; color: var(--muted); font-size: .76rem; line-height: 1.55; }
.magic-policy-copy a, .guest-policy-copy a { color: var(--green); font-weight: 700; }
.check-row { display: flex; align-items: flex-start; gap: 9px; font-size: .8rem; color: #4b5550; }
.check-row input { width: 17px; min-height: 17px; flex: 0 0 auto; margin-top: 2px; accent-color: var(--green); }
.button { min-height: 46px; padding: 11px 19px; border: 0; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-weight: 750; text-decoration: none; transition: transform .18s ease, background .18s ease, opacity .18s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:focus-visible, .tool-card:focus-visible, .dialog-close:focus-visible, .locale-switch:focus-visible { outline: 3px solid rgba(201,109,82,.35); outline-offset: 2px; }
.button:disabled, .tool-card:disabled { cursor: not-allowed; opacity: .45; }
.button-primary { color: #fff; background: var(--green); }
.button-primary:hover:not(:disabled) { background: var(--green-dark); }
.button-secondary { color: var(--green-dark); background: var(--sage); }
.button-quiet { color: var(--green); background: transparent; border: 1px solid var(--line); }
.button-full { width: 100%; }
.compact-form { margin-top: 12px; }
.signed-in-copy { margin: 0 0 22px; }
.notice { margin: 0 0 20px; padding: 13px 15px; border-radius: 13px; font-size: .9rem; }
.notice-error { color: var(--danger); background: #f9e9e6; }
.notice-success { color: var(--green-dark); background: var(--sage); }
.form-unavailable { display: block; color: var(--danger) !important; }
.access-legal { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; gap: 20px; color: var(--muted); font-size: .8rem; }

.companion-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 70px; }
.companion-heading { display: flex; justify-content: space-between; align-items: end; gap: 30px; }
.companion-heading h1 { font-size: clamp(2.7rem, 5vw, 5.2rem); }
.companion-heading p:not(.companion-eyebrow) { max-width: 650px; margin: 16px 0 0; color: var(--muted); font-size: 1.05rem; }
.access-pill { min-width: 132px; padding: 13px 17px; display: grid; background: var(--sage); border-radius: 16px; }
.access-pill span, .access-pill small { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; }
.access-pill strong { overflow-wrap: anywhere; }
.compact-boundary { margin-top: 16px; }
.chat-layout { margin-top: 30px; display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 20px; align-items: start; }
.chat-panel { min-height: 620px; display: grid; grid-template-rows: 1fr auto auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.chat-messages { height: 510px; padding: clamp(20px, 4vw, 38px); overflow-y: auto; overscroll-behavior: contain; }
.chat-empty { min-height: 100%; display: grid; place-content: center; justify-items: center; gap: 15px; color: var(--muted); text-align: center; }
.chat-empty p { max-width: 330px; }
.margo-orb { width: 62px; height: 62px; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, var(--coral), #a8483a); border-radius: 50%; font: 500 2rem Georgia, serif; box-shadow: 0 12px 28px rgba(169,72,58,.2); }
.chat-message { width: min(76%, 660px); margin: 0 0 18px; padding: 15px 18px; border-radius: 18px; }
.chat-message p { margin: 5px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-label { font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; opacity: .68; }
.message-user { margin-left: auto; color: #fff; background: var(--green); border-bottom-right-radius: 5px; }
.message-assistant { background: #eef2ed; border-bottom-left-radius: 5px; }
.typing-indicator { width: max-content; margin: 0 0 8px 30px; padding: 9px 13px; background: #eef2ed; border-radius: 15px; }
.typing-indicator > span:not(.sr-only) { width: 6px; height: 6px; margin: 0 2px; display: inline-block; background: var(--muted); border-radius: 50%; animation: companion-pulse 1s infinite alternate; }
.typing-indicator > span:nth-child(2) { animation-delay: .18s; }
.typing-indicator > span:nth-child(3) { animation-delay: .36s; }
@keyframes companion-pulse { to { transform: translateY(-4px); opacity: .45; } }
.chat-composer { padding: 14px; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; border-top: 1px solid var(--line); background: #fafbf9; }
.chat-composer textarea { min-height: 52px; max-height: 170px; padding: 14px 15px; resize: vertical; }
.guest-storage-consent { grid-column: 1 / -1; display: grid; gap: 4px; color: var(--muted); font-size: .72rem; line-height: 1.45; }
.guest-storage-consent label { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.guest-storage-consent input { flex: 0 0 auto; width: 16px; height: 16px; margin-top: 2px; accent-color: var(--green); }
.guest-storage-consent a { width: max-content; color: var(--green); font-weight: 750; }
.companion-tools { display: grid; gap: 12px; }
.guest-save-card { padding: 22px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 16px 40px rgba(34,48,41,.1); }
.guest-save-card h2 { margin: 0 0 10px; font: 500 1.75rem/1.05 Georgia, serif; letter-spacing: -.025em; }
.guest-save-card > p:not(.companion-eyebrow) { margin: 0 0 18px; color: var(--muted); font-size: .9rem; }
.guest-save-form { display: grid; gap: 11px; }
.guest-save-form label { display: grid; gap: 6px; font-size: .82rem; font-weight: 750; }
.guest-save-form input { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid #cfd3ce; border-radius: 13px; color: var(--ink); background: #fff; outline: none; }
.guest-save-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(25,79,61,.13); }
.tool-card { width: 100%; min-height: 90px; padding: 17px; border: 1px solid var(--line); border-radius: 18px; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; color: var(--ink); background: rgba(255,255,255,.82); cursor: pointer; text-align: left; }
.tool-card > span { width: 34px; height: 34px; display: grid; place-items: center; background: var(--sage); border-radius: 50%; font-size: 1.1rem; }
.emergency-note { padding: 16px; color: #6f5048; background: #f7ece8; border-radius: 16px; font-size: .76rem; }
.unavailable-panel, .locked-panel { margin-top: 34px; padding: clamp(30px, 6vw, 70px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-align: center; }
.unavailable-panel .margo-orb { margin: 0 auto 20px; }
.unavailable-panel h2, .locked-panel h2 { margin: 0 0 10px; font-family: Georgia, serif; font-size: 2rem; font-weight: 500; }
.unavailable-panel p, .locked-panel p { max-width: 580px; margin: 0 auto 22px; color: var(--muted); }

.companion-dialog { width: min(580px, calc(100% - 28px)); max-height: min(760px, calc(100vh - 40px)); padding: 28px; color: var(--ink); background: var(--panel); border: 0; border-radius: 24px; box-shadow: 0 32px 90px rgba(10,30,22,.28); overflow-y: auto; }
.companion-dialog::backdrop { background: rgba(17,26,22,.52); backdrop-filter: blur(3px); }
.companion-dialog h2 { margin: 0 42px 8px 0; font: 500 2rem Georgia, serif; }
.companion-dialog > p { color: var(--muted); }
.dialog-close-form { position: absolute; top: 17px; right: 17px; }
.dialog-close { width: 36px; height: 36px; border: 0; border-radius: 50%; color: var(--ink); background: #eef0ec; cursor: pointer; font-size: 1.4rem; }
.consent-form { margin-top: 22px; display: grid; gap: 12px; }
.toggle-row { min-height: 54px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 18px; font-size: .9rem; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-row i { width: 46px; height: 26px; position: relative; display: block; background: #c8cdc7; border-radius: 999px; transition: background .2s; }
.toggle-row i::after { width: 20px; height: 20px; position: absolute; top: 3px; left: 3px; content: ""; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.toggle-row input:checked + i { background: var(--green); }
.toggle-row input:checked + i::after { transform: translateX(20px); }
.toggle-row input:focus-visible + i { outline: 3px solid rgba(201,109,82,.35); outline-offset: 2px; }
.memory-section { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
.memory-section h3 { margin: 0 0 12px; }
.memory-row { padding: 11px 0; display: flex; justify-content: space-between; align-items: start; gap: 12px; border-bottom: 1px solid #ecece8; font-size: .88rem; }
.memory-delete { padding: 4px 8px; border: 0; color: var(--danger); background: transparent; cursor: pointer; font-weight: 700; }
.privacy-data-actions { margin-top: 24px; padding-top: 20px; display: grid; gap: 10px; border-top: 1px solid var(--line); }
.danger-button { min-height: 44px; padding: 10px 16px; border: 1px solid #d6a39b; border-radius: 999px; color: var(--danger); background: #fff; cursor: pointer; font-weight: 750; }
.danger-button:disabled { cursor: not-allowed; opacity: .42; }
.danger-solid { color: #fff; background: var(--danger); border-color: var(--danger); }
.danger-dialog > p { color: #704b44; }
.muted-copy { color: var(--muted); font-size: .88rem; }
.handoff-form { margin-top: 22px; display: grid; gap: 18px; }
.handoff-form input, .handoff-form select, .handoff-form textarea { min-height: 48px; padding: 9px 12px; }
.handoff-form textarea { resize: vertical; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: min(390px, calc(100% - 48px)); padding: 13px 17px; color: #fff; background: var(--green-dark); border-radius: 13px; box-shadow: var(--shadow); }
.toast-error { background: var(--danger); }
.sr-only { width: 1px; height: 1px; position: absolute; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
    .access-shell { grid-template-columns: 1fr; padding-top: 2vh; }
    .access-intro h1 { font-size: clamp(3rem, 13vw, 5.6rem); }
    .chat-layout { grid-template-columns: 1fr; }
    .companion-tools { grid-template-columns: 1fr 1fr; }
    .guest-save-card { max-width: 620px; }
    .emergency-note { grid-column: 1 / -1; }
}

@media (max-width: 650px) {
    .companion-topbar, .access-shell, .companion-shell { width: min(100% - 24px, 1180px); }
    .companion-topbar { min-height: 64px; }
    .access-shell { gap: 30px; padding-bottom: 40px; }
    .access-intro h1 { font-size: clamp(2.7rem, 15vw, 4.6rem); }
    .access-card { padding: 22px 17px; border-radius: 22px; }
    .access-columns { grid-template-columns: 1fr; gap: 25px; }
    .access-divider { height: 1px; }
    .companion-shell { padding-top: 24px; }
    .companion-heading { display: grid; }
    .companion-heading h1 { font-size: 2.8rem; }
    .access-pill { width: max-content; min-width: 120px; }
    .chat-panel { min-height: calc(100vh - 300px); border-radius: 19px; }
    .chat-messages { height: min(54vh, 500px); padding: 17px; }
    .chat-message { width: 89%; }
    .chat-composer { grid-template-columns: 1fr; }
    .chat-composer .button { width: 100%; }
    .companion-tools { grid-template-columns: 1fr; }
    .emergency-note { grid-column: auto; }
    .companion-dialog { padding: 24px 19px; border-radius: 20px; }
    .toast { right: 12px; bottom: 12px; max-width: calc(100% - 24px); }
    .guest-mode .companion-topbar { min-height: 56px; }
    .guest-mode .brand-mark { width: 34px; height: 34px; }
    .guest-mode .companion-shell { padding-top: 10px; }
    .guest-mode .companion-heading { gap: 10px; }
    .guest-mode .companion-heading h1 { font-size: 2.2rem; }
    .guest-mode .companion-heading p:not(.companion-eyebrow) { margin-top: 8px; font-size: .9rem; }
    .guest-mode .companion-eyebrow { margin-bottom: 5px; font-size: .68rem; }
    .guest-mode .access-pill { width: 100%; padding: 8px 11px; grid-template-columns: auto auto 1fr; align-items: baseline; gap: 7px; }
    .guest-mode .access-pill small { text-align: right; }
    .guest-mode .compact-boundary { margin-top: 8px; font-size: .72rem; }
    .guest-mode .chat-layout { margin-top: 12px; }
    .guest-mode .chat-panel { min-height: 390px; }
    .guest-mode .chat-messages { height: 250px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
