/* Optional sync/sharing UI. Kept separate from style.css so the module can be
   cherry-picked without touching the editor's base styles. */

.sync-button {
    position: relative;
}

.sync-button .sync-dot {
    position: absolute;
    top: 5px;
    right: 5px;
    display: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--panel);
}

.sync-button.has-remote .sync-dot {
    display: block;
}

.sync-button.has-remote:not(.local-changes):not(.remote-changes):not(.sync-error) .sync-dot {
    background: var(--ok);
    box-shadow: 0 0 0 2px var(--panel);
}

.sync-button.remote-changes .sync-dot {
    background: #f0b72f;
}

.sync-button.sync-error .sync-dot {
    background: var(--danger);
}

.sync-button.read-only {
    color: var(--text-faint);
}

.sync-button.busy svg {
    opacity: 0.45;
    animation: sync-pulse 0.9s ease-in-out infinite;
}

@keyframes sync-pulse {
    50% { opacity: 0.2; }
}

/* Current remote card */

.sync-hero {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
}

.sync-hero.read-only {
    border-color: rgba(240, 183, 47, 0.28);
}

.sync-hero.empty {
    background: linear-gradient(180deg, var(--panel-raised), var(--bg));
}

.sync-hero-head {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 6px;
}

.sync-hero-title {
    overflow: hidden;
    margin-bottom: 4px;
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sync-chip {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--panel-raised);
    color: var(--text-muted);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.sync-chip.writable {
    background: var(--accent-soft);
    color: var(--accent);
}

.sync-chip.read-only {
    background: rgba(240, 183, 47, 0.13);
    color: #f0b72f;
}

.sync-revision {
    margin-left: auto;
    color: var(--text-faint);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
}

.sync-code {
    display: inline-flex;
    max-width: 100%;
    margin: 0 0 7px;
    padding: 3px 7px;
    overflow: hidden;
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text-muted);
    font-family: var(--font-code);
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sync-code:active {
    border-color: var(--accent);
    color: var(--accent);
}

.sync-state {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
}

.sync-state.ok { color: var(--ok); }
.sync-state.local { color: var(--accent); }
.sync-state.warn { color: #f0b72f; }
.sync-state.error { color: var(--danger); }

.sync-facts {
    margin-top: 4px;
    color: var(--text-faint);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
}

.sync-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-top: 11px;
}

.sync-actions.two {
    margin-top: 10px;
}

.sync-action {
    min-height: 36px;
}

.sheet-button.disabled,
.sheet-button:disabled {
    cursor: not-allowed;
    opacity: 0.42;
}

.sync-note {
    margin: 0 0 10px;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.45;
}

.sync-quick-note {
    margin-top: 8px;
    padding: 8px 9px;
    border-left: 2px solid var(--border);
    color: var(--text-faint);
    font-size: 10.5px;
    line-height: 1.4;
}

/* Linked remotes */

.sync-remote-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.sync-remote {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 7px 7px 10px;
    border: 1px solid var(--border-soft);
    border-radius: 9px;
    background: var(--bg);
}

.sync-remote.current {
    border-color: rgba(108, 182, 255, 0.32);
    background: var(--accent-soft);
}

.sync-remote.missing {
    border-color: rgba(244, 112, 103, 0.32);
}

.sync-remote-main {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
}

.sync-remote-name {
    overflow: hidden;
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sync-remote-meta {
    color: var(--text-faint);
    font-size: 9.5px;
    font-variant-numeric: tabular-nums;
}

.sync-remote-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
}

.sync-mini {
    height: 26px;
    padding: 0 7px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel-raised);
    color: var(--text-muted);
    font-size: 9.5px;
    font-weight: 700;
}

.sync-mini:active {
    background: var(--panel-hover);
    color: var(--text);
}

.sync-mini.danger:active {
    color: var(--danger);
}

.sync-current-label {
    padding: 0 3px;
    color: var(--accent);
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
}

.sync-empty-row {
    padding: 12px 4px;
    color: var(--text-faint);
    font-size: 11px;
}

/* Open-by-ID and form fields */

.sync-open-row {
    display: flex;
    gap: 6px;
}

.sync-input {
    min-width: 0;
    height: 36px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-code);
    font-size: 11px;
}

.sync-input:focus {
    border-color: var(--accent);
    outline: none;
}

.sync-open-row .sync-input {
    flex: 1 1 auto;
}

.sync-open-button {
    flex: 0 0 auto;
    min-height: 36px;
}

.sync-refresh {
    margin-top: 9px;
}

.sync-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 4px 0 10px;
}

.sync-field-label {
    color: var(--text-faint);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.sync-name-input {
    width: 100%;
    font-family: var(--font-ui);
    font-size: 12px;
}

/* Share options */

.sync-options {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.sync-option {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 9px 10px;
    border: 1px solid var(--border-soft);
    border-radius: 9px;
    background: var(--bg);
    cursor: pointer;
}

.sync-option:has(input:checked) {
    border-color: rgba(108, 182, 255, 0.42);
    background: var(--accent-soft);
}

.sync-option.disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.sync-option input {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    margin: 1px 0 0;
    accent-color: var(--accent-strong);
}

.sync-option-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.sync-option-title {
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
}

.sync-option-hint {
    color: var(--text-faint);
    font-size: 10px;
    line-height: 1.35;
}

.sync-warning {
    margin-top: 8px;
    padding: 8px 9px;
    border: 1px solid rgba(240, 183, 47, 0.25);
    border-radius: 8px;
    background: rgba(240, 183, 47, 0.08);
    color: #f0b72f;
    font-size: 10px;
    line-height: 1.4;
}

.sync-create {
    width: 100%;
    margin-top: 10px;
}

.sync-footnote {
    margin-top: 9px;
    color: var(--text-faint);
    font-size: 9.5px;
    line-height: 1.4;
}

/* Created-link result */

.sync-result {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
}

.sync-result-name {
    margin: 7px 0 4px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.sync-url {
    margin: 7px 0;
    padding: 8px;
    overflow-wrap: anywhere;
    border: 1px solid var(--border-soft);
    border-radius: 7px;
    background: var(--panel);
    color: var(--text-muted);
    font-family: var(--font-code);
    font-size: 10px;
    line-height: 1.4;
}

.sync-result-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.sync-result-actions .sheet-button {
    flex: 1 1 0;
}

/* Light theme */

body.theme-light .sync-hero,
body.theme-light .sync-remote,
body.theme-light .sync-result,
body.theme-light .sync-option {
    background: #ffffff;
}

body.theme-light .sync-hero.empty {
    background: #f6f8fa;
}

body.theme-light .sync-button .sync-dot {
    box-shadow: 0 0 0 2px var(--panel);
}

@media (max-width: 360px) {
    .sync-actions {
        gap: 5px;
    }

    .sync-action {
        min-height: 34px;
        padding: 0 6px;
        font-size: 10.5px;
    }

    .sync-result-actions {
        flex-direction: column;
    }
}
