/*
 * Working without internet (round 6, lowconn): the offline banner, the
 * "Edit text" editor of a saved document, the sign-out question, and the
 * documents kept on this device. Loaded by lowconn.partials.offline.
 */

/* ---------- The banner: one calm line at the foot of the page ---------- */

.hp-offline-bar {
    position: fixed;
    z-index: 85;
    inset-inline: 0;
    bottom: calc(var(--hp-tabbar-h, 0px) + 14px + env(safe-area-inset-bottom, 0px));
    margin-inline: auto;
    width: min(680px, calc(100% - 24px));
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "mark text close" "mark actions close";
    align-items: center;
    column-gap: 12px;
    padding: 12px 10px 12px 14px;
    border-radius: 18px;
    background: linear-gradient(165deg, #12503e, var(--hx-stage) 78%);
    color: var(--hx-on-stage);
    border: 1px solid rgba(240, 214, 170, .32);
    box-shadow: 0 24px 50px -24px rgba(4, 23, 15, .65), inset 0 1px 0 rgba(240, 214, 170, .14);
    font: 500 .94rem/1.45 var(--hx-f-body);
}
html[dir="rtl"] .hp-offline-bar { padding: 12px 14px 12px 10px; }
.hp-offline-bar[hidden] { display: none; }
.hp-offline-bar.is-in { animation: hp-offline-in .32s var(--hx-ease) both; }
@keyframes hp-offline-in {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: none; }
}

.hp-offline-bar-mark {
    grid-area: mark;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(217, 178, 119, .16);
    border: 1px solid rgba(217, 178, 119, .45);
    color: var(--hx-cream);
}
.hp-offline-bar-mark svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hp-offline-bar[data-kind="syncing"] .hp-offline-bar-mark svg,
.hp-offline-bar[data-kind="synced"] .hp-offline-bar-mark svg,
.hp-offline-bar[data-kind="info"] .hp-offline-bar-mark svg { display: none; }
.hp-offline-bar[data-kind="syncing"] .hp-offline-bar-mark::before,
.hp-offline-bar[data-kind="synced"] .hp-offline-bar-mark::before,
.hp-offline-bar[data-kind="info"] .hp-offline-bar-mark::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--hx-cream);
}
.hp-offline-bar[data-kind="synced"] .hp-offline-bar-mark::before { background: #7fd1a8; }
.hp-offline-bar[data-kind="syncing"] .hp-offline-bar-mark::before { animation: hp-offline-pulse 1.1s ease-in-out 6; }
@keyframes hp-offline-pulse { 50% { opacity: .35; transform: scale(.7); } }
.hp-offline-bar[data-kind="conflict"],
.hp-offline-bar[data-kind="attention"] { border-color: rgba(217, 178, 119, .75); }

.hp-offline-bar-text {
    grid-area: text;
    margin: 0;
    color: inherit;
}
.hp-offline-bar-actions {
    grid-area: actions;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
}
.hp-offline-bar-actions:empty { display: none; }
.hp-offline-bar-link {
    appearance: none;
    padding: 4px 0 0;
    border: 0;
    background: none;
    color: var(--hx-cream);
    font: 700 .9rem/1.3 var(--hx-f-body);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    cursor: pointer;
}
.hp-offline-bar-link:hover { color: #f0d6aa; }
.hp-offline-bar-close {
    grid-area: close;
    align-self: start;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--hx-on-stage-2);
    cursor: pointer;
}
.hp-offline-bar-close:hover { background: rgba(244, 236, 221, .1); color: var(--hx-on-stage); }
.hp-offline-bar-close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.hp-offline-bar :is(a, button):focus-visible { outline: 2px solid var(--hx-focus-on-stage); outline-offset: 2px; border-radius: 6px; }
html[dir="rtl"] .hp-offline-bar { font-family: "HP Arabic", var(--hx-f-body); }

@media (max-width: 640px) {
    .hp-offline-bar { width: calc(100% - 16px); font-size: .9rem; border-radius: 16px; }
}

/* ---------- AI needs the internet: quieter while offline ---------- */

html.hp-is-offline :is(#humanizeBtn, [data-hp-parts-start], #customRewriteButton, [data-hp-explain-open], [data-hp-rp-open]),
html.hp-is-offline .document-tools [data-option],
html.hp-is-offline .tool-button[data-option] {
    opacity: .5;
    filter: saturate(.35);
    cursor: help;
}

/* ---------- "Edit text" on a saved document ---------- */

.hp-docedit-open .icon { width: 16px; height: 16px; }
.hp-docedit {
    margin-top: 4px;
}
.hp-docedit[hidden] { display: none; }
.hp-docedit-area {
    display: block;
    width: 100%;
    min-height: 240px;
    resize: vertical;
    padding: 18px 20px;
    border: 1.5px solid var(--hx-line-2);
    border-radius: 16px;
    background: var(--hx-surface);
    color: var(--hx-ink);
    font: inherit;
    line-height: 1.75;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 10px 24px -20px rgba(12, 30, 22, .35);
}
.hp-docedit-area:focus { outline: none; border-color: var(--hx-royal); }
.hp-docedit-area:focus-visible { outline: 2px solid var(--hx-focus); outline-offset: 2px; }
.hp-docedit-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin-top: 12px;
}
.hp-docedit-status {
    margin: 0;
    flex: 1 1 220px;
    color: var(--hx-ink-3);
    font-size: .9rem;
}
.hp-docedit-actions { display: flex; gap: 8px; }
.hp-docedit-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--hx-quill-soft);
    color: var(--hx-quill-ink);
    border: 1px solid rgba(184, 137, 74, .35);
    font-size: .86rem;
    font-weight: 600;
}
.hp-docedit-badge::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--hx-quill);
}
.hp-docedit-badge[hidden] { display: none; }

html[data-hp-theme="dark"] .hp-docedit-area {
    background: var(--hx-surface-2);
    border-color: var(--hx-line-2);
    box-shadow: none;
}
html[data-hp-theme="dark"] .hp-docedit-badge {
    background: rgba(217, 178, 119, .12);
    color: var(--hx-cream);
    border-color: rgba(217, 178, 119, .4);
}

/* ---------- Signing out with edits not saved yet ---------- */

.hp-offline-dialog {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(4, 23, 15, .55);
}
.hp-offline-dialog-card {
    width: min(440px, 100%);
    padding: 24px 24px 20px;
    border-radius: 22px;
    background: var(--hx-surface);
    color: var(--hx-ink);
    border: 1px solid var(--hx-line);
    box-shadow: var(--hx-shadow-lg);
}
.hp-offline-dialog-card h2 {
    margin: 0;
    font: 400 1.6rem/1.2 var(--hx-f-display);
}
html[dir="rtl"] .hp-offline-dialog-card h2 { font: 700 1.3rem/1.4 "HP Arabic", var(--hx-f-body); }
.hp-offline-dialog-card p { margin: 10px 0 0; color: var(--hx-ink-2); line-height: 1.6; }
.hp-offline-dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.hp-offline-dialog-actions button {
    min-height: 44px;
    padding: 0 18px;
    border-radius: 999px;
    font: 700 .92rem var(--hx-f-body);
    cursor: pointer;
}
.hp-offline-dialog-stay { border: 0; background: var(--hx-royal); color: #fff; }
.hp-offline-dialog-go { border: 1.5px solid var(--hx-line-2); background: transparent; color: var(--hx-danger); }
.hp-offline-dialog-actions button:focus-visible { outline: 2px solid var(--hx-focus); outline-offset: 2px; }
html[data-hp-theme="dark"] .hp-offline-dialog-stay { background: var(--hx-cream); color: var(--hx-stage); }
html[data-hp-theme="dark"] .hp-offline-dialog-go { color: #f0a59b; }

/* ---------- The documents list: what this device keeps ---------- */

.hp-offline-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: max-content;
    margin: 6px 0 0;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--hx-royal-soft);
    color: var(--hx-royal);
    font-size: .76rem;
    font-weight: 700;
    letter-spacing: .01em;
}
.hp-offline-chip::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}
html[data-hp-theme="dark"] .hp-offline-chip { background: rgba(127, 209, 168, .12); color: #9fdcbd; }
html.hp-is-offline .document-card.hp-offline-missing { opacity: .55; }

@media (prefers-reduced-motion: reduce) {
    .hp-offline-bar.is-in,
    .hp-offline-bar[data-kind="syncing"] .hp-offline-bar-mark::before { animation: none; }
}

/* The offline text moved to its own document after a conflict. */
.hp-docedit-badge.is-moved { background: var(--hx-royal-soft); color: var(--hx-royal); border-color: rgba(15, 69, 54, .25); }
.hp-docedit-badge.is-moved::before { background: var(--hx-royal); }
html[data-hp-theme="dark"] .hp-docedit-badge.is-moved { background: rgba(127, 209, 168, .12); color: #9fdcbd; border-color: rgba(127, 209, 168, .35); }
html[data-hp-theme="dark"] .hp-docedit-badge.is-moved::before { background: #9fdcbd; }

/* Save stays in sight above the banner when the editor opens. */
.hp-docedit-foot { scroll-margin-bottom: calc(var(--hp-tabbar-h, 0px) + 110px); }
